Disaggregate
Disaggregate Smart Meter data

Array< T > Class Template Reference

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>

Inheritance diagram for Array< T >:
Collaboration diagram for Array< T >:

List of all members.

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.
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.

Detailed Description

template<class T>
class Array< T >

Array class. At its core it's just a wrapper around a C-style array. With lots of added functionality for signal processing.

Definition at line 29 of file Array.h.


Constructor & Destructor Documentation

template<class T>
Array< T >::Array ( ) [inline]

Definition at line 51 of file Array.h.

template<class T>
Array< T >::Array ( const size_t  _size) [inline, explicit]
Parameters:
_sizeSize of array

Definition at line 55 of file Array.h.

template<class T>
Array< T >::Array ( const size_t  _size,
const T *  _data 
) [inline, explicit]

Constructor for building an Array from an existing C-array.

Parameters:
_sizeSize of array
_dataPointer to C-style array

Definition at line 66 of file Array.h.

template<class T>
Array< T >::Array ( const Array< T > &  other) [inline]

Copy constructor.

Definition at line 81 of file Array.h.

template<class T>
virtual Array< T >::~Array ( ) [inline, virtual]

Definition at line 91 of file Array.h.


Member Function Documentation

template<class T>
void Array< T >::copyCrop ( const Array< T > &  source,
const size_t  cropFront,
const size_t  cropBack 
) [inline]

Copy from source to this object, starting at cropFront index and ignoring the last cropBack items from the source.

Definition at line 682 of file Array.h.

template<class T>
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.

Deprecated:
This doesn't work anywhere near as well as findPeaks(). But leaving this function in the code in case it comes in handy.
Returns:
'start' and 'end' parameters are return parameters
Parameters:
peakthe index of the highest value in the peak
startreturn parameter = index of the start of the hill
endreturn parameter = index of the end of the hill
retriesthe "tolerance"

Definition at line 473 of file Array.h.

template<class T>
virtual void Array< T >::drawGraph ( const std::string  details,
const std::string  xlabel = "",
const std::string  ylabel = "",
const std::string  args = "" 
) const [inline, virtual]
Parameters:
detailsType 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().

Here is the caller graph for this function:

template<class T>
void Array< T >::dumpToFile ( const std::string &  filename) const [inline]
Parameters:
filenameExcluding 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().

Here is the caller graph for this function:

template<class T>
void Array< T >::findPeaks ( std::list< size_t > *  boundaries) [inline]

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...

Parameters:
boundariesoutput parameter

Definition at line 566 of file Array.h.

Referenced by Signature::updatePowerStates().

Here is the caller graph for this function:

template<class T>
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().

Here is the caller graph for this function:

template<class T>
void Array< T >::getDelta ( Array< T > *  grad,
const double  multiplier = 1 
) const [inline]
Parameters:
gradReturn parameter. Comes in as an instantiated but empty Array. Leaves as an Array of deltas.
multiplierUseful 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().

Here is the caller graph for this function:

template<class T>
const T Array< T >::getDelta ( const size_t  i) const [inline]
Returns:
 data[i+1] - data[i] 

Definition at line 545 of file Array.h.

template<class T>
const std::string Array< T >::getDeviceName ( ) const [inline]

Definition at line 205 of file Array.h.

Referenced by Histogram::Histogram().

Here is the caller graph for this function:

template<class T>
const size_t Array< T >::getNumLeadingZeros ( ) [inline]

Definition at line 701 of file Array.h.

Referenced by Signature::Signature().

Here is the caller graph for this function:

template<class T>
const size_t Array< T >::getNumTrailingZeros ( ) [inline]

Definition at line 711 of file Array.h.

Referenced by Signature::Signature().

Here is the caller graph for this function:

template<class T>
const size_t Array< T >::getSize ( ) const [inline]

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().

Here is the caller graph for this function:

template<class T>
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().

Here is the caller graph for this function:

template<class T>
const size_t Array< T >::getSmoothing ( ) const [inline]

Definition at line 174 of file Array.h.

Referenced by Array< Sample_t >::copyCrop(), Signature::drawHistWithStateBars(), Histogram::Histogram(), and Array< Sample_t >::operator=().

Here is the caller graph for this function:

template<class T>
const size_t Array< T >::getUpstreamSmoothing ( ) const [inline]
See also:
upstreamSmoothing

Definition at line 190 of file Array.h.

Referenced by Array< Sample_t >::copyCrop(), Signature::drawHistWithStateBars(), and Array< Sample_t >::operator=().

Here is the caller graph for this function:

template<class T>
void Array< T >::loadData ( std::fstream &  fs) [inline]

Load data from a CSV file with a single column.

Parameters:
fsAn opened and valid file stream containing a CSV datafile.

Definition at line 286 of file Array.h.

Referenced by Signature::Signature().

Here is the caller graph for this function:

template<class T>
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'.

Returns:
maxValue

Definition at line 371 of file Array.h.

Referenced by Array< Sample_t >::max().

Here is the caller graph for this function:

template<class T>
const size_t Array< T >::max ( T *  maxValue,
std::list< size_t > &  mask 
) const [inline]

Find the max value outside of the mask.

Returns:
an index to the max value. If there are two equal values then we only return the first we come to.
Parameters:
maxValueReturn the max value value
maska 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.

Definition at line 405 of file Array.h.

template<class T>
Array<T>& Array< T >::operator= ( const Array< T > &  source) [inline]

Definition at line 104 of file Array.h.

template<class T>
bool Array< T >::operator== ( const Array< T > &  other) [inline]

Definition at line 117 of file Array.h.

template<class T>
T& Array< T >::operator[] ( const size_t  i) [inline]

Mutable subscript operator. Fast. No range checking.

Definition at line 138 of file Array.h.

template<class T>
const T& Array< T >::operator[] ( const size_t  i) const [inline]

Const subscript operator. Fast. No range checking.

Definition at line 146 of file Array.h.

template<class T>
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.

Parameters:
destinationInitially an empty Array<Sample_t>. Returned with Rolling Averages.
RAlengthnumber 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().

Here is the caller graph for this function:

template<class T>
T Array< T >::rollingAv ( const size_t  i,
size_t  RAlength 
) const [inline]
Returns:
an average of the RAlength items nearest to i
Parameters:
iIndex of the smoothed rolling average.
RAlengthLength of rolling average. Must be odd. Can be 1.

Definition at line 332 of file Array.h.

template<class T>
void Array< T >::setAllEntriesTo ( const T  initValue) [inline]

Initialise all array entries to a single value. Does not reset 'deviceName' or 'smoothing' or 'upstreamSmoothing'.

Definition at line 214 of file Array.h.

template<class T>
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().

Here is the caller graph for this function:

template<class T>
void Array< T >::setSize ( const size_t  _size) [inline]

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().

Here is the caller graph for this function:

template<class T>
void Array< T >::setSmoothing ( const size_t  _smoothing) [inline]

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().

Here is the caller graph for this function:

template<class T>
void Array< T >::setUpstreamSmoothing ( const size_t  _upstreamSmoothing) [inline]

Definition at line 195 of file Array.h.

Referenced by Array< Sample_t >::getDelta(), and Array< Sample_t >::rollingAv().

Here is the caller graph for this function:


Friends And Related Function Documentation

template<class T>
std::ostream& operator<< ( std::ostream &  o,
const Array< T > &  a 
) [friend]

Definition at line 723 of file Array.h.


Member Data Documentation

template<class T>
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().

template<class T>
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().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Friends