changes from the laptop

- some should be the same as previous commit (sorry!)
- some should be new: LINT checks, ...?
This commit is contained in:
2017-05-24 10:03:39 +02:00
parent f67f95d1ce
commit 04d8ae8c74
42 changed files with 1344 additions and 60 deletions

View File

@@ -9,5 +9,6 @@
#include "distribution/Region.h"
#include "distribution/Triangle.h"
#include "distribution/NormalN.h"
#include "distribution/Rectangular.h"
#endif // DISTRIBUTIONS_H

View File

@@ -3,6 +3,7 @@
#include "../Assertions.h"
#include "../Exception.h"
#include "../data/Timestamp.h"
#include <vector>
#include <algorithm>
@@ -49,7 +50,7 @@ public:
// interpolate
const int idx1 = (idx2 > 0) ? (idx2 - 1) : (idx2);
const float percent = (key - entries[idx1].key) / (float) (entries[idx2].key - entries[idx1].key);
const float percent = getPercent(key, entries[idx1].key, entries[idx2].key); //(key - entries[idx1].key) / (float) (entries[idx2].key - entries[idx1].key);
const Value res = entries[idx1].value + (entries[idx2].value - entries[idx1].value) * percent;
return res;
@@ -57,6 +58,16 @@ public:
protected:
/** special interpolation for the timestamp class */
static inline float getPercent(const Timestamp key, const Timestamp t1, const Timestamp t2) {
return (key - t1).ms() / (float) (t2 - t1).ms();
}
/** interpolation for generic datatypes [int, float, double, ..] */
template <typename T> static inline float getPercent(const T key, const T t1, const T t2) {
return (key - t1) / (float) (t2 - t1);
}
/** get the nearest index for the given key */
int getIdxAfter(const Key key) const {

49
math/MovingStdDevTS.h Normal file
View File

@@ -0,0 +1,49 @@
#ifndef MOVINGSTDDEVTS_H
#define MOVINGSTDDEVTS_H
#include "MovingAverageTS.h"
/**
* moving stadnard-deviation using a given time-region
*/
template <typename T> class MovingStdDevTS {
private:
MovingAverageTS<T> avg;
MovingAverageTS<T> avg2;
public:
/** ctor with the window-size to use */
MovingStdDevTS(const Timestamp window, const T zeroElement) : avg(window, zeroElement), avg2(window, zeroElement) {
;
}
/** add a new entry */
void add(const Timestamp ts, const T& data) {
// E(x)
avg.add(ts, data);
// E(x^2)
avg2.add(ts, data*data);
}
/** get the current std-dev */
T get() const {
const T e = avg.get();
const T e2 = avg2.get();
const T var = e2 - e*e;
return std::sqrt(var);
}
};
#endif // MOVINGSTDDEVTS_H

View File

@@ -0,0 +1,46 @@
#ifndef RECTANGULAR_H
#define RECTANGULAR_H
#include <cmath>
#include <random>
#include "../Random.h"
#include "../../Assertions.h"
#include "Normal.h"
namespace Distribution {
/** normal distribution */
template <typename T> class Rectangular {
private:
const T mu;
const T h;
const T width;
public:
/** ctor */
Rectangular(const T mu, const T width) : mu(mu), h(1.0/width), width(width) {
}
/** get probability for the given value */
T getProbability(const T val) const {
const T diff = std::abs(val - mu);
return (diff < width/2) ? (h) : (0.0);
}
/** get the probability for the given value */
static T getProbability(const T mu, const T width, const T val) {
Rectangular<T> dist(mu, width);
return dist.getProbability(val);
}
};
}
#endif // RECTANGULAR_H