- 3.0.2 core module.
RBFGaussActivation.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <cmath>
5 #include <math.h>
6 
7 #include "../activations/ActivationBase.hpp"
9 
10 namespace ct {
11 namespace core {
12 namespace tpl {
13 
14 template <typename SCALAR, typename TRAIT = typename ct::core::tpl::TraitSelector<SCALAR>::Trait>
15 class RBFGaussActivation : public ActivationBase<SCALAR>
16 {
17 public:
19  RBFGaussActivation(const SCALAR mu, const SCALAR sigma) : mu_(mu), sigma_(sigma)
20  {
21  sigma2inv_ = SCALAR(1.0) / (SCALAR(2.0) * sigma_ * sigma_);
22  factor_ = SCALAR(1.0) / sqrt(SCALAR(2.0) * M_PI * sigma_ * sigma_);
23  }
24  virtual ~RBFGaussActivation() {}
26  : mu_(arg.mu_), sigma_(arg.sigma_), sigma2inv_(arg.sigma2inv_), factor_(arg.factor_)
27  {
28  }
29 
30  virtual void loadConfigFile(const std::string& filename, const std::string& termName, bool verbose = false) override
31  {
32  boost::property_tree::ptree pt;
33  boost::property_tree::read_info(filename, pt);
34  mu_ = pt.get<SCALAR>(termName + ".mu");
35  sigma_ = pt.get<SCALAR>(termName + ".sigma");
36  // factors used for efficient computeActivation calculation
37  sigma2inv_ = -SCALAR(1.0) / (SCALAR(2.0) * sigma_ * sigma_);
38  factor_ = SCALAR(1.0) / sqrt(SCALAR(2.0) * M_PI * sigma_ * sigma_);
39  }
40 
41  virtual bool isActive(const SCALAR t) override { return true; }
42  virtual SCALAR computeActivation(const SCALAR t) override
43  {
44  return factor_ * exp((t - mu_) * (t - mu_) * sigma2inv_);
45  }
46 
47  virtual void printInfo() override
48  {
49  std::cout << "RBF costfunction time activation" << std::endl;
50  std::cout << "mu: " << mu_ << "s \t sigma: " << sigma_ << "s" << std::endl;
51  }
52 
53 private:
54  SCALAR mu_;
55  SCALAR sigma_;
56  SCALAR sigma2inv_;
57  SCALAR factor_;
58 };
59 } //namespace tpl
60 
62 } //namespact core
63 } //namespace ct
RBFGaussActivation(const SCALAR mu, const SCALAR sigma)
Definition: RBFGaussActivation.h:19
virtual bool isActive(const SCALAR t) override
return if term is active
Definition: RBFGaussActivation.h:41
RBFGaussActivation()
Definition: RBFGaussActivation.h:18
virtual void loadConfigFile(const std::string &filename, const std::string &termName, bool verbose=false) override
load activations from file
Definition: RBFGaussActivation.h:30
RBFGaussActivation(const RBFGaussActivation &arg)
Definition: RBFGaussActivation.h:25
Definition: RBFGaussActivation.h:15
CppAD::AD< CppAD::cg::CG< double > > SCALAR
virtual ~RBFGaussActivation()
Definition: RBFGaussActivation.h:24
Definition: ActivationBase.hpp:18
const bool verbose
Definition: JacobianCGTest.h:19
virtual void printInfo() override
print to console
Definition: RBFGaussActivation.h:47
virtual SCALAR computeActivation(const SCALAR t) override
compute activation multiplier based on scalar input
Definition: RBFGaussActivation.h:42