For a base class library based on object-oriented data clustering, the design of the algorithm class (algorithm, specifically the clustering algorithm clustering algorithms) is an essential part.
Clustering algorithms are numerous, but all have the following three common attributes: (1) parameter (parameters or arguments) (2) result (clustering results) (3) Clustering algorithm itself (perform data clustering) (4) Different clustering algorithms require different set of parameters (Arguments), resulting in different clustering results (Results); Arguments
All clustering algorithms require parameters (sometimes even arguments) when performing data clustering, and different algorithms require different types of parameters. For example, the K-means algorithm needs to specify the number of clusters first, and the FCM Clustering algorithm also requires the membership degree of the sample and class.
The Additional class is used to hold parameters of any visible (type arbitrary boost::any);
Class Additional
{public
: const
boost::any& get (const std::string& name) const;
void Insert (const std::string& name, const boost::any& value);
Std::map<std::string, boost::any> additional;
Protected:
Additional () {}
};
In our design, we also take the dataset (DataSet) as well as the distance metric class (distance measure, which almost all clustering algorithms need to measure distance) as parameters.
Class Arguments:p ublic Additional
{public
:
boost::shared_ptr<dataset> ds;
Boost::shared_ptr<distance> dist;
};
Results
Similar to the Arguments class, different clustering algorithms produce different clustering results, such as K-means clustering algorithm produces hard clustering results, and FCM Clustering algorithm produces fuzzy clustering results.
Class Results:p ublic Additional
{public
:
void Reset ();
Empty cluster results
std::vector<size> CM;
Store the category of the sample
//This is not what the clustering algorithm is going to do
};
Clustering Algorithms
Here, we will give the design of the base class algorithm of all clustering algorithm;
class algorithm {public:virtual ~algorithm () {} virtual arguments& getarguments ();
Non-const-type member function Virtual const results& getresults () const;
virtual void reset () const;
virtual void clusterize ();
protected:virtual void Setuparguments ();
virtual void performclustering () const = 0;
virtual void Fetchresults () const = 0;
Boost::shared_ptr<dataset> _ds;
mutable Results _results;
Arguments _arguments; Aggregation relationship};