1 #ifndef PROXYBASEDAGGLO_H
2 #define PROXYBASEDAGGLO_H
4 #include "../base/algorithm.h"
5 #include "../base/inputsetter.h"
6 #include "../base/measuresetter.h"
7 #include "../base/dissimilaritymeasure.h"
8 #include "../base/proxygenerator.h"
9 #include "../base/solutionprovider.h"
10 #include "../datastructure/doublesolution.h"
56 virtual void setInput(std::vector<T*>
const*);
76 generator(g==NULL?NULL:g->clone()), measure(m==NULL?NULL:m->clone()), mode(cm)
81 Algorithm(rhs), input(rhs.input), generator(rhs.generator==NULL?NULL:rhs.generator->clone()),
82 measure(rhs.measure==NULL?NULL:rhs.measure->clone()), mode(rhs.mode)
89 Algorithm::operator=(rhs);
92 delete this->generator;
96 this->input = rhs.
input;
97 this->mode = rhs.
mode;
103 delete this->generator;
104 delete this->measure;
109 if (this->input==NULL)
111 if (this->generator==NULL)
113 if (this->measure==NULL)
121 unsigned int N = this->input->size();
124 std::clog <<
"CluE::ProxyBasedAgglo<T>::compute() - starting with " << N <<
" singleton clusters..." << std::endl;
125 std::vector<std::vector<T*> > partitionzero;
126 for (
unsigned int i=0; i<N; i++)
128 std::vector<T*> singleton;
129 singleton.push_back((*this->input)[i]);
130 partitionzero.push_back(singleton);
132 solution->
partitions.push_back(partitionzero);
135 std::vector<T> zeroproxies;
136 for (
unsigned int i=0; i<N; i++)
137 zeroproxies.push_back(generator->generate(solution->
partitions[0][i]));
138 solution->
proxysets.push_back(zeroproxies);
143 if (this->mode==Precompute)
145 std::clog <<
"CluE::ProxyBasedAgglo<T>::compute() - precomputing dissimilarities..." << std::endl;
146 dis =
new double[N*N];
148 for (
unsigned int i=0; i<N; i++)
149 for (
unsigned int j=0; j<N; j++)
151 dis[N*i+j] = this->measure->dissimilarity(solution->
proxysets[0][i], solution->
proxysets[0][j]);
155 for (
unsigned int n=1; n<N; n++)
157 std::clog <<
"CluE::ProxyBasedAgglo<T>::compute() - currently computing round " << n << std::endl;
161 double min = std::numeric_limits<double>::infinity();
162 for (
unsigned int i=0; i<N-n+1; i++)
163 for (
unsigned int j=0; j<N-n+1; j++)
169 if (this->mode==Precompute)
172 d = this->measure->dissimilarity(solution->
proxysets[n-1][i], solution->
proxysets[n-1][j]);
195 while (!solution->
partitions[n][second].empty())
209 if (this->mode==Precompute)
212 for (
unsigned int i=0; i<N-n; i++)
214 dis[N*second+i] = dis[N*(N-n)+i];
215 dis[N*i+second] = dis[N*i+(N-n)];
218 for (
unsigned int i=0; i<N-n; i++)
220 dis[N*first+i] = this->measure->dissimilarity(solution->
proxysets[n][first], solution->
proxysets[n][i]);
221 dis[N*i+first] = this->measure->dissimilarity(solution->
proxysets[n][i], solution->
proxysets[n][first]);
227 solution->
seconds=double(end-start)/CLOCKS_PER_SEC;
228 std::clog <<
"CluE::ProxyBasedAgglo<T>::compute() - finished" << std::endl;
239 this->generator = g==NULL?NULL:g->
clone();
244 this->measure = m==NULL?NULL:m->
clone();
Data structure for partitions and proxies.
DissimilarityMeasure< T > * measure
virtual void setMeasure(DissimilarityMeasure< T > *)
ProxyBasedAgglo< T > & operator=(const ProxyBasedAgglo< T > &)
virtual ProxyGenerator< T > * clone() const =0
ComputationMode
On demand computation / pre-computation.
ProxyGenerator< T > * generator
static ProxyBasedAgglo< T > * toProxyBasedAgglo(Algorithm *s)
Does a dynamic cast of the given Algorithm to ProxyBasedAgglo.
Abstract base class for mechanisms that compute a proxy or representative object for a given set of o...
std::vector< T * > const * input
virtual DoubleSolution< T > * compute()
virtual DissimilarityMeasure< T > * clone() const =0
Abstract base class for algorithms.
virtual ~ProxyBasedAgglo()
Interface to propagate the ability to set a DissimilarityMeasure.
slow, needs no extra memory
void setGenerator(ProxyGenerator< T > *)
std::vector< std::vector< T > > proxysets
Abstract base class for dissimilarity measurement.
Indicates that a computation entered an invalid configuration state.
virtual void setInput(std::vector< T * > const *)
Agglomerative proxy-based clustering algorithm.
ProxyBasedAgglo(std::vector< T * > const *=NULL, ProxyGenerator< T > *=NULL, DissimilarityMeasure< T > *=NULL, ComputationMode=OnDemand)
std::vector< std::vector< std::vector< T * > > > partitions