SHOGUN  6.1.3
TwoDistributionTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (w) 2012 - 2013 Heiko Strathmann
4  * Written (w) 2014 - 2017 Soumyajit De
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * The views and conclusions contained in the software and documentation are those
28  * of the authors and should not be interpreted as representing official policies,
29  * either expressed or implied, of the Shogun Development Team.
30  */
31 
37 
38 using namespace shogun;
39 using namespace internal;
40 
42 {
43 }
44 
46 {
47 }
48 
50 {
51  REQUIRE(samples_from_p, "Samples from P cannot be NULL!\n");
52  auto& dm=get_data_mgr();
53  dm.samples_at(0)=samples_from_p;
54 }
55 
57 {
58  const auto& dm=get_data_mgr();
59  return dm.samples_at(0);
60 }
61 
63 {
64  REQUIRE(samples_from_q, "Samples from Q cannot be NULL!\n");
65  auto& dm=get_data_mgr();
66  dm.samples_at(1)=samples_from_q;
67 }
68 
70 {
71  const auto& dm=get_data_mgr();
72  return dm.samples_at(1);
73 }
74 
76 {
77  auto& dm=get_data_mgr();
78  dm.num_samples_at(0)=num_samples_from_p;
79 }
80 
82 {
83  const auto& dm=get_data_mgr();
84  return dm.num_samples_at(0);
85 }
86 
88 {
89  auto& dm=get_data_mgr();
90  dm.num_samples_at(1)=num_samples_from_q;
91 }
92 
94 {
95  const auto& dm=get_data_mgr();
96  return dm.num_samples_at(1);
97 }
98 
100 {
101  auto& data_mgr=get_data_mgr();
102  bool is_blockwise=data_mgr.is_blockwise();
103  data_mgr.set_blockwise(false);
104 
105  data_mgr.start();
106  auto samples=data_mgr.next();
107  REQUIRE(!samples.empty(), "Could not fetch samples!\n");
108 
109  CFeatures *samples_p=samples[0][0];
110  CFeatures *samples_q=samples[1][0];
111 
112  distance->cleanup();
113  distance->remove_lhs_and_rhs();
114  REQUIRE(distance->init(samples_p, samples_q), "Could not initialize distance instance!\n");
115  auto dist_mat=distance->get_distance_matrix<float32_t>();
116  distance->remove_lhs_and_rhs();
117  distance->cleanup();
118 
119  samples.clear();
120  data_mgr.end();
121  data_mgr.set_blockwise(is_blockwise);
122 
123  auto precomputed_distance=new CCustomDistance();
124  precomputed_distance->set_full_distance_matrix_from_full(dist_mat.data(), dist_mat.num_rows, dist_mat.num_cols);
125  return precomputed_distance;
126 }
127 
129 {
130  REQUIRE(distance!=nullptr, "Distance instance cannot be NULL!\n");
131  auto& data_mgr=get_data_mgr();
132  bool is_blockwise=data_mgr.is_blockwise();
133  data_mgr.set_blockwise(false);
134 
135  data_mgr.start();
136  auto samples=data_mgr.next();
137  REQUIRE(!samples.empty(), "Could not fetch samples!\n");
138 
139  CFeatures *samples_p=samples[0][0];
140  CFeatures *samples_q=samples[1][0];
141  auto p_and_q=samples_p->create_merged_copy(samples_q);
142 
143  samples.clear();
144  data_mgr.end();
145  data_mgr.set_blockwise(is_blockwise);
146 
147  distance->cleanup();
148  distance->remove_lhs_and_rhs();
149  REQUIRE(distance->init(p_and_q, p_and_q), "Could not initialize distance instance!\n");
150  auto dist_mat=distance->get_distance_matrix<float32_t>();
151  distance->remove_lhs_and_rhs();
152  distance->cleanup();
153 
154  auto precomputed_distance=new CCustomDistance();
155  precomputed_distance->set_triangle_distance_matrix_from_full(dist_mat.data(), dist_mat.num_rows, dist_mat.num_cols);
156  return precomputed_distance;
157 }
158 
160 {
161  return "TwoDistributionTest";
162 }
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
virtual const char * get_name() const
virtual void cleanup()=0
Class Distance, a base class for all the distances used in the Shogun toolbox.
Definition: Distance.h:87
int32_t index_t
Definition: common.h:72
void set_num_samples_p(index_t num_samples_from_p)
#define REQUIRE(x,...)
Definition: SGIO.h:181
virtual void set_p(CFeatures *samples_from_p)
Hypothesis test base class. Provides an interface for statistical hypothesis testing via three method...
virtual void set_q(CFeatures *samples_from_q)
virtual CFeatures * create_merged_copy(CList *others)
Definition: Features.h:252
CCustomDistance * compute_joint_distance(CDistance *distance)
virtual void remove_lhs_and_rhs()
Definition: Distance.cpp:123
const index_t get_num_samples_q() const
internal::DataManager & get_data_mgr()
CCustomDistance * compute_distance(CDistance *distance)
float float32_t
Definition: common.h:59
void set_num_samples_q(index_t num_samples_from_q)
const index_t get_num_samples_p() const
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
Meta test-type for 2-distribution statistical tests.
Definition: TestTypes.h:52
The class Features is the base class of all feature objects.
Definition: Features.h:69
SGMatrix< float64_t > get_distance_matrix()
Definition: Distance.h:156
The Custom Distance allows for custom user provided distance matrices.
virtual bool init(CFeatures *lhs, CFeatures *rhs)
Definition: Distance.cpp:57

SHOGUN Machine Learning Toolbox - Documentation