PhaseWeight.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2004 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/General/Pulsar/PhaseWeight.h
10 
11 #ifndef __Pulsar_PhaseWeight_h
12 #define __Pulsar_PhaseWeight_h
13 
14 #include "Reference.h"
15 #include "Estimate.h"
16 
17 namespace Pulsar {
18 
19  class Profile;
20 
22 
24  class PhaseWeight : public Reference::Able {
25 
26  public:
27 
30 
32  PhaseWeight (const Profile*);
33 
34  PhaseWeight (unsigned nbin);
35  PhaseWeight (unsigned nbin, float set_all);
36 
39 
41  PhaseWeight (const std::vector<float>& weight);
42 
44  ~PhaseWeight ();
45 
48 
51 
54 
56  float& operator [] (unsigned i) { built = false; return weight[i]; }
57 
59  const float& operator [] (unsigned i) const { return weight[i]; }
60 
62  void resize (unsigned nbin) { weight.resize(nbin); }
63 
65  unsigned get_nbin () const { return weight.size(); }
66 
68  double get_frequency () const { return reference_frequency; }
69 
71  void set_frequency (double f) { reference_frequency = f; }
72 
74  void set_all (float weight);
75 
77  void negate ();
78 
80  double get_weight_sum () const;
81 
83  unsigned get_nonzero_weight_count () const;
84 
86  std::string get_start_index () const;
87 
89  std::string get_end_index () const;
90 
92  double get_weight_max () const;
93 
95  void get_weights (std::vector<float>& weights) const;
96 
98  void weight_Profile (Profile* profile) const;
99 
101  void set_Profile (const Profile* profile) const;
102 
104  double get_weighted_sum () const;
105 
107  float get_avg () const;
108 
110  float get_rms () const;
111 
113  float get_min () const;
114 
116  float get_max () const;
117 
119  float get_median () const;
120 
122  float get_median_difference () const;
123 
125  Estimate<double> get_mean () const;
126 
129 
131  void stats (const Profile* profile,
132  double* mean, double* variance=0,
133  double* varmean=0, double* varvar=0) const;
134 
136  float* get_weights () { return &(weight[0]); }
137 
139  const float* get_weights() const { return &(weight[0]); }
140 
142  void get_filtered (std::vector<float>& amps,
143  bool equal = false, float wt = 0) const;
144 
146  class Interface;
147 
148  protected:
149 
152 
154  std::vector<float> weight;
155 
158 
160  mutable bool built;
161 
163  mutable Estimate<double> mean;
164 
166  mutable Estimate<double> variance;
167 
169  mutable float median;
170  mutable bool median_computed;
171 
173  mutable float median_diff;
174  mutable bool median_diff_computed;
175 
177  mutable std::vector<float> non_zero;
178 
180  void fill_non_zero (const char* method) const;
181 
183  void build () const;
184 
186  void init ();
187 
189  void check_Profile (const char* method) const;
190 
192  void check_weight (unsigned nbin, const char* method) const;
193 
194  };
195 
196 }
197 
198 
199 #endif // !defined __Pulsar_PhaseWeight_h
void stats(const Profile *profile, double *mean, double *variance=0, double *varmean=0, double *varvar=0) const
Get the statistics of the weighted phase bins (deprecated interface)
Definition: PhaseWeight.C:420
void check_weight(unsigned nbin, const char *method) const
Check that the size of the weights vector is equal to nbin.
Definition: PhaseWeight.C:382
unsigned get_nbin() const
Get the number of weights in the array.
Definition: PhaseWeight.h:70
float get_max() const
Get the minimum amplitude with non-zero weight.
Definition: PhaseWeight.C:207
const float * get_amps() const
Return a pointer to the amplitudes array.
Definition: ProfileAmps.C:141
void get_filtered(std::vector< float > &amps, bool equal=false, float wt=0) const
Return the filtered amplitudes for which weight != val.
Definition: PhaseWeight.C:510
std::string get_end_index() const
Get the end of the phase region with non-zero weight.
Definition: PhaseWeight.C:176
const PhaseWeight & operator+=(const PhaseWeight &weight)
Forms the sum of this and weight.
Definition: PhaseWeight.C:83
std::string get_start_index() const
Get the beginning of the phase region with non-zero weight.
Definition: PhaseWeight.C:153
bool built
Flag set when the statistics have been calculated.
Definition: PhaseWeight.h:165
float * get_weights()
Return the base address of the weights array.
Definition: PhaseWeight.h:141
Stores a weight for each Profile phase bin.
Definition: PhaseWeight.h:29
void resize(unsigned nbin)
Resize the weights array.
Definition: PhaseWeight.h:67
Any quantity recorded as a function of pulse phase.
Definition: Profile.h:45
unsigned get_nonzero_weight_count() const
Get the count of all non-zero weights.
Definition: PhaseWeight.C:142
Estimate< double > get_variance() const
Get the weighted variance of the Profile amplitudes.
Definition: PhaseWeight.C:351
unsigned get_nbin() const
Return the number of bins.
Definition: ProfileAmps.h:50
static bool verbose
flag controls the amount output to stderr by Profile methods
Definition: Profile.h:53
void check_Profile(const char *method) const
Check that the profile attribute is set.
Definition: PhaseWeight.C:374
float get_median_difference() const
Get the median difference between the median and non-zero amplitudes.
Definition: PhaseWeight.C:281
float median_diff
The median difference of all phase bins with non-zero weight.
Definition: PhaseWeight.h:178
double get_weighted_sum() const
Get the weighted total of the amplitudes.
Definition: PhaseWeight.C:316
const PhaseWeight & operator*=(const PhaseWeight &weight)
Forms the product of this and weight.
Definition: PhaseWeight.C:98
void set_frequency(double f)
Set the reference frequency.
Definition: PhaseWeight.h:76
double reference_frequency
The reference frequency.
Definition: PhaseWeight.h:151
void negate()
Set all weights to the logical negation of their current value.
Definition: PhaseWeight.C:121
double get_frequency() const
Get the reference frequency.
Definition: PhaseWeight.h:73
float get_min() const
Get the minimum amplitude with non-zero weight.
Definition: PhaseWeight.C:225
void weight_Profile(Profile *profile) const
Weight the Profile amplitudes by the weights.
Definition: PhaseWeight.C:408
std::vector< float > non_zero
working space for median computation
Definition: PhaseWeight.h:182
Estimate< double > variance
The weighted variance of the Profile.
Definition: PhaseWeight.h:171
std::vector< float > weight
The weights.
Definition: PhaseWeight.h:159
float get_avg() const
Get the weighted average of the Profile amplitudes.
Definition: PhaseWeight.C:345
void build() const
Compute the mean and variance attributes.
Definition: PhaseWeight.C:390
~PhaseWeight()
Destructor.
Definition: PhaseWeight.C:66
const PhaseWeight & operator=(const PhaseWeight &weight)
Assignment operator.
Definition: PhaseWeight.C:71
float & operator[](unsigned i)
Array operator.
Definition: PhaseWeight.h:61
double get_weight_max() const
Get the max of all weights.
Definition: PhaseWeight.C:198
Archive statistics text interface.
Definition: PhaseWeightInterface.h:25
Reference::To< const Profile, false > profile
The Profile to which the weights apply.
Definition: PhaseWeight.h:162
float get_median() const
Get the median amplitude with non-zero weight.
Definition: PhaseWeight.C:259
Defines the PSRCHIVE library.
Definition: CalSource.h:17
Estimate< double > mean
The weighted mean of the Profile.
Definition: PhaseWeight.h:168
float median
The median of all phase bins with non-zero weight.
Definition: PhaseWeight.h:174
float get_rms() const
Get the weighted rms of the Profile amplitudes.
Definition: PhaseWeight.C:368
double get_weight_sum() const
Get the sum of all weights.
Definition: PhaseWeight.C:134
PhaseWeight()
Default constructor.
Definition: PhaseWeight.C:28
void set_all(float weight)
Set all weights to the specified value.
Definition: PhaseWeight.C:114
void fill_non_zero(const char *method) const
fill the non_zero vector
Definition: PhaseWeight.C:244
void init()
Initialize attributes to default values.
Definition: PhaseWeight.C:18
void set_Profile(const Profile *profile) const
Set the Profile from which statistics are calculated.
Definition: PhaseWeight.C:303
Estimate< double > get_mean() const
Get the weighted mean of the Profile amplitudes.
Definition: PhaseWeight.C:334

Generated using doxygen 1.8.17