14 #ifndef spectrumsolverH
15 #define spectrumsolverH
33 void exec(
const std::vector<std::complex<double> >& memin, std::vector<std::complex<double> >& memout,
34 int t0,
double tol, FFT::twindowfunc windowfunc,
double windowlength)
throw (
XKameError&);
35 const std::vector<std::complex<double> >& ifft()
const {
return m_ifft;}
37 const std::vector<std::pair<double, double> >&
peaks()
const {
return m_peaks;}
39 typedef double (*tfuncIC)(
double sigma2,
int p,
int t);
45 static double icAIC(
double loglikelifood,
int k,
int n);
48 static double icAICc(
double loglikelifood,
int k,
int n);
51 static double icHQ(
double loglikelifood,
int k,
int n);
54 static double icMDL(
double loglikelifood,
int k,
int n);
56 static double windowLength(
int tdlen,
int t0,
double windowlength);
59 static void window(
int t,
int t0, FFT::twindowfunc windowfunc,
60 double windowlength, std::vector<double> &window);
62 virtual bool isFT()
const {
return false;}
64 virtual void genSpectrum(
const std::vector<std::complex<double> >& memin,
65 std::vector<std::complex<double> >& memout,
66 int t0,
double tol, FFT::twindowfunc windowfunc,
double windowlength) = 0;
67 std::vector<std::complex<double> > m_ifft;
68 std::vector<std::pair<double, double> > m_peaks;
74 double numberOfNoises(
const std::vector<std::complex<double> >& memin);
76 void genIFFT(
const std::vector<std::complex<double> >& wavein);
79 double lspe(
const std::vector<std::complex<double> >& wavein,
int origin,
80 const std::vector<double>& psd, std::vector<std::complex<double> >& waveout,
81 double tol,
bool powfit, FFT::twindowfunc windowfunc);
83 double stepLSPE(
const std::vector<std::complex<double> >& wavein,
int origin,
84 const std::vector<double>& psd, std::vector<std::complex<double> >& waveout,
85 bool powfit,
double &coeff,
const std::vector<double> &weight);
87 shared_ptr<FFT> m_fftN, m_ifftN;
88 int fftlen()
const {
return m_ifftN->length();}
92 void autoCorrelation(
const std::vector<std::complex<double> >&wave,
93 std::vector<std::complex<double> >&corr);
102 virtual void genSpectrum(
const std::vector<std::complex<double> >& memin,
103 std::vector<std::complex<double> >& memout,
104 int t0,
double tol, FFT::twindowfunc windowfunc,
double windowlength);
106 virtual bool isFT()
const {
return true;}
114 virtual void genSpectrum(
const std::vector<std::complex<double> >& memin,
115 std::vector<std::complex<double> >& memout,
116 int t0,
double tol, FFT::twindowfunc windowfunc,
double windowlength);
118 void setup(
unsigned int t,
unsigned int n);
119 double stepMEM(
const std::vector<std::complex<double> >& memin, std::vector<std::complex<double> >& memout,
120 double alpha,
double sigma,
int t0,
double tol);
121 void solveZ(
double tol);
123 std::vector<std::complex<double> > m_lambda, m_accumDY, m_accumDYFT;
124 shared_ptr<FFT> m_fftT;
125 std::vector<double> m_accumG2;
132 template <
class T,
class X>
136 virtual void genSpectrum(
const std::vector<std::complex<double> >& memin,
137 std::vector<std::complex<double> >& memout,
138 int t0,
double tol, FFT::twindowfunc windowfunc,
double windowlength) {
139 m_preprocessor.exec(memin, memout, t0, tol, windowfunc, windowlength);
140 int t = memin.size();
141 int n = memout.size();
144 t0a += (-t0a / n + 1) * n;
145 std::vector<std::complex<double> > nsin(t);
146 for(
int i = 0; i < t; i++) {
147 int j = (t0a + i) % n;
148 nsin[i] = m_preprocessor.ifft()[j];
150 T::genSpectrum(nsin, memout, t0, tol, windowfunc, windowlength);