29 #include "../system/eptexception.h"
40 EptAssert (n>=0 and v.size()>0,
"Parameters inconsistent");
42 for (
size_t i=0; i<v.size(); ++i)
45 sum += v[i] * pow(1.0*i,1.0*n);
47 EptAssert (norm>0,
"The norm should be positive");
60 for (
auto x : v) sum -= (x>0 ? x*log(x) : 0);
71 assert(v.size()>0 and q != 1);
73 for (
auto x : v) sum += pow(x,q);
74 return log(sum) / (1-q);
84 return std::accumulate(vec.begin(), vec.end(), 0.0);
95 EptAssert (norm!=0,
"Vectors with norm zero cannot be normalized");
96 for (
auto &x : vec) x /= norm;
121 std::vector<double> &Y,
122 std::function<
double(
double y)> f,
125 assert(X.size()>0 and Y.size()>0);
126 double xs1 = f(-0.5);
128 double leftarea = (x1-xs1+0.5)*X[x1];
129 for (
int y=0; y<static_cast<int>(Y.size()); ++y)
131 double xs2 = f(y+0.5);
134 for (
int x=x1+1; x<=x2; ++x) sum += X[x];
135 double rightarea = (x2-xs2+0.5)*X[x2];
136 Y[y] = (sum + leftarea - rightarea) * pow(xs1*xs2,exponent);
137 x1=x2; xs1=xs2; leftarea=rightarea;
155 assert (i>=0 and i<N and j>i and j<=N);
156 return std::distance(X.begin(), std::max_element(X.begin()+i,X.begin()+j));
161 return std::distance(X.begin(), std::max_element(X.begin(),X.end()));
166 auto maxElem = std::max_element(std::next(x.begin()), std::prev(x.end()));
167 int maxIndex = std::distance(x.begin(), maxElem);
169 double y1 = *std::prev(maxElem);
170 double y2 = *maxElem;
171 double y3 = *std::next(maxElem);
172 double x1 = maxIndex - 1, x2 = maxIndex, x3 = maxIndex + 1;
175 return (x3 * x3 * (y2 - y1) + x2 * x2 * (y1 - y3) + x1 * x1 * (y3 - y2)) / 2.0 / (x3 * (y2 - y1) + x2 * (y1 - y3) + x1 * (y3 - y2));
182 end = std::min(end, Y.size());
183 for (
size_t i = start; i < end; ++i)
186 mean += Y[i] * Y[i] * i;
198 EptAssert(xmax > xmin,
"xmax should be larger than xmin");
199 return std::max(xmin, std::min(xmax, x));