1 /** @file clusterinternal.h
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 Cluster
& get_cluster(Xapian::doccount i
);
59 /// Return the cluster at index 'i'
60 const Cluster
& get_cluster(Xapian::doccount i
) const;
62 /// Clear all the clusters in the ClusterSet
63 void clear_clusters();
65 /** Recalculate the centroids for all the clusters
68 void recalculate_centroids();
71 /** Internal class for Cluster
73 class Xapian::Cluster::Internal
: public Xapian::Internal::intrusive_base
{
74 /// Copies are not allowed
75 Internal(const Internal
&);
77 /// Assignment is not allowed
78 void operator=(const Internal
&);
80 /// Documents (or Points in the vector space) within the cluster
81 std::vector
<Point
> cluster_docs
;
83 /// Point or Document representing the cluster centroid
87 /// Constructor that initialises cluster with centroid
88 explicit Internal(const Centroid
¢roid_
) : centroid(centroid_
) {}
96 /// Returns size of the cluster
97 Xapian::doccount
size() const;
99 /// Add a document to the cluster
100 void add_point(const Point
&point
);
102 /// Clear the cluster values
105 /// Return the point at the given index in the cluster
106 Point
& get_point(Xapian::doccount i
);
108 /// Return the point at the given index in the cluster
109 const Point
& get_point(Xapian::doccount i
) const;
111 /// Return the documents that are contained within the cluster
112 DocumentSet
get_documents() const;
114 /// Return the current centroid of the cluster
115 const Centroid
& get_centroid() const;
117 /// Set the centroid of the Cluster to 'centroid'
118 void set_centroid(const Centroid
¢roid
);
120 /** Recalculate the centroid of the Cluster after each iteration
121 * of the KMeans algorithm by taking the mean of all document vectors (Points)
122 * that belong to the Cluster
127 /** Internal class for DocumentSet
129 class Xapian::DocumentSet::Internal
: public Xapian::Internal::intrusive_base
{
130 /// Copies are not allowed.
131 Internal(const Internal
&);
133 /// Assignment is not allowed.
134 void operator=(const Internal
&);
136 /// Vector storing the documents for this DocumentSet
137 std::vector
<Xapian::Document
> documents
;
146 /// Returns the size of the DocumentSet
147 Xapian::doccount
size() const;
149 /// Returns the Document at the index 'i' in the DocumentSet
150 Xapian::Document
& get_document(Xapian::doccount i
);
152 /// Returns the Document at the index 'i' in the DocumentSet
153 const Xapian::Document
& get_document(Xapian::doccount i
) const;
155 /// Add a new Document to the DocumentSet
156 void add_document(const Xapian::Document
&document
);