6 #include "../activations/ActivationBase.hpp" 13 template <typename SCALAR, typename TRAIT = typename ct::core::tpl::TraitSelector<SCALAR>::Trait>
20 const SCALAR activation_offset,
21 const SCALAR period_offset)
22 : active_percentage_(active_percentage),
24 activation_offset_(activation_offset),
25 period_offset_(period_offset)
30 : active_percentage_(arg.active_percentage_),
32 activation_offset_(arg.activation_offset_),
33 period_offset_(arg.period_offset_),
38 virtual void loadConfigFile(
const std::string& filename,
const std::string& termName,
bool verbose =
false)
override 40 boost::property_tree::ptree pt;
41 boost::property_tree::read_info(filename, pt);
43 active_percentage_ = pt.get<
SCALAR>(termName +
".active_percentage");
44 period_ = pt.get<
SCALAR>(termName +
".period");
45 activation_offset_ = pt.get<
SCALAR>(termName +
".activation_offset");
46 period_offset_ = pt.get<
SCALAR>(termName +
".period_offset");
47 t_end_ = pt.get<
SCALAR>(termName +
".t_end");
49 if (activation_offset_ + active_percentage_ * period_ > period_)
51 throw std::runtime_error(
52 "Activation offset plus active period percentage exceed period time. Adjust settings");
61 template <
typename S = SCALAR>
65 if (t >= period_offset_ && t < t_end_)
67 SCALAR t0 = t - period_offset_;
68 SCALAR t0norm = fmod(t0, period_);
69 if (t0norm >= activation_offset_ && t0norm < (activation_offset_ + active_percentage_ * period_))
75 template <
typename S = SCALAR>
84 std::cout <<
"Cost function active at periodic times: " << std::endl;
85 std::cout <<
"Period: " << period_ <<
"\nOffset after period start: " << activation_offset_ <<
"s" 87 std::cout <<
"Offset between t0: " << period_offset_ <<
"s" << std::endl;
88 std::cout <<
"Active for " << 100 * active_percentage_ <<
"% of the period" << std::endl;
std::enable_if<!std::is_same< S, double >::value, bool >::type isActiveSpecialized(const SCALAR t)
Definition: PeriodicActivation.hpp:76
virtual void printInfo() override
print to console
Definition: PeriodicActivation.hpp:82
PeriodicActivation(const PeriodicActivation &arg)
Definition: PeriodicActivation.hpp:29
virtual bool isActive(const SCALAR t) override
return if term is active
Definition: PeriodicActivation.hpp:60
PeriodicActivation()
Definition: PeriodicActivation.hpp:17
CppAD::AD< CppAD::cg::CG< double > > SCALAR
Definition: PeriodicActivation.hpp:14
Definition: ActivationBase.hpp:18
std::enable_if< std::is_same< S, double >::value, bool >::type isActiveSpecialized(const SCALAR t)
Definition: PeriodicActivation.hpp:62
const bool verbose
Definition: JacobianCGTest.h:19
virtual ~PeriodicActivation()
Definition: PeriodicActivation.hpp:28
virtual SCALAR computeActivation(const SCALAR t) override
compute activation multiplier based on scalar input
Definition: PeriodicActivation.hpp:81
virtual void loadConfigFile(const std::string &filename, const std::string &termName, bool verbose=false) override
load activations from file
Definition: PeriodicActivation.hpp:38
PeriodicActivation(const SCALAR active_percentage, const SCALAR period, const SCALAR activation_offset, const SCALAR period_offset)
Definition: PeriodicActivation.hpp:18