covariant.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2020 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// epsic/src/covariant.h
10
11#ifndef __epsic_covariant_h
12#define __epsic_covariant_h
13
14#include "modulated.h"
15#include "Matrix.h"
16
17#include <queue>
18
19/***************************************************************************
20 *
21 * models covariant mode intensities
22 *
23 ***************************************************************************/
24
25namespace epsic
26{
27 class covariant_coordinator;
28
29 class covariant_mode : public modulated_mode
30 {
31 friend class covariant_coordinator;
32
33 covariant_coordinator* coordinator;
34 unsigned index;
35 std::queue<double> amps;
36
37 public:
38
39 // initialize based on the modulation index beta
40 covariant_mode (mode* s) : modulated_mode (s) { coordinator = 0; }
41
42 // return a random scalar modulation factor
43 double modulation ();
44
45 double get_mod_mean () const;
46 double get_mod_variance () const;
47 };
48
49 class covariant_coordinator
50 {
51 private:
52 covariant_mode* out[2];
53
54 friend class covariant_mode;
55 void get();
56
57 // coefficient of mode intensity correlation
58 double correlation;
59
60 protected:
61
63 virtual void get_modulation (double& A, double& B) = 0;
64
65 public:
66
68 covariant_coordinator (double correlation);
69
71 virtual ~covariant_coordinator () {}
72
73 double get_correlation () const { return correlation; }
74
75 double get_intensity_covariance () const
76 { return correlation * sqrt( get_mod_variance (0) * get_mod_variance (1) ); }
77
78 virtual double get_mod_mean (unsigned mode_index) const = 0;
79 virtual double get_mod_variance (unsigned mode_index) const = 0;
80
81 modulated_mode* get_modulated_mode (unsigned index, mode*);
82 };
83
84 class bivariate_lognormal_modes : public covariant_coordinator
85 {
86 Matrix<2,2,double> meansq;
87 Vector<2,double> mean;
88 unsigned count;
89
90 Matrix<2,2,double> correlator;
91 void build ();
92 bool built;
93 double log_sigma[2];
94
96 BoxMuller* normal;
97
98 protected:
99 void get_modulation (double& A, double& B);
100
101 public:
102
103 bivariate_lognormal_modes (double correlation)
104 : covariant_coordinator(correlation)
105 { built = false; set_beta(0,1.0); set_beta(1,1.0); }
106
107 ~bivariate_lognormal_modes ();
108
109 void set_beta (unsigned index, double);
110
111 double get_mod_mean (unsigned mode_index) const { return 1.0; }
112 double get_mod_variance (unsigned i) const { return exp(log_sigma[i]*log_sigma[i]) - 1.0; }
113
115 virtual BoxMuller* get_normal () { return normal; }
116 virtual void set_normal (BoxMuller* n) { normal = n; }
117 };
118
119} // namespace epsic
120
121#endif // ! defined __epsic_covariant_h

Generated using doxygen 1.14.0