ComponentModel.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2006 by Russell Edwards
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/Timing/Pulsar/ComponentModel.h
10 
11 #ifndef __Pulsar_ComponentModel_h
12 #define __Pulsar_ComponentModel_h
13 
14 #include "Pulsar/ProfileShiftEstimator.h"
15 #include "MEAL/Univariate.h"
16 
17 #include <map>
18 
19 namespace MEAL
20 {
21  class Scalar;
22  class ScalarParameter;
23  class ScaledVonMises;
24  class ScaledVonMisesDeriv;
25 }
26 
27 namespace Pulsar
28 {
29  class Profile;
30  class Archive;
31 
33 
35  {
36  public:
37 
39  ComponentModel ();
40 
42  ComponentModel (const std::string& filename);
43 
45  double get_gate_duty_cycle() const { return gate; }
46 
48  virtual void set_gate_duty_cycle (double turns) { gate = turns; }
49 
51  Estimate<double> get_shift () const;
52 
54  std::string get_name () const { return filename; }
55 
58 
60  ComponentModel* clone () const { return new ComponentModel(*this); }
61 
64 
66  double get_reduced_chisq () const { return chisq / nfree; }
67 
69  double get_absolute_phase () const;
70 
71  // I/O
72  void load (const char *fname);
73  void unload (const char *fname) const;
74 
76  void set_log_height (bool flag=true);
77  bool get_log_height () const { return log_height; }
78 
80  void set_retain_memory (bool flag=true);
81  bool get_retain_memory () const { return retain_memory; }
82 
83  void set_fix_widths (bool flag=true);
84  bool get_fix_widths () const { return fix_widths; }
85 
86  void set_fit_primary_first (bool flag=true);
87  bool get_fit_primary_first () const { return fit_primary_first; }
88 
89  void set_report_absolute_phases (bool flag=true);
90  bool get_report_absolute_phases () const { return report_absolute_phases; }
91 
92  void set_report_widths (bool flag=true) { report_widths = flag; }
93  bool get_report_widths () const { return report_widths; }
94 
95  // Manipulation
100  void add_component (double centre, double concentration, double height,
101  const char *name);
102 
103  void remove_component (unsigned icomp);
104 
105  MEAL::ScaledVonMises *get_component(unsigned icomp);
106 
107  unsigned get_ncomponents() const;
108 
110  void align (const Profile *profile);
111 
113  void align_to_model (Profile* profile);
114 
116  void get_best_alignment (const Profile* profile, double& phase, double& scale);
117 
119  void fix_relative_phases ();
120 
122  void set_zap_height_ratio (float r) { zap_height_ratio = r; }
123  float get_zap_height_ratio () const { return zap_height_ratio; }
124 
126  void set_zap_concentration_ratio (float r) { zap_concentration_ratio = r; }
127  float get_zap_concentration_ratio () const { return zap_concentration_ratio; }
128 
129  // Fitting
130 
131  void set_fit_derivative (bool flag) { fit_derivative = flag; }
132  void set_threshold (float t) { threshold = t; }
133 
134  void set_infit (unsigned icomponent, unsigned iparam, bool infit);
135  void set_infit (const char *fitstring);
136 
137  void fit (const Profile *profile);
138 
139  float get_chisq () const { return chisq; }
140  unsigned get_nfree () const { return nfree; }
141 
142  // Evaluating
143  void evaluate (float *vals, unsigned nvals, int icomp=-1) ;
144 
145  protected:
146 
147  std::vector< Reference::To<MEAL::ScaledVonMises> > components;
148 
149  mutable std::vector< Reference::To<MEAL::ScaledVonMises> > backup;
150 
151  // set all infit flags of the specified component to false
152  void freeze (unsigned icomponent) const;
153 
154  // restore all infit flags of the specified component from backup
155  void unfreeze (unsigned icomponent) const;
156 
157  std::vector<std::string> component_names;
158 
159  mutable std::vector< Reference::To<MEAL::ScaledVonMisesDeriv> > derivative;
160 
162  std::map<unsigned, std::string> comments;
163 
166 
167  double gate;
168 
169  bool fit_derivative;
170  float threshold;
171 
172  bool log_height;
173  bool retain_memory;
174  bool fix_widths;
175  bool fit_primary_first;
176  bool report_absolute_phases;
177  bool report_widths;
178 
179  float zap_height_ratio;
180  float zap_concentration_ratio;
181 
182  void build () const;
183  void check (const char* method, unsigned icomponent) const;
184 
185  void clear ();
186  void init ();
187 
188  private:
189 
190  float chisq;
191  unsigned nfree;
192  std::string filename;
193  };
194 }
195 
196 #endif
void fit(const Pulsar::Parameters *model, std::vector< toa > &data, Pulsar::Parameters *postfit=NULL, bool track=false, Tempo::toa::State min_state=Tempo::toa::Normal)
void set_constraint(unsigned iparam, Scalar *scalar)
void fix_relative_phases()
Fix the relative phases of the components.
Definition: ComponentModel.C:72
void phase(Profile *input)
Compute the phase of the input complex-valued Profile.
Definition: Fourier.C:135
MEAL::Univariate< MEAL::Scalar > * get_model()
Get the component model.
Definition: ComponentModel.C:65
std::string get_name() const
Return the name of the file from which the component model was loaded.
Definition: ComponentModel.h:54
const float * get_amps() const
Return a pointer to the amplitudes array.
Definition: ProfileAmps.C:141
Estimate< double > get_shift() const
Return the shift estimate.
Definition: ComponentModel.C:130
void frc1d(size_t nfft, float *into, const float *from)
std::map< unsigned, std::string > comments
comments, indexed by line number
Definition: ComponentModel.h:162
ComponentModel * clone() const
Return a copy constructed instance of self.
Definition: ComponentModel.h:60
void set_zap_height_ratio(float r)
Remove components with small heights.
Definition: ComponentModel.h:122
Estimate< double > shift(const Profile &std) const
Returns the shift (in turns) between profile and standard.
Definition: Profile_shift.C:20
void bcr1d(size_t nfft, float *into, const float *from)
Any quantity recorded as a function of pulse phase.
Definition: Profile.h:45
void set_zap_concentration_ratio(float r)
Remove components with large concentrations (narrow widths)
Definition: ComponentModel.h:126
void set_retain_memory(bool flag=true)
Previous best fit model will be first guess on next call to get_shift.
Definition: ComponentModel.C:106
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
Value get_Value(const Type &value)
void set_value(const Type &value)
double get_absolute_phase() const
Return the absolute phase.
Definition: ComponentModel.C:208
void rotate_phase(double phase)
rotates the profile by phase (in turns)
Definition: Profile_rotate.C:35
ComponentModel()
Default constructor.
Definition: ComponentModel.C:54
void add_model(T *model)
void derivative(unsigned npts, float *data)
void align_to_model(Profile *profile)
Roughly align the Profile to match the phases and heights of the components.
Definition: ComponentModel.C:411
void set_model(T *model)
void set_log_height(bool flag=true)
All heights will be treated as log(height)
Definition: ComponentModel.C:97
void add_component(double centre, double concentration, double height, const char *name)
Definition: ComponentModel.C:367
TextInterface::Parser * get_interface()
Return a text interface that can be used to configure this instance.
Definition: ComponentModel.C:950
Models a pulse profile using multiple components.
Definition: ComponentModel.h:34
Algorithms that estimate the phase shift from a single pulse profile.
Definition: ProfileShiftEstimator.h:25
PhaseWeight * baseline() const
Return a new PhaseWeight instance with the baseline phase bins masked.
Definition: Profile_baseline.C:15
double get_reduced_chisq() const
Return the statistical goodness-of-fit.
Definition: ComponentModel.h:66
Defines the PSRCHIVE library.
Definition: CalSource.h:17
void align(const Profile *profile)
Roughly align the phases and heights of the components to match the Profile.
Definition: ComponentModel.C:448
double get_gate_duty_cycle() const
Get the fraction of the pulse period modelled (in turns)
Definition: ComponentModel.h:45
void sum(const Profile *profile)
add profile to this
Definition: Profile.C:336
virtual void set_gate_duty_cycle(double turns)
Set the fraction of the pulse period modelled (in turns)
Definition: ComponentModel.h:48
void get_best_alignment(const Profile *profile, double &phase, double &scale)
Returns the best fit phase and scale that aligns the model to the Profile.
Definition: ComponentModel.C:426

Generated using doxygen 1.8.17