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
17namespace Pulsar {
18
19 class Profile;
20
22
25
26 public:
27
29 PhaseWeight ();
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 void copy (const PhaseWeight& weight);
49 void copy (const PhaseWeight* weight) { copy(*weight); }
50
53 void elementwise_sum (const PhaseWeight& weight);
54 void elementwise_sume (const PhaseWeight* weight) { elementwise_sum(*weight); }
55
58 void elementwise_product (const PhaseWeight& weight);
59 void elementwise_product (const PhaseWeight* weight) { elementwise_product(*weight); }
60
62 float& operator [] (unsigned i) { built = false; return weight[i]; }
63
65 const float& operator [] (unsigned i) const { return weight[i]; }
66
68 float& at (unsigned i) { built = false; return weight[i]; }
69
71 const float& at (unsigned i) const { return weight[i]; }
72
74 void resize (unsigned nbin) { weight.resize(nbin); }
75
77 unsigned get_nbin () const { return weight.size(); }
78
80 double get_frequency () const { return reference_frequency; }
81
83 void set_frequency (double f) { reference_frequency = f; }
84
86 void set_all (float weight);
87
89 void negate ();
90
92 double get_weight_sum () const;
93
95 unsigned get_nonzero_weight_count () const;
96
98 std::string get_start_index () const;
99
101 std::string get_end_index () const;
102
104 double get_weight_max () const;
105
107 void get_weights (std::vector<float>& weights) const;
108
110 void weight_Profile (Profile* profile) const;
111
113 void set_Profile (const Profile* profile) const;
114
116 double get_weighted_sum () const;
117
119 float get_avg () const;
120
122 float get_rms () const;
123
125 float get_min () const;
126
128 float get_max () const;
129
131 float get_median () const;
132
134 float get_median_difference () const;
135
137 Estimate<double> get_mean () const;
138
141
143 void stats (const Profile* profile,
144 double* mean, double* variance=0,
145 double* varmean=0, double* varvar=0) const;
146
148 float* get_weights () { return &(weight[0]); }
149
151 const float* get_weights() const { return &(weight[0]); }
152
154 void get_filtered (std::vector<float>& amps,
155 bool equal = false, float wt = 0) const;
156
158 class Interface;
159
160 protected:
161
164
166 std::vector<float> weight;
167
170
172 mutable bool built;
173
176
179
181 mutable float median;
182 mutable bool median_computed;
183
185 mutable float median_diff;
186 mutable bool median_diff_computed;
187
189 mutable std::vector<float> non_zero;
190
192 void fill_non_zero (const char* method) const;
193
195 void build () const;
196
198 void init ();
199
201 void check_Profile (const char* method) const;
202
204 void check_weight (unsigned nbin, const char* method) const;
205
206 };
207
208}
209
210
211#endif // !defined __Pulsar_PhaseWeight_h
float median_diff
The median difference of all phase bins with non-zero weight.
Definition PhaseWeight.h:185
void set_all(float weight)
Set all weights to the specified value.
Definition PhaseWeight.C:127
std::string get_end_index() const
Get the end of the phase region with non-zero weight.
Definition PhaseWeight.C:189
float & at(unsigned i)
Array operator.
Definition PhaseWeight.h:68
float get_median_difference() const
Get the median difference between the median and non-zero amplitudes.
Definition PhaseWeight.C:294
Estimate< double > mean
The weighted mean of the Profile.
Definition PhaseWeight.h:175
~PhaseWeight()
Destructor.
Definition PhaseWeight.C:66
Estimate< double > variance
The weighted variance of the Profile.
Definition PhaseWeight.h:178
const float * get_weights() const
Return the base address of the weights array.
Definition PhaseWeight.h:151
bool built
Flag set when the statistics have been calculated.
Definition PhaseWeight.h:172
unsigned get_nonzero_weight_count() const
Get the count of all non-zero weights.
Definition PhaseWeight.C:155
unsigned get_nbin() const
Get the number of weights in the array.
Definition PhaseWeight.h:77
double get_weight_sum() const
Get the sum of all weights.
Definition PhaseWeight.C:147
const PhaseWeight & operator=(const PhaseWeight &weight)
Assignment operator.
Definition PhaseWeight.C:71
float * get_weights()
Return the base address of the weights array.
Definition PhaseWeight.h:148
const float & at(unsigned i) const
Array operator.
Definition PhaseWeight.h:71
void negate()
Set all weights to the logical negation of their current value.
Definition PhaseWeight.C:134
double get_weight_max() const
Get the max of all weights.
Definition PhaseWeight.C:211
double get_frequency() const
Get the reference frequency.
Definition PhaseWeight.h:80
float get_max() const
Get the minimum amplitude with non-zero weight.
Definition PhaseWeight.C:220
float get_median() const
Get the median amplitude with non-zero weight.
Definition PhaseWeight.C:272
PhaseWeight()
Default constructor.
Definition PhaseWeight.C:28
void check_weight(unsigned nbin, const char *method) const
Check that the size of the weights vector is equal to nbin.
Definition PhaseWeight.C:395
std::vector< float > non_zero
working space for median computation
Definition PhaseWeight.h:189
float get_rms() const
Get the weighted rms of the Profile amplitudes.
Definition PhaseWeight.C:381
Estimate< double > get_variance() const
Get the weighted variance of the Profile amplitudes.
Definition PhaseWeight.C:364
float get_min() const
Get the minimum amplitude with non-zero weight.
Definition PhaseWeight.C:238
void fill_non_zero(const char *method) const
fill the non_zero vector
Definition PhaseWeight.C:257
void weight_Profile(Profile *profile) const
Weight the Profile amplitudes by the weights.
Definition PhaseWeight.C:421
void set_Profile(const Profile *profile) const
Set the Profile from which statistics are calculated.
Definition PhaseWeight.C:316
void set_frequency(double f)
Set the reference frequency.
Definition PhaseWeight.h:83
double get_weighted_sum() const
Get the weighted total of the amplitudes.
Definition PhaseWeight.C:329
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:523
float & operator[](unsigned i)
Array operator.
Definition PhaseWeight.h:62
const PhaseWeight & operator+=(const PhaseWeight &weight)
Forms the element-wise sum of this and weight.
Definition PhaseWeight.C:88
float median
The median of all phase bins with non-zero weight.
Definition PhaseWeight.h:181
void resize(unsigned nbin)
Resize the weights array.
Definition PhaseWeight.h:74
std::vector< float > weight
The weights.
Definition PhaseWeight.h:166
const PhaseWeight & operator*=(const PhaseWeight &weight)
Forms the element-wise product of this and weight.
Definition PhaseWeight.C:108
std::string get_start_index() const
Get the beginning of the phase region with non-zero weight.
Definition PhaseWeight.C:166
void build() const
Compute the mean and variance attributes.
Definition PhaseWeight.C:403
double reference_frequency
The reference frequency.
Definition PhaseWeight.h:163
void init()
Initialize attributes to default values.
Definition PhaseWeight.C:18
float get_avg() const
Get the weighted average of the Profile amplitudes.
Definition PhaseWeight.C:358
void check_Profile(const char *method) const
Check that the profile attribute is set.
Definition PhaseWeight.C:387
Estimate< double > get_mean() const
Get the weighted mean of the Profile amplitudes.
Definition PhaseWeight.C:347
Reference::To< const Profile, false > profile
The Profile to which the weights apply.
Definition PhaseWeight.h:169
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:433
Any quantity recorded as a function of pulse phase.
Definition Profile.h:40
Defines the PSRCHIVE library.
Definition CalSource.h:17

Generated using doxygen 1.14.0