CompareWith.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2021 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/General/Pulsar/CompareWith.h
10 
11 #ifndef __CompareWith_h
12 #define __CompareWith_h
13 
14 #include "Pulsar/HasArchive.h"
15 #include "Pulsar/TimeDomainCovariance.h"
16 #include "Pulsar/ScrunchFactor.h"
17 
18 #include "ChiSquared.h"
19 #include "ndArray.h"
20 
21 class BinaryStatistic;
22 class UnaryStatistic;
23 
24 namespace Pulsar {
25 
27 
29  {
30  protected:
31 
34 
37 
39  void (HasArchive::* primary) (Index);
40  unsigned nprimary;
41 
43  void (HasArchive::* compare) (Index);
44  unsigned ncompare;
45 
48 
50 
52  bool use_null_space;
53 
55  bool transpose;
56 
58  virtual void setup (unsigned start_primary, unsigned nprimary = 1);
59 
62 
64  bool is_setup;
65 
66  void set (ndArray<2,double>& result,
67  unsigned iprimary, unsigned icompare,
68  double value);
69 
71  void check ();
72 
74  void compute_mean (unsigned start_primary, unsigned nprimary);
76 
78 
81 
83  void get_amps (std::vector<double>& amps, const Profile* profile);
84 
86  void get_residual (std::vector<double>& amps,
87  const std::vector<double>& mamps);
88 
91 
93  BinaryStatistics::ChiSquared chi;
94 
96  virtual void compute (unsigned iprimary, ndArray<2,double>& result) = 0;
97 
99  std::vector<bool> compute_mask;
100 
101 
103  FILE* fptr;
104 
105  public:
106 
107  CompareWith ();
108 
109  void set_statistic (BinaryStatistic*);
110  void set_data (HasArchive*);
111 
113  void set_setup_data (const Archive*);
114 
116  void set_bscrunch (const ScrunchFactor& f) { bscrunch_factor = f; }
117 
119  const ScrunchFactor get_bscrunch () const { return bscrunch_factor; }
120 
122  /* Not all comparisons require a global set up */
123  bool get_setup () { return is_setup; }
124 
125  void set_transpose (bool);
126  void set_primary (unsigned n, void (HasArchive::*) (Index));
127  void set_compare (unsigned n, void (HasArchive::*) (Index));
128 
129  void set_compare_all (bool flag = true) { compare_all = flag; }
130 
132  void set_compute_mask (const std::vector<bool>& flags)
133  { compute_mask = flags; }
134 
135  virtual void compute (ndArray<2,double>& result);
136 
138  void set_file (FILE* f) { fptr = f; }
139 
140  };
141 }
142 
143 #endif
void bscrunch(Container *, const ScrunchFactor &)
Integrate phase bins.
Definition: ScrunchFactor.h:116
bool setup_completed
Set true when setup has completed.
Definition: CompareWith.h:61
Reference::To< GeneralizedChiSquared > gcs
Loops over two dimensions of an Archive, comparing profiles.
Definition: CompareWith.h:28
virtual void setup(unsigned start_primary, unsigned nprimary=1)
Perform an eigenanalysis and set up the generalized chi squared.
Definition: CompareWith.C:626
virtual void compute(unsigned iprimary, ndArray< 2, double > &result)=0
Compute the comparison summary for primary dimension.
Combines an index value and integrate flag.
Definition: Index.h:24
const float * get_amps() const
Return a pointer to the amplitudes array.
Definition: ProfileAmps.C:141
void(HasArchive::* primary)(Index)
Pointer to the method used to loop over the primary dimension.
Definition: CompareWith.h:39
ScrunchFactor bscrunch_factor
Compute covariance matrix from bscrunched clone of data.
Definition: CompareWith.h:80
void set_amps(const T *data)
set the amplitudes array equal to the contents of the data array
Definition: ProfileAmps.h:89
Any quantity recorded as a function of pulse phase.
Definition: Profile.h:45
const ScrunchFactor get_bscrunch() const
Get the phase bin scrunch factor.
Definition: CompareWith.h:119
The primary interface to pulsar observational data.
Definition: Archive.h:45
void check()
Check that necessary attributes have been set.
Definition: CompareWith.C:131
void compute_mean(unsigned start_primary, unsigned nprimary)
Compute the mean of the profiles to be compared.
Definition: CompareWith.C:943
unsigned get_nbin() const
Return the number of bins.
Definition: ProfileAmps.h:50
HasArchive * data
Interface to the Archive.
Definition: CompareWith.h:36
Manages a combined scrunch factor or target dimension.
Definition: ScrunchFactor.h:25
virtual Profile * clone() const
returns a pointer to a new copy of self
Definition: Profile.C:124
Reference::To< Profile > temp
After call to get_residual, also stores residual profile amplitudes.
Definition: CompareWith.h:90
bool model_residual
Compute the covariance matrix of the best-fit residual.
Definition: CompareWith.h:51
bool is_setup
Set true when setup has completed during set_setup_data.
Definition: CompareWith.h:64
BinaryStatistics::ChiSquared chi
Used to compute the residual.
Definition: CompareWith.h:93
bool transpose
Transpose indeces when computing results.
Definition: CompareWith.h:55
double get(const std::vector< double > &, const std::vector< double > &)
const std::vector< double > & get_residual() const
void set_bscrunch(const ScrunchFactor &f)
Compute covariance matrix from bscrunched clone of data.
Definition: CompareWith.h:116
void set_compute_mask(const std::vector< bool > &flags)
Flags for subset of primary axis to be computed.
Definition: CompareWith.h:132
bool verbose
Definition: timer++.C:25
std::vector< bool > compute_mask
Flags for subset of sub-integrations to be computed.
Definition: CompareWith.h:99
Reference::To< BinaryStatistic > statistic
Used to perform comparison.
Definition: CompareWith.h:33
Defines the PSRCHIVE library.
Definition: CalSource.h:17
bool get_setup()
Return true if call to set_setup_data sets anything up.
Definition: CompareWith.h:123
void(HasArchive::* compare)(Index)
Pointer to the method used to loop over the compare dimension.
Definition: CompareWith.h:43
bool compare_all
Compare over both dimensions.
Definition: CompareWith.h:47
void set_file(FILE *f)
Set the file to which auxiliary data will be printed.
Definition: CompareWith.h:138
void get_residual(std::vector< double > &amps, const std::vector< double > &mamps)
Set amps to the residual after best fit of amps to mamps.
Definition: CompareWith.C:230
Manages an archive and its index interface.
Definition: HasArchive.h:29
FILE * fptr
File to which auxiliary data will be printed.
Definition: CompareWith.h:103
void get_amps(std::vector< double > &amps, const Profile *profile)
Set amps to the normalized and bscrunched profile amplitudes.
Definition: CompareWith.C:189
void set_setup_data(const Archive *)
Use to compute the covariance matrix before an fscrunch or tscrunch.
Definition: CompareWith.C:83

Generated using doxygen 1.8.17