ReFRACtor
log_interpolate.h
Go to the documentation of this file.
1 #ifndef LOG_INTERPOLATE_H
2 #define LOG_INTERPOLATE_H
3 #include "linear_interpolate.h"
4 #include <vector>
5 #include <boost/shared_ptr.hpp>
6 #include <boost/foreach.hpp>
7 #include <cmath>
8 
9 namespace FullPhysics {
10 /****************************************************************/
14 template<class TX, class TY> class LogLinearInterpolate :
15  public Printable<LogLinearInterpolate<TX,TY> > {
16 public:
17  typedef typename
19 
20 //-----------------------------------------------------------------------
23 //-----------------------------------------------------------------------
24 
26  // Gcc 4.2 does not like having template default arugment. As an
27  // easy workaround, use the hardcoded value for extrapolate
28  // template<class I1, class I2> LogLinearInterpolate(I1 xstart, I1 xend,
29  // I2 ystart, BehaviorOutOfRange Out_of_range =
30  // LinearInterpolate<TX, TY>::OUT_OF_RANGE_EXTRAPOLATE)
31  template<class I1, class I2> LogLinearInterpolate(I1 xstart, I1 xend,
32  I2 ystart, BehaviorOutOfRange Out_of_range = BehaviorOutOfRange(0))
33  {
34  std::vector<TX> xval(xstart, xend);
35  BOOST_FOREACH(TX &x ,xval)
36  x = std::log(x);
37  interp = LinearInterpolate<TX,TY>(xval.begin(), xval.end(), ystart,
38  Out_of_range);
39  }
40  TY operator()(const TX& x) const
41  {
42  return interp(std::log(x));
43  }
44  void print(std::ostream& Os) const { Os << "LogLinearInterpolate"; }
45 private:
47 };
48 
49 /****************************************************************/
53 template<class TX, class TY> class LogLogInterpolate :
54  public Printable<LogLogInterpolate<TX, TY> > {
55 public:
56  typedef typename
59  // Gcc 4.2 does not like having template default arugment. As an
60  // easy workaround, use the hardcoded value for extrapolate
61  // template<class I1, class I2> LogLogInterpolate(I1 xstart, I1 xend,
62  // I2 ystart, BehaviorOutOfRange Out_of_range =
63  // LinearInterpolate<TX, TY>::OUT_OF_RANGE_EXTRAPOLATE)
64  template<class I1, class I2> LogLogInterpolate(I1 xstart, I1 xend,
65  I2 ystart, BehaviorOutOfRange Out_of_range = BehaviorOutOfRange(0))
66  {
67  std::vector<TX> xval;
68  std::vector<TY> yval;
69  for(; xstart != xend; ++xstart, ++ystart) {
70  xval.push_back(std::log(*xstart));
71  yval.push_back(std::log(*ystart));
72  }
73  interp = LinearInterpolate<TX, TY>(xval.begin(), xval.end(), yval.begin(),
74  Out_of_range);
75  }
76  TY operator()(const TX& x) const
77  {
78  return std::exp(interp(std::log(x)));
79  }
80  void print(std::ostream& Os) const { Os << "LogLogInterpolate"; }
81 private:
83 };
84 
85 /****************************************************************/
88 template<> class LogLogInterpolate<AutoDerivative<double>, AutoDerivative<double> >:
89  public Printable<LogLogInterpolate<AutoDerivative<double>, AutoDerivative<double> > > {
90 public:
93  // Gcc 4.2 does not like having template default arugment. As an
94  // easy workaround, use the hardcoded value for extrapolate
95  // template<class I1, class I2> LogLogInterpolate(I1 xstart, I1 xend,
96  // I2 ystart, BehaviorOutOfRange Out_of_range =
97  // LinearInterpolate<AutoDerivative<double>, AutoDerivative<double> >::OUT_OF_RANGE_EXTRAPOLATE)
98  template<class I1, class I2> LogLogInterpolate(I1 xstart, I1 xend,
99  I2 ystart, BehaviorOutOfRange Out_of_range = BehaviorOutOfRange(0))
100  {
101  std::vector<AutoDerivative<double> > xval;
102  std::vector<AutoDerivative<double> > yval;
103  for(; xstart != xend; ++xstart, ++ystart) {
104  xval.push_back(std::log(*xstart));
105  yval.push_back(std::log(*ystart));
106  }
107  interp = LinearInterpolate<AutoDerivative<double>, AutoDerivative<double> >(xval.begin(), xval.end(), yval.begin(),
108  Out_of_range);
109  }
111  {
112  return std::exp(interp(std::log(x)));
113  }
114 
116  const AutoDerivativeRef<double>& res) const
117  {
118  interp.interpolate(std::log(x), res);
119  res = std::exp(res);
120  }
121 
122  void print(std::ostream& Os) const { Os << "LogLogInterpolate"; }
123 private:
124  LinearInterpolate<AutoDerivative<double>, AutoDerivative<double> > interp;
125 };
126 
127 /****************************************************************/
131 template<class TX, class TY> class LinearLogInterpolate :
132  public Printable<LinearLogInterpolate<TX, TY> > {
133 public:
134  typedef typename
137  // Gcc 4.2 does not like having template default arugment. As an
138  // easy workaround, use the hardcoded value for extrapolate
139  // template<class I1, class I2> LinearLogInterpolate(I1 xstart, I1 xend,
140  // I2 ystart, BehaviorOutOfRange Out_of_range =
141  // LinearInterpolate<TX, TY>::OUT_OF_RANGE_EXTRAPOLATE)
142  template<class I1, class I2> LinearLogInterpolate(I1 xstart, I1 xend,
143  I2 ystart, BehaviorOutOfRange Out_of_range = BehaviorOutOfRange(0))
144  {
145  std::vector<TX> xval;
146  std::vector<TY> yval;
147  for(; xstart != xend; ++xstart, ++ystart) {
148  xval.push_back(*xstart);
149  yval.push_back(std::log(*ystart));
150  }
151  interp = LinearInterpolate<TX, TY>(xval.begin(), xval.end(), yval.begin(),
152  Out_of_range);
153  }
154  TY operator()(const TX& x) const
155  {
156  return std::exp(interp(x));
157  }
158  void print(std::ostream& Os) const { Os << "LinearLogInterpolate"; }
159 private:
161 };
162 
163 /****************************************************************/
166 template<> class LinearLogInterpolate<AutoDerivative<double>, AutoDerivative<double> >:
167  public Printable<LinearLogInterpolate<AutoDerivative<double>, AutoDerivative<double> > > {
168 public:
169  typedef LinearInterpolate<AutoDerivative<double>, AutoDerivative<double> >::BehaviorOutOfRange BehaviorOutOfRange;
171  // Gcc 4.2 does not like having template default arugment. As an
172  // easy workaround, use the hardcoded value for extrapolate
173  // template<class I1, class I2> LinearLogInterpolate(I1 xstart, I1 xend,
174  // I2 ystart, BehaviorOutOfRange Out_of_range =
175  // LinearInterpolate<AutoDerivative<double>, AutoDerivative<double> >::OUT_OF_RANGE_EXTRAPOLATE)
176  template<class I1, class I2> LinearLogInterpolate(I1 xstart, I1 xend,
177  I2 ystart, BehaviorOutOfRange Out_of_range = BehaviorOutOfRange(0))
178  {
179  std::vector<AutoDerivative<double> > xval;
180  std::vector<AutoDerivative<double> > yval;
181  for(; xstart != xend; ++xstart, ++ystart) {
182  xval.push_back(*xstart);
183  yval.push_back(std::log(*ystart));
184  }
185  interp = LinearInterpolate<AutoDerivative<double>, AutoDerivative<double> >(xval.begin(), xval.end(), yval.begin(),
186  Out_of_range);
187  }
189  {
190  return std::exp(interp(x));
191  }
192 
194  const AutoDerivativeRef<double>& res) const
195  {
196  interp.interpolate(x, res);
197  res = std::exp(res);
198  }
199 
200  void print(std::ostream& Os) const { Os << "LinearLogInterpolate"; }
201 private:
202  LinearInterpolate<AutoDerivative<double>, AutoDerivative<double> > interp;
203 };
204 
205 
206 }
207 #endif
LinearInterpolate< TX, TY >::BehaviorOutOfRange BehaviorOutOfRange
TY operator()(const TX &x) const
TY operator()(const TX &x) const
void print(std::ostream &Os) const
LinearInterpolate< TX, TY >::BehaviorOutOfRange BehaviorOutOfRange
LinearInterpolate< TX, TY >::BehaviorOutOfRange BehaviorOutOfRange
This class takes a set of points and values, and linearly interpolates between those values...
Wrapper around LinearInterpolate that uses log(y) rather than x and y when interpolating.
void print(std::ostream &Os) const
Wrapper around LinearInterpolate that uses log(x) rather than x in interpolating. ...
Helper class that gives us a reference that we can assign a AutoDerivative to and write into the corr...
LinearLogInterpolate(I1 xstart, I1 xend, I2 ystart, BehaviorOutOfRange Out_of_range=BehaviorOutOfRange(0))
AutoDerivative< double > operator()(const AutoDerivative< double > &x) const
This is a Mixin for classes that can be printed.
Definition: printable.h:24
void interpolate(const AutoDerivative< double > &x, const AutoDerivativeRef< double > &res) const
LogLinearInterpolate(I1 xstart, I1 xend, I2 ystart, BehaviorOutOfRange Out_of_range=BehaviorOutOfRange(0))
LinearInterpolate< AutoDerivative< double >, AutoDerivative< double > >::BehaviorOutOfRange BehaviorOutOfRange
LinearInterpolate< AutoDerivative< double >, AutoDerivative< double > >::BehaviorOutOfRange BehaviorOutOfRange
There are a number of tools that can be used to do "Automatic Differentiation" (see for example http:...
void interpolate(const AutoDerivative< double > &x, const AutoDerivativeRef< double > &res) const
LogLogInterpolate(I1 xstart, I1 xend, I2 ystart, BehaviorOutOfRange Out_of_range=BehaviorOutOfRange(0))
AutoDerivative< double > operator()(const AutoDerivative< double > &x) const
TY operator()(const TX &x) const
LinearLogInterpolate(I1 xstart, I1 xend, I2 ystart, BehaviorOutOfRange Out_of_range=BehaviorOutOfRange(0))
Wrapper around LinearInterpolate that uses log(x) and log(y) rather than x and y when interpolating...
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
LogLogInterpolate(I1 xstart, I1 xend, I2 ystart, BehaviorOutOfRange Out_of_range=BehaviorOutOfRange(0))
void print(std::ostream &Os) const

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:11