4 /* Copyright (C) 2017 Richhiey Thomas
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 #include <xapian/intrusive_ptr.h>
26 /** Internal class for ClusterSet
28 class Xapian::ClusterSet::Internal
: public Xapian::Internal::intrusive_base
{
29 /// Copies are not allowed
30 Internal(const Internal
&);
32 /// Assignment is not allowed
33 void operator=(const Internal
&);
35 /** A vector storing the clusters that are created by the
38 std::vector
<Cluster
> clusters
;
47 /// Add a cluster to the ClusterSet
48 void add_cluster(const Cluster
& cluster
);
50 /// Add the point to the cluster at position 'index'
51 void add_to_cluster(const Point
& point
, unsigned int index
);
53 /// Return the number of clusters
54 Xapian::doccount
size() const;
56 /// Return the cluster at index 'i'
57 const Cluster
& get_cluster(Xapian::doccount i
) const;
59 /// Clear all the clusters in the ClusterSet
60 void clear_clusters();
62 /** Recalculate the centroids for all the clusters
65 void recalculate_centroids();
68 /** Internal class for Cluster
70 class Xapian::Cluster::Internal
: public Xapian::Internal::intrusive_base
{
71 /// Copies are not allowed
72 Internal(const Internal
&);
74 /// Assignment is not allowed
75 void operator=(const Internal
&);
77 /// Documents (or Points in the vector space) within the cluster
78 std::vector
<Point
> cluster_docs
;
80 /// Point or Document representing the cluster centroid
84 /// Constructor that initialises cluster with centroid
85 explicit Internal(const Centroid
& centroid_
) : centroid(centroid_
) {}
93 /// Returns size of the cluster
94 Xapian::doccount
size() const;
96 /// Add a document to the cluster
97 void add_point(const Point
& point
);
99 /// Clear the cluster values
102 /// Return the point at the given index in the cluster
103 const Point
& get_point(Xapian::doccount i
) const;
105 /// Return the documents that are contained within the cluster
106 DocumentSet
get_documents() const;
108 /// Return the current centroid of the cluster
109 const Centroid
& get_centroid() const;
111 /// Set the centroid of the Cluster to 'centroid'
112 void set_centroid(const Centroid
& centroid
);
114 /** Recalculate the centroid of the Cluster after each iteration
115 * of the KMeans algorithm by taking the mean of all document vectors
116 * (Points) that belong to the Cluster
121 /** Internal class for DocumentSet
123 class Xapian::DocumentSet::Internal
: public Xapian::Internal::intrusive_base
{
124 /// Copies are not allowed.
125 Internal(const Internal
&);
127 /// Assignment is not allowed.
128 void operator=(const Internal
&);
130 /// Vector storing the documents for this DocumentSet
131 std::vector
<Xapian::Document
> documents
;
140 /// Returns the size of the DocumentSet
141 Xapian::doccount
size() const;
143 /// Returns the Document at the index 'i' in the DocumentSet
144 const Xapian::Document
& get_document(Xapian::doccount i
) const;
146 /// Add a new Document to the DocumentSet
147 void add_document(const Xapian::Document
& document
);