00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __MATH_HPP__
00017 #define __MATH_HPP__
00018
00019 #include <magic/mobject.h>
00020 #include <magic/mpackarray.h>
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <math.h>
00032
00033
00034 BEGIN_NAMESPACE (MagiC);
00035
00036
00039 int rnd (int range);
00040
00043 double frnd ();
00044
00048 double gaussrnd (double stdv);
00049
00052 inline double sqr (double x) {return x*x;}
00053
00054
00055
00056 template <class T>
00057 inline T sqr (T x) {
00058 return x*x;
00059 }
00060
00063 inline double sigmoid (double x) {return 1/(1+exp(-x));}
00064
00065
00066
00067
00068
00069
00072 inline void swap (double& x, double& y) {double tmp=x; x=y; y=tmp;}
00073
00074 #define UNDEFINED_FLOAT 1.2345E30
00075
00078 inline bool is_undef (double x) {
00079 return x>=1.2345E29;
00080 }
00081
00085 typedef PackArray<double> Vector;
00086
00088 double sum (const Vector& x);
00090 double min (const Vector& x);
00092 int minIndex (const Vector& x);
00094 double max (const Vector& x);
00096 int maxIndex (const Vector& x);
00098 double avg (const Vector& x);
00100 double stddev (const Vector& x);
00102 double stdmerr (const Vector& x);
00103
00107 Vector histogram (const Vector& x, int n);
00108
00110 void add (Vector& x, double m);
00111
00114 void multiply (Vector& x, double m);
00115
00118 void multiplyToUnity (Vector& x);
00119
00124 #ifndef ROUND_DOUBLE_THRESHOLD
00125 #define ROUND_DOUBLE_THRESHOLD 1e-15
00126 #endif
00127
00128 inline bool isRoundZero (double x) {
00129 return fabs(x) < ROUND_DOUBLE_THRESHOLD;
00130 }
00131
00132 END_NAMESPACE;
00133
00134 #endif
00135