- 3.0.2 core module.
LinearActivation.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../activations/ActivationBase.hpp"
5 
6 namespace ct {
7 namespace core {
8 namespace tpl {
9 
10 template <typename SCALAR, typename TRAIT = typename ct::core::tpl::TraitSelector<SCALAR>::Trait>
11 class LinearActivation : public ActivationBase<SCALAR>
12 {
13 public:
14  LinearActivation() = default;
15  LinearActivation(const SCALAR t_on, const SCALAR t_off, const SCALAR slope, const SCALAR startVal)
16  : t_on_(t_on), t_off_(t_off), slope_(slope), startVal_(startVal)
17  {
18  }
19  virtual ~LinearActivation() = default;
21  : t_on_(arg.t_on_), t_off_(arg.t_off_), slope_(arg.slope_), startVal_(arg.startVal_)
22  {
23  }
24  virtual void loadConfigFile(const std::string& filename, const std::string& termName, bool verbose = false) override
25  {
26  boost::property_tree::ptree pt;
27  boost::property_tree::read_info(filename, pt);
28  t_on_ = pt.get<SCALAR>(termName + ".t_on");
29  t_off_ = pt.get<SCALAR>(termName + ".t_off");
30  slope_ = pt.get<SCALAR>(termName + ".slope");
31  startVal_ = pt.get<SCALAR>(termName + ".startVal");
32  }
33 
35  virtual bool isActive(const SCALAR t) override { return (t >= t_on_ && t < t_off_); }
37  virtual SCALAR computeActivation(const SCALAR t) override { return startVal_ + slope_ * (t - t_on_); }
38  virtual void printInfo() override
39  {
40  std::cout << "Cost function with linear activation active from " << t_on_ << " s with value " << startVal_
41  << ", increasing by " << slope_ << " per second and ending at " << t_off_ << " s." << std::endl;
42  }
43 
44 private:
45  SCALAR t_on_;
46  SCALAR t_off_;
47  SCALAR slope_;
48  SCALAR startVal_;
49 };
50 
51 } // namespace tpl
52 
54 } // namespace core
55 } // namespace ct
Definition: LinearActivation.hpp:11
LinearActivation(const LinearActivation &arg)
Definition: LinearActivation.hpp:20
virtual SCALAR computeActivation(const SCALAR t) override
within this time-window, the activation is saturated
Definition: LinearActivation.hpp:37
virtual void printInfo() override
print to console
Definition: LinearActivation.hpp:38
LinearActivation(const SCALAR t_on, const SCALAR t_off, const SCALAR slope, const SCALAR startVal)
Definition: LinearActivation.hpp:15
CppAD::AD< CppAD::cg::CG< double > > SCALAR
Definition: ActivationBase.hpp:18
const bool verbose
Definition: JacobianCGTest.h:19
virtual void loadConfigFile(const std::string &filename, const std::string &termName, bool verbose=false) override
load activations from file
Definition: LinearActivation.hpp:24
virtual bool isActive(const SCALAR t) override
this activation is active in a strict time window
Definition: LinearActivation.hpp:35
virtual ~LinearActivation()=default