SHOGUN  3.2.1
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
HypothesisTest.cpp
浏览该文件的文档.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (w) 2012-2013 Heiko Strathmann
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * The views and conclusions contained in the software and documentation are those
27  * of the authors and should not be interpreted as representing official policies,
28  * either expressed or implied, of the Shogun Development Team.
29  */
30 
32 #include <shogun/base/Parameter.h>
33 
34 using namespace shogun;
35 
37 {
38  init();
39 }
40 
42 {
43 }
44 
45 void CHypothesisTest::init()
46 {
47  SG_ADD(&m_num_null_samples, "num_null_samples",
48  "Number of permutation iterations for sampling null",
51  "null_approximation_method",
52  "Method for approximating null distribution",
54 
57 }
58 
60  ENullApproximationMethod null_approximation_method)
61 {
62  m_null_approximation_method=null_approximation_method;
63 }
64 
66 {
67  m_num_null_samples=num_null_samples;
68 }
69 
71 {
72  float64_t result=0;
73 
75  {
76  /* sample a bunch of MMD values from null distribution */
78 
79  /* find out percentile of parameter "statistic" in null distribution */
80  values.qsort();
81  float64_t i=values.find_position_to_insert(statistic);
82 
83  /* return corresponding p-value */
84  result=1.0-i/values.vlen;
85  }
86  else
87  SG_ERROR("Unknown method to approximate null distribution!\n");
88 
89  return result;
90 }
91 
93 {
94  float64_t result=0;
95 
97  {
98  /* sample a bunch of MMD values from null distribution */
100 
101  /* return value of (1-alpha) quantile */
102  result=values[index_t(CMath::floor(values.vlen*(1-alpha)))];
103  }
104  else
105  SG_ERROR("Unknown method to approximate null distribution!\n");
106 
107  return result;
108 }
109 
111 {
112  /* baseline method here is simply to compute statistic and p-value
113  * separately */
114  float64_t statistic=compute_statistic();
115  return compute_p_value(statistic);
116 }
117 
119 {
120  float64_t p_value=perform_test();
121  return p_value<alpha;
122 }
index_t find_position_to_insert(T element)
Definition: SGVector.cpp:237
int32_t index_t
Definition: common.h:60
virtual float64_t compute_p_value(float64_t statistic)
#define SG_ERROR(...)
Definition: SGIO.h:131
static float64_t floor(float64_t d)
Definition: Math.h:271
virtual float64_t compute_threshold(float64_t alpha)
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:102
virtual void set_num_null_samples(index_t num_null_samples)
virtual SGVector< float64_t > sample_null()=0
double float64_t
Definition: common.h:48
int machine_int_t
Definition: common.h:57
ENullApproximationMethod m_null_approximation_method
virtual float64_t perform_test()
virtual void set_null_approximation_method(ENullApproximationMethod null_approximation_method)
#define SG_ADD(...)
Definition: SGObject.h:71
virtual float64_t compute_statistic()=0
index_t vlen
Definition: SGVector.h:706
ENullApproximationMethod

SHOGUN 机器学习工具包 - 项目文档