Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,704 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Restructuring Shogun's statistical hypothesis testing framework. | ||
* Copyright (C) 2016 Soumyajit De | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <shogun/hypothesistest/BTestMMD.h> | ||
#include <shogun/hypothesistest/internals/DataManager.h> | ||
#include <shogun/mathematics/Math.h> | ||
#include <shogun/mathematics/Statistics.h> | ||
|
||
using namespace shogun; | ||
using namespace internal; | ||
|
||
CBTestMMD::CBTestMMD() : CMMD<CBTestMMD>() | ||
{ | ||
} | ||
|
||
CBTestMMD::~CBTestMMD() | ||
{ | ||
} | ||
|
||
void CBTestMMD::set_blocksize(index_t blocksize) | ||
{ | ||
get_data_manager().set_blocksize(blocksize); | ||
} | ||
|
||
void CBTestMMD::set_num_blocks_per_burst(index_t num_blocks_per_burst) | ||
{ | ||
get_data_manager().set_num_blocks_per_burst(num_blocks_per_burst); | ||
} | ||
|
||
mmd::WithinBlockDirect CBTestMMD::get_direct_estimation_method() | ||
{ | ||
static mmd::WithinBlockDirect method; | ||
return method; | ||
} | ||
|
||
const float64_t CBTestMMD::normalize_statistic(float64_t statistic) const | ||
{ | ||
const DataManager& dm = get_data_manager(); | ||
const index_t Nx = dm.num_samples_at(0); | ||
const index_t Ny = dm.num_samples_at(1); | ||
const index_t Bx = dm.blocksize_at(0); | ||
const index_t By = dm.blocksize_at(1); | ||
return Nx * Ny * statistic * CMath::sqrt((Bx + By)/float64_t(Nx + Ny)) / (Nx + Ny); | ||
} | ||
|
||
const float64_t CBTestMMD::normalize_variance(float64_t variance) const | ||
{ | ||
const DataManager& dm = get_data_manager(); | ||
const index_t Bx = dm.blocksize_at(0); | ||
const index_t By = dm.blocksize_at(1); | ||
return variance * CMath::sq(Bx * By / float64_t(Bx + By)); | ||
} | ||
|
||
float64_t CBTestMMD::compute_p_value(float64_t statistic) | ||
{ | ||
float64_t result = 0; | ||
switch (get_null_approximation_method()) | ||
{ | ||
case N_METHOD::MMD1_GAUSSIAN: | ||
{ | ||
float64_t sigma_sq = compute_variance(); | ||
float64_t std_dev = CMath::sqrt(sigma_sq); | ||
result = 1.0 - CStatistics::normal_cdf(statistic, std_dev); | ||
break; | ||
} | ||
default: | ||
{ | ||
result = CHypothesisTest::compute_p_value(statistic); | ||
break; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
float64_t CBTestMMD::compute_threshold(float64_t alpha) | ||
{ | ||
float64_t result = 0; | ||
switch (get_null_approximation_method()) | ||
{ | ||
case N_METHOD::MMD1_GAUSSIAN: | ||
{ | ||
float64_t sigma_sq = compute_variance(); | ||
float64_t std_dev = CMath::sqrt(sigma_sq); | ||
result = 1.0 - CStatistics::inverse_normal_cdf(1 - alpha, 0, std_dev); | ||
break; | ||
} | ||
default: | ||
{ | ||
result = CHypothesisTest::compute_threshold(alpha); | ||
break; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
const char* CBTestMMD::get_name() const | ||
{ | ||
return "BTestMMD"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Restructuring Shogun's statistical hypothesis testing framework. | ||
* Copyright (C) 2016 Soumyajit De | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef B_TEST_MMD_H_ | ||
#define B_TEST_MMD_H_ | ||
|
||
#include <shogun/hypothesistest/MMD.h> | ||
#include <shogun/hypothesistest/internals/mmd/WithinBlockDirect.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
class CBTestMMD : public CMMD<CBTestMMD> | ||
{ | ||
friend class CMMD; | ||
public: | ||
CBTestMMD(); | ||
virtual ~CBTestMMD(); | ||
|
||
virtual void ugly_hack_for_class_list() override {} | ||
|
||
void set_blocksize(index_t blocksize); | ||
void set_num_blocks_per_burst(index_t num_blocks_per_burst); | ||
|
||
virtual float64_t compute_p_value(float64_t statistic) override; | ||
virtual float64_t compute_threshold(float64_t alpha) override; | ||
|
||
virtual const char* get_name() const; | ||
private: | ||
static internal::mmd::WithinBlockDirect get_direct_estimation_method(); | ||
const float64_t normalize_statistic(float64_t statistic) const; | ||
const float64_t normalize_variance(float64_t variance) const; | ||
}; | ||
|
||
} | ||
#endif // B_TEST_MMD_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Restructuring Shogun's statistical hypothesis testing framework. | ||
* Copyright (C) 2016 Soumyajit De | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <shogun/kernel/Kernel.h> | ||
#include <shogun/hypothesistest/IndependenceTest.h> | ||
#include <shogun/hypothesistest/internals/KernelManager.h> | ||
#include <shogun/hypothesistest/internals/TestTypes.h> | ||
|
||
using namespace shogun; | ||
using namespace internal; | ||
|
||
CIndependenceTest::CIndependenceTest() : CTwoDistributionTest(IndependenceTest::num_kernels) | ||
{ | ||
} | ||
|
||
CIndependenceTest::~CIndependenceTest() | ||
{ | ||
} | ||
|
||
void CIndependenceTest::set_kernel_p(CKernel* kernel_p) | ||
{ | ||
auto& km = get_kernel_manager(); | ||
km.kernel_at(0) = kernel_p; | ||
} | ||
|
||
CKernel* CIndependenceTest::get_kernel_p() const | ||
{ | ||
const auto& km = get_kernel_manager(); | ||
return km.kernel_at(0); | ||
} | ||
|
||
void CIndependenceTest::set_kernel_q(CKernel* kernel_q) | ||
{ | ||
auto& km = get_kernel_manager(); | ||
km.kernel_at(1) = kernel_q; | ||
} | ||
|
||
CKernel* CIndependenceTest::get_kernel_q() const | ||
{ | ||
const auto& km = get_kernel_manager(); | ||
return km.kernel_at(1); | ||
} | ||
|
||
const char* CIndependenceTest::get_name() const | ||
{ | ||
return "IndependenceTest"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Restructuring Shogun's statistical hypothesis testing framework. | ||
* Copyright (C) 2016 Soumyajit De | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef INDEPENDENCE_TEST_H_ | ||
#define INDEPENDENCE_TEST_H_ | ||
|
||
#include <shogun/hypothesistest/TwoDistributionTest.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
class CKernel; | ||
|
||
class CIndependenceTest : public CTwoDistributionTest | ||
{ | ||
public: | ||
CIndependenceTest(); | ||
virtual ~CIndependenceTest(); | ||
|
||
void set_kernel_p(CKernel* kernel_p); | ||
CKernel* get_kernel_p() const; | ||
|
||
void set_kernel_q(CKernel* kernel_q); | ||
CKernel* get_kernel_q() const; | ||
|
||
virtual float64_t compute_statistic() = 0; | ||
virtual SGVector<float64_t> sample_null() = 0; | ||
|
||
virtual const char* get_name() const; | ||
}; | ||
|
||
} | ||
#endif // INDEPENDENCE_TEST_H_ |
Oops, something went wrong.