statistics.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00038 #include "fastlib/math/statistics.h"
00039 #include <math.h>
00040
00041
00042 namespace math {
00043
00044 double Mean(Vector V) {
00045 double c = 0.0;
00046 index_t n = V.length();
00047 for (index_t i=0; i<n; i++)
00048 c = c + V[i];
00049 return c / n;
00050 }
00051
00052 double Var(Vector V) {
00053 double c = 0.0, mean, va, ep;
00054 index_t n = V.length();
00055
00056 for (index_t i=0; i<n; i++)
00057 c = c + V[i];
00058 mean = c / n;
00059
00060 ep = 0.0; va = 0.0;
00061 for (index_t i=0; i<n; i++) {
00062 c = V[i] - mean;
00063 ep = ep + c;
00064 va = va + c * c;
00065 }
00066 return (va - ep * ep / n) / (n - 1);
00067 }
00068
00069 double Std(Vector V) {
00070 return sqrt( Var(V) );
00071 }
00072
00073 double Sigmoid(double x) {
00074 return 1.0 / ( 1.0 + exp(-x) );
00075 }
00076
00077
00078 };