Disaggregate
Disaggregate Smart Meter data
|
Array class. At its core it's just a wrapper around a C-style array. With lots of added functionality for signal processing. More...
#include <Array.h>
Public Member Functions | |
Constructors and destructors | |
Array () | |
Array (const size_t _size) | |
Array (const size_t _size, const T *_data) | |
Constructor for building an Array from an existing C-array. | |
Array (const Array< T > &other) | |
Copy constructor. | |
virtual | ~Array () |
Operators | |
Array< T > & | operator= (const Array< T > &source) |
bool | operator== (const Array< T > &other) |
Getters and setters | |
T & | operator[] (const size_t i) |
Mutable subscript operator. Fast. No range checking. | |
const T & | operator[] (const size_t i) const |
Const subscript operator. Fast. No range checking. | |
void | setSize (const size_t _size) |
const size_t | getSize () const |
const size_t | getSmoothing () const |
void | setSmoothing (const size_t _smoothing) |
Used simply to keep tracking of smoothing parameters throughout the workflow. | |
const size_t | getUpstreamSmoothing () const |
void | setUpstreamSmoothing (const size_t _upstreamSmoothing) |
void | setDeviceName (const std::string _deviceName) |
const std::string | getDeviceName () const |
void | setAllEntriesTo (const T initValue) |
Initialise all array entries to a single value. Does not reset 'deviceName' or 'smoothing' or 'upstreamSmoothing'. | |
File IO and graph drawing | |
void | dumpToFile (const std::string &filename) const |
const std::string | getSmoothedGradOfHistFilename () const |
virtual const std::string | getBaseFilename () const |
virtual void | drawGraph (const std::string details, const std::string xlabel="", const std::string ylabel="", const std::string args="") const |
void | loadData (std::fstream &fs) |
Load data from a CSV file with a single column. | |
Smoothing | |
void | rollingAv (Array< Sample_t > *destination, const size_t RAlength=5) const |
Returns a rolling average of same length as the original array. | |
T | rollingAv (const size_t i, size_t RAlength) const |
Cropping | |
void | copyCrop (const Array< T > &source, const size_t cropFront, const size_t cropBack) |
Copy from source to this object, starting at cropFront index and ignoring the last cropBack items from the source. | |
const size_t | getNumLeadingZeros () |
const size_t | getNumTrailingZeros () |
Protected Attributes | |
T * | data |
size_t | size |
Number of members. size_t is 8bytes wide on x86_64. | |
size_t | smoothing |
Does this array represent data which has been smoothed? | |
size_t | upstreamSmoothing |
If this array has been produced by processing a previous array, and that array was smoothed then 'upstreamSmoothing' records the smoothing of the upstream array. Else=0. | |
std::string | deviceName |
Most arrays are associated with a device. If not, just leave blank. | |
Friends | |
std::ostream & | operator<< (std::ostream &o, const Array< T > &a) |
Functions used mostly by the histogram approach | |
static const size_t | HIST_GRADIENT_RA_LENGTH = 17 |
Length of rolling average of histogram gradient. Best if odd. | |
const size_t | max (T *maxValue, const size_t start=0, size_t end=0) const |
Return the index of and the value of the largest element of the Array, ignoring the members between 'start' and 'end'. | |
const size_t | max (T *maxValue, std::list< size_t > &mask) const |
Find the max value outside of the mask. | |
void | descendPeak (const size_t peak, size_t *start, size_t *end, size_t retries=1) |
Find where the peak plateaus or starts climbing again. | |
void | getDelta (Array< T > *grad, const double multiplier=1) const |
const T | getDelta (const size_t i) const |
void | findPeaks (std::list< size_t > *boundaries) |
Attempts to automatically find the peaks. |
Array class. At its core it's just a wrapper around a C-style array. With lots of added functionality for signal processing.
void Array< T >::descendPeak | ( | const size_t | peak, |
size_t * | start, | ||
size_t * | end, | ||
size_t | retries = 1 |
||
) | [inline] |
Find where the peak plateaus or starts climbing again.
peak | the index of the highest value in the peak |
start | return parameter = index of the start of the hill |
end | return parameter = index of the end of the hill |
retries | the "tolerance" |
virtual void Array< T >::drawGraph | ( | const std::string | details, |
const std::string | xlabel = "" , |
||
const std::string | ylabel = "" , |
||
const std::string | args = "" |
||
) | const [inline, virtual] |
details | Type of graph e.g. "gradient". NOT device name, which gets added automatically. |
Definition at line 256 of file Array.h.
Referenced by Signature::Signature(), and Signature::updatePowerStates().
void Array< T >::dumpToFile | ( | const std::string & | filename | ) | const [inline] |
filename | Excluding path and suffix. DATA_OUTPUT_PATH and .dat will be added. |
Definition at line 228 of file Array.h.
Referenced by Array< Sample_t >::drawGraph(), Signature::drawHistWithStateBars(), and Array< Sample_t >::findPeaks().
Attempts to automatically find the peaks.
Starts from end of array and works backwards. At each step, calculates a rolling average of the gradient. If the value of this rolling average is above KNEE_GRAD_THRESHOLD then it enters the 'ASCENDING' state... etc...
boundaries | output parameter |
Definition at line 566 of file Array.h.
Referenced by Signature::updatePowerStates().
virtual const std::string Array< T >::getBaseFilename | ( | ) | const [inline, virtual] |
Reimplemented in Histogram.
Definition at line 247 of file Array.h.
Referenced by Array< Sample_t >::drawGraph().
void Array< T >::getDelta | ( | Array< T > * | grad, |
const double | multiplier = 1 |
||
) | const [inline] |
grad | Return parameter. Comes in as an instantiated but empty Array. Leaves as an Array of deltas. |
multiplier | Useful for negating the gradient, for example (by setting multiplier=-1 ). |
Definition at line 522 of file Array.h.
Referenced by Array< Sample_t >::findPeaks(), and Array< Sample_t >::getDelta().
const std::string Array< T >::getDeviceName | ( | ) | const [inline] |
Definition at line 205 of file Array.h.
Referenced by Histogram::Histogram().
Definition at line 701 of file Array.h.
Referenced by Signature::Signature().
Definition at line 711 of file Array.h.
Referenced by Signature::Signature().
Definition at line 169 of file Array.h.
Referenced by Device::findAlignment(), Device::getStartTimes(), PowerStateGraph::indexOfNextSpike(), Device::LMS(), Statistic< Sample_t >::Statistic(), Statistic< Sample_t >::update(), and PowerStateGraph::update().
const std::string Array< T >::getSmoothedGradOfHistFilename | ( | ) | const [inline] |
Definition at line 242 of file Array.h.
Referenced by Signature::drawHistWithStateBars(), and Array< Sample_t >::findPeaks().
Definition at line 174 of file Array.h.
Referenced by Array< Sample_t >::copyCrop(), Signature::drawHistWithStateBars(), Histogram::Histogram(), and Array< Sample_t >::operator=().
upstreamSmoothing
Definition at line 190 of file Array.h.
Referenced by Array< Sample_t >::copyCrop(), Signature::drawHistWithStateBars(), and Array< Sample_t >::operator=().
void Array< T >::loadData | ( | std::fstream & | fs | ) | [inline] |
Load data from a CSV file with a single column.
fs | An opened and valid file stream containing a CSV datafile. |
Definition at line 286 of file Array.h.
Referenced by Signature::Signature().
const size_t Array< T >::max | ( | T * | maxValue, |
const size_t | start = 0 , |
||
size_t | end = 0 |
||
) | const [inline] |
Return the index of and the value of the largest element of the Array, ignoring the members between 'start' and 'end'.
Definition at line 371 of file Array.h.
Referenced by Array< Sample_t >::max().
const size_t Array< T >::max | ( | T * | maxValue, |
std::list< size_t > & | mask | ||
) | const [inline] |
Find the max value outside of the mask.
maxValue | Return the max value value |
mask | a list of (mask start index, mask end index) pairs describing the mask. The masks must not overlap. The mask includes the start and end index. |
void Array< T >::rollingAv | ( | Array< Sample_t > * | destination, |
const size_t | RAlength = 5 |
||
) | const [inline] |
Returns a rolling average of same length as the original array.
destination | Initially an empty Array<Sample_t>. Returned with Rolling Averages. |
RAlength | number of items to use in the average. Must be odd. |
Definition at line 313 of file Array.h.
Referenced by Array< Sample_t >::findPeaks(), and Array< Sample_t >::rollingAv().
void Array< T >::setAllEntriesTo | ( | const T | initValue | ) | [inline] |
void Array< T >::setDeviceName | ( | const std::string | _deviceName | ) | [inline] |
Definition at line 200 of file Array.h.
Referenced by Array< Sample_t >::getDelta(), and Array< Sample_t >::rollingAv().
Definition at line 151 of file Array.h.
Referenced by Array< Sample_t >::Array(), Array< Sample_t >::copyCrop(), Signature::downSample(), Array< Sample_t >::getDelta(), Array< Sample_t >::loadData(), Array< Sample_t >::operator=(), and Array< Sample_t >::rollingAv().
Used simply to keep tracking of smoothing parameters throughout the workflow.
Definition at line 182 of file Array.h.
Referenced by Array< Sample_t >::getDelta(), and Array< Sample_t >::rollingAv().
Definition at line 195 of file Array.h.
Referenced by Array< Sample_t >::getDelta(), and Array< Sample_t >::rollingAv().
std::ostream& operator<< | ( | std::ostream & | o, |
const Array< T > & | a | ||
) | [friend] |
Definition at line 34 of file Array.h.
Referenced by Array< Sample_t >::Array(), Array< Sample_t >::copyCrop(), Array< Sample_t >::descendPeak(), Array< Sample_t >::findPeaks(), Array< Sample_t >::getDelta(), Array< Sample_t >::getNumLeadingZeros(), Array< Sample_t >::getNumTrailingZeros(), Array< Sample_t >::loadData(), Array< Sample_t >::max(), Array< Sample_t >::operator=(), Array< Sample_t >::operator==(), Array< Sample_t >::operator[](), Array< Sample_t >::rollingAv(), Array< Sample_t >::setAllEntriesTo(), Array< Sample_t >::setSize(), and Array< Sample_t >::~Array().
std::string Array< T >::deviceName [protected] |
Most arrays are associated with a device. If not, just leave blank.
Definition at line 40 of file Array.h.
Referenced by Array< Sample_t >::copyCrop(), Array< Sample_t >::getBaseFilename(), Array< Sample_t >::getDelta(), Array< Sample_t >::getDeviceName(), Array< Sample_t >::getSmoothedGradOfHistFilename(), Array< Sample_t >::operator=(), Array< Sample_t >::rollingAv(), and Array< Sample_t >::setDeviceName().
const size_t Array< T >::HIST_GRADIENT_RA_LENGTH = 17 [static] |
Length of rolling average of histogram gradient. Best if odd.
Definition at line 555 of file Array.h.
Referenced by Signature::drawHistWithStateBars(), Array< Sample_t >::findPeaks(), and Array< Sample_t >::getSmoothedGradOfHistFilename().
Number of members. size_t is 8bytes wide on x86_64.
Definition at line 35 of file Array.h.
Referenced by Array< Sample_t >::Array(), Array< Sample_t >::copyCrop(), Array< Sample_t >::descendPeak(), Array< Sample_t >::findPeaks(), Array< Sample_t >::getDelta(), Array< Sample_t >::getNumLeadingZeros(), Array< Sample_t >::getNumTrailingZeros(), Array< Sample_t >::getSize(), Array< Sample_t >::max(), Array< Sample_t >::operator=(), Array< Sample_t >::operator==(), Array< Sample_t >::rollingAv(), Array< Sample_t >::setAllEntriesTo(), and Array< Sample_t >::setSize().
Does this array represent data which has been smoothed?
Definition at line 36 of file Array.h.
Referenced by Array< Sample_t >::copyCrop(), Array< Sample_t >::getBaseFilename(), Array< Sample_t >::getDelta(), Array< Sample_t >::getSmoothing(), Array< Sample_t >::operator=(), Array< Sample_t >::rollingAv(), and Array< Sample_t >::setSmoothing().
size_t Array< T >::upstreamSmoothing [protected] |
If this array has been produced by processing a previous array, and that array was smoothed then 'upstreamSmoothing' records the smoothing of the upstream array. Else=0.
Definition at line 37 of file Array.h.
Referenced by Array< Sample_t >::copyCrop(), Array< Sample_t >::getBaseFilename(), Array< Sample_t >::getUpstreamSmoothing(), Array< Sample_t >::operator=(), and Array< Sample_t >::setUpstreamSmoothing().