3 #include <fluxionum/FluxionumException.h>
4 #include <fluxionum/AbstractDesignMatrix.h>
5 #include <fluxionum/TemporalDesignMatrix.h>
6 #include <fluxionum/FluxionumTypes.h>
168 template <
typename TimeType,
typename VarType>
215 arma::Col<TimeType>
t;
220 arma::Mat<VarType>
A;
237 vector<string>
const &
columnNames=vector<string>(0),
239 DiffDesignMatrixType
diffType=DiffDesignMatrixType::UNKNOWN
255 arma::Col<TimeType>
const &
t,
256 arma::Mat<VarType>
const &
A,
258 vector<string>
const &
columnNames=vector<string>(0),
259 DiffDesignMatrixType
diffType=DiffDesignMatrixType::UNKNOWN
279 DiffDesignMatrixType
diffType=DiffDesignMatrixType::UNKNOWN
282 std::unordered_map<string, string> kv;
284 size_t const tCol = (size_t) std::strtoul(
285 kv.at(
"TIME_COLUMN").c_str(),
nullptr, 10
287 if(kv.find(
"DIFF_TYPE") != kv.end()){
288 string diffTypeStr = kv.at(
"DIFF_TYPE");
289 string::iterator begin = diffTypeStr.begin();
290 string::iterator end = diffTypeStr.end();
291 std::function<bool(
char const)> filter = [&] (
294 return c==
' ' || c==
'\t';
296 end = std::remove_if(
297 diffTypeStr.begin(), diffTypeStr.end(), filter
299 diffTypeStr = string(begin, end);
300 if(diffTypeStr ==
"FORWARD_FINITE_DIFFERENCES"){
301 diffType = DiffDesignMatrixType::FORWARD_FINITE_DIFFERENCES;
303 else if(diffTypeStr ==
"CENTRAL_FINITE_DIFFERENCES"){
304 diffType = DiffDesignMatrixType::CENTRAL_FINITE_DIFFERENCES;
335 DiffDesignMatrixType
const diffType,
341 case DiffDesignMatrixType::FORWARD_FINITE_DIFFERENCES:{
342 arma::uvec
const tSort = (sort) ?
344 arma::Col<TimeType>
const t = (sort) ?
346 arma::Mat<VarType>
const X = (sort) ?
347 tdm.
getX().rows(tSort) : tdm.
getX();
348 arma::Mat<VarType> DXDT = arma::diff(X, 1, 0);
349 DXDT.each_col() /= arma::diff(
t, 1);
351 t.subvec(0,
t.n_elem-2),
359 case DiffDesignMatrixType::CENTRAL_FINITE_DIFFERENCES:{
360 arma::uvec
const tSort = (sort) ?
362 arma::Col<TimeType>
const t = (sort) ?
364 arma::Mat<VarType>
const X = (sort) ?
365 tdm.
getX().rows(tSort) : tdm.
getX();
366 arma::Col<TimeType> T(
367 (
t.subvec(0,
t.n_elem-2) +
t.subvec(1,
t.n_elem-1))
369 arma::Mat<VarType> DXDT(
370 (X.rows(2, X.n_rows-1) - X.rows(0, X.n_rows-3))
372 DXDT.each_col() /= arma::diff(T, 1);
373 T = T.subvec(0, T.n_elem-2) / 2.0;
384 std::stringstream ss;
385 ss <<
"DiffDesignMatrix::DiffDesignMatrix("
386 "TemporalDesignMatrix const &, DiffType const) failed."
387 "\n\tUnexpected differential type";
405 inline VarType&
operator() (
size_t const i,
size_t const j)
override
481 inline arma::Mat<VarType>
const &
getA()
const {
return A;}
The abstract class which represents the fundamentals of any design matrix.
Definition: AbstractDesignMatrix.h:26
string const & getColumnName(size_t const j) const
Obtain the name of the -th column.
Definition: AbstractDesignMatrix.h:111
vector< string > columnNames
The column names for the DesignMatrix. It can be either an empty vector when no column names are spec...
Definition: AbstractDesignMatrix.h:35
bool hasColumnNames() const
Check whether there are available column names for the AbstractDesignMatrix (true) or not (false)
Definition: AbstractDesignMatrix.h:104
vector< string > const & getColumnNames() const
Obtain a constant/read reference to the column names.
Definition: AbstractDesignMatrix.h:126
arma::Mat< T > const & getX() const
Obtain a constant/read reference to the matrix.
Definition: DesignMatrix.h:219
The heart of a differential design matrix is the idea that the columns are defining the values of var...
Definition: DiffDesignMatrix.h:169
string timeName
The name of the time field.
Definition: DiffDesignMatrix.h:226
DiffDesignMatrix(arma::Col< TimeType > const &t, arma::Mat< VarType > const &A, string const &timeName="time", vector< string > const &columnNames=vector< string >(0), DiffDesignMatrixType diffType=DiffDesignMatrixType::UNKNOWN)
Build a DiffDesignMatrix from given armadillo column vector of time values and given armadillo matrix...
Definition: DiffDesignMatrix.h:254
TimeType & operator[](size_t const i)
Access to the component of the sorted time vector.
Definition: DiffDesignMatrix.h:415
TimeType tb
The end value for the differential time interval, .
Definition: DiffDesignMatrix.h:190
size_t getNumRows() const override
Obtain the number of rows of the DiffDesignMatrix .
Definition: DiffDesignMatrix.h:443
DiffDesignMatrix(vector< string > const &columnNames=vector< string >(0), string const timeName="time", DiffDesignMatrixType diffType=DiffDesignMatrixType::UNKNOWN)
Build a DiffDesignMatrix with no data.
Definition: DiffDesignMatrix.h:236
virtual void shiftTime(TimeType const x)
Add given time to all time values in vector .
Definition: DiffDesignMatrix.h:430
string const & getTimeName() const
Obtain the name of the time attribute.
Definition: DiffDesignMatrix.h:469
size_t getNumColumns() const override
Obtain the number of columns of the DiffDesignMatrix .
Definition: DiffDesignMatrix.h:450
DiffDesignMatrix(string const &path, string const &timeName="time", DiffDesignMatrixType diffType=DiffDesignMatrixType::UNKNOWN)
Build a DiffDesignMatrix from data in file at given path.
Definition: DiffDesignMatrix.h:276
arma::Mat< VarType > const & getA() const
Obtain a constant/read reference to the matrix.
Definition: DiffDesignMatrix.h:481
arma::Col< TimeType > t
The sorted series of time values so is strictly satisfied and the -th time value corresponds to the ...
Definition: DiffDesignMatrix.h:215
enum DiffDesignMatrixType diffType
Specify the type of differential of the DiffDesignMatrix.
Definition: DiffDesignMatrix.h:182
arma::Col< TimeType > const & getTimeVector() const
Obtain the sorted series of time values DiffDesignMatrix::t.
Definition: DiffDesignMatrix.h:475
DiffDesignMatrix(TemporalDesignMatrix< TimeType, VarType > const &tdm, DiffDesignMatrixType const diffType, bool const sort=true)
Build a DiffDesignMatrix from given TemporalDesignMatrix.
Definition: DiffDesignMatrix.h:333
arma::Mat< VarType > A
The matrix, whether it comes from forward finite differences or from central finite differences.
Definition: DiffDesignMatrix.h:220
size_t getNumElements() const override
Obtain the number of elements of the DiffDesignMatrix .
Definition: DiffDesignMatrix.h:457
VarType & operator()(size_t const i, size_t const j) override
Access to the component of the design matrix.
Definition: DiffDesignMatrix.h:405
TimeType ta
The starting value for differential time interval, .
Definition: DiffDesignMatrix.h:186
DiffDesignMatrixType getDiffType() const
Obtain the type of differential of the DiffDesignMatrix.
Definition: DiffDesignMatrix.h:463
Base class for fluxionum exceptions.
Definition: FluxionumException.h:16
This class represents a DesignMatrix where each row satisfy that its elements can be placed into a co...
Definition: TemporalDesignMatrix.h:74
string const & getTimeName() const
Obtain the name of the time attribute.
Definition: TemporalDesignMatrix.h:424
arma::Col< TimeType > const & getTimeVector() const
Obtain a constant/read reference to the time vector .
Definition: TemporalDesignMatrix.h:418
Class to read design matrices.
Definition: DesignMatrixReader.h:44
virtual fluxionum::DesignMatrix< VarType > read(unordered_map< string, string > *keyval=nullptr)
Read the design matrix.