11 return std::make_shared<Density>(shared_from_this());
16 return std::make_shared<RandomVariable>(shared_from_this());
22 refs.reserve(vec.size());
25 for(
int i=0; i<vec.size(); ++i)
26 refs.push_back(std::cref(vec.at(i)));
46 assert(wrt<inputs.size());
55 Eigen::VectorXd newIn = newInputs.at(wrt).get();
56 newInputs.at(wrt) = std::cref(newIn);
60 const int dim = inputs.at(wrt).get().size();
62 Eigen::VectorXd output(dim);
63 for(
int i=0; i<dim; ++i){
65 double eps = std::max(1
e-8, 1
e-10*std::abs(inputs.at(wrt).get()(i)));
69 output(i) = (newF-f0)/eps;
70 newIn(i) = inputs.at(wrt).get()(i);
77 unsigned int const inWrt2,
79 Eigen::VectorXd
const& vec)
94 unsigned int const inWrt2,
96 Eigen::VectorXd
const& vec)
98 const double stepSize = 1
e-8 / vec.norm();
100 Eigen::VectorXd grad2;
103 Eigen::VectorXd x2 = input.at(inWrt2).get() + stepSize * vec;
104 input2.at(inWrt2) = std::cref(x2);
107 return (grad2 - grad1)/stepSize;
virtual Eigen::VectorXd GradLogDensityImpl(unsigned int wrt, ref_vector< Eigen::VectorXd > const &inputs)
virtual double LogDensityImpl(ref_vector< Eigen::VectorXd > const &inputs)
Implement the log-density.
std::shared_ptr< Density > AsDensity()
Returns a density built from this distribution.
virtual Eigen::VectorXd SampleImpl(ref_vector< Eigen::VectorXd > const &inputs)
Sample the distribution.
virtual Eigen::VectorXd ApplyLogDensityHessian(unsigned int const inWrt1, unsigned int const inWrt2, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &vec)
virtual double LogDensity(ref_vector< Eigen::VectorXd > const &inputs)
Evaluate the log-density.
Eigen::VectorXd Sample()
Sample the distribution with no inputs.
virtual Eigen::VectorXd GradLogDensity(unsigned int wrt, std::vector< Eigen::VectorXd > const &inputs)
ref_vector< const Eigen::VectorXd > ToRefVector(std::vector< Eigen::VectorXd > const &anyVec) const
std::shared_ptr< RandomVariable > AsVariable()
Returns a random variable built from this distribution.
const unsigned int varSize
const Eigen::VectorXi hyperSizes
virtual Eigen::VectorXd ApplyLogDensityHessianImpl(unsigned int wrt1, unsigned int wrt2, ref_vector< Eigen::VectorXd > const &inputs, Eigen::VectorXd const &vec)
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...