Drake
system_identification.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <set>
5 #include <stdexcept>
6 #include <string>
7 #include <tuple>
8 #include <utility>
9 #include <vector>
10 
13 #include "drake/common/trig_poly.h"
14 
15 namespace drake {
16 namespace solvers {
17 
19 
40 template <typename CoefficientType>
42  public:
43  typedef ::Polynomial<CoefficientType> PolyType;
44  typedef typename PolyType::Monomial MonomialType;
45  typedef typename PolyType::Term TermType;
46  typedef typename PolyType::VarType VarType;
47  typedef std::map<PolyType, VarType> LumpingMapType;
48  typedef std::map<VarType, CoefficientType> PartialEvalType;
49 
51 
68  static LumpingMapType GetLumpedParametersFromPolynomial(
69  const PolyType& poly,
70  const std::set<VarType>& parameter_vars);
71 
73 
78  static LumpingMapType GetLumpedParametersFromPolynomials(
79  const std::vector<PolyType>& polys,
80  const std::set<VarType>& parameter_vars);
81 
83 
92  const PolyType& poly,
93  const LumpingMapType& lumped_parameters);
94 
109  static std::pair<PartialEvalType, CoefficientType> EstimateParameters(
110  const VectorXPoly& polys,
111  const std::vector<PartialEvalType>& active_var_values);
112 
116  LumpingMapType lumped_parameters;
117 
121 
123  PartialEvalType lumped_parameter_values;
124 
128 
130  CoefficientType rms_error;
131  };
132 
149  const VectorXTrigPoly& polys,
150  const std::vector<PartialEvalType>& active_var_values);
151 
152 
153  private:
155  SystemIdentification() = delete;
157 
158 
159 
169  static std::set<MonomialType>
170  GetAllCombinationsOfVars(
171  const std::vector<PolyType>& polys,
172  const std::set<VarType>& vars);
173 
175 
183  static bool MonomialMatches(
184  const MonomialType& haystack,
185  const MonomialType& needle,
186  const std::set<VarType>& active_vars);
187 
189 
199  static std::pair<CoefficientType, PolyType>
200  CanonicalizePolynomial(const PolyType& poly);
201 
204  static VarType CreateUnusedVar(const std::string& prefix,
205  const std::set<VarType>& vars_in_use);
206 
217  static std::tuple<const std::set<VarType>,
218  const std::set<VarType>,
219  const std::set<VarType>> ClassifyVars(
220  const std::vector<Polynomiald>& polys,
221  const std::vector<PartialEvalType>& active_var_values);
222 };
223 } // namespace solvers
224 } // namespace drake
static PolyType RewritePolynomialWithLumpedParameters(const PolyType &poly, const LumpingMapType &lumped_parameters)
Rewrite a Polynomial in terms of lumped parameters.
Definition: system_identification.cc:165
PartialEvalType lumped_parameter_values
The estimated value for each lumped parameter.
Definition: system_identification.h:123
static std::pair< PartialEvalType, CoefficientType > EstimateParameters(const VectorXPoly &polys, const std::vector< PartialEvalType > &active_var_values)
Estimate some parameters of a polynomial based on empirical data.
Definition: system_identification.cc:243
Eigen::Matrix< Polynomiald, Eigen::Dynamic, 1 > VectorXPoly
A column vector of polynomials; used in several optimization classes.
Definition: polynomial.h:502
NOTE: The contents of this class are for the most part direct ports of drake/systems/plants//inverseK...
Definition: automotive_demo.cc:88
std::map< VarType, CoefficientType > PartialEvalType
Definition: system_identification.h:48
STL namespace.
LumpingMapType lumped_parameters
The lumped parameters that were used in system ID.
Definition: system_identification.h:116
Utility functions for system identification.
Definition: system_identification.h:41
A scalar multi-variate polynomial, modeled after the msspoly in spotless.
Definition: polynomial.h:42
CoefficientType rms_error
The root-mean-square error of the estimation step.
Definition: system_identification.h:130
std::vector< double > vector
Definition: translator_test.cc:20
static LumpingMapType GetLumpedParametersFromPolynomials(const std::vector< PolyType > &polys, const std::set< VarType > &parameter_vars)
Same as GetLumpedParametersFromPolynomial but for multiple Polynomials.
Definition: system_identification.cc:87
PolyType::Term TermType
Definition: system_identification.h:45
::Polynomial< CoefficientType > PolyType
Definition: system_identification.h:43
A helper struct to hold System ID results.
Definition: system_identification.h:114
static LumpingMapType GetLumpedParametersFromPolynomial(const PolyType &poly, const std::set< VarType > &parameter_vars)
Extract lumped parameters from a given polynomial.
Definition: system_identification.cc:77
unsigned int VarType
Definition: polynomial.h:45
VectorXTrigPoly lumped_polys
The input polynomials, rewritten using the lumped parameters so that only active variable and first-o...
Definition: system_identification.h:120
const VectorXDecisionVariable * vars
Definition: nlopt_solver.cc:103
std::map< PolyType, VarType > LumpingMapType
Definition: system_identification.h:47
static SystemIdentificationResult LumpedSystemIdentification(const VectorXTrigPoly &polys, const std::vector< PartialEvalType > &active_var_values)
Performs full lumped-parameter identification of a system of TrigPolys.
Definition: system_identification.cc:332
Eigen::Matrix< TrigPolyd, Eigen::Dynamic, 1 > VectorXTrigPoly
A column vector of TrigPoly; used in several optimization classes.
Definition: trig_poly.h:463
PolyType::Monomial MonomialType
Definition: system_identification.h:44
#define DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(Classname)
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN deletes the special member functions for copy-construction, copy-assignment, move-construction, and move-assignment.
Definition: drake_copyable.h:35
VectorXTrigPoly partially_evaluated_polys
The input polynomials, with all estimates substituted in so that only active variables remain...
Definition: system_identification.h:127
Provides careful macros to selectively enable or disable the special member functions for copy-constr...
PolyType::VarType VarType
Definition: system_identification.h:46