SoftClusteringModel.h
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief Model for "soft" clustering.
6  *
7  *
8  *
9  * \author T. Glasmachers
10  * \date 2011
11  *
12  *
13  * \par Copyright 1995-2017 Shark Development Team
14  *
15  * <BR><HR>
16  * This file is part of Shark.
17  * <http://shark-ml.org/>
18  *
19  * Shark is free software: you can redistribute it and/or modify
20  * it under the terms of the GNU Lesser General Public License as published
21  * by the Free Software Foundation, either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * Shark is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU Lesser General Public License for more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public License
30  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
33 //===========================================================================
34 
35 #ifndef SHARK_MODELS_CLUSTERING_SOFTCLUSTERINGMODEL_H
36 #define SHARK_MODELS_CLUSTERING_SOFTCLUSTERINGMODEL_H
37 
38 
40 
41 
42 namespace shark {
43 
44 
45 ///
46 /// \brief Model for "soft" clustering.
47 ///
48 /// \par
49 /// The SoftClusteringModel is based on an AbstractClustering
50 /// object. Given an input, the model outputs the cluster
51 /// membership function, which consists of a non-negative
52 /// value per cluster, and all memberships add up to one.
53 ///
54 /// \par
55 /// See also HardClusteringModel for the best matching cluster.
56 ///
57 template <class InputT>
58 class SoftClusteringModel : public ClusteringModel<InputT, RealVector>
59 {
62  typedef typename base_type::InputType InputType;
63  typedef typename base_type::OutputType OutputType;
64  typedef typename base_type::BatchOutputType BatchOutputType;
65  typedef typename base_type::BatchInputType BatchInputType;
66 public:
67  /// Constructor
68  SoftClusteringModel(ClusteringType* clustering)
69  : base_type(clustering){
71  clustering->hasSoftMembershipFunction(),
72  "[SoftClusteringModel] Clustering does not support soft membership function"
73  );
74  }
75 
76  /// \brief From INameable: return the class name.
77  std::string name() const
78  { return "SoftClusteringModel"; }
79 
80  Shape inputShape()const{
81  return this->mep_clustering->inputShape();
82  }
84  return this->mep_clustering->numberOfClusters();
85  }
86 
87  /// \brief Compute best matching cluster.
88  ///
89  /// \par
90  /// The actual computation is redirected to the clustering object.
91  void eval(InputType const & pattern, OutputType& output)const{
92  output = this->mep_clustering->softMembership(pattern);
93  }
94 
95  /// \brief Compute best matching cluster for a batch of inputs.
96  ///
97  /// \par
98  /// The actual computation is redirected to the clustering object.
99  void eval(BatchInputType const & patterns, BatchOutputType& outputs)const{
100  outputs = this->mep_clustering->softMembership(patterns);
101  }
102 };
103 
104 
105 }
106 #endif