00001 #ifndef __MATH_HPP__
00002 #define __MATH_HPP__
00003
00004 #include <magic/mobject.h>
00005 #include <magic/mpackarray.h>
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <math.h>
00017
00018
00021 int rnd (int range);
00022
00025 double frnd ();
00026
00030 double gaussrnd (double stdv);
00031
00034 inline double sqr (double x) {return x*x;}
00035
00036
00037
00038 template <class T>
00039 inline T sqr (T x) {
00040 return x*x;
00041 }
00042
00045 inline double sigmoid (double x) {return 1/(1+exp(-x));}
00046
00047
00048
00049
00050
00051
00054 inline void swap (double& x, double& y) {double tmp=x; x=y; y=tmp;}
00055
00056 #define UNDEFINED_FLOAT 1.2345E30
00057
00060 inline bool is_undef (double x) {
00061 return x>=1.2345E29;
00062 }
00063
00067 typedef PackArray<double> Vector;
00068
00070 double sum (const Vector& x);
00072 double min (const Vector& x);
00074 int minIndex (const Vector& x);
00076 double max (const Vector& x);
00078 int maxIndex (const Vector& x);
00080 double avg (const Vector& x);
00082 double stddev (const Vector& x);
00084 double stdmerr (const Vector& x);
00085
00089 Vector histogram (const Vector& x, int n);
00090
00092 void add (Vector& x, double m);
00093
00096 void multiply (Vector& x, double m);
00097
00100 void multiplyToUnity (Vector& x);
00101
00102 #endif