|
|
|
@ -50,6 +50,8 @@
@@ -50,6 +50,8 @@
|
|
|
|
|
#include "block/Block.hpp" |
|
|
|
|
#include "block/BlockParam.hpp" |
|
|
|
|
|
|
|
|
|
#include "matrix/math.hpp" |
|
|
|
|
|
|
|
|
|
namespace control |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
@ -553,4 +555,51 @@ private:
@@ -553,4 +555,51 @@ private:
|
|
|
|
|
|
|
|
|
|
int __EXPORT blockRandGaussTest(); |
|
|
|
|
|
|
|
|
|
template<class Type, size_t M> |
|
|
|
|
class __EXPORT BlockStats: public Block |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
// methods
|
|
|
|
|
BlockStats(SuperBlock *parent, |
|
|
|
|
const char *name) : |
|
|
|
|
Block(parent, name), |
|
|
|
|
_sum(), |
|
|
|
|
_sumSq(), |
|
|
|
|
_count(0) |
|
|
|
|
{ |
|
|
|
|
}; |
|
|
|
|
virtual ~BlockStats() {}; |
|
|
|
|
void update(const matrix::Vector<Type, M> &u) |
|
|
|
|
{ |
|
|
|
|
_sum += u; |
|
|
|
|
_sumSq += u.emult(u); |
|
|
|
|
_count += 1; |
|
|
|
|
} |
|
|
|
|
void reset() |
|
|
|
|
{ |
|
|
|
|
_sum.setZero(); |
|
|
|
|
_sumSq.setZero(); |
|
|
|
|
_count = 0; |
|
|
|
|
} |
|
|
|
|
// accessors
|
|
|
|
|
size_t getCount() { return _count; } |
|
|
|
|
matrix::Vector<Type, M> getMean() { return _sum / _count; } |
|
|
|
|
matrix::Vector<Type, M> getVar() |
|
|
|
|
{ |
|
|
|
|
return (_sumSq - _sum.emult(_sum) / _count) / _count; |
|
|
|
|
} |
|
|
|
|
matrix::Vector<Type, M> getStdDev() |
|
|
|
|
{ |
|
|
|
|
return getVar().pow(0.5); |
|
|
|
|
} |
|
|
|
|
private: |
|
|
|
|
// attributes
|
|
|
|
|
matrix::Vector<Type, M> _sum; |
|
|
|
|
matrix::Vector<Type, M> _sumSq; |
|
|
|
|
size_t _count; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
int __EXPORT blockStatsTest(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace control
|
|
|
|
|