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>
20#include "../../../common/def.hpp"
21#include "../../../common/information.hpp"
22#include "../../interface.hpp"
81 this->initial_value_m =
right.initial_value_m;
82 this->estimation_type_m =
right.estimation_type_m;
115 if (std::isnan(
x) || std::isinf(
x)) {
129 out <<
"{\"id\": " <<
p.id_m
131 <<
",\n\"estimated_value\": " <<
sanitize_val(
p.final_value_m);
132 out <<
",\n\"estimation_type\": \"" <<
p.estimation_type_m <<
"\"\n}";
163 this->storage_m = std::make_shared<std::vector<Parameter>>();
164 this->storage_m->resize(1);
178 this->storage_m = std::make_shared<std::vector<Parameter>>();
179 this->storage_m->resize(
size);
180 for (
size_t i = 0;
i <
size;
i++) {
191 if (
static_cast<size_t>(
x.size()) !=
size) {
192 throw std::invalid_argument(
193 "Error in call to ParameterVector(Rcpp::NumericVector x, size_t "
194 "size): x.size() != size argument.");
197 this->storage_m = std::make_shared<std::vector<Parameter>>();
199 size_t n = std::min(
static_cast<size_t>(
x.size()),
size);
200 this->storage_m->resize(
n);
201 for (
size_t i = 0;
i <
n;
i++) {
213 this->storage_m = std::make_shared<std::vector<Parameter>>();
214 this->storage_m->resize(
v.size());
215 for (
size_t i = 0;
i <
v.size();
i++) {
243 if (
static_cast<size_t>(
pos) == 0 ||
244 static_cast<size_t>(
pos) > this->storage_m->size()) {
245 throw std::invalid_argument(
"ParameterVector: Index out of range");
247 fims::to_string(this->
size()));
250 return Rcpp::wrap(this->storage_m->at(
pos - 1));
261 if (
pos >= this->storage_m->size()) {
262 throw std::invalid_argument(
"ParameterVector: Index out of range");
264 return (this->storage_m->at(
pos));
281 size_t size() {
return this->storage_m->size(); }
298 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
300 this->storage_m->at(
i).estimation_type_m.set(
"fixed_effects");
302 this->storage_m->at(
i).estimation_type_m.set(
"constant");
315 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
317 this->storage_m->at(
i).estimation_type_m.set(
"random_effects");
319 this->storage_m->at(
i).estimation_type_m.set(
"constant");
332 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
342 Rcpp::Rcout << this->storage_m->data() <<
"\n";
344 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
360 size_t size =
v.size();
361 for (
size_t i = 0;
i < size - 1;
i++) {
364 out <<
v[size - 1] <<
"]";
395 this->storage_m = std::make_shared<std::vector<double>>();
396 this->storage_m->resize(1);
410 this->storage_m = std::make_shared<std::vector<double>>();
411 this->storage_m->resize(
size);
421 this->storage_m = std::make_shared<std::vector<double>>();
422 this->storage_m->assign(
x.begin(),
x.end());
431 this->storage_m = std::make_shared<std::vector<double>>();
432 this->storage_m->resize(
v.size());
433 for (
size_t i = 0;
i <
v.size();
i++) {
451 this->storage_m->assign(
v.begin(),
v.end());
466 this->storage_m->resize(
orig.size());
467 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
468 this->storage_m->at(
i) =
orig[
i];
478 Rcpp::NumericVector
ret(this->storage_m->size());
479 for (
size_t i = 0;
i < this->
size();
i++) {
480 ret[
i] = this->storage_m->at(
i);
498 if (
static_cast<size_t>(
pos) == 0 ||
499 static_cast<size_t>(
pos) > this->storage_m->size()) {
500 throw std::invalid_argument(
"RealVector: Index out of range");
502 fims::to_string(this->
size()));
505 return Rcpp::wrap(this->storage_m->at(
pos - 1));
516 if (
pos >= this->storage_m->size()) {
517 throw std::invalid_argument(
"RealVector: Index out of range");
519 return (this->storage_m->at(
pos));
531 void set(
size_t pos,
const double&
p) { this->storage_m->at(
pos) =
p; }
536 size_t size() {
return this->storage_m->size(); }
553 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
563 Rcpp::Rcout << this->storage_m->data() <<
"\n";
565 for (
size_t i = 0;
i < this->storage_m->size();
i++) {
584 static std::vector<std::shared_ptr<FIMSRcppInterfaceBase>>
591 Rcpp::Rcout <<
"fims_rcpp_interface_base::add_to_fims_tmb(): Not yet "
607 return "{\"name\": \"not yet implemented\"}";
617 std::stringstream
ss;
618 if (value == std::numeric_limits<double>::infinity()) {
619 ss <<
"\"Infinity\"";
620 }
else if (value == -std::numeric_limits<double>::infinity()) {
621 ss <<
"\"-Infinity\"";
622 }
else if (value != value) {
626 ss << std::fixed << std::setprecision(16) << value;
634 std::stringstream
ss;
636 for (
size_t i = 0;
i <
rep;
i++) {
637 for (
size_t j =
start;
j < end;
j++) {
649std::vector<std::shared_ptr<FIMSRcppInterfaceBase>>
Base class for all interface objects.
Definition rcpp_interface_base.hpp:575
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:633
bool finalized
Is the object already finalized? The default is false.
Definition rcpp_interface_base.hpp:580
std::string value_to_string(double value)
Report the parameter value as a string.
Definition rcpp_interface_base.hpp:616
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:585
virtual bool add_to_fims_tmb()
A virtual method to inherit to add objects to the TMB model.
Definition rcpp_interface_base.hpp:590
virtual std::string to_json()
Convert the data to json representation for the output.
Definition rcpp_interface_base.hpp:605
virtual void finalize()
Extracts derived quantities back to the Rcpp interface object from the Information object.
Definition rcpp_interface_base.hpp:600
An Rcpp interface class that defines the ParameterVector class.
Definition rcpp_interface_base.hpp:143
ParameterVector(size_t size)
The constructor.
Definition rcpp_interface_base.hpp:176
void show()
The printing methods for a ParameterVector.
Definition rcpp_interface_base.hpp:341
void set_all_random(bool random)
Sets all Parameters within a ParameterVector as random effects.
Definition rcpp_interface_base.hpp:314
void resize(size_t size)
Resizes a ParameterVector to the desired length.
Definition rcpp_interface_base.hpp:288
size_t size()
Returns the size of a ParameterVector.
Definition rcpp_interface_base.hpp:281
ParameterVector(Rcpp::NumericVector x, size_t size)
The constructor for initializing a parameter vector.
Definition rcpp_interface_base.hpp:190
static uint32_t id_g
The static ID of the Parameter object.
Definition rcpp_interface_base.hpp:148
uint32_t id_m
The local ID of the Parameter object.
Definition rcpp_interface_base.hpp:156
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:242
ParameterVector(const fims::Vector< double > &v)
The constructor for initializing a parameter vector.
Definition rcpp_interface_base.hpp:211
ParameterVector(const ParameterVector &other)
The constructor.
Definition rcpp_interface_base.hpp:170
virtual uint32_t get_id()
Gets the ID of the ParameterVector object.
Definition rcpp_interface_base.hpp:229
void fill(double value)
Sets the value of all Parameters in the ParameterVector to the provided value.
Definition rcpp_interface_base.hpp:331
Parameter & operator[](size_t pos)
The accessor where the first index starts is zero.
Definition rcpp_interface_base.hpp:235
Parameter & get(size_t pos)
An internal accessor for calling a position of a ParameterVector from R.
Definition rcpp_interface_base.hpp:260
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:276
ParameterVector()
The constructor.
Definition rcpp_interface_base.hpp:161
std::shared_ptr< std::vector< Parameter > > storage_m
Parameter storage.
Definition rcpp_interface_base.hpp:152
virtual ~ParameterVector()
Destroy the Parameter Vector object.
Definition rcpp_interface_base.hpp:224
void set_all_estimable(bool estimable)
Sets all Parameters within a ParameterVector as estimable.
Definition rcpp_interface_base.hpp:297
An Rcpp interface that defines the Parameter class.
Definition rcpp_interface_base.hpp:32
double initial_value_m
The initial value of the parameter.
Definition rcpp_interface_base.hpp:45
Parameter(double value)
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:89
Parameter(double value, std::string estimation_type)
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:59
Parameter & operator=(const Parameter &right)
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:76
Parameter()
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:98
double final_value_m
The final value of the parameter.
Definition rcpp_interface_base.hpp:49
SharedString estimation_type_m
A string indicating the estimation type. Options are: constant, fixed_effects, or random_effects,...
Definition rcpp_interface_base.hpp:54
uint32_t id_m
The local ID of the Parameter object.
Definition rcpp_interface_base.hpp:41
static uint32_t id_g
The static ID of the Parameter object.
Definition rcpp_interface_base.hpp:37
Parameter(const Parameter &other)
The constructor for initializing a parameter.
Definition rcpp_interface_base.hpp:67
An Rcpp interface class that defines the RealVector class.
Definition rcpp_interface_base.hpp:375
double & get(size_t pos)
An internal accessor for calling a position of a RealVector from R.
Definition rcpp_interface_base.hpp:515
virtual ~RealVector()
Destroy the real Vector object.
Definition rcpp_interface_base.hpp:442
size_t size()
Returns the size of a RealVector.
Definition rcpp_interface_base.hpp:536
RealVector(const RealVector &other)
The constructor.
Definition rcpp_interface_base.hpp:402
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:531
RealVector(size_t size)
The constructor.
Definition rcpp_interface_base.hpp:408
void resize(size_t size)
Resizes a RealVector to the desired length.
Definition rcpp_interface_base.hpp:543
std::shared_ptr< std::vector< double > > storage_m
real storage.
Definition rcpp_interface_base.hpp:384
RealVector & operator=(const Rcpp::NumericVector &v)
Definition rcpp_interface_base.hpp:450
uint32_t id_m
The local ID of the RealVector object.
Definition rcpp_interface_base.hpp:388
void fill(double value)
Sets the value of all elements in the RealVector to the provided value.
Definition rcpp_interface_base.hpp:552
Rcpp::NumericVector toRVector()
Definition rcpp_interface_base.hpp:477
static uint32_t id_g
The static ID of the RealVector object.
Definition rcpp_interface_base.hpp:380
virtual uint32_t get_id()
Gets the ID of the RealVector object.
Definition rcpp_interface_base.hpp:458
RealVector(Rcpp::NumericVector x, size_t size)
The constructor for initializing a real vector.
Definition rcpp_interface_base.hpp:419
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:497
double & operator[](size_t pos)
The accessor where the first index starts is zero.
Definition rcpp_interface_base.hpp:490
RealVector(const fims::Vector< double > &v)
The constructor for initializing a real vector.
Definition rcpp_interface_base.hpp:429
void show()
The printing methods for a RealVector.
Definition rcpp_interface_base.hpp:562
void fromRVector(const Rcpp::NumericVector &orig)
Definition rcpp_interface_base.hpp:465
RealVector()
The constructor.
Definition rcpp_interface_base.hpp:393
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:639
#define FIMS_ERROR_LOG(MESSAGE)
Definition def.hpp:655
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:128
double sanitize_val(double x)
Sanitize a double value by replacing NaN or Inf with -999.0.
Definition rcpp_interface_base.hpp:114
Code to create shared pointers to allow for the wrapper functions in R to work correctly so the live ...