|
| 1 | +/* |
| 2 | +This class is a data structure to store the already solved |
| 3 | +nnls algorithm outputs. It is meant to reduce the memory overhead |
| 4 | +used by the nnls matrices/vectors and just store info on |
| 5 | +the full solution and components of the solution. Originally, |
| 6 | +components of the solution were stored as full waveforms, but |
| 7 | +this would crash due to memory overusage. This class stores |
| 8 | +components as a tuple of time index and scale factor applied to template. |
| 9 | +-Evan Angelico, 7/11/2019 |
| 10 | +*/ |
| 11 | + |
| 12 | + |
| 13 | +#ifndef NnlsSolution_H |
| 14 | +#define NnlsSolution_H |
| 15 | + |
| 16 | +#include <SerialisableObject.h> |
| 17 | +#include "Waveform.h" |
| 18 | + |
| 19 | +using namespace std; |
| 20 | + |
| 21 | +class NnlsSolution : public SerialisableObject |
| 22 | +{ |
| 23 | + friend class boost::serialization::access; |
| 24 | + |
| 25 | +public: |
| 26 | + NnlsSolution() : component_times(vector<double>{}), component_scales(vector<double>{}), templateWaveform(Waveform<double>{}),templateTimes(vector<double>{}),fullNnlsWaveform(Waveform<double>{}) {serialise=true;} |
| 27 | + ~NnlsSolution(); |
| 28 | + void AddComponent(double t, double s); |
| 29 | + void SetFullSoln(Waveform<double> fullsoln); //sum of all components, full waveform fit |
| 30 | + void SetTemplate(Waveform<double> tmpwfm, vector<double> temptimes); |
| 31 | + inline int GetNumberOfComponents() {return component_times.size();} //how many components are populated in components vector |
| 32 | + inline double GetComponentTime(int index) {return component_times.at(index);} |
| 33 | + inline double GetComponentScale(int index) {return component_scales.at(index);} |
| 34 | + |
| 35 | + bool Print() { |
| 36 | + int verbose=0; |
| 37 | + bool filled = false; |
| 38 | + if(component_times.size() != 0) filled = true; |
| 39 | + cout << "Solution filled?: " << filled << endl; |
| 40 | + if(filled) cout << "Number of components: " << component_times.size() << endl; |
| 41 | + if(verbose){ |
| 42 | + cout<<"Times and scales:" << endl; |
| 43 | + for(int i = 0; i < component_times.size(); i++){ |
| 44 | + cout << component_times.at(i) << ", " << component_scales.at(i) << endl; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + return true; |
| 49 | + } |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +protected: |
| 54 | + //components of the solution are pairs of doubles |
| 55 | + //first element is the time, second element is the scale |
| 56 | + //at which a template waveform appears relative to the |
| 57 | + //raw waveform in the time units of the raw waveform |
| 58 | + vector<double> component_times; |
| 59 | + vector<double> component_scales; |
| 60 | + Waveform<double> templateWaveform; //template used in the nnls algo, at the time binning used in the algorithm |
| 61 | + vector<double> templateTimes; //time series of length of templateWaveform |
| 62 | + Waveform<double> fullNnlsWaveform; //the full solution, sum of all components |
| 63 | + |
| 64 | + template<class Archive> void serialize(Archive & ar, const unsigned int version){ |
| 65 | + if(serialise){ |
| 66 | + ar & component_times; |
| 67 | + ar & component_scales; |
| 68 | + ar & templateWaveform; |
| 69 | + ar & templateTimes; |
| 70 | + ar & fullNnlsWaveform; |
| 71 | + } |
| 72 | + } |
| 73 | +}; |
| 74 | + |
| 75 | + |
| 76 | +#endif |
0 commit comments