Skip to content

Commit

Permalink
Merge pull request #216 from karlnapf/master
Browse files Browse the repository at this point in the history
confidence interval example and some minor fixes
  • Loading branch information
Soeren Sonnenburg committed Jul 20, 2011
2 parents 1e6799c + 3d831f7 commit 43cd548
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/undocumented/libshogun/Makefile
Expand Up @@ -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)
Expand Down
@@ -0,0 +1,43 @@
/*
* 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 <shogun/base/init.h>
#include <shogun/mathematics/Statistics.h>
#include <shogun/mathematics/Math.h>

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<float64_t> data(10, true);
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));

data.free_vector();

SG_SPRINT("\nEND\n");
exit_shogun();

return 0;
}

8 changes: 4 additions & 4 deletions src/shogun/mathematics/Statistics.cpp
Expand Up @@ -13,8 +13,8 @@
* for shogun)
*/

#include "mathematics/Statistics.h"
#include "mathematics/Math.h"
#include <shogun/mathematics/Statistics.h>
#include <shogun/mathematics/Math.h>

using namespace shogun;

Expand Down Expand Up @@ -61,8 +61,8 @@ float64_t CStatistics::confidence_intervals_mean(SGVector<float64_t> 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);
Expand Down
4 changes: 3 additions & 1 deletion src/shogun/mathematics/Statistics.h
Expand Up @@ -16,7 +16,7 @@
#ifndef __STATISTICS_H_
#define __STATISTICS_H_

#include "base/SGObject.h"
#include <shogun/base/SGObject.h>

namespace shogun
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 43cd548

Please sign in to comment.