ProfileShiftFit.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2008 by Paul Demorest
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 #ifndef __Pulsar_ProfileShiftFit_h
10 #define __Pulsar_ProfileShiftFit_h
11 
12 #include "Pulsar/Algorithm.h"
13 #include "FTransform.h"
14 #include "Estimate.h"
15 #include "toa.h"
16 #include "BoxMuller.h"
17 
18 namespace Pulsar
19 {
20  class Profile;
21  class Integration;
22 
24 
43  class ProfileShiftFit : public Algorithm
44  {
45 
46  public:
47 
49  enum Error_Method {
50  Traditional_Chi2, // Chi-squared 2nd derivatives
51  MCMC_Variance, // Shift variance from MCMC
52  Numerical, // Shift variance from numerical integration
53  };
54 
56  ProfileShiftFit ();
57 
60 
62  void reset();
63 
65  void set_nharm(unsigned nh);
66 
68  unsigned get_nharm();
69 
71  void set_error_method(Error_Method e) { err_meth = e; }
72 
74  void set_mcmc_iterations(int nit) { mcmc_it = nit; }
75 
77  int get_mcmc_iterations() const { return mcmc_it; }
78 
80  void set_standard (const Profile* p);
81 
83  void set_Profile (const Profile* p);
84 
86  void compute();
87 
89  Tempo::toa toa (const Integration*);
90 
93 
96 
98  double get_mse();
99 
101  double get_sigma2();
102 
104  double get_snr();
105 
107  double get_reduced_chisq () const;
108 
110 
114  double get_effective_duty_cycle () const;
115 
117  void apply_scale_and_shift(Profile *p);
118 
120  int mcmc_trials;
121  int mcmc_accept;
122 
125 
126  protected:
127 
129  void init();
130 
132  void choose_nharm ();
133 
135  unsigned nharm;
136 
138  unsigned effective_nharm;
139 
142 
144  unsigned nbins_std;
145 
147  float *fstd;
148 
150  double std_pow;
151 
154 
156  unsigned nbins_prof;
157 
159  float *fprof;
160 
162  float *fccf;
163 
165  unsigned nbins_ccf;
166 
167 
169  double ccf(double phi);
170 
172  double dccf(double phi);
173 
175  double d2ccf(double phi);
176 
178  double log_shift_pdf(double phi);
179 
181  double log_shift_pdf_pos(double phi);
182 
185 
187  void error_traditional();
188 
190  void error_numerical();
191 
193  void error_mcmc_pdf_var();
194 
196  int mcmc_it;
197 
199  bool computed;
200 
202  double shift;
203 
205  double eshift;
206 
208  double correction;
209 
211  double scale;
212 
214  double escale;
215 
217  double sigma2;
218 
220  double mse;
221 
223  double chi2;
224 
226  unsigned dof;
227 
229  double snr;
230 
231  private:
232 
234  BoxMuller nrand;
235 
237  double mcmc_state;
238 
240  double mcmc_log_pdf;
241 
243  void mcmc_init();
244 
246  double mcmc_sample();
247 
249  double max_log_pdf;
250 
252  static double f_pdf(double phi, void *_psf);
253  static double f_pdf_x2(double phi, void *_psf);
254 
255  };
256 
257 }
258 
259 
260 #endif
261 
262 
263 
unsigned nbins_ccf
Number of bins in ccf.
Definition: ProfileShiftFit.h:170
double sigma2
Current sigma^2 estimate.
Definition: ProfileShiftFit.h:222
double escale
Current scale error.
Definition: ProfileShiftFit.h:219
void error_numerical()
Calculate "traditional" parameter uncertainties.
Definition: ProfileShiftFit.C:474
ProfileShiftFit()
Default constructor.
Definition: ProfileShiftFit.C:74
void set_error_method(Error_Method e)
Set the error method.
Definition: ProfileShiftFit.h:76
unsigned nharm
Number of harmonics to use.
Definition: ProfileShiftFit.h:140
void set_standard(const Profile *p)
Set the standard or template profile to use.
Definition: ProfileShiftFit.C:123
void apply_scale_and_shift(Profile *p)
Determine, then apply a shift a scale to data profile.
Definition: ProfileShiftFit.C:621
Error_Method err_meth
Error method to use.
Definition: ProfileShiftFit.h:189
double chi2
Current fit Chi^2 (not reduced)
Definition: ProfileShiftFit.h:228
double get_reduced_chisq() const
Get the reduced chi-squared.
Definition: ProfileShiftFit.C:612
void frc1d(size_t nfft, float *into, const float *from)
unsigned nbins_std
Current template nbin.
Definition: ProfileShiftFit.h:149
int mcmc_trials
Current MCMC accept stats.
Definition: ProfileShiftFit.h:125
double get_effective_duty_cycle() const
Get the effective duty cycle of the standard.
Definition: ProfileShiftFit.C:591
void set_Profile(const Profile *p)
Set the data profile to use.
Definition: ProfileShiftFit.C:164
void bcr1d(size_t nfft, float *into, const float *from)
unsigned effective_nharm
Effective number of harmonics = min (nharm, nbins_prof/2-1)
Definition: ProfileShiftFit.h:143
void set_amps(const T *data)
set the amplitudes array equal to the contents of the data array
Definition: ProfileAmps.h:89
const ScalarMath log(const ScalarMath &x)
bool choose_maximum_harmonic
Set true when set_standard should choose the maximum harmonic.
Definition: ProfileShiftFit.h:129
void error_traditional()
Calculate "traditional" parameter uncertainties.
Definition: ProfileShiftFit.C:357
unsigned get_last_harmonic() const
Get the index of the last significant harmonic.
Definition: LastHarmonic.C:75
void set_nharm(unsigned nh)
Set the number of harmonics to use for fit.
Definition: ProfileShiftFit.C:90
Any quantity recorded as a function of pulse phase.
Definition: Profile.h:45
unsigned get_nbin() const
Return the number of bins.
Definition: ProfileAmps.h:50
void scale(double scale)
multiplies each bin of the profile by scale
Definition: Profile.C:311
unsigned get_nharm()
Get the number of harmonics currently in use.
Definition: ProfileShiftFit.C:118
const ScalarMath sqrt(const ScalarMath &x)
double d2ccf(double phi)
Evaluate d^2(ccf)/d(phi)^2 at phase shift phi.
Definition: ProfileShiftFit.C:241
void rotate_phase(double phase)
rotates the profile by phase (in turns)
Definition: Profile_rotate.C:35
unsigned get_onpulse_nbin() const
Get the number of phase bins in the on pulse window.
Definition: ProfileStats.C:289
bool computed
Have valid results been computed.
Definition: ProfileShiftFit.h:204
double snr
Current profile SNR.
Definition: ProfileShiftFit.h:234
void set_Profile(const Profile *psd)
Set the flucuation power spectral density from which the last harmonic will be computed.
Definition: LastHarmonic.C:37
double eshift
Current shift error.
Definition: ProfileShiftFit.h:210
double log_shift_pdf(double phi)
Returns log of a value proportional to the posterior shift PDF.
Definition: ProfileShiftFit.C:343
double ccf(double phi)
Evaluate ccf at phase shift phi.
Definition: ProfileShiftFit.C:204
double mse
Current fit MSE.
Definition: ProfileShiftFit.h:225
void reset()
Reset everything to zero, free internal memory.
Definition: ProfileShiftFit.C:82
Array of Profiles integrated over the same time interval.
Definition: Integration.h:37
double log_shift_pdf_pos(double phi)
Same as above, but with scale>0 prior.
Definition: ProfileShiftFit.C:350
Reference::To< const Profile > prof
Current data profile.
Definition: ProfileShiftFit.h:158
int get_mcmc_iterations() const
Get number of iterations.
Definition: ProfileShiftFit.h:82
unsigned dof
Current degrees of freedom.
Definition: ProfileShiftFit.h:231
Estimate< double > get_shift()
Get the resulting shift.
Definition: ProfileShiftFit.C:561
Finds the last significant harmonic in a flucuation power spectral density.
Definition: LastHarmonic.h:37
T get_value() const
unsigned nbins_prof
Number of bins in profile.
Definition: ProfileShiftFit.h:161
double scale
Current scale result.
Definition: ProfileShiftFit.h:216
double get_scale(size_t nfft, type t)
double correction
Correction for profile nbins != template nbins.
Definition: ProfileShiftFit.h:213
Calculates profile shifts by fitting to a template/standard.
Definition: ProfileShiftFit.h:48
void set_mcmc_iterations(int nit)
Set number of iterations for MCMC errors.
Definition: ProfileShiftFit.h:79
float * fccf
Current freq domain cross-correlation function.
Definition: ProfileShiftFit.h:167
double get_mse()
Get the resulting Mean Squared Error (per fit DOF)
Definition: ProfileShiftFit.C:573
~ProfileShiftFit()
Destructor.
Definition: ProfileShiftFit.C:80
double shift
Current shift result.
Definition: ProfileShiftFit.h:207
void detect(Profile *input)
Square-law detect the input complex-valued Profile.
Definition: Fourier.C:103
double std_pow
Template normalization factor.
Definition: ProfileShiftFit.h:155
void init()
Initialize vars.
Definition: ProfileShiftFit.C:40
Defines the PSRCHIVE library.
Definition: CalSource.h:17
double get_snr()
Get the resulting SNR.
Definition: ProfileShiftFit.C:579
Estimate< double > get_total(bool subtract_baseline=true) const
Returns the total flux of the on-pulse phase bins.
Definition: ProfileStats.C:251
void compute()
Run the fit.
Definition: ProfileShiftFit.C:261
Computes pulse profile statistics.
Definition: ProfileStats.h:35
float * fstd
R2C FFT of current template.
Definition: ProfileShiftFit.h:152
Reference::To< const Profile > std
Current template profile.
Definition: ProfileShiftFit.h:146
Estimate< double > get_scale()
Get the resulting scale factor.
Definition: ProfileShiftFit.C:567
void set_profile(const Profile *)
Set the Profile from which statistics will be derived.
Definition: ProfileStats.C:115
double dccf(double phi)
Evaluate d(ccf)/d(phi) at phase shift phi.
Definition: ProfileShiftFit.C:222
int mcmc_it
Number of iterations to use for MCMC.
Definition: ProfileShiftFit.h:201
Tempo::toa toa(const Integration *)
Return a TOA object for the current fit.
Definition: ProfileShiftFit.C:547
double get_sigma2()
Get the resulting noise per harmonic.
Definition: ProfileShiftFit.C:585
void error_mcmc_pdf_var()
Calculate shift uncertainty as posterior PDF variance using MCMC.
Definition: ProfileShiftFit.C:482
float * fprof
R2C FFT of current profile.
Definition: ProfileShiftFit.h:164
void choose_nharm()
Choose the maximum number of harmonics using LastHarmonic.
Definition: ProfileShiftFit.C:153
Error_Method
Method to use for calculating shift error.
Definition: ProfileShiftFit.h:54

Generated using doxygen 1.8.17