9#ifndef FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_INTERFACE_BASE_HPP
10#define FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_INTERFACE_BASE_HPP
15#include <RcppCommon.h>
21#include "../../interface.hpp"
80 this->initial_value_m =
right.initial_value_m;
81 this->estimation_type_m =
right.estimation_type_m;
103#ifdef FIMS_HEADER_ONLY
114 if (std::isnan(
x) || std::isinf(
x)) {
128 out <<
"{\"id\": " <<
p.id_m
130 <<
",\n\"estimated_value\": " <<
sanitize_val(
p.final_value_m);
131 out <<
",\n\"estimation_type\": \"" <<
p.estimation_type_m <<
"\"\n}";
164 this->storage_m = std::make_shared<std::vector<Parameter>>();
165 this->storage_m->resize(1);
172 : storage_m(
other.storage_m), id_m(
other.id_m) {}
179 this->storage_m = std::make_shared<std::vector<Parameter>>();
180 this->storage_m->resize(size);
181 for (
size_t i = 0;
i < size;
i++) {
192 const size_t input_size =
static_cast<size_t>(
x.size());
194 throw std::invalid_argument(
195 "ParameterVector::ParameterVector(Rcpp::NumericVector, size_t): `x` "
200 std::to_string(size) +
201 "). Received length: " + std::to_string(
input_size) +
".");
204 this->storage_m = std::make_shared<std::vector<Parameter>>();
207 this->storage_m->resize(
n);
208 for (
size_t i = 0;
i <
n;
i++) {
209 storage_m->at(
i).initial_value_m =
x[
i];
220 this->storage_m = std::make_shared<std::vector<Parameter>>();
221 this->storage_m->resize(
v.size());
222 for (
size_t i = 0;
i <
v.size();
i++) {
223 storage_m->at(
i).initial_value_m =
v[
i];
250 if (
static_cast<size_t>(
pos) == 0 ||
251 static_cast<size_t>(
pos) > this->storage_m->size()) {
252 throw std::invalid_argument(
"ParameterVector: Index out of range");
254 fims::to_string(this->size()));
257 return Rcpp::wrap(this->storage_m->at(
pos - 1));
268 if (
pos >= this->storage_m->size()) {
269 throw std::invalid_argument(
"ParameterVector: Index out of range");
271 return (this->storage_m->at(
pos));
288 size_t size() {
return this->storage_m->size(); }
295 void resize(
size_t size) { this->storage_m->resize(size); }
301 if (
values.size() !=
this->storage_m->size()) {
303 const size_t vector_size = this->storage_m->size();
304 throw std::invalid_argument(
305 "ParameterVector::set_values(): `values` length (" +
307 ") must equal the ParameterVector "
309 std::to_string(
vector_size) +
"). Received length: " +
310 std::to_string(
input_size) +
". Pass a numeric vector of length " +
313 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
314 this->storage_m->at(
i).initial_value_m =
values[
i];
323 const size_t vector_size = this->storage_m->size();
327 throw std::invalid_argument(
328 "ParameterVector::set_estimation_types(): `estimation_types` length "
331 ") must be 1 (broadcast) or equal to the ParameterVector size (" +
334 "Received length: " +
337 "Pass a single estimation type to apply to all elements, or a "
338 "vector of length " +
345 throw std::invalid_argument(
346 "Invalid estimation_type: " +
est_type +
347 ". Valid options are: constant, fixed_effects, or random_effects.");
355 this->storage_m->at(
i).estimation_type_m.set(
est_type);
367 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
368 storage_m->at(
i).initial_value_m = value;
377 Rcpp::Rcout << this->storage_m->data() <<
"\n";
379 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
380 Rcpp::Rcout << storage_m->at(
i) <<
" ";
385#ifdef FIMS_HEADER_ONLY
398 size_t size =
v.size();
399 for (
size_t i = 0;
i < size - 1;
i++) {
402 out <<
v[size - 1] <<
"]";
433 this->storage_m = std::make_shared<std::vector<double>>();
434 this->storage_m->resize(1);
448 this->storage_m = std::make_shared<std::vector<double>>();
449 this->storage_m->resize(
size);
459 this->storage_m = std::make_shared<std::vector<double>>();
460 const size_t input_size =
static_cast<size_t>(
x.size());
462 throw std::invalid_argument(
463 "RealVector::RealVector(Rcpp::NumericVector, size_t): `x` length (" +
465 ") must equal the requested "
467 std::to_string(
size) +
468 "). Received length: " + std::to_string(
input_size) +
".");
470 this->storage_m->assign(
x.begin(),
x.end());
479 this->storage_m = std::make_shared<std::vector<double>>();
480 this->storage_m->resize(
v.size());
481 for (
size_t i = 0;
i <
v.size();
i++) {
499 this->storage_m->assign(
v.begin(),
v.end());
514 this->storage_m->resize(
orig.size());
515 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
516 this->storage_m->at(
i) =
orig[
i];
526 Rcpp::NumericVector
ret(this->storage_m->size());
527 for (
size_t i = 0;
i < this->
size();
i++) {
528 ret[
i] = this->storage_m->at(
i);
546 if (
static_cast<size_t>(
pos) == 0 ||
547 static_cast<size_t>(
pos) > this->storage_m->size()) {
548 throw std::invalid_argument(
"RealVector: Index out of range");
550 fims::to_string(this->
size()));
553 return Rcpp::wrap(this->storage_m->at(
pos - 1));
564 if (
pos >= this->storage_m->size()) {
565 throw std::invalid_argument(
"RealVector: Index out of range");
567 return (this->storage_m->at(
pos));
579 void set(
size_t pos,
const double&
p) { this->storage_m->at(
pos) =
p; }
584 size_t size() {
return this->storage_m->size(); }
601 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
611 Rcpp::Rcout << this->storage_m->data() <<
"\n";
613 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
618#ifdef FIMS_HEADER_ONLY
633 bool finalized =
false;
637 static std::vector<std::shared_ptr<FIMSRcppInterfaceBase>>
644 Rcpp::Rcout <<
"fims_rcpp_interface_base::add_to_fims_tmb(): Not yet "
660 return "{\"name\": \"not yet implemented\"}";
670 std::stringstream
ss;
671 if (value == std::numeric_limits<double>::infinity()) {
672 ss <<
"\"Infinity\"";
673 }
else if (value == -std::numeric_limits<double>::infinity()) {
674 ss <<
"\"-Infinity\"";
675 }
else if (value != value) {
679 ss << std::fixed << std::setprecision(16) << value;
687 std::stringstream
ss;
689 for (
size_t i = 0;
i <
rep;
i++) {
690 for (
size_t j =
start;
j < end;
j++) {
Base class for all interface objects.
Definition rcpp_interface_base.hpp:628
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:686
std::string value_to_string(double value)
Report the parameter value as a string.
Definition rcpp_interface_base.hpp:669
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:638
virtual bool add_to_fims_tmb()
A virtual method to inherit to add objects to the TMB model.
Definition rcpp_interface_base.hpp:643
virtual std::string to_json()
Convert the data to json representation for the output.
Definition rcpp_interface_base.hpp:658
virtual void finalize()
Extracts derived quantities back to the Rcpp interface object from the Information object.
Definition rcpp_interface_base.hpp:653
An Rcpp interface class that defines the ParameterVector class.
Definition rcpp_interface_base.hpp:144
ParameterVector(size_t size)
The constructor.
Definition rcpp_interface_base.hpp:177
void show()
The printing methods for a ParameterVector.
Definition rcpp_interface_base.hpp:376
void resize(size_t size)
Resizes a ParameterVector to the desired length.
Definition rcpp_interface_base.hpp:295
size_t size()
Returns the size of a ParameterVector.
Definition rcpp_interface_base.hpp:288
ParameterVector(Rcpp::NumericVector x, size_t size)
The constructor for initializing a parameter vector.
Definition rcpp_interface_base.hpp:191
void set_estimation_types(Rcpp::CharacterVector estimation_types)
Sets the estimation type for all Parameters within a ParameterVector.
Definition rcpp_interface_base.hpp:322
static uint32_t id_g
The static ID of the Parameter object.
Definition rcpp_interface_base.hpp:149
uint32_t id_m
The local ID of the Parameter object.
Definition rcpp_interface_base.hpp:157
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:249
ParameterVector(const fims::Vector< double > &v)
The constructor for initializing a parameter vector.
Definition rcpp_interface_base.hpp:218
ParameterVector(const ParameterVector &other)
The constructor.
Definition rcpp_interface_base.hpp:171
virtual uint32_t get_id()
Gets the ID of the ParameterVector object.
Definition rcpp_interface_base.hpp:236
void fill(double value)
Sets the value of all Parameters in the ParameterVector to the provided value.
Definition rcpp_interface_base.hpp:366
void set_values(Rcpp::NumericVector values)
Sets the initial values for all Parameters within a ParameterVector.
Definition rcpp_interface_base.hpp:300
Parameter & operator[](size_t pos)
The accessor where the first index starts is zero.
Definition rcpp_interface_base.hpp:242
Parameter & get(size_t pos)
An internal accessor for calling a position of a ParameterVector from R.
Definition rcpp_interface_base.hpp:267
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:283
ParameterVector()
The constructor.
Definition rcpp_interface_base.hpp:162
std::shared_ptr< std::vector< Parameter > > storage_m
Parameter storage.
Definition rcpp_interface_base.hpp:153
virtual ~ParameterVector()
Destroy the Parameter Vector object.
Definition rcpp_interface_base.hpp:231
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:88
Parameter(double value, std::string estimation_type)
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:58
Parameter & operator=(const Parameter &right)
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:75
Parameter()
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:97
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:53
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
Parameter(const Parameter &other)
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:66
An Rcpp interface class that defines the RealVector class.
Definition rcpp_interface_base.hpp:413
double & get(size_t pos)
An internal accessor for calling a position of a RealVector from R.
Definition rcpp_interface_base.hpp:563
virtual ~RealVector()
Destroy the real Vector object.
Definition rcpp_interface_base.hpp:490
size_t size()
Returns the size of a RealVector.
Definition rcpp_interface_base.hpp:584
RealVector(const RealVector &other)
The constructor.
Definition rcpp_interface_base.hpp:440
Rcpp::NumericVector get_values()
Definition rcpp_interface_base.hpp:525
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:579
RealVector(size_t size)
The constructor.
Definition rcpp_interface_base.hpp:446
void resize(size_t size)
Resizes a RealVector to the desired length.
Definition rcpp_interface_base.hpp:591
std::shared_ptr< std::vector< double > > storage_m
real storage.
Definition rcpp_interface_base.hpp:422
RealVector & operator=(const Rcpp::NumericVector &v)
Definition rcpp_interface_base.hpp:498
uint32_t id_m
The local ID of the RealVector object.
Definition rcpp_interface_base.hpp:426
void fill(double value)
Sets the value of all elements in the RealVector to the provided value.
Definition rcpp_interface_base.hpp:600
static uint32_t id_g
The static ID of the RealVector object.
Definition rcpp_interface_base.hpp:418
void set_values(const Rcpp::NumericVector &orig)
Definition rcpp_interface_base.hpp:513
virtual uint32_t get_id()
Gets the ID of the RealVector object.
Definition rcpp_interface_base.hpp:506
RealVector(Rcpp::NumericVector x, size_t size)
The constructor for initializing a real vector.
Definition rcpp_interface_base.hpp:457
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:545
double & operator[](size_t pos)
The accessor where the first index starts is zero.
Definition rcpp_interface_base.hpp:538
RealVector(const fims::Vector< double > &v)
The constructor for initializing a real vector.
Definition rcpp_interface_base.hpp:477
void show()
The printing methods for a RealVector.
Definition rcpp_interface_base.hpp:610
RealVector()
The constructor.
Definition rcpp_interface_base.hpp:431
A class that provides shared ownership of a string.
Definition rcpp_shared_primitive.hpp:1513
Definition fims_vector.hpp:27
#define FIMS_WARNING_LOG(MESSAGE)
Definition def.hpp:648
#define FIMS_ERROR_LOG(MESSAGE)
Definition def.hpp:664
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:235
std::ostream & operator<<(std::ostream &out, const Parameter &p)
Output for std::ostream& for a parameter.
Definition rcpp_interface_base.hpp:127
double sanitize_val(double x)
Sanitize a double value by replacing NaN or Inf with -999.0.
Definition rcpp_interface_base.hpp:113
Code to create shared pointers to allow for the wrapper functions in R to work correctly so the live ...