gradient-ascent.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018,
3  * Julian Viereck
4  *
5  * CNRS/AIST
6  *
7  */
8 
10 #include <dynamic-graph/factory.h>
11 
12 #include <boost/function.hpp>
13 #include <sot/core/factory.hh>
15 
16 namespace dg = ::dynamicgraph;
17 
18 /* ---------------------------------------------------------------------------*/
19 /* ------- GENERIC HELPERS -------------------------------------------------- */
20 /* ---------------------------------------------------------------------------*/
21 
22 namespace dynamicgraph {
23 namespace sot {
24 
25 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(GradientAscent, "GradientAscent");
26 
27 /* --------------------------------------------------------------------- */
28 /* --- CLASS ----------------------------------------------------------- */
29 /* --------------------------------------------------------------------- */
30 
31 GradientAscent::GradientAscent(const std::string &n)
32  : Entity(n),
33  gradientSIN(NULL, "GradientAscent(" + n + ")::input(vector)::gradient"),
34  learningRateSIN(NULL,
35  "GradientAscent(" + n + ")::input(double)::learningRate"),
36  refresherSINTERN("GradientAscent(" + n + ")::intern(dummy)::refresher"),
37  valueSOUT(boost::bind(&GradientAscent::update, this, _1, _2),
38  gradientSIN << refresherSINTERN,
39  "GradientAscent(" + n + ")::output(vector)::value"),
40  init(false) {
41  // Register signals into the entity.
44 }
45 
47 
48 /* --- COMPUTE ----------------------------------------------------------- */
49 /* --- COMPUTE ----------------------------------------------------------- */
50 /* --- COMPUTE ----------------------------------------------------------- */
51 
53  const sigtime_t &inTime) {
54  const dynamicgraph::Vector &gradient = gradientSIN(inTime);
55  const double &learningRate = learningRateSIN(inTime);
56 
57  if (init == false) {
58  init = true;
59  value = gradient;
60  value.setZero();
61  res.resize(value.size());
62  }
63 
64  value += learningRate * gradient;
65  res = value;
66  return res;
67 }
68 
69 } /* namespace sot */
70 } /* namespace dynamicgraph */
dynamicgraph::sot::GradientAscent
Definition: gradient-ascent.hh:33
dynamicgraph::TimeDependency
factory.hh
dynamicgraph::sot::GradientAscent::learningRateSIN
SignalPtr< double, sigtime_t > learningRateSIN
Definition: gradient-ascent.hh:38
dynamicgraph
dynamicgraph::Entity
boost
dynamicgraph::sot::GradientAscent::update
dynamicgraph::Vector & update(dynamicgraph::Vector &res, const sigtime_t &inTime)
Definition: gradient-ascent.cpp:52
dynamicgraph::sot::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeaturePosture, "FeaturePosture")
res
res
dynamicgraph::sot::GradientAscent::GradientAscent
GradientAscent(const std::string &n)
Definition: gradient-ascent.cpp:31
dynamicgraph::sigtime_t
int64_t sigtime_t
dynamicgraph::sot::GradientAscent::value
dynamicgraph::Vector value
Definition: gradient-ascent.hh:50
dynamicgraph::sot::GradientAscent::~GradientAscent
virtual ~GradientAscent(void)
Definition: gradient-ascent.cpp:46
dynamicgraph::sot::GradientAscent::gradientSIN
SignalPtr< dynamicgraph::Vector, sigtime_t > gradientSIN
Definition: gradient-ascent.hh:37
gradient-ascent.hh
dynamicgraph::Vector
Eigen::VectorXd Vector
update
AABB & update(const Vec3f &a, const Vec3f &b)
dynamicgraph::sot::GradientAscent::refresherSINTERN
SignalTimeDependent< size_type, sigtime_t > refresherSINTERN
Definition: gradient-ascent.hh:39
all-commands.h
init
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
n
Vec3f n
dynamicgraph::sot::GradientAscent::valueSOUT
SignalTimeDependent< dynamicgraph::Vector, sigtime_t > valueSOUT
Definition: gradient-ascent.hh:40


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:31