25 template<
typename T,
int N,
int M>
33 template<
typename T,
int N,
int M>
34 adoreMatrix<T, N, 1>
evaluate_poly(
const adoreMatrix<T, N, M + 1>& data,
const T &
x)
36 adoreMatrix<T, N, 1>
y = dlib::colm(data, M);
37 for (
int i = M - 1; i >= 0; i--)
40 y =
y + dlib::colm(data, i);
51 template<
typename T,
int N,
int M>
52 adoreMatrix<T, N, M + 1>
stretch_poly_parameters(adoreMatrix<T, N, M + 1> data,
const T& a,
const T& b,
const T& c,
const T& d)
54 T s = (b - a) / (d - c);
56 adoreMatrix<T, N, 1> y_tmp;
57 adoreMatrix<T, 1, M + 1> ones_data = dlib::ones_matrix<T>(1, M + 1);
58 adoreMatrix<T, N, M + 1> new_data = dlib::zeros_matrix<T>(N, M + 1);
59 set_colm(new_data, 0) = evaluate_poly<T, N, M>(data, -c*s + a);
60 for (
int i = 1; i <= M; i++)
65 poly_parameter_derivative<T, N, M>(data);
66 poly_parameter_derivative<T, 1, M>(ones_data);
67 set_colm(new_data, i) = evaluate_poly<T, N, M>(data, -c*s + a) / ones_data(0) * si;
75 template<
typename T,
int N,
int M>
78 for (
int i = 0; i < M; i++)
80 dlib::set_colm(p, i) = dlib::colm(p, i + 1) * (T)(i + 1);
82 dlib::set_colm(p, M) = dlib::zeros_matrix<T>(N, 1);
90 template<
typename T,
int M>
93 adoreMatrix<T, 1, M + 1> ones_data = dlib::ones_matrix<T>(1, M + 1);
94 adoreMatrix<T, 1, M + 1> new_data = dlib::zeros_matrix<T>(1, M + 1);
96 for (
int i = 1; i <= M; i++)
98 poly_parameter_derivative<T, 1, M>(ones_data);
99 new_data(i) = c(i) / ones_data(0);
108 template<
typename T,
int N,
int M>
109 void bound_poly(
const adoreMatrix<T, N, M + 1>& data,
const T&
x0,
const T&
x1, adoreMatrix<T, N, 1> & ymin, adoreMatrix<T, N, 1> & ymax)
111 adoreMatrix<T, N, M + 1> n_data = stretch_poly_parameters<T, N, M>(data,
x0,
x1, 0, 1);
112 ymin = colm(n_data, 0);
114 adoreMatrix<T, N, 1> b;
117 for (
int k = 0; k <= M; k++)
119 b = dlib::zeros_matrix<T>(N, 1);
120 for (
int r = 0;
r <= k;
r++)
124 T c = k_choose_r / M_choose_r;
125 for (
int j = 0; j < N; j++)
127 b(j) += n_data(j,
r)*c;
138 template<
typename T,
int M>
151 return evaluate_poly<T, 1, M>(
m_data,
x)(0);
179 new_data = dlib::colm(
m_data, dlib::range(1, M));
180 for (
int i = 0; i < M; i++)
182 new_data(0, i) = new_data(0, i) * (T)(i + 1);
187 virtual void bound(
const DT& xmin,
const DT& xmax,
CT& ymin,
CT& ymax)
override
189 adoreMatrix<T, 1, 1> ymin_tmp;
190 adoreMatrix<T, 1, 1> ymax_tmp;
191 bound_poly<T, 1, M>(
m_data, xmin, xmax, ymin_tmp, ymax_tmp);
200 template<
typename T,
int N,
int M>
208 typedef adoreMatrix<T, N, 1>
CT;
213 for (
int i = 0; i < N; i++)
222 return evaluate_poly<T, N, M>(
m_data,
x);
251 adoreMatrix<T, N, M> new_data;
252 new_data = dlib::colm(
m_data, dlib::range(1, M));
253 for (
int i = 0; i < M; i++)
255 dlib::set_colm(new_data, i) = dlib::colm(
m_data, i + 1) * (T)(i + 1);
261 virtual void bound(
const DT& xmin,
const DT& xmax,
CT& ymin,
CT& ymax)
override
263 bound_poly<T, N, M>(
m_data, xmin, xmax, ymin, ymax);
282 auto scalar =
clone();
283 auto der = scalar->create_derivative();
287 virtual void bound(
const DT& xmin,
const DT& xmax, T& ymin, T& ymax)
override
289 adoreMatrix<T, 1, 1> ymin_tmp;
290 adoreMatrix<T, 1, 1> ymax_tmp;
299 virtual T
fi(T
x,
int row)
const override
301 return evaluate_poly<T, 1, M>(rowm(
m_data, row),
x)(0);
307 virtual void multiply(adoreMatrix<T, 0, 0> A,
int rowi,
int rowj)
override
309 dlib::set_subm(
m_data, dlib::range(rowi, rowj),dlib::range(1,M)) = A * dlib::subm(
m_data, dlib::range(rowi, rowj),dlib::range(1,M));
311 virtual void add(adoreMatrix<T, 0, 1> b,
int rowi,
int rowj)
override
313 dlib::set_subm(
m_data, dlib::range(rowi, rowj), dlib::range(0, 0)) = subm(
m_data, dlib::range(rowi, rowj), dlib::range(0, 0)) + b;
#define adoreMatrix
Definition: adoremath.h:31
Definition: alfunction.h:74
Definition: alfunction.h:214
T DT
Definition: alfunction.h:216
adoreMatrix< T, N, 1 > CT
Definition: alfunction.h:217
Definition: alfunction.h:38
Definition: lpolynomial.h:268
virtual void setLimits(DT lo, DT hi) override
Definition: lpolynomial.h:278
LPolynomialM * m_parent
Definition: lpolynomial.h:270
virtual ALFunction< DT, T > * clone() override
Definition: lpolynomial.h:279
OneDimension()
Definition: lpolynomial.h:273
OneDimension(LPolynomialM *parent, int row)
Definition: lpolynomial.h:274
int m_row
Definition: lpolynomial.h:271
virtual void bound(const DT &xmin, const DT &xmax, T &ymin, T &ymax) override
Definition: lpolynomial.h:287
virtual T f(DT x) const override
Definition: lpolynomial.h:275
virtual DT limitLo() const override
Definition: lpolynomial.h:277
virtual DT limitHi() const override
Definition: lpolynomial.h:276
virtual ALFunction< DT, T > * create_derivative() override
Definition: lpolynomial.h:280
Definition: lpolynomial.h:202
virtual ALFunction< DT, CT > * clone() override
Definition: lpolynomial.h:239
virtual T fi(T x, int row) const override
Definition: lpolynomial.h:299
virtual void multiply(adoreMatrix< T, 0, 0 > A, int rowi, int rowj) override
Definition: lpolynomial.h:307
virtual ALFunction< DT, CT > * create_derivative() override
Definition: lpolynomial.h:243
LPolynomialM(const adoreMatrix< T, N, M+1 > &data, T xmin, T xmax)
Definition: lpolynomial.h:211
T DT
Definition: lpolynomial.h:209
virtual void setLimits(DT lo, DT hi) override
Definition: lpolynomial.h:234
T m_xmax
Definition: lpolynomial.h:206
virtual SUBFUN * dimension(int i) override
Definition: lpolynomial.h:303
virtual DT limitHi() const override
Definition: lpolynomial.h:224
T m_xmin
Definition: lpolynomial.h:205
virtual DT limitLo() const override
Definition: lpolynomial.h:229
OneDimension single_dimensions[N]
Definition: lpolynomial.h:296
virtual void add(adoreMatrix< T, 0, 1 > b, int rowi, int rowj) override
Definition: lpolynomial.h:311
virtual CT f(DT x) const override
Definition: lpolynomial.h:220
adoreMatrix< T, N, M+1 > m_data
Definition: lpolynomial.h:204
adoreMatrix< T, N, 1 > CT
Definition: lpolynomial.h:208
ALFunction< T, T > SUBFUN
Definition: lpolynomial.h:298
virtual void bound(const DT &xmin, const DT &xmax, CT &ymin, CT &ymax) override
Definition: lpolynomial.h:261
Definition: lpolynomial.h:140
virtual void setLimits(DT lo, DT hi) override
Definition: lpolynomial.h:161
virtual ALFunction< DT, CT > * create_derivative() override
Definition: lpolynomial.h:170
T DT
Definition: lpolynomial.h:142
virtual void bound(const DT &xmin, const DT &xmax, CT &ymin, CT &ymax) override
Definition: lpolynomial.h:187
virtual ALFunction< DT, CT > * clone() override
Definition: lpolynomial.h:166
T CT
Definition: lpolynomial.h:143
DT m_xmin
Definition: lpolynomial.h:145
virtual CT f(DT x) const override
Definition: lpolynomial.h:149
adoreMatrix< T, 1, M+1 > m_data
Definition: lpolynomial.h:144
DT m_xmax
Definition: lpolynomial.h:145
virtual DT limitHi() const override
Definition: lpolynomial.h:153
virtual DT limitLo() const override
Definition: lpolynomial.h:157
LPolynomialS(const adoreMatrix< T, 1, M+1 > &data, DT xmin, DT xmax)
Definition: lpolynomial.h:147
adoreMatrix< T, N, M+1 > stretch_poly_parameters(adoreMatrix< T, N, M+1 > data, const T &a, const T &b, const T &c, const T &d)
Definition: lpolynomial.h:52
adoreMatrix< T, N, 1 > evaluate_poly(const adoreMatrix< T, N, M+1 > &data, const T &x)
Definition: lpolynomial.h:34
void poly_parameter_derivative(adoreMatrix< T, N, M+1 > &p)
Definition: lpolynomial.h:76
adoreMatrix< T, 1, M+1 > poly_parameter_for_initial_condition(adoreMatrix< T, M+1, 1 > c)
Definition: lpolynomial.h:91
void bound_poly(const adoreMatrix< T, N, M+1 > &data, const T &x0, const T &x1, adoreMatrix< T, N, 1 > &ymin, adoreMatrix< T, N, 1 > &ymax)
Definition: lpolynomial.h:109
int binomial(int n, int k)
Definition: adoremath.h:161
T min(T a, T b, T c, T d)
Definition: adoremath.h:663
adoreMatrix< T, N, M > max(adoreMatrix< T, N, M > a, const adoreMatrix< T, N, M > &b)
Definition: adoremath.h:686
x0
Definition: adore_set_goal.py:25
x
Definition: adore_set_goal.py:30
y
Definition: adore_set_goal.py:31
x1
Definition: adore_set_pose.py:28
r
Definition: adore_suppress_lanechanges.py:209
Definition: areaofeffectconverter.h:20