1 #ifndef KCENTEREVALUAR_H
2 #define KCENTEREVALUAR_H
4 #include "../base/measuresetter.h"
5 #include "../base/partitionprovider.h"
6 #include "../base/proxyevaluation.h"
7 #include "../base/combinedevaluation.h"
8 #include "../base/dissimilaritymeasure.h"
43 virtual double proxycost(std::vector<T*>
const& points, std::vector<T>
const& proxies)
const;
48 virtual double proxycost(std::vector<T*>
const& points, std::vector<T*>
const& proxies)
const;
53 virtual double proxycost(std::vector<T*>
const& points,
ProxyProvider<T> const &proxySource,
unsigned int solutionIndex)
const;
64 virtual double proxycost(std::vector<T*>
const& points, std::vector<T>
const& proxies,
unsigned int index)
const;
69 virtual double proxycost(std::vector<T*>
const& points, std::vector<T*>
const& proxies,
unsigned int index)
const;
74 virtual double proxycost(std::vector<T*>
const& points,
ProxyProvider<T> const &proxySource,
unsigned int solutionIndex,
unsigned int proxyIndex)
const;
85 virtual double combinedcost(std::vector<std::vector<T*> >
const& clusters, std::vector<T>
const& proxies)
const;
90 virtual double combinedcost(std::vector<std::vector<T*> >
const& clusters, std::vector<T*>
const& proxies)
const;
107 virtual double combinedcost(std::vector<T*>
const& cluster, T
const& proxy)
const;
123 std::vector<double>
proxycostGeneric(std::vector<T*>
const& points, std::vector<T>
const& proxies)
const;
128 std::vector<double>
proxycostGeneric(std::vector<T*>
const& points, std::vector<T*>
const& proxies)
const;
135 measure(measure==0 ? 0 : measure->clone())
141 measure(kce.measure == 0 ? 0 : kce.measure->clone())
168 std::vector<double> values = proxycostGeneric(points, proxies);
169 int numOfValues = values.size();
172 for(
int i = 0; i < numOfValues; i++)
174 if(values[i] > result)
183 std::vector<double> values = proxycostGeneric(points, proxies);
184 int numOfValues = values.size();
187 for(
int i = 0; i < numOfValues; i++)
189 if(values[i] > result)
198 return proxycost(points, provider.
proxies(solutionIndex));
209 std::vector<double> values = proxycostGeneric(points, proxies);
210 return values.at(index);
215 std::vector<double> values = proxycostGeneric(points, proxies);
216 return values.at(index);
221 return proxycost(points, provider.
proxies(solutionIndex), proxyIndex);
226 return proxycost(points, provider.
discrete_proxies(solutionIndex), proxyIndex);
234 this->measure = measure->
clone();
240 int numOfPoints = points.size();
241 int numOfProxies = proxies.size();
243 std::vector<double> result(numOfProxies, 0);
245 for(
int i = 0; i < numOfPoints; i++)
247 T* point = points[i];
249 double min = this->measure->dissimilarity(*point, proxies[0]);
250 int assignedProxy = 0;
251 for(
int j = 1; j < numOfProxies; j++)
253 T proxy = proxies[j];
254 double candidate = this->measure->dissimilarity(*point, proxy);
262 if(min > result[assignedProxy])
263 result[assignedProxy] = min;
271 int numOfPoints = points.size();
272 int numOfProxies = proxies.size();
274 std::vector<double> result(numOfProxies, 0);
276 for(
int i = 0; i < numOfPoints; i++)
278 T* point = points[i];
280 double min = this->measure->dissimilarity(*point, *proxies[0]);
281 int assignedProxy = 0;
282 for(
int j = 1; j < numOfProxies; j++)
284 T* proxy = proxies[j];
285 double candidate = this->measure->dissimilarity(*point, *proxy);
293 if(min > result[assignedProxy])
294 result[assignedProxy] = min;
306 int numOfClusters = clusters.size();
307 int numOfProxies = proxies.size();
308 int minNumOfClustersProxies = numOfClusters < numOfProxies ? numOfClusters : numOfProxies;
310 for(
int i = 0; i < minNumOfClustersProxies; i++)
312 double cost = combinedcost(clusters[i], proxies[i]);
317 if(numOfClusters < numOfProxies)
319 std::clog <<
"CluE::KCenterEvaluator<T>::combinedcost(std::vector<std::vector<T*> >, std::vector<T>) - WARNING: More proxies than clusters: ignoring redundant proxies." << std::endl;
321 else if(numOfClusters > numOfProxies)
323 std::clog <<
"CluE::KCenterEvaluator<T>::combinedcost(std::vector<std::vector<T*> >, std::vector<T>) - WARNING: Less proxies than clusters: assigning remaining points to proxies." << std::endl;
324 for(
int i = numOfProxies; i < numOfClusters; i++)
326 double cost = proxycost(clusters[i], proxies);
339 int numOfClusters = clusters.size();
340 int numOfProxies = proxies.size();
341 int minNumOfClustersProxies = numOfClusters < numOfProxies ? numOfClusters : numOfProxies;
343 for(
int i = 0; i < minNumOfClustersProxies; i++)
350 if(numOfClusters < numOfProxies)
352 std::clog <<
"CluE::KCenterEvaluator<T>::combinedcost(std::vector<std::vector<T*> >, std::vector<T*>) - WARNING: More proxies than clusters: ignoring redundant proxies." << std::endl;
354 else if(numOfClusters > numOfProxies)
356 std::clog <<
"CluE::KCenterEvaluator<T>::combinedcost(std::vector<std::vector<T*> >, std::vector<T*>) - WARNING: Less proxies than clusters: assigning remaining points to proxies." << std::endl;
357 for(
int i = numOfProxies; i < numOfClusters; i++)
359 double cost = proxycost(clusters[i], proxies);
370 return combinedcost(clusterProvider.
clustering(solutionIndex), proxyProvider.
proxies(solutionIndex));
382 int numOfPoints = cluster.size();
383 for(
int i = 0; i < numOfPoints; i++)
385 double cost = this->measure->dissimilarity(*cluster[i], proxy);
395 return combinedcost(clusterProvider.
cluster(solutionIndex, proxyIndex), proxyProvider.
proxy(solutionIndex, proxyIndex));
virtual ~KCenterEvaluator()
Calculates the k-center weight.
virtual T * discrete_proxy(unsigned int solutionIndex, unsigned int proxyIndex) const =0
Returns a pointer to the proxy for the specified clustering and cluster.
KCenterEvaluator< T > & operator=(const KCenterEvaluator< T > &)
Abstract base class to access the results of proxy / center based clustering algorithms.
Abstract base class to access results of proxy / center based clustering algorithms.
KCenterEvaluator(DissimilarityMeasure< T > const *measure=0)
Instantiates KCenterEvaluator, optionally with a DissimilarityMeasure to use when calculation the max...
virtual std::vector< T * > cluster(unsigned int solutionIndex, unsigned int partitionIndex) const =0
Returns a vector of pointers to the elements of a particular cluster from the specified clustering...
Abstract class. Proxy based evaluation algorithms may be optimized by deriving from this class...
virtual double combinedcost(std::vector< std::vector< T * > > const &clusters, std::vector< T > const &proxies) const
Calculates the k-center weight of a given clustering.
virtual double combinedcost(std::vector< std::vector< T * > > const &partitioning, std::vector< T > const &proxies) const =0
Calculates the cost related to the proxies, based on the partitions.
virtual T proxy(unsigned int solutionIndex, unsigned int proxyIndex) const =0
returns the proxy for the specified clustering and cluster
virtual DissimilarityMeasure< T > * clone() const =0
virtual std::vector< std::vector< T * > > clustering(unsigned int solutionIndex) const =0
Returns the specified clustering as a vector of vector of pointers to the elements.
virtual std::vector< T * > discrete_proxies(unsigned int solutionIndex) const =0
Returns a vector of pointers to the proxies for the specified clustering.
virtual void setMeasure(DissimilarityMeasure< T > const *measure)
Sets the DissimilarityMeasure used when calculating the radius.
virtual double proxycost(std::vector< T * > const &points, std::vector< T > const &proxies) const
Assigns all points to a proxy and calculates the k-center weight of the resulting clustering...
Interface to propagate the ability to set a DissimilarityMeasure.
Abstract class for proxy-based evaluation algorithms.
Abstract base class to access results of partition based clustering algorithms.
virtual std::vector< T > proxies(unsigned int solutionIndex) const =0
returns the proxies for the specified clustering
Abstract base class for dissimilarity measurement.
DissimilarityMeasure< T > * measure
std::vector< double > proxycostGeneric(std::vector< T * > const &points, std::vector< T > const &proxies) const
Provides a k-center weight result per cluster (may be added, chosen from, ...).