changes from the laptop
- some should be the same as previous commit (sorry!) - some should be new: LINT checks, ...?
This commit is contained in:
46
math/distribution/Rectangular.h
Normal file
46
math/distribution/Rectangular.h
Normal 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
|
||||
Reference in New Issue
Block a user