Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added new sample code

  • Loading branch information...
commit 5f73ad6ea50c753b3d8878ec3e07527e7e33dc0d 1 parent b886236
Victor authored April 18, 2012
1  examples/undocumented/libshogun/Makefile
@@ -75,6 +75,7 @@ TARGETS = basic_minimal \
75 75
 		  serialization_basic_tests \
76 76
 		  library_cover_tree \
77 77
 		  kernel_machine_train_locked \
  78
+		  statistics \
78 79
 
79 80
 all: $(TARGETS)
80 81
 
53  examples/undocumented/libshogun/statistics.cpp
... ...
@@ -0,0 +1,53 @@
  1
+/*
  2
+ * This program is free software; you can redistribute it and/or modify
  3
+ * it under the terms of the GNU General Public License as published by
  4
+ * the Free Software Foundation; either version 3 of the License, or
  5
+ * (at your option) any later version.
  6
+ *
  7
+ * Written (W) 2011 Heiko Strathmann
  8
+ * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
  9
+ * Written (W) 2012 Victor Sadkov
  10
+ * Copyright (C) 2011 Moscow State University
  11
+ */
  12
+
  13
+#include <shogun/base/init.h>
  14
+#include <shogun/mathematics/Statistics.h>
  15
+#include <shogun/mathematics/Math.h>
  16
+
  17
+using namespace shogun;
  18
+
  19
+void print_message(FILE* target, const char* str)
  20
+{
  21
+	fprintf(target, "%s", str);
  22
+}
  23
+
  24
+const int DATA_SIZE=100;
  25
+
  26
+int main(int argc, char **argv)
  27
+{
  28
+	init_shogun(&print_message, &print_message, &print_message);
  29
+
  30
+	SGVector<float64_t> data(DATA_SIZE, true);
  31
+	CMath::random_vector(data.vector, data.vlen, 0.0, 1.0);
  32
+
  33
+	// for (int32_t i=0; i<DATA_SIZE; i++)
  34
+		// SG_SPRINT("data[%02d] = %.5lf%s", i, data[i], (i+1)%4?"\t":"\n");
  35
+
  36
+	float64_t low, up, mean;
  37
+	float64_t error_prob=0.1;
  38
+	mean=CStatistics::confidence_intervals_mean(data, error_prob, low, up);
  39
+
  40
+	SG_SPRINT("sample mean: %f. True mean lies in [%f,%f] with %f%%\n",
  41
+			mean, low, up, 100*(1-error_prob));
  42
+
  43
+	SG_SPRINT("variance: %f\n", CStatistics::variance(data));
  44
+	SG_SPRINT("deviation: %f\n", CStatistics::std_deviation(data));
  45
+
  46
+	data.free_vector();
  47
+
  48
+	SG_SPRINT("\nEND\n");
  49
+	exit_shogun();
  50
+
  51
+	return 0;
  52
+}
  53
+

0 notes on commit 5f73ad6

Please sign in to comment.
Something went wrong with that request. Please try again.