From 4c34b9726b6c745062115a011d75ce44f373eba7 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Wed, 20 Jul 2011 14:08:25 +0200 Subject: [PATCH 1/6] added important comment --- src/shogun/mathematics/Statistics.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/shogun/mathematics/Statistics.h b/src/shogun/mathematics/Statistics.h index 6b607207436..fe91f00c79d 100644 --- a/src/shogun/mathematics/Statistics.h +++ b/src/shogun/mathematics/Statistics.h @@ -55,6 +55,8 @@ class CStatistics: public CSGObject * asuming that the actual variance and mean are unknown (These are * estimated by the samples) * + * Only for normally distributed data + * * @param values vector of values that are used for calculations * @param alpha actual mean lies in confidence interval with (1-alpha)*100% * @param conf_int_low lower confidence interval border is written here From 2898c6a4866eb303909eb00648f84c1baddc7e26 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Wed, 20 Jul 2011 14:26:36 +0200 Subject: [PATCH 2/6] use absolute value of inverse student t value (symmetric anyways) --- src/shogun/mathematics/Statistics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shogun/mathematics/Statistics.cpp b/src/shogun/mathematics/Statistics.cpp index b3ac16d358b..c9fbacb3a91 100644 --- a/src/shogun/mathematics/Statistics.cpp +++ b/src/shogun/mathematics/Statistics.cpp @@ -61,8 +61,8 @@ float64_t CStatistics::confidence_intervals_mean(SGVector values, /* degrees of freedom */ int32_t deg=values.vlen-1; - /* compute t-value */ - float64_t t=inverse_student_t_distribution(deg, alpha); + /* compute absolute value of t-value */ + float64_t t=CMath::abs(inverse_student_t_distribution(deg, alpha)); /* values for calculating confidence interval */ float64_t std_dev=std_deviation(values); From a19dcaea1b2b9d109465c8e893bb6f94f5d206e1 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Wed, 20 Jul 2011 14:26:42 +0200 Subject: [PATCH 3/6] initial add --- .../mathematics_confidence_intervals.cpp | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/undocumented/libshogun/mathematics_confidence_intervals.cpp diff --git a/examples/undocumented/libshogun/mathematics_confidence_intervals.cpp b/examples/undocumented/libshogun/mathematics_confidence_intervals.cpp new file mode 100644 index 00000000000..032837db642 --- /dev/null +++ b/examples/undocumented/libshogun/mathematics_confidence_intervals.cpp @@ -0,0 +1,41 @@ +/* + * 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. + * + * Written (W) 2011 Heiko Strathmann + * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society + */ + +#include +#include +#include + +using namespace shogun; + +void print_message(FILE* target, const char* str) +{ + fprintf(target, "%s", str); +} + +int main(int argc, char **argv) +{ + init_shogun(&print_message, &print_message, &print_message); + + SGVector data(10); + CMath::range_fill_vector(data.vector, data.vlen, 1.0); + + float64_t low, up, mean; + float64_t error_prob=0.05; + mean=CStatistics::confidence_intervals_mean(data, error_prob, low, up); + + SG_SPRINT("sample mean: %f. True mean lies in [%f,%f] with %f%%\n", + mean, low, up, 100*(1-error_prob)); + + SG_SPRINT("\nEND\n"); + exit_shogun(); + + return 0; +} + From 7055cec2fba430ac82b60c714bfeff11f532db0c Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Wed, 20 Jul 2011 14:27:28 +0200 Subject: [PATCH 4/6] added confidence interval example --- examples/undocumented/libshogun/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/undocumented/libshogun/Makefile b/examples/undocumented/libshogun/Makefile index d0df2cad4cf..1d77dcb51b5 100644 --- a/examples/undocumented/libshogun/Makefile +++ b/examples/undocumented/libshogun/Makefile @@ -24,6 +24,7 @@ TARGETS = basic_minimal classifier_libsvm classifier_minimal_svm \ modelselection_grid_search_simple features_subset_labels \ features_subset_simple_features \ features_subset_sparse_features \ + mathematics_confidence_intervals all: $(TARGETS) From 5de9e44d70028b679ddebb10f47a8e1ec8f3e541 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Wed, 20 Jul 2011 14:30:53 +0200 Subject: [PATCH 5/6] corrected includes --- src/shogun/mathematics/Statistics.cpp | 4 ++-- src/shogun/mathematics/Statistics.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shogun/mathematics/Statistics.cpp b/src/shogun/mathematics/Statistics.cpp index c9fbacb3a91..db78e2448f7 100644 --- a/src/shogun/mathematics/Statistics.cpp +++ b/src/shogun/mathematics/Statistics.cpp @@ -13,8 +13,8 @@ * for shogun) */ -#include "mathematics/Statistics.h" -#include "mathematics/Math.h" +#include +#include using namespace shogun; diff --git a/src/shogun/mathematics/Statistics.h b/src/shogun/mathematics/Statistics.h index fe91f00c79d..ec1ee1a3501 100644 --- a/src/shogun/mathematics/Statistics.h +++ b/src/shogun/mathematics/Statistics.h @@ -16,7 +16,7 @@ #ifndef __STATISTICS_H_ #define __STATISTICS_H_ -#include "base/SGObject.h" +#include namespace shogun { From 3d831f7622ed9657297e2b0acf5e6646b7ff41c1 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Wed, 20 Jul 2011 14:33:34 +0200 Subject: [PATCH 6/6] fixed mem-leak --- .../libshogun/mathematics_confidence_intervals.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/undocumented/libshogun/mathematics_confidence_intervals.cpp b/examples/undocumented/libshogun/mathematics_confidence_intervals.cpp index 032837db642..e39916e9816 100644 --- a/examples/undocumented/libshogun/mathematics_confidence_intervals.cpp +++ b/examples/undocumented/libshogun/mathematics_confidence_intervals.cpp @@ -23,7 +23,7 @@ int main(int argc, char **argv) { init_shogun(&print_message, &print_message, &print_message); - SGVector data(10); + SGVector data(10, true); CMath::range_fill_vector(data.vector, data.vlen, 1.0); float64_t low, up, mean; @@ -33,6 +33,8 @@ int main(int argc, char **argv) SG_SPRINT("sample mean: %f. True mean lies in [%f,%f] with %f%%\n", mean, low, up, 100*(1-error_prob)); + data.free_vector(); + SG_SPRINT("\nEND\n"); exit_shogun();