9#ifndef FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_INTERFACE_BASE_HPP
10#define FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_INTERFACE_BASE_HPP
12#include <RcppCommon.h>
16#include "../../../common/def.hpp"
17#include "../../../common/information.hpp"
18#include "../../interface.hpp"
59 double min_m = -std::numeric_limits<double>::infinity();
64 double max_m = std::numeric_limits<double>::infinity();
100 this->initial_value_m =
right.initial_value_m;
101 this->estimation_type_m =
right.estimation_type_m;
102 this->min_m =
right.min_m;
103 this->max_m =
right.max_m;
136 if (std::isnan(x) || std::isinf(x)) {
150 out <<
"{\"id\": " <<
p.id_m
152 <<
",\n\"estimated_value\": " <<
sanitize_val(
p.final_value_m)
155 if (
p.min_m == -std::numeric_limits<double>::infinity()) {
156 out <<
"\"-Infinity\"";
160 out <<
",\n\"max\": ";
161 if (
p.max_m == std::numeric_limits<double>::infinity()) {
162 out <<
"\"Infinity\"";
167 out <<
",\n\"estimation_type\": \"" <<
p.estimation_type_m <<
"\"\n}";
198 this->storage_m = std::make_shared<std::vector<Parameter>>();
199 this->storage_m->resize(1);
213 this->storage_m = std::make_shared<std::vector<Parameter>>();
214 this->storage_m->resize(
size);
215 for (
size_t i = 0;
i <
size;
i++) {
226 if (
static_cast<size_t>(x.size()) !=
size) {
227 throw std::invalid_argument(
228 "Error in call to ParameterVector(Rcpp::NumericVector x, size_t "
229 "size): x.size() != size argument.");
232 this->storage_m = std::make_shared<std::vector<Parameter>>();
234 size_t n = std::min(
static_cast<size_t>(x.size()),
size);
235 this->storage_m->resize(
n);
236 for (
size_t i = 0;
i <
n;
i++) {
248 this->storage_m = std::make_shared<std::vector<Parameter>>();
249 this->storage_m->resize(
v.size());
250 for (
size_t i = 0;
i <
v.size();
i++) {
278 if (
static_cast<size_t>(
pos) == 0 ||
279 static_cast<size_t>(
pos) > this->storage_m->size()) {
280 throw std::invalid_argument(
"ParameterVector: Index out of range");
282 fims::to_string(this->
size()));
285 return Rcpp::wrap(this->storage_m->at(
pos - 1));
296 if (
pos >= this->storage_m->size()) {
297 throw std::invalid_argument(
"ParameterVector: Index out of range");
299 return (this->storage_m->at(
pos));
316 size_t size() {
return this->storage_m->size(); }
333 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
335 this->storage_m->at(
i).estimation_type_m.set(
"fixed_effects");
337 this->storage_m->at(
i).estimation_type_m.set(
"constant");
350 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
352 this->storage_m->at(
i).estimation_type_m.set(
"random_effects");
354 this->storage_m->at(
i).estimation_type_m.set(
"constant");
367 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
379 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
391 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
401 Rcpp::Rcout << this->storage_m->data() <<
"\n";
403 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
419 size_t size =
v.size();
420 for (
size_t i = 0;
i < size - 1;
i++) {
423 out <<
v[size - 1] <<
"]";
454 this->storage_m = std::make_shared<std::vector<double>>();
455 this->storage_m->resize(1);
469 this->storage_m = std::make_shared<std::vector<double>>();
470 this->storage_m->resize(
size);
480 this->storage_m = std::make_shared<std::vector<double>>();
481 this->storage_m->assign(x.begin(), x.end());
490 this->storage_m = std::make_shared<std::vector<double>>();
491 this->storage_m->resize(
v.size());
492 for (
size_t i = 0;
i <
v.size();
i++) {
510 this->storage_m->assign(
v.begin(),
v.end());
525 this->storage_m->resize(
orig.size());
526 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
527 this->storage_m->at(
i) =
orig[
i];
537 Rcpp::NumericVector
ret(this->storage_m->size());
538 for (
size_t i = 0;
i < this->
size();
i++) {
539 ret[
i] = this->storage_m->at(
i);
557 if (
static_cast<size_t>(
pos) == 0 ||
558 static_cast<size_t>(
pos) > this->storage_m->size()) {
559 throw std::invalid_argument(
"RealVector: Index out of range");
561 fims::to_string(this->
size()));
564 return Rcpp::wrap(this->storage_m->at(
pos - 1));
575 if (
pos >= this->storage_m->size()) {
576 throw std::invalid_argument(
"RealVector: Index out of range");
578 return (this->storage_m->at(
pos));
590 void set(
size_t pos,
const double&
p) { this->storage_m->at(
pos) =
p; }
595 size_t size() {
return this->storage_m->size(); }
612 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
622 Rcpp::Rcout << this->storage_m->data() <<
"\n";
624 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
643 static std::vector<std::shared_ptr<FIMSRcppInterfaceBase>>
650 Rcpp::Rcout <<
"fims_rcpp_interface_base::add_to_fims_tmb(): Not yet "
666 return "{\"name\": \"not yet implemented\"}";
673 std::map<std::string, std::vector<double>>& se_values,
675 auto se_vals = se_values.find(name);
676 if (
se_vals != se_values.end()) {
702 std::map<std::string, std::vector<double>>& se_values) {
713 std::stringstream
ss;
714 if (value == std::numeric_limits<double>::infinity()) {
715 ss <<
"\"Infinity\"";
716 }
else if (value == -std::numeric_limits<double>::infinity()) {
717 ss <<
"\"-Infinity\"";
718 }
else if (value != value) {
722 ss << std::fixed << std::setprecision(16) << value;
730 std::stringstream
ss;
732 for (
size_t i = 0;
i <
rep;
i++) {
733 for (
size_t j =
start;
j < end;
j++) {
745std::vector<std::shared_ptr<FIMSRcppInterfaceBase>>
Base class for all interface objects.
Definition rcpp_interface_base.hpp:634
std::string make_dimensions(uint32_t start, uint32_t end, uint32_t rep=1)
Make a string of dimensions for the model.
Definition rcpp_interface_base.hpp:729
bool finalized
Is the object already finalized? The default is false.
Definition rcpp_interface_base.hpp:639
std::string value_to_string(double value)
Report the parameter value as a string.
Definition rcpp_interface_base.hpp:712
virtual void set_uncertainty(std::map< std::string, std::vector< double > > &se_values)
Set uncertainty values for the interface object.
Definition rcpp_interface_base.hpp:701
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:644
void get_se_values(std::string name, std::map< std::string, std::vector< double > > &se_values, fims::Vector< double > &values)
Method to extract standard error values from the se_values working map.
Definition rcpp_interface_base.hpp:672
virtual bool add_to_fims_tmb()
A virtual method to inherit to add objects to the TMB model.
Definition rcpp_interface_base.hpp:649
virtual std::string to_json()
Convert the data to json representation for the output.
Definition rcpp_interface_base.hpp:664
virtual void finalize()
Extracts derived quantities back to the Rcpp interface object from the Information object.
Definition rcpp_interface_base.hpp:659
An Rcpp interface class that defines the ParameterVector class.
Definition rcpp_interface_base.hpp:178
ParameterVector(size_t size)
The constructor.
Definition rcpp_interface_base.hpp:211
void show()
The printing methods for a ParameterVector.
Definition rcpp_interface_base.hpp:400
void set_all_random(bool random)
Sets all Parameters within a ParameterVector as random effects.
Definition rcpp_interface_base.hpp:349
void resize(size_t size)
Resizes a ParameterVector to the desired length.
Definition rcpp_interface_base.hpp:323
size_t size()
Returns the size of a ParameterVector.
Definition rcpp_interface_base.hpp:316
ParameterVector(Rcpp::NumericVector x, size_t size)
The constructor for initializing a parameter vector.
Definition rcpp_interface_base.hpp:225
static uint32_t id_g
The static ID of the Parameter object.
Definition rcpp_interface_base.hpp:183
uint32_t id_m
The local ID of the Parameter object.
Definition rcpp_interface_base.hpp:191
SEXP at(R_xlen_t pos)
The accessor where the first index starts at one. This function is for calling accessing from R.
Definition rcpp_interface_base.hpp:277
ParameterVector(const fims::Vector< double > &v)
The constructor for initializing a parameter vector.
Definition rcpp_interface_base.hpp:246
ParameterVector(const ParameterVector &other)
The constructor.
Definition rcpp_interface_base.hpp:205
virtual uint32_t get_id()
Gets the ID of the ParameterVector object.
Definition rcpp_interface_base.hpp:264
void fill_max(double value)
Assigns the given values to the maximum value of all elements in the vector.
Definition rcpp_interface_base.hpp:390
void fill(double value)
Sets the value of all Parameters in the ParameterVector to the provided value.
Definition rcpp_interface_base.hpp:366
Parameter & operator[](size_t pos)
The accessor where the first index starts is zero.
Definition rcpp_interface_base.hpp:270
Parameter & get(size_t pos)
An internal accessor for calling a position of a ParameterVector from R.
Definition rcpp_interface_base.hpp:295
void set(size_t pos, const Parameter &p)
An internal setter for setting a position of a ParameterVector from R.
Definition rcpp_interface_base.hpp:311
ParameterVector()
The constructor.
Definition rcpp_interface_base.hpp:196
std::shared_ptr< std::vector< Parameter > > storage_m
Parameter storage.
Definition rcpp_interface_base.hpp:187
virtual ~ParameterVector()
Destroy the Parameter Vector object.
Definition rcpp_interface_base.hpp:259
void fill_min(double value)
Assigns the given values to the minimum value of all elements in the vector.
Definition rcpp_interface_base.hpp:378
void set_all_estimable(bool estimable)
Sets all Parameters within a ParameterVector as estimable.
Definition rcpp_interface_base.hpp:332
An Rcpp interface that defines the Parameter class.
Definition rcpp_interface_base.hpp:31
double initial_value_m
The initial value of the parameter.
Definition rcpp_interface_base.hpp:44
Parameter(double value)
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:110
double uncertainty_m
The standard error of the parameter estimate, where the default is -999.0.
Definition rcpp_interface_base.hpp:54
Parameter & operator=(const Parameter &right)
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:95
Parameter(double value, double min, double max, std::string estimation_type)
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:74
Parameter()
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:119
double final_value_m
The final value of the parameter.
Definition rcpp_interface_base.hpp:48
SharedString estimation_type_m
A string indicating the estimation type. Options are: constant, fixed_effects, or random_effects,...
Definition rcpp_interface_base.hpp:69
uint32_t id_m
The local ID of the Parameter object.
Definition rcpp_interface_base.hpp:40
static uint32_t id_g
The static ID of the Parameter object.
Definition rcpp_interface_base.hpp:36
double max_m
The maximum possible parameter value, where the default is positive infinity.
Definition rcpp_interface_base.hpp:64
Parameter(const Parameter &other)
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:84
double min_m
The minimum possible parameter value, where the default is negative infinity.
Definition rcpp_interface_base.hpp:59
An Rcpp interface class that defines the RealVector class.
Definition rcpp_interface_base.hpp:434
double & get(size_t pos)
An internal accessor for calling a position of a RealVector from R.
Definition rcpp_interface_base.hpp:574
virtual ~RealVector()
Destroy the real Vector object.
Definition rcpp_interface_base.hpp:501
size_t size()
Returns the size of a RealVector.
Definition rcpp_interface_base.hpp:595
RealVector(const RealVector &other)
The constructor.
Definition rcpp_interface_base.hpp:461
void set(size_t pos, const double &p)
An internal setter for setting a position of a RealVector from R.
Definition rcpp_interface_base.hpp:590
RealVector(size_t size)
The constructor.
Definition rcpp_interface_base.hpp:467
void resize(size_t size)
Resizes a RealVector to the desired length.
Definition rcpp_interface_base.hpp:602
std::shared_ptr< std::vector< double > > storage_m
real storage.
Definition rcpp_interface_base.hpp:443
RealVector & operator=(const Rcpp::NumericVector &v)
Definition rcpp_interface_base.hpp:509
uint32_t id_m
The local ID of the RealVector object.
Definition rcpp_interface_base.hpp:447
void fill(double value)
Sets the value of all elements in the RealVector to the provided value.
Definition rcpp_interface_base.hpp:611
Rcpp::NumericVector toRVector()
Definition rcpp_interface_base.hpp:536
static uint32_t id_g
The static ID of the RealVector object.
Definition rcpp_interface_base.hpp:439
virtual uint32_t get_id()
Gets the ID of the RealVector object.
Definition rcpp_interface_base.hpp:517
RealVector(Rcpp::NumericVector x, size_t size)
The constructor for initializing a real vector.
Definition rcpp_interface_base.hpp:478
SEXP at(R_xlen_t pos)
The accessor where the first index starts at one. This function is for calling accessing from R.
Definition rcpp_interface_base.hpp:556
double & operator[](size_t pos)
The accessor where the first index starts is zero.
Definition rcpp_interface_base.hpp:549
RealVector(const fims::Vector< double > &v)
The constructor for initializing a real vector.
Definition rcpp_interface_base.hpp:488
void show()
The printing methods for a RealVector.
Definition rcpp_interface_base.hpp:621
void fromRVector(const Rcpp::NumericVector &orig)
Definition rcpp_interface_base.hpp:524
RealVector()
The constructor.
Definition rcpp_interface_base.hpp:452
A class that provides shared ownership of a string.
Definition rcpp_shared_primitive.hpp:1508
Definition fims_vector.hpp:27
#define FIMS_WARNING_LOG(MESSAGE)
Definition def.hpp:598
#define FIMS_ERROR_LOG(MESSAGE)
Definition def.hpp:606
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:279
std::ostream & operator<<(std::ostream &out, const Parameter &p)
Output for std::ostream& for a parameter.
Definition rcpp_interface_base.hpp:149
double sanitize_val(double x)
Sanitize a double value by replacing NaN or Inf with -999.0.
Definition rcpp_interface_base.hpp:135
Code to create shared pointers to allow for the wrapper functions in R to work correctly so the live ...