mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-04-10 19:20:44 +01:00
Various Eigen types brought into Latan scope
This commit is contained in:
parent
fc18acc4bb
commit
b8f8d66418
@ -76,7 +76,7 @@ void AsciiFile::save(const DMatSample &s, const std::string &name)
|
|||||||
fileStream_ << "#L latan_begin rs_sample " << name << endl;
|
fileStream_ << "#L latan_begin rs_sample " << name << endl;
|
||||||
fileStream_ << s.size() << endl;
|
fileStream_ << s.size() << endl;
|
||||||
save(s[central], name + "_C");
|
save(s[central], name + "_C");
|
||||||
for (int i = 0; i < static_cast<int>(s.size()); ++i)
|
for (Index i = 0; i < s.size(); ++i)
|
||||||
{
|
{
|
||||||
save(s[i], name + "_S_" + strFrom(i));
|
save(s[i], name + "_S_" + strFrom(i));
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ mat:
|
|||||||
OPEN MAT ID INT floats CLOSE MAT
|
OPEN MAT ID INT floats CLOSE MAT
|
||||||
{
|
{
|
||||||
const unsigned int nRow = state->doubleQueue.size()/$INT, nCol = $INT;
|
const unsigned int nRow = state->doubleQueue.size()/$INT, nCol = $INT;
|
||||||
int i, j, r = 0;
|
Index i, j, r = 0;
|
||||||
|
|
||||||
if (state->doubleQueue.size() != nRow*nCol)
|
if (state->doubleQueue.size() != nRow*nCol)
|
||||||
{
|
{
|
||||||
@ -161,7 +161,7 @@ rg_state:
|
|||||||
LATAN_ERROR(Size, "random generator state '" + *state->streamName
|
LATAN_ERROR(Size, "random generator state '" + *state->streamName
|
||||||
+ ":" + $ID + "' has a wrong size");
|
+ ":" + $ID + "' has a wrong size");
|
||||||
}
|
}
|
||||||
for (unsigned int i = 0; i < RLXG_STATE_SIZE; ++i)
|
for (Index i = 0; i < RLXG_STATE_SIZE; ++i)
|
||||||
{
|
{
|
||||||
state->stateBuf[i] = state->intQueue.front();
|
state->stateBuf[i] = state->intQueue.front();
|
||||||
state->intQueue.pop();
|
state->intQueue.pop();
|
||||||
|
@ -52,7 +52,7 @@ double CompiledDoubleFunction::operator()(const double *arg) const
|
|||||||
{
|
{
|
||||||
double result;
|
double result;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < getNArg(); ++i)
|
for (Index i = 0; i < getNArg(); ++i)
|
||||||
{
|
{
|
||||||
context_->vTable["x_" + strFrom(i)] = arg[i];
|
context_->vTable["x_" + strFrom(i)] = arg[i];
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public:
|
|||||||
template <typename FileType>
|
template <typename FileType>
|
||||||
void load(const std::string &listFileName, const std::string &dataName);
|
void load(const std::string &listFileName, const std::string &dataName);
|
||||||
// resampling
|
// resampling
|
||||||
Sample<T> bootstrapMean(const unsigned int nSample, RandGen& generator);
|
Sample<T> bootstrapMean(const Index nSample, RandGen& generator);
|
||||||
private:
|
private:
|
||||||
// mean from pointer vector for resampling
|
// mean from pointer vector for resampling
|
||||||
void ptVectorMean(T &m, const std::vector<const T *> &v);
|
void ptVectorMean(T &m, const std::vector<const T *> &v);
|
||||||
@ -93,7 +93,7 @@ void Dataset<T>::load(const std::string &listFileName,
|
|||||||
}
|
}
|
||||||
listFile.close();
|
listFile.close();
|
||||||
this->resize(dataFileName.size());
|
this->resize(dataFileName.size());
|
||||||
for (unsigned int i = 0; i < dataFileName.size(); ++i)
|
for (Index i = 0; i < static_cast<Index>(dataFileName.size()); ++i)
|
||||||
{
|
{
|
||||||
file.open(dataFileName[i], File::Mode::read);
|
file.open(dataFileName[i], File::Mode::read);
|
||||||
(*this)[i] = file.template read<T>(dataName);
|
(*this)[i] = file.template read<T>(dataName);
|
||||||
@ -103,21 +103,20 @@ void Dataset<T>::load(const std::string &listFileName,
|
|||||||
|
|
||||||
// resampling //////////////////////////////////////////////////////////////////
|
// resampling //////////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Sample<T> Dataset<T>::bootstrapMean(const unsigned int nSample,
|
Sample<T> Dataset<T>::bootstrapMean(const Index nSample, RandGen& generator)
|
||||||
RandGen& generator)
|
|
||||||
{
|
{
|
||||||
unsigned int nData = this->size();
|
Index nData = this->size();
|
||||||
std::vector<const T *> data(nData);
|
std::vector<const T *> data(nData);
|
||||||
Sample<T> s(nSample);
|
Sample<T> s(nSample);
|
||||||
|
|
||||||
for (unsigned int j = 0; j < nData; ++j)
|
for (Index j = 0; j < nData; ++j)
|
||||||
{
|
{
|
||||||
data[j] = &((*this)[j]);
|
data[j] = &((*this)[j]);
|
||||||
}
|
}
|
||||||
ptVectorMean(s[central], data);
|
ptVectorMean(s[central], data);
|
||||||
for (unsigned int i = 0; i < nSample; ++i)
|
for (Index i = 0; i < nSample; ++i)
|
||||||
{
|
{
|
||||||
for (unsigned int j = 0; j < nData; ++j)
|
for (Index j = 0; j < nData; ++j)
|
||||||
{
|
{
|
||||||
data[j] = &((*this)[generator.discreteUniform(nData)]);
|
data[j] = &((*this)[generator.discreteUniform(nData)]);
|
||||||
}
|
}
|
||||||
|
@ -42,28 +42,31 @@ using namespace std;
|
|||||||
using namespace Latan;
|
using namespace Latan;
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Function implementation *
|
* DoubleFunction implementation *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
const DoubleFunction::vecFunc DoubleFunction::nullFunction_ = nullptr;
|
||||||
|
|
||||||
// constructor /////////////////////////////////////////////////////////////////
|
// constructor /////////////////////////////////////////////////////////////////
|
||||||
Function::Function(const unsigned nArg)
|
DoubleFunction::DoubleFunction(const Index nArg, const vecFunc &f)
|
||||||
: nArg_(nArg)
|
: buffer_(new DVec(nArg))
|
||||||
|
, f_(f)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// access //////////////////////////////////////////////////////////////////////
|
// access //////////////////////////////////////////////////////////////////////
|
||||||
unsigned int Function::getNArg(void) const
|
Index DoubleFunction::getNArg(void) const
|
||||||
{
|
{
|
||||||
return nArg_;
|
return buffer_->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
void DoubleFunction::setFunction(const vecFunc &f)
|
||||||
* DoubleFunction implementation *
|
{
|
||||||
******************************************************************************/
|
f_ = f;
|
||||||
// constructor /////////////////////////////////////////////////////////////////
|
}
|
||||||
DoubleFunction::DoubleFunction(const unsigned nArg, vecFunc f)
|
|
||||||
: Function(nArg)
|
void DoubleFunction::setNArg(const Index nArg)
|
||||||
, buffer_(new DVec(nArg))
|
{
|
||||||
, f_(f)
|
buffer_->resize(nArg);
|
||||||
{}
|
}
|
||||||
|
|
||||||
// function call ///////////////////////////////////////////////////////////////
|
// function call ///////////////////////////////////////////////////////////////
|
||||||
double DoubleFunction::operator()(const double *arg) const
|
double DoubleFunction::operator()(const double *arg) const
|
||||||
@ -85,7 +88,7 @@ double DoubleFunction::operator()(const DVec &arg) const
|
|||||||
|
|
||||||
double DoubleFunction::operator()(const std::vector<double> &arg) const
|
double DoubleFunction::operator()(const std::vector<double> &arg) const
|
||||||
{
|
{
|
||||||
if (arg.size() != getNArg())
|
if (arg.size() != static_cast<unsigned int>(getNArg()))
|
||||||
{
|
{
|
||||||
LATAN_ERROR(Size, "function argument vector has a wrong size (expected "
|
LATAN_ERROR(Size, "function argument vector has a wrong size (expected "
|
||||||
+ strFrom(getNArg()) + ", got " + strFrom(arg.size())
|
+ strFrom(getNArg()) + ", got " + strFrom(arg.size())
|
||||||
@ -97,7 +100,7 @@ double DoubleFunction::operator()(const std::vector<double> &arg) const
|
|||||||
|
|
||||||
double DoubleFunction::operator()(std::stack<double> &arg) const
|
double DoubleFunction::operator()(std::stack<double> &arg) const
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < getNArg(); ++i)
|
for (Index i = 0; i < getNArg(); ++i)
|
||||||
{
|
{
|
||||||
if (arg.empty())
|
if (arg.empty())
|
||||||
{
|
{
|
||||||
@ -120,7 +123,7 @@ double DoubleFunction::operator()(const double x0, ...) const
|
|||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
va_start(va, x0);
|
va_start(va, x0);
|
||||||
for (unsigned int i = 1; i < getNArg(); ++i)
|
for (Index i = 1; i < getNArg(); ++i)
|
||||||
{
|
{
|
||||||
(*buffer_)(i) = va_arg(va, double);
|
(*buffer_)(i) = va_arg(va, double);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#define Latan_Function_hpp_
|
#define Latan_Function_hpp_
|
||||||
|
|
||||||
#include <latan/Global.hpp>
|
#include <latan/Global.hpp>
|
||||||
|
#include <latan/Mat.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
@ -28,34 +29,22 @@
|
|||||||
|
|
||||||
BEGIN_NAMESPACE
|
BEGIN_NAMESPACE
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* Base function class *
|
|
||||||
******************************************************************************/
|
|
||||||
class Function
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// constructor
|
|
||||||
explicit Function(const unsigned nArg);
|
|
||||||
// destructor
|
|
||||||
virtual ~Function(void) = default;
|
|
||||||
// access
|
|
||||||
unsigned int getNArg(void) const;
|
|
||||||
private:
|
|
||||||
const unsigned int nArg_;
|
|
||||||
};
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Double function class *
|
* Double function class *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
class DoubleFunction: public Function
|
class DoubleFunction
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef std::function<double(const double *)> vecFunc;
|
typedef std::function<double(const double *)> vecFunc;
|
||||||
public:
|
public:
|
||||||
// constructor
|
// constructor
|
||||||
explicit DoubleFunction(const unsigned nArg, vecFunc f = nullptr);
|
DoubleFunction(const Index nArg = 0, const vecFunc &f = nullFunction_);
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~DoubleFunction(void) = default;
|
virtual ~DoubleFunction(void) = default;
|
||||||
|
// access
|
||||||
|
Index getNArg(void) const;
|
||||||
|
void setFunction(const vecFunc &f);
|
||||||
|
void setNArg(const Index nArg);
|
||||||
// function call
|
// function call
|
||||||
double operator()(const DVec &arg) const;
|
double operator()(const DVec &arg) const;
|
||||||
double operator()(const std::vector<double> &arg) const;
|
double operator()(const std::vector<double> &arg) const;
|
||||||
@ -67,6 +56,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
std::shared_ptr<DVec> buffer_;
|
std::shared_ptr<DVec> buffer_;
|
||||||
vecFunc f_;
|
vecFunc f_;
|
||||||
|
static const vecFunc nullFunction_;
|
||||||
};
|
};
|
||||||
|
|
||||||
END_NAMESPACE
|
END_NAMESPACE
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
#ifndef Latan_Global_hpp_
|
#ifndef Latan_Global_hpp_
|
||||||
#define Latan_Global_hpp_
|
#define Latan_Global_hpp_
|
||||||
|
|
||||||
|
#include <latan/Eigen/Dense>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <latan/Eigen/Dense>
|
#include <sstream>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
#define BEGIN_NAMESPACE namespace Latan {
|
#define BEGIN_NAMESPACE namespace Latan {
|
||||||
#define END_NAMESPACE }
|
#define END_NAMESPACE }
|
||||||
@ -53,7 +55,53 @@ Class & operator=(const Eigen::EigenBase<Derived> &m)\
|
|||||||
|
|
||||||
BEGIN_NAMESPACE
|
BEGIN_NAMESPACE
|
||||||
|
|
||||||
// Environment
|
// Eigen type aliases //////////////////////////////////////////////////////////
|
||||||
|
const int dynamic = -1;
|
||||||
|
|
||||||
|
// array types
|
||||||
|
template <typename T, int nRow = dynamic, int nCol = dynamic>
|
||||||
|
using Array = Eigen::Array<T, nRow, nCol>;
|
||||||
|
|
||||||
|
// matrix types
|
||||||
|
template <typename T, int nRow = dynamic, int nCol = dynamic>
|
||||||
|
using Mat = Eigen::Matrix<T, nRow, nCol>;
|
||||||
|
|
||||||
|
typedef Mat<int> IMat;
|
||||||
|
typedef Mat<double> DMatBase;
|
||||||
|
|
||||||
|
// vector types
|
||||||
|
template <typename T>
|
||||||
|
using Vec = Mat<T, dynamic, 1>;
|
||||||
|
|
||||||
|
typedef Vec<int> IVec;
|
||||||
|
typedef Vec<double> DVec;
|
||||||
|
|
||||||
|
// block types
|
||||||
|
template <typename Derived>
|
||||||
|
using Block = Eigen::Block<Derived>;
|
||||||
|
template <typename Derived>
|
||||||
|
using ConstBlock = const Eigen::Block<const Derived>;
|
||||||
|
|
||||||
|
template <typename Derived>
|
||||||
|
using Row = typename Derived::RowXpr;
|
||||||
|
template <typename Derived>
|
||||||
|
using ConstRow = typename Derived::ConstRowXpr;
|
||||||
|
|
||||||
|
template <typename Derived>
|
||||||
|
using Col = typename Derived::ColXpr;
|
||||||
|
template <typename Derived>
|
||||||
|
using ConstCol = typename Derived::ConstColXpr;
|
||||||
|
|
||||||
|
// map type
|
||||||
|
template <typename Derived>
|
||||||
|
using Map = Eigen::Map<Derived>;
|
||||||
|
template <typename Derived>
|
||||||
|
using ConstMap = Eigen::Map<const Derived>;
|
||||||
|
|
||||||
|
// Index type //////////////////////////////////////////////////////////////////
|
||||||
|
typedef DMatBase::Index Index;
|
||||||
|
|
||||||
|
// Environment /////////////////////////////////////////////////////////////////
|
||||||
namespace Env
|
namespace Env
|
||||||
{
|
{
|
||||||
extern const std::string fullName;
|
extern const std::string fullName;
|
||||||
@ -62,9 +110,6 @@ namespace Env
|
|||||||
extern const std::string msgPrefix;
|
extern const std::string msgPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
// vector type
|
|
||||||
typedef Eigen::VectorXd DVec;
|
|
||||||
|
|
||||||
// pointer type test
|
// pointer type test
|
||||||
template <typename Derived, typename Base>
|
template <typename Derived, typename Base>
|
||||||
inline bool isDerivedFrom(const Base *pt)
|
inline bool isDerivedFrom(const Base *pt)
|
||||||
@ -72,7 +117,7 @@ inline bool isDerivedFrom(const Base *pt)
|
|||||||
return (dynamic_cast<const Derived *>(pt) != nullptr);
|
return (dynamic_cast<const Derived *>(pt) != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// string conversions
|
// string conversions //////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline T strTo(const std::string &str)
|
inline T strTo(const std::string &str)
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,7 @@ DMat::DMat(void)
|
|||||||
: Base()
|
: Base()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DMat::DMat(const unsigned int nRow, const unsigned int nCol)
|
DMat::DMat(const Index nRow, const Index nCol)
|
||||||
: Base(nRow, nCol)
|
: Base(nRow, nCol)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -20,20 +20,23 @@
|
|||||||
#ifndef Latan_Mat_hpp_
|
#ifndef Latan_Mat_hpp_
|
||||||
#define Latan_Mat_hpp_
|
#define Latan_Mat_hpp_
|
||||||
|
|
||||||
#include <latan/Eigen/Dense>
|
|
||||||
#include <latan/Global.hpp>
|
#include <latan/Global.hpp>
|
||||||
#include <latan/IOObject.hpp>
|
#include <latan/IOObject.hpp>
|
||||||
|
|
||||||
|
#define FOR_MAT(mat, i, j) \
|
||||||
|
for (Index j = 0; j < mat.cols(); ++j)\
|
||||||
|
for (Index i = 0; i < mat.rows(); ++i)
|
||||||
|
|
||||||
BEGIN_NAMESPACE
|
BEGIN_NAMESPACE
|
||||||
|
|
||||||
class DMat: public Eigen::MatrixXd, public IoObject
|
class DMat: public DMatBase, public IoObject
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef Eigen::MatrixXd Base;
|
typedef DMatBase Base;
|
||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
DMat(void);
|
DMat(void);
|
||||||
DMat(const unsigned int nRow, const unsigned int nCol);
|
DMat(const Index nRow, const Index nCol);
|
||||||
EIGEN_EXPR_CTOR(DMat, DMat, Base, MatrixBase)
|
EIGEN_EXPR_CTOR(DMat, DMat, Base, MatrixBase)
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~DMat(void) = default;
|
virtual ~DMat(void) = default;
|
||||||
|
@ -193,9 +193,9 @@ const string &ExprNode::getName(void) const
|
|||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ExprNode::getNArg(void) const
|
Index ExprNode::getNArg(void) const
|
||||||
{
|
{
|
||||||
return static_cast<unsigned int>(arg_.size());
|
return static_cast<Index>(arg_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
const ExprNode * ExprNode::getParent(void) const
|
const ExprNode * ExprNode::getParent(void) const
|
||||||
@ -203,7 +203,7 @@ const ExprNode * ExprNode::getParent(void) const
|
|||||||
return parent_;
|
return parent_;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ExprNode::getLevel(void) const
|
Index ExprNode::getLevel(void) const
|
||||||
{
|
{
|
||||||
if (getParent())
|
if (getParent())
|
||||||
{
|
{
|
||||||
@ -230,16 +230,16 @@ void ExprNode::pushArg(ExprNode *node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ExprNode operators //////////////////////////////////////////////////////////
|
// ExprNode operators //////////////////////////////////////////////////////////
|
||||||
const ExprNode &ExprNode::operator[](const unsigned int i) const
|
const ExprNode &ExprNode::operator[](const Index i) const
|
||||||
{
|
{
|
||||||
return *arg_[i];
|
return *arg_[static_cast<unsigned int>(i)];
|
||||||
}
|
}
|
||||||
|
|
||||||
ostream &Latan::operator<<(ostream &out, const ExprNode &n)
|
ostream &Latan::operator<<(ostream &out, const ExprNode &n)
|
||||||
{
|
{
|
||||||
unsigned int level = n.getLevel();
|
Index level = n.getLevel();
|
||||||
|
|
||||||
for (unsigned int i = 0; i <= level; ++i)
|
for (Index i = 0; i <= level; ++i)
|
||||||
{
|
{
|
||||||
if (i == level)
|
if (i == level)
|
||||||
{
|
{
|
||||||
@ -255,7 +255,7 @@ ostream &Latan::operator<<(ostream &out, const ExprNode &n)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
out << " " << n.getName() << endl;
|
out << " " << n.getName() << endl;
|
||||||
for (unsigned int i = 0; i < n.getNArg(); ++i)
|
for (Index i = 0; i < n.getNArg(); ++i)
|
||||||
{
|
{
|
||||||
out << n[i];
|
out << n[i];
|
||||||
}
|
}
|
||||||
@ -283,7 +283,7 @@ void SemicolonNode::compile(Program &program) const
|
|||||||
{
|
{
|
||||||
auto &n = *this;
|
auto &n = *this;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < getNArg(); ++i)
|
for (Index i = 0; i < getNArg(); ++i)
|
||||||
{
|
{
|
||||||
bool isAssign = isDerivedFrom<AssignNode>(&n[i]);
|
bool isAssign = isDerivedFrom<AssignNode>(&n[i]);
|
||||||
bool isSemiColumn = isDerivedFrom<SemicolonNode>(&n[i]);
|
bool isSemiColumn = isDerivedFrom<SemicolonNode>(&n[i]);
|
||||||
@ -330,7 +330,7 @@ void MathOpNode::compile(Program &program) const
|
|||||||
{
|
{
|
||||||
auto &n = *this;
|
auto &n = *this;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < n.getNArg(); ++i)
|
for (Index i = 0; i < n.getNArg(); ++i)
|
||||||
{
|
{
|
||||||
n[i].compile(program);
|
n[i].compile(program);
|
||||||
}
|
}
|
||||||
@ -348,7 +348,7 @@ void FuncNode::compile(Program &program) const
|
|||||||
{
|
{
|
||||||
auto &n = *this;
|
auto &n = *this;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < n.getNArg(); ++i)
|
for (Index i = 0; i < n.getNArg(); ++i)
|
||||||
{
|
{
|
||||||
n[i].compile(program);
|
n[i].compile(program);
|
||||||
}
|
}
|
||||||
@ -401,9 +401,9 @@ MathInterpreter::MathInterpreter(const std::string &code)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// access //////////////////////////////////////////////////////////////////////
|
// access //////////////////////////////////////////////////////////////////////
|
||||||
const Instruction * MathInterpreter::operator[](const unsigned int i) const
|
const Instruction * MathInterpreter::operator[](const Index i) const
|
||||||
{
|
{
|
||||||
return program_[i].get();
|
return program_[static_cast<unsigned int>(i)].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const ExprNode * MathInterpreter::getAST(void) const
|
const ExprNode * MathInterpreter::getAST(void) const
|
||||||
|
@ -159,13 +159,13 @@ public:
|
|||||||
virtual ~ExprNode() = default;
|
virtual ~ExprNode() = default;
|
||||||
// access
|
// access
|
||||||
const std::string& getName(void) const;
|
const std::string& getName(void) const;
|
||||||
unsigned int getNArg(void) const;
|
Index getNArg(void) const;
|
||||||
const ExprNode * getParent(void) const;
|
const ExprNode * getParent(void) const;
|
||||||
unsigned int getLevel(void) const;
|
Index getLevel(void) const;
|
||||||
void setName(const std::string &name);
|
void setName(const std::string &name);
|
||||||
void pushArg(ExprNode *node);
|
void pushArg(ExprNode *node);
|
||||||
// operator
|
// operator
|
||||||
const ExprNode &operator[](const unsigned int i) const;
|
const ExprNode &operator[](const Index i) const;
|
||||||
// compile
|
// compile
|
||||||
virtual void compile(Program &program) const = 0;
|
virtual void compile(Program &program) const = 0;
|
||||||
private:
|
private:
|
||||||
@ -241,7 +241,7 @@ public:
|
|||||||
// destructor
|
// destructor
|
||||||
~MathInterpreter(void) = default;
|
~MathInterpreter(void) = default;
|
||||||
// access
|
// access
|
||||||
const Instruction * operator[](const unsigned int i) const;
|
const Instruction * operator[](const Index i) const;
|
||||||
const ExprNode * getAST(void) const;
|
const ExprNode * getAST(void) const;
|
||||||
// initialization
|
// initialization
|
||||||
void setCode(const std::string &code);
|
void setCode(const std::string &code);
|
||||||
|
@ -32,9 +32,9 @@ Minimizer::Minimizer(Verbosity verbosity)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
// access //////////////////////////////////////////////////////////////////////
|
// access //////////////////////////////////////////////////////////////////////
|
||||||
unsigned int Minimizer::getDim(void) const
|
Index Minimizer::getDim(void) const
|
||||||
{
|
{
|
||||||
return static_cast<unsigned int>(x_.size());
|
return x_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
DVec & Minimizer::getState(void)
|
DVec & Minimizer::getState(void)
|
||||||
|
@ -45,7 +45,7 @@ public:
|
|||||||
// destructor
|
// destructor
|
||||||
virtual ~Minimizer(void) = default;
|
virtual ~Minimizer(void) = default;
|
||||||
// access
|
// access
|
||||||
unsigned int getDim(void) const;
|
Index getDim(void) const;
|
||||||
Verbosity getVerbosity(void) const;
|
Verbosity getVerbosity(void) const;
|
||||||
void setInit(const DVec &x0);
|
void setInit(const DVec &x0);
|
||||||
void setVerbosity(const Verbosity verbosity);
|
void setVerbosity(const Verbosity verbosity);
|
||||||
|
@ -70,7 +70,7 @@ const DVec & MinuitMinimizer::operator()(const DoubleFunction &f)
|
|||||||
MinuitFunction minuitF(f);
|
MinuitFunction minuitF(f);
|
||||||
MnUserParameters parameters;
|
MnUserParameters parameters;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < x.size(); ++i)
|
for (Index i = 0; i < x.size(); ++i)
|
||||||
{
|
{
|
||||||
parameters.Add("x_" + strFrom(i), x(i), 0.1*fabs(x(i)));
|
parameters.Add("x_" + strFrom(i), x(i), 0.1*fabs(x(i)));
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,11 @@
|
|||||||
|
|
||||||
BEGIN_NAMESPACE
|
BEGIN_NAMESPACE
|
||||||
|
|
||||||
class RandGenState: public Eigen::Array<int, RLXG_STATE_SIZE, 1>,
|
class RandGenState: public Array<int, RLXG_STATE_SIZE, 1>,
|
||||||
public IoObject
|
public IoObject
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef Eigen::Array<int, RLXG_STATE_SIZE, 1> Base;
|
typedef Array<int, RLXG_STATE_SIZE, 1> Base;
|
||||||
public:
|
public:
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~RandGenState(void) = default;
|
virtual ~RandGenState(void) = default;
|
||||||
|
@ -31,15 +31,15 @@ DMatSample::DMatSample(void)
|
|||||||
: Sample<DMat>()
|
: Sample<DMat>()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DMatSample::DMatSample(const unsigned int nSample, const unsigned int nRow,
|
DMatSample::DMatSample(const Index nSample, const Index nRow,
|
||||||
const unsigned int nCol)
|
const Index nCol)
|
||||||
: Sample<DMat>(nSample)
|
: Sample<DMat>(nSample)
|
||||||
{
|
{
|
||||||
resizeMat(nRow, nCol);
|
resizeMat(nRow, nCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
// resize all matrices /////////////////////////////////////////////////////////
|
// resize all matrices /////////////////////////////////////////////////////////
|
||||||
void DMatSample::resizeMat(const unsigned int nRow, const unsigned int nCol)
|
void DMatSample::resizeMat(const Index nRow, const Index nCol)
|
||||||
{
|
{
|
||||||
this->unaryExpr([nRow, nCol](DMat &m){m.resize(nRow, nCol);});
|
this->unaryExpr([nRow, nCol](DMat &m){m.resize(nRow, nCol);});
|
||||||
}
|
}
|
||||||
|
@ -54,13 +54,12 @@ class DMatSample: public Sample<DMat>, public IoObject
|
|||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
DMatSample(void);
|
DMatSample(void);
|
||||||
DMatSample(const unsigned int nSample, const unsigned int nRow,
|
DMatSample(const Index nSample, const Index nRow, const Index nCol);
|
||||||
const unsigned int nCol);
|
|
||||||
using Sample<DMat>::Sample;
|
using Sample<DMat>::Sample;
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~DMatSample(void) = default;
|
virtual ~DMatSample(void) = default;
|
||||||
// resize all matrices
|
// resize all matrices
|
||||||
void resizeMat(const unsigned int nRow, const unsigned int nCol);
|
void resizeMat(const Index nRow, const Index nCol);
|
||||||
// IO type
|
// IO type
|
||||||
virtual IoType getType(void) const;
|
virtual IoType getType(void) const;
|
||||||
};
|
};
|
||||||
|
@ -30,28 +30,28 @@ BEGIN_NAMESPACE
|
|||||||
* Array class with statistics *
|
* Array class with statistics *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
template <typename T, unsigned int offset = 0>
|
template <typename T, unsigned int offset = 0>
|
||||||
class StatArray: public Eigen::Array<T, Eigen::Dynamic, 1>
|
class StatArray: public Array<T, dynamic, 1>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef Eigen::Array<T, Eigen::Dynamic, 1> Base;
|
typedef Array<T, dynamic, 1> Base;
|
||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
StatArray(void);
|
StatArray(void);
|
||||||
StatArray(const unsigned int size);
|
StatArray(const Index size);
|
||||||
EIGEN_EXPR_CTOR(StatArray, unique_arg(StatArray<T, offset>), Base,
|
EIGEN_EXPR_CTOR(StatArray, unique_arg(StatArray<T, offset>), Base,
|
||||||
ArrayBase)
|
ArrayBase)
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~StatArray(void) = default;
|
virtual ~StatArray(void) = default;
|
||||||
// access
|
// access
|
||||||
unsigned int size(void) const;
|
Index size(void) const;
|
||||||
// operators
|
// operators
|
||||||
T & operator[](const int s);
|
T & operator[](const int s);
|
||||||
const T & operator[](const int s) const;
|
const T & operator[](const int s) const;
|
||||||
// statistics
|
// statistics
|
||||||
void bin(unsigned int binSize);
|
void bin(Index binSize);
|
||||||
T mean(const unsigned int pos, const unsigned int n) const;
|
T mean(const Index pos, const Index n) const;
|
||||||
T mean(void) const;
|
T mean(void) const;
|
||||||
T variance(const unsigned int pos, const unsigned int n) const;
|
T variance(const Index pos, const Index n) const;
|
||||||
T variance(void) const;
|
T variance(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -76,13 +76,13 @@ StatArray<T, offset>::StatArray(void)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
template <typename T, unsigned int offset>
|
template <typename T, unsigned int offset>
|
||||||
StatArray<T, offset>::StatArray(const unsigned int size)
|
StatArray<T, offset>::StatArray(const Index size)
|
||||||
: Base(static_cast<typename Base::Index>(size + offset))
|
: Base(static_cast<typename Base::Index>(size + offset))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// access //////////////////////////////////////////////////////////////////////
|
// access //////////////////////////////////////////////////////////////////////
|
||||||
template <typename T, unsigned int offset>
|
template <typename T, unsigned int offset>
|
||||||
unsigned int StatArray<T, offset>::size(void) const
|
Index StatArray<T, offset>::size(void) const
|
||||||
{
|
{
|
||||||
return Base::size() - offset;
|
return Base::size() - offset;
|
||||||
}
|
}
|
||||||
@ -103,11 +103,11 @@ const T & StatArray<T, offset>::operator[](const int s) const
|
|||||||
|
|
||||||
// statistics //////////////////////////////////////////////////////////////////
|
// statistics //////////////////////////////////////////////////////////////////
|
||||||
template <typename T, unsigned int offset>
|
template <typename T, unsigned int offset>
|
||||||
void StatArray<T, offset>::bin(unsigned int binSize)
|
void StatArray<T, offset>::bin(Index binSize)
|
||||||
{
|
{
|
||||||
unsigned int q = size()/binSize, r = size()%binSize;
|
Index q = size()/binSize, r = size()%binSize;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < q; ++i)
|
for (Index i = 0; i < q; ++i)
|
||||||
{
|
{
|
||||||
(*this)[i] = mean(i*binSize, binSize);
|
(*this)[i] = mean(i*binSize, binSize);
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ void StatArray<T, offset>::bin(unsigned int binSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, unsigned int offset>
|
template <typename T, unsigned int offset>
|
||||||
T StatArray<T, offset>::mean(const unsigned int pos, const unsigned int n) const
|
T StatArray<T, offset>::mean(const Index pos, const Index n) const
|
||||||
{
|
{
|
||||||
T result;
|
T result;
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ T StatArray<T, offset>::mean(void) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, unsigned int offset>
|
template <typename T, unsigned int offset>
|
||||||
T StatArray<T, offset>::variance(const unsigned int pos, const unsigned int n) const
|
T StatArray<T, offset>::variance(const Index pos, const Index n) const
|
||||||
{
|
{
|
||||||
T s, sqs, result;
|
T s, sqs, result;
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <latan/Dataset.hpp>
|
#include <latan/Dataset.hpp>
|
||||||
|
|
||||||
#ifndef DEF_NSAMPLE
|
#ifndef DEF_NSAMPLE
|
||||||
#define DEF_NSAMPLE 100u
|
#define DEF_NSAMPLE 100
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -22,7 +22,7 @@ static void usage(const string &cmdName)
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
unsigned int nSample = DEF_NSAMPLE;
|
Index nSample = DEF_NSAMPLE;
|
||||||
string manFileName, name, outFileName, stateFileName;
|
string manFileName, name, outFileName, stateFileName;
|
||||||
char *cmdName;
|
char *cmdName;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ int main(int argc, char *argv[])
|
|||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case 'n':
|
case 'n':
|
||||||
nSample = strTo<unsigned int>(optarg);
|
nSample = strTo<Index>(optarg);
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
stateFileName = optarg;
|
stateFileName = optarg;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user