Toast++  1.0.2 (r.539)
Forward and inverse modelling in optical tomography
pscaler.h
1 // -*-C++-*-
2 // ==========================================================================
3 // Parameter scaling
4 // ==========================================================================
5 
6 #ifndef __PSCALER_H
7 #define __PSCALER_H
8 
9 #include "stoastlib.h"
10 
11 // =========================================================================
12 
13 class STOASTLIB Scaler {
14 public:
15  Scaler () {}
16  virtual const char *ScalingMethod() const = 0;
17  virtual RVector Scale (const RVector &unscaled) const = 0;
18  virtual RVector Unscale (const RVector &scaled) const = 0;
19  virtual RVector JScale (const RVector &unscaled) const = 0;
20  virtual void ScaleJacobian (const RVector &unscaled, RMatrix &J) const {
21  return J.ColScale (JScale (unscaled));
22  }
23  virtual void ScaleGradient (const RVector &unscaled, RVector &grad) const {
24  grad *= JScale (unscaled);
25  }
26 };
27 
28 class STOASTLIB NullScaler: public Scaler {
29 public:
30  NullScaler (): Scaler () {}
31  const char *ScalingMethod () const { return "NULL"; }
32  RVector Scale (const RVector &unscaled) const { return unscaled; }
33  RVector Unscale (const RVector &scaled) const { return scaled; }
34  RVector JScale (const RVector &unscaled) const {
35  RVector s(unscaled.Dim()); s = 1.0; return s;
36  }
37  void ScaleJacobian (const RVector &unscaled, RMatrix &J) const {}
38  void ScaleGradient (const RVector &unscaled, RVector &grad) const {}
39 };
40 
41 class STOASTLIB ConstScaler: public Scaler {
42 public:
43  ConstScaler (const RVector &scale): Scaler () { sc = scale; }
44  const char *ScalingMethod () const { return "CONST"; }
45  RVector Scale (const RVector &unscaled) const { return unscaled*sc; }
46  RVector Unscale (const RVector &scaled) const { return scaled/sc; }
47  RVector JScale (const RVector &unscaled) const { return inv(sc); }
48 private:
49  RVector sc;
50 };
51 
52 class STOASTLIB LogScaler: public Scaler {
53 public:
54  LogScaler (): Scaler () {}
55  const char *ScalingMethod () const { return "LOG"; }
56  RVector Scale (const RVector &unscaled) const { return log(unscaled); }
57  RVector Unscale (const RVector &scaled) const { return exp(scaled); }
58  RVector JScale (const RVector &unscaled) const { return unscaled; }
59 };
60 
61 class STOASTLIB LinLogScaler: public Scaler {
62 public:
63  LinLogScaler (const RVector &scale): Scaler () { sc = scale; }
64  const char *ScalingMethod () const { return "LINLOG"; }
65  RVector Scale (const RVector &unscaled) const { return log(unscaled*sc); }
66  RVector Unscale (const RVector &scaled) const { return exp(scaled)/sc; }
67  RVector JScale (const RVector &unscaled) const { return unscaled; }
68 private:
69  RVector sc;
70 };
71 
72 class STOASTLIB BoundLogScaler: public Scaler {
73 public:
74  BoundLogScaler (const RVector &_xmin, const RVector &_xmax): Scaler()
75  { xmin = _xmin, xmax = _xmax; }
76  const char *ScalingMethod () const { return "BOUNDED_LOG"; }
77  RVector Scale (const RVector &unscaled) const
78  { return log ((unscaled-xmin)*(xmax-unscaled)); }
79  RVector Unscale (const RVector &scaled) const;
80  RVector JScale (const RVector &unscaled) const;
81 private:
82  RVector xmin, xmax;
83 };
84 
85 #endif // !__PSCALER_H
Definition: pscaler.h:28
Definition: pscaler.h:72
Definition: pscaler.h:52
Definition: pscaler.h:61
int Dim() const
Returns the size of the vector.
Definition: vector.h:295
Definition: pscaler.h:13
Definition: pscaler.h:41