Toast++  1.0.2 (r.539)
Forward and inverse modelling in optical tomography
of.h
1 // -*-C++-*-
2 // ==========================================================================
3 // Objective function for parameter optimisation
4 // ==========================================================================
5 
6 #ifndef __OF_H
7 #define __OF_H
8 
9 #include "stoastlib.h"
10 
11 class Raster;
12 class Solution;
13 template<class T>class TFwdSolver;
14 
15 typedef enum {
16  PRIOR_NONE_OLD,
17  PRIOR_LAPLACIAN_OLD,
18  PRIOR_DIAG_OLD
19 } PRIOR_OLD;
20 
21 // =========================================================================
22 
23 class STOASTLIB ObjectiveFunction {
24 public:
25  ObjectiveFunction (const Raster *_raster);
26  void SetData (const RVector *_data);
27  void SetSD (const RVector *_sd);
28  void SetScalingMatrix (const RMatrix *mat);
29  void SetGMRFParam (double _gmrf_exp, double _hypermua, double _hyperkappa,
30  const int *_nbg_rowptr, const int *_nbg_colidx);
31  void SetTVParam (double _tv_beta2, double _hypermua, double _hyperkappa);
32  const RVector *Data () { return data; }
33  const RVector *SD () { return sd; }
34  double get_posterior (const RVector *proj) const;
35  //double get_prior (const Solution *sol) const;
36  static double get_prior (PRIOR_OLD prior, const RVector &x, const RVector &xp,
37  const RVector &x0, double tau, const RCompRowMatrix &LTL);
38  static double get_value (const RVector &data, const RVector &proj,
39  const RVector &sd, const RMatrix *scale = 0);
40  double get_value (const RVector *proj, const Solution *sol = 0) const;
41  void add_gradient_data (RVector &grad, const Raster &raster,
42  const CFwdSolver &FWS, const RVector &proj,
43  CVector *dphi, const CCompRowMatrix &mvec) const;
44  void add_gradient_prior (const Solution &so, RVector &grad) const;
45  void get_gradient (const Raster &raster,
46  const CFwdSolver &FWS, const RVector &proj,
47  CVector *dphi, const CCompRowMatrix &mvec, const Solution *sol,
48  RVector &grad) const;
49  RVector get_gradient ();
50 
51 private:
52  const RVector *data;
53  const RVector *sd;
54  const RMatrix *scale;
55  bool apply_prior;
56  double gmrf_exp;
57  double tv_beta2;
58  double hyper[2];
59  const int *nbg_rowptr, *nbg_colidx;
60  const Raster *raster;
61 };
62 
63 inline void ObjectiveFunction::SetData (const RVector *_data)
64 { data = _data; }
65 
66 inline void ObjectiveFunction::SetSD (const RVector *_sd)
67 { sd = _sd; }
68 
69 inline void ObjectiveFunction::SetScalingMatrix (const RMatrix *mat)
70 { scale = mat; }
71 
72 inline void ObjectiveFunction::SetGMRFParam (double _gmrf_exp,
73  double _hypermua, double _hyperkappa,
74  const int *_nbg_rowptr, const int *_nbg_colidx)
75 {
76  gmrf_exp = _gmrf_exp;
77  hyper[0] = _hypermua;
78  hyper[1] = _hyperkappa;
79  nbg_rowptr = _nbg_rowptr;
80  nbg_colidx = _nbg_colidx;
81  apply_prior = true;
82 }
83 
84 // =========================================================================
85 // this should probably go into ObjectiveFunction, or into a new class
86 // 'Prior'
87 
88 STOASTLIB double penalty_tikh0 (const RVector &x, const RVector &x0,
89  const RVector &xs);
90 STOASTLIB void penalty_gradient_tikh0_add (const RVector &x, const RVector &x0,
91  const RVector &xs, RVector &grad, const double tau);
92 STOASTLIB void penalty_gradient_tikh0_rescale_add (const RVector &x, const RVector &x0,
93  RVector &grad, const double tau);
94 STOASTLIB double penalty_tikh1 (const RVector &x, const RVector &x0,
95  const double tau1, const double tau2,const RCompRowMatrix &LTL);
96 STOASTLIB void penalty_gradient_tikh1_add (const RVector &x, const RVector &x0,
97  RVector &grad, const double tau1, const double tau2,
98  const RCompRowMatrix &LTL);
99 
100 #endif // !__OF_H
Definition: of.h:23
Base class for mapping between mesh and an independent basis representation.
Definition: raster.h:20
Templated forward solver class.
Definition: fwdsolver.h:37
Definition: solution.h:39