Vespucci  1.0.0
testahca.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2014-2016 Wright State University - All Rights Reserved
3  Daniel P. Foose - Maintainer/Lead Developer
4 
5  This file is part of Vespucci.
6 
7  Vespucci is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Vespucci is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Vespucci. If not, see <http://www.gnu.org/licenses/>.
19 *******************************************************************************/
20 #include <QObject>
21 #include <QtTest>
23 #include "testahca.h"
24 TestAHCA::TestAHCA(QObject *parent)
25  : QObject(parent)
26 {
27  std::vector<std::string> metrics= {"euclidean",
28  "squaredeuclidean",
29  "manhattan",
30  "chebyshev",
31  "cosine",
32  "correlation"};
33  std::vector<std::string> linkages = {"average",
34  "centroid",
35  "ward",
36  "complete",
37  "single"};
38  for (auto linkage: linkages)
39  for (auto metric: metrics)
40  ahca_obj.push_back(Vespucci::Math::Clustering::AHCA(linkage, metric));
41  arma::mat data = arma::randu<arma::mat>(1024, 50);
42  for (auto ahca: ahca_obj){
43  ahca.Link(data);
44  }
45 }
46 
50 void TestAHCA::testCompleteClusters()
51 {
52  for (auto ahca: ahca_obj){
53  arma::mat assignments = ahca.Cluster(15);
54  for (arma::uword i = 0; i < assignments.n_cols; ++i){
55  arma::uvec unique_values = arma::find_unique(assignments.col(i));
56  QCOMPARE((i + 1), unique_values.n_elem);
57  }
58  }
59 }
60 
64 void TestAHCA::testExclusiveClusters()
65 {
66  for (auto ahca: ahca_obj){
67  std::map<size_t, nodevec> clusters = ahca.clusters();
68  arma::uvec indices;
69  for (size_t i = 1; i < 15; ++i){
70  nodevec current_clusters = clusters[i];
71  for (auto current_cluster: current_clusters){
72  if (!indices.n_rows)
73  indices = current_cluster->GetChildIndices();
74  else
75  indices = arma::join_vert(indices, current_cluster->GetChildIndices());
76  }
77  arma::uvec unique_values = arma::find_unique(indices);
78  arma::uword unique_count = unique_values.n_rows;
79  QCOMPARE(unique_count, indices.n_rows);
80  }
81  }
82 }
std::vector< node_t * > nodevec
TestAHCA(QObject *parent)
Definition: testahca.cpp:24
The AHCA class Handles agglomerative hierarchical clustering of data This class holds a tree which re...