28#include "gsl/gsl_sf_pow_int.h"
33std::vector< std::vector< std::vector<int> > >
Tanh::_tdi;
35Tanh::Tanh(
double x0,
double lambda,
int max_index) : _x0(x0), _lambda(lambda) {
42 return new Tanh(*
this);
48 double lam_n = gsl_sf_pow_int(
_lambda,
n);
50 for (
size_t i = 0; i <
_tdi[
n].size(); i++)
51 t += 1./lam_n*
static_cast<double>(
_tdi[
n][i][0])
52 *gsl_sf_pow_int(tanh_x,
_tdi[
n][i][1]);
59 double lam_n = gsl_sf_pow_int(
_lambda,
n);
61 for (
size_t i = 0; i <
_tdi[
n].size(); i++) {
62 t += 1./lam_n*
static_cast<double>(
_tdi[
n][i][0])
63 *gsl_sf_pow_int(tanh_x,
_tdi[
n][i][1]);
79 if (
_tdi.size() == 0) {
80 _tdi.push_back(std::vector< std::vector<int> >(1, std::vector<int>(2)));
84 for (
size_t i =
_tdi.size(); i <
n+1; ++i) {
85 _tdi.push_back(std::vector< std::vector<int> >());
86 for (
size_t j = 0; j <
_tdi[i-1].size(); ++j) {
87 int value =
_tdi[i-1][j][1];
89 std::vector<int> new_vec(
_tdi[i-1][j]);
92 _tdi[i].push_back(new_vec);
93 std::vector<int> new_vec2(
_tdi[i-1][j]);
94 new_vec2[0] *= -value;
96 _tdi[i].push_back(new_vec2);
114 out <<
"Tanh model with centre length: " <<
_x0
Tps< T > tanh(const Tps< T > &x)
Hyperbolic tangent.
std::vector< std::vector< int > > CompactVector(std::vector< std::vector< int > > vec)
Calculate the Tanh function (e.g.
virtual void setMaximumDerivative(size_t n)
Set the maximum derivative prior to tracking.
static void setTanhDiffIndices(size_t n)
Set the value of tanh differential indices to nth order differentials.
double function(double x, int n) const
Double Tanh is given by .
double getNegTanh(double x, int n) const
Returns the value of tanh((x-x0)/lambda) or its derivative.
std::ostream & print(std::ostream &out) const
Prints a human readable string to out.
static std::vector< std::vector< int > > getTanhDiffIndices(size_t n)
Get all the tanh differential indices .
void rescale(double scaleFactor)
Rescale the end field by a factor x0.
~Tanh()
Destructor (no mallocs so does nothing)
Tanh * clone() const
Inherited copy constructor.
static std::vector< std::vector< std::vector< int > > > _tdi
_tdi indexes powers of tanh in d^n tanh/dx^n as sum of powers of tanh
Tanh()
Default constructor (initialises x0 and lambda to 0)
double getTanh(double x, int n) const
Returns the value of tanh((x+x0)/lambda) or its derivative.