Object-oriented-class design (vi)--algorithm class

Source: Internet
Author: User

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}; 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.