diff --git a/fastlib2/fastlib/math/build.py b/fastlib2/fastlib/math/build.py index 82f07d103c..d5c3acb7fb 100644 --- a/fastlib2/fastlib/math/build.py +++ b/fastlib2/fastlib/math/build.py @@ -1,7 +1,7 @@ librule( - sources = ["discrete.cc", "geometry.cc"], - headers = ["discrete.h", "geometry.h", "kernel.h", "math.h"], + sources = ["discrete.cc", "geometry.cc", "statistics.cc"], + headers = ["discrete.h", "geometry.h", "statistics.h", "kernel.h", "math.h"], deplibs = ["fastlib/base:base", "fastlib/col:col"] ) diff --git a/fastlib2/fastlib/math/statistics.cc b/fastlib2/fastlib/math/statistics.cc new file mode 100644 index 0000000000..d4f4eb7ff9 --- /dev/null +++ b/fastlib2/fastlib/math/statistics.cc @@ -0,0 +1,48 @@ +// Copyright 2007 Georgia Institute of Technology. All rights reserved. +// ABSOLUTELY NOT FOR DISTRIBUTION +/** + * @file statistics.cc + * + * Implementation for statistics helpers. + */ + +#include "statistics.h" +#include "math.h" + +namespace math { + +double Mean(Vector V) { + double c = 0.0; + index_t n = V.length(); + for (index_t i=0; i + +namespace math { + /** + * Computes the mean value of a vector. + * Don't forget initializing V before using this function + * + * @param V the input vector + * @return the mean value + */ + double Mean(Vector V); + + /** + * Computes the variance of a vector using "corrected two-pass algorithm". + * See "Numerical Recipes in C" for reference. + * Don't forget initializing V before using this function. + * + * @param V the input vector + * @return the variance + */ + double Var(Vector V); + + /** + * Computes the standard deviation of a vector. + * Don't forget initializing V before using this function. + * + * @param V the input vector + * @return the standard deviation + */ + double Std(Vector V); + + /** + * Computes the sigmoid function of a real number x + * Sigmoid(x) = 1/[1+exp(-x)] + * + * @param x the input real number + * @return the sigmoid function value + */ + double Sigmoid(double x); +}; + +#endif