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"
80 this->initial_value_m =
right.initial_value_m;
81 this->estimation_type_m =
right.estimation_type_m;
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}";
162 this->storage_m = std::make_shared<std::vector<Parameter>>();
163 this->storage_m->resize(1);
177 this->storage_m = std::make_shared<std::vector<Parameter>>();
178 this->storage_m->resize(
size);
179 for (
size_t i = 0;
i <
size;
i++) {
190 if (
static_cast<size_t>(
x.size()) !=
size) {
191 throw std::invalid_argument(
192 "Error in call to ParameterVector(Rcpp::NumericVector x, size_t "
193 "size): x.size() != size argument.");
196 this->storage_m = std::make_shared<std::vector<Parameter>>();
198 size_t n = std::min(
static_cast<size_t>(
x.size()),
size);
199 this->storage_m->resize(
n);
200 for (
size_t i = 0;
i <
n;
i++) {
212 this->storage_m = std::make_shared<std::vector<Parameter>>();
213 this->storage_m->resize(
v.size());
214 for (
size_t i = 0;
i <
v.size();
i++) {
242 if (
static_cast<size_t>(
pos) == 0 ||
243 static_cast<size_t>(
pos) > this->storage_m->size()) {
244 throw std::invalid_argument(
"ParameterVector: Index out of range");
246 fims::to_string(this->
size()));
249 return Rcpp::wrap(this->storage_m->at(
pos - 1));
260 if (
pos >= this->storage_m->size()) {
261 throw std::invalid_argument(
"ParameterVector: Index out of range");
263 return (this->storage_m->at(
pos));
280 size_t size() {
return this->storage_m->size(); }
297 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
299 this->storage_m->at(
i).estimation_type_m.set(
"fixed_effects");
301 this->storage_m->at(
i).estimation_type_m.set(
"constant");
314 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
316 this->storage_m->at(
i).estimation_type_m.set(
"random_effects");
318 this->storage_m->at(
i).estimation_type_m.set(
"constant");
331 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
341 Rcpp::Rcout << this->storage_m->data() <<
"\n";
343 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
359 size_t size =
v.size();
360 for (
size_t i = 0;
i < size - 1;
i++) {
363 out <<
v[size - 1] <<
"]";
394 this->storage_m = std::make_shared<std::vector<double>>();
395 this->storage_m->resize(1);
409 this->storage_m = std::make_shared<std::vector<double>>();
410 this->storage_m->resize(
size);
420 this->storage_m = std::make_shared<std::vector<double>>();
421 this->storage_m->assign(
x.begin(),
x.end());
430 this->storage_m = std::make_shared<std::vector<double>>();
431 this->storage_m->resize(
v.size());
432 for (
size_t i = 0;
i <
v.size();
i++) {
450 this->storage_m->assign(
v.begin(),
v.end());
465 this->storage_m->resize(
orig.size());
466 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
467 this->storage_m->at(
i) =
orig[
i];
477 Rcpp::NumericVector
ret(this->storage_m->size());
478 for (
size_t i = 0;
i < this->
size();
i++) {
479 ret[
i] = this->storage_m->at(
i);
497 if (
static_cast<size_t>(
pos) == 0 ||
498 static_cast<size_t>(
pos) > this->storage_m->size()) {
499 throw std::invalid_argument(
"RealVector: Index out of range");
501 fims::to_string(this->
size()));
504 return Rcpp::wrap(this->storage_m->at(
pos - 1));
515 if (
pos >= this->storage_m->size()) {
516 throw std::invalid_argument(
"RealVector: Index out of range");
518 return (this->storage_m->at(
pos));
530 void set(
size_t pos,
const double&
p) { this->storage_m->at(
pos) =
p; }
535 size_t size() {
return this->storage_m->size(); }
552 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
562 Rcpp::Rcout << this->storage_m->data() <<
"\n";
564 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
583 static std::vector<std::shared_ptr<FIMSRcppInterfaceBase>>
590 Rcpp::Rcout <<
"fims_rcpp_interface_base::add_to_fims_tmb(): Not yet "
606 return "{\"name\": \"not yet implemented\"}";
616 std::stringstream
ss;
617 if (value == std::numeric_limits<double>::infinity()) {
618 ss <<
"\"Infinity\"";
619 }
else if (value == -std::numeric_limits<double>::infinity()) {
620 ss <<
"\"-Infinity\"";
621 }
else if (value != value) {
625 ss << std::fixed << std::setprecision(16) << value;
633 std::stringstream
ss;
635 for (
size_t i = 0;
i <
rep;
i++) {
636 for (
size_t j =
start;
j < end;
j++) {
648std::vector<std::shared_ptr<FIMSRcppInterfaceBase>>
Base class for all interface objects.
Definition rcpp_interface_base.hpp:574
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:632
bool finalized
Is the object already finalized? The default is false.
Definition rcpp_interface_base.hpp:579
std::string value_to_string(double value)
Report the parameter value as a string.
Definition rcpp_interface_base.hpp:615
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:584
virtual bool add_to_fims_tmb()
A virtual method to inherit to add objects to the TMB model.
Definition rcpp_interface_base.hpp:589
virtual std::string to_json()
Convert the data to json representation for the output.
Definition rcpp_interface_base.hpp:604
virtual void finalize()
Extracts derived quantities back to the Rcpp interface object from the Information object.
Definition rcpp_interface_base.hpp:599
An Rcpp interface class that defines the ParameterVector class.
Definition rcpp_interface_base.hpp:142
ParameterVector(size_t size)
The constructor.
Definition rcpp_interface_base.hpp:175
void show()
The printing methods for a ParameterVector.
Definition rcpp_interface_base.hpp:340
void set_all_random(bool random)
Sets all Parameters within a ParameterVector as random effects.
Definition rcpp_interface_base.hpp:313
void resize(size_t size)
Resizes a ParameterVector to the desired length.
Definition rcpp_interface_base.hpp:287
size_t size()
Returns the size of a ParameterVector.
Definition rcpp_interface_base.hpp:280
ParameterVector(Rcpp::NumericVector x, size_t size)
The constructor for initializing a parameter vector.
Definition rcpp_interface_base.hpp:189
static uint32_t id_g
The static ID of the Parameter object.
Definition rcpp_interface_base.hpp:147
uint32_t id_m
The local ID of the Parameter object.
Definition rcpp_interface_base.hpp:155
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:241
ParameterVector(const fims::Vector< double > &v)
The constructor for initializing a parameter vector.
Definition rcpp_interface_base.hpp:210
ParameterVector(const ParameterVector &other)
The constructor.
Definition rcpp_interface_base.hpp:169
virtual uint32_t get_id()
Gets the ID of the ParameterVector object.
Definition rcpp_interface_base.hpp:228
void fill(double value)
Sets the value of all Parameters in the ParameterVector to the provided value.
Definition rcpp_interface_base.hpp:330
Parameter & operator[](size_t pos)
The accessor where the first index starts is zero.
Definition rcpp_interface_base.hpp:234
Parameter & get(size_t pos)
An internal accessor for calling a position of a ParameterVector from R.
Definition rcpp_interface_base.hpp:259
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:275
ParameterVector()
The constructor.
Definition rcpp_interface_base.hpp:160
std::shared_ptr< std::vector< Parameter > > storage_m
Parameter storage.
Definition rcpp_interface_base.hpp:151
virtual ~ParameterVector()
Destroy the Parameter Vector object.
Definition rcpp_interface_base.hpp:223
void set_all_estimable(bool estimable)
Sets all Parameters within a ParameterVector as estimable.
Definition rcpp_interface_base.hpp:296
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:374
double & get(size_t pos)
An internal accessor for calling a position of a RealVector from R.
Definition rcpp_interface_base.hpp:514
virtual ~RealVector()
Destroy the real Vector object.
Definition rcpp_interface_base.hpp:441
size_t size()
Returns the size of a RealVector.
Definition rcpp_interface_base.hpp:535
RealVector(const RealVector &other)
The constructor.
Definition rcpp_interface_base.hpp:401
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:530
RealVector(size_t size)
The constructor.
Definition rcpp_interface_base.hpp:407
void resize(size_t size)
Resizes a RealVector to the desired length.
Definition rcpp_interface_base.hpp:542
std::shared_ptr< std::vector< double > > storage_m
real storage.
Definition rcpp_interface_base.hpp:383
RealVector & operator=(const Rcpp::NumericVector &v)
Definition rcpp_interface_base.hpp:449
uint32_t id_m
The local ID of the RealVector object.
Definition rcpp_interface_base.hpp:387
void fill(double value)
Sets the value of all elements in the RealVector to the provided value.
Definition rcpp_interface_base.hpp:551
Rcpp::NumericVector toRVector()
Definition rcpp_interface_base.hpp:476
static uint32_t id_g
The static ID of the RealVector object.
Definition rcpp_interface_base.hpp:379
virtual uint32_t get_id()
Gets the ID of the RealVector object.
Definition rcpp_interface_base.hpp:457
RealVector(Rcpp::NumericVector x, size_t size)
The constructor for initializing a real vector.
Definition rcpp_interface_base.hpp:418
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:496
double & operator[](size_t pos)
The accessor where the first index starts is zero.
Definition rcpp_interface_base.hpp:489
RealVector(const fims::Vector< double > &v)
The constructor for initializing a real vector.
Definition rcpp_interface_base.hpp:428
void show()
The printing methods for a RealVector.
Definition rcpp_interface_base.hpp:561
void fromRVector(const Rcpp::NumericVector &orig)
Definition rcpp_interface_base.hpp:464
RealVector()
The constructor.
Definition rcpp_interface_base.hpp:392
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:545
#define FIMS_ERROR_LOG(MESSAGE)
Definition def.hpp:553
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:239
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 ...