FIMS  v0.8.0
Loading...
Searching...
No Matches
rcpp_data.hpp
Go to the documentation of this file.
1
9#ifndef FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_DATA_HPP
10#define FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_DATA_HPP
11
12#include "../../../common/information.hpp"
14
20 public:
24 Rcpp::NumericVector observed_data;
28 Rcpp::NumericVector uncertainty;
32 static uint32_t id_g;
43 static std::map<uint32_t, std::shared_ptr<DataInterfaceBase>> live_objects;
44
49 this->id = DataInterfaceBase::id_g++;
50 /* Create instance of map: key is id and value is pointer to
51 DataInterfaceBase */
52 // DataInterfaceBase::live_objects[this->id] = this;
53 }
54
64
68 virtual ~DataInterfaceBase() {}
69
73 virtual uint32_t get_id() { return this->id; }
74
78 virtual bool add_to_fims_tmb() { return true; };
79};
80// static id of the DataInterfaceBase object
82// local id of the DataInterfaceBase object map relating the ID of the
83// DataInterfaceBase to the DataInterfaceBase objects
84std::map<uint32_t, std::shared_ptr<DataInterfaceBase>>
86
92 public:
112
117 this->amax = amax;
118 this->ymax = ymax;
119 this->age_comp_data.resize(amax * ymax);
120 this->uncertainty.resize(amax * ymax);
122 std::make_shared<AgeCompDataInterface>(*this);
125 }
126
138
143
148 virtual uint32_t get_id() { return this->id; }
149
157 virtual std::string to_json() {
158 std::stringstream ss;
159
160 ss << "{\n";
161 ss << " \"name\": \"AgeComp\",\n";
162 ss << " \"id\":" << this->id << ",\n";
163 ss << " \"type\": \"data\",\n";
164 ss << " \"dimensionality\": {\n";
165 ss << " \"header\": [" << "\"n_ages\", \"n_years\"" << "],\n";
166 ss << " \"dimensions\": [" << amax << ", " << ymax << "]\n},\n";
167 ss << " \"value\": [";
168 for (size_t i = 0; i < age_comp_data.size() - 1; i++) {
169 ss << age_comp_data[i] << ", ";
170 }
171 ss << age_comp_data[age_comp_data.size() - 1] << "],\n";
172 ss << "\"uncertainty\":[ ";
173 for (size_t i = 0; i < uncertainty.size() - 1; i++) {
174 ss << uncertainty[i] << ", ";
175 }
176 ss << uncertainty[uncertainty.size() - 1] << "]\n";
177 ss << "}";
178 return ss.str();
179 }
180
181#ifdef TMB_MODEL
182
183 template <typename Type>
185 std::shared_ptr<fims_data_object::DataObject<Type>> age_comp_data =
186 std::make_shared<fims_data_object::DataObject<Type>>(this->ymax,
187 this->amax);
188
189 age_comp_data->id = this->id;
190 for (int y = 0; y < ymax; y++) {
191 for (int a = 0; a < amax; a++) {
192 int i_age_year = y * amax + a;
193 age_comp_data->at(y, a) = this->age_comp_data[i_age_year];
194 age_comp_data->uncertainty[i_age_year] = this->uncertainty[i_age_year];
195 }
196 }
197
198 std::shared_ptr<fims_info::Information<Type>> info =
200
201 info->data_objects[this->id] = age_comp_data;
202
203 return true;
204 }
205
210 virtual bool add_to_fims_tmb() {
211#ifdef TMBAD_FRAMEWORK
214#else
219#endif
220
221 return true;
222 }
223
224#endif
225};
226
232 public:
252
257 this->lmax = lmax;
258 this->ymax = ymax;
259 this->length_comp_data.resize(lmax * ymax);
260 this->uncertainty.resize(lmax * ymax);
262 std::make_shared<LengthCompDataInterface>(*this);
265 }
266
278
283
288 virtual uint32_t get_id() { return this->id; }
289
297 virtual std::string to_json() {
298 std::stringstream ss;
299
300 ss << "{\n";
301 ss << " \"name\": \"LengthComp\",\n";
302 ss << " \"id\":" << this->id << ",\n";
303 ss << " \"type\": \"data\",\n";
304 ss << " \"dimensionality\": {\n";
305 ss << " \"header\": [" << "\"n_lengths\", \"n_years\"" << "],\n";
306 ss << " \"dimensions\": [" << lmax << ", " << ymax << "]\n},\n";
307 ss << " \"value\": [";
308 for (size_t i = 0; i < length_comp_data.size() - 1; i++) {
309 ss << length_comp_data[i] << ", ";
310 }
311 ss << length_comp_data[length_comp_data.size() - 1] << "],\n";
312 ss << "\"uncertainty\": [ ";
313 for (size_t i = 0; i < uncertainty.size() - 1; i++) {
314 ss << uncertainty[i] << ", ";
315 }
316 ss << uncertainty[uncertainty.size() - 1] << "]\n";
317 ss << "}";
318 return ss.str();
319 }
320
321#ifdef TMB_MODEL
322 template <typename Type>
324 std::shared_ptr<fims_data_object::DataObject<Type>> length_comp_data =
325 std::make_shared<fims_data_object::DataObject<Type>>(this->ymax,
326 this->lmax);
327 length_comp_data->id = this->id;
328 for (int y = 0; y < ymax; y++) {
329 for (int l = 0; l < lmax; l++) {
330 int i_length_year = y * lmax + l;
331 length_comp_data->at(y, l) = this->length_comp_data[i_length_year];
332 length_comp_data->uncertainty[i_length_year] =
333 this->uncertainty[i_length_year];
334 }
335 }
336 std::shared_ptr<fims_info::Information<Type>> info =
338 info->data_objects[this->id] = length_comp_data;
339 return true;
340 }
341
346 virtual bool add_to_fims_tmb() {
347#ifdef TMBAD_FRAMEWORK
350#else
355#endif
356
357 return true;
358 }
359#endif
360};
361
367 public:
381
386 this->ymax = ymax;
387 this->index_data.resize(ymax);
388 this->uncertainty.resize(ymax);
390 std::make_shared<IndexDataInterface>(*this);
393 }
394
405
410
415 virtual uint32_t get_id() { return this->id; }
416
424 virtual std::string to_json() {
425 std::stringstream ss;
426
427 ss << "{\n";
428 ss << " \"name\": \"Index\",\n";
429 ss << " \"id\": " << this->id << ",\n";
430 ss << " \"type\": \"data\",\n";
431 ss << " \"dimensionality\": {\n";
432 ss << " \"header\": [" << "\"n_years\"" << "],\n";
433 ss << " \"dimensions\": [" << ymax << "]\n},\n";
434 ss << " \"value\": [";
435 for (size_t i = 0; i < index_data.size() - 1; i++) {
436 ss << index_data[i] << ", ";
437 }
438 ss << index_data[index_data.size() - 1] << "],\n";
439 ss << "\"uncertainty\": [ ";
440 for (size_t i = 0; i < uncertainty.size() - 1; i++) {
441 ss << uncertainty[i] << ", ";
442 }
443 ss << uncertainty[uncertainty.size() - 1] << "]\n";
444 ss << "}";
445 return ss.str();
446 }
447
448#ifdef TMB_MODEL
449
450 template <typename Type>
452 std::shared_ptr<fims_data_object::DataObject<Type>> data =
453 std::make_shared<fims_data_object::DataObject<Type>>(this->ymax);
454
455 data->id = this->id;
456
457 for (int y = 0; y < ymax; y++) {
458 data->at(y) = this->index_data[y];
459 data->uncertainty[y] = this->uncertainty[y];
460 }
461
462 std::shared_ptr<fims_info::Information<Type>> info =
464
465 info->data_objects[this->id] = data;
466 return true;
467 }
468
473 virtual bool add_to_fims_tmb() {
474#ifdef TMBAD_FRAMEWORK
477#else
482#endif
483
484 return true;
485 }
486
487#endif
488};
489
495 public:
509
514 this->ymax = ymax;
515 this->landings_data.resize(ymax);
516 this->uncertainty.resize(ymax);
518 std::make_shared<LandingsDataInterface>(*this);
521 }
522
533
538
543 virtual uint32_t get_id() { return this->id; }
544
552 virtual std::string to_json() {
553 std::stringstream ss;
554
555 ss << "{\n";
556 ss << " \"name\": \"Landings\",\n";
557 ss << " \"id\": " << this->id << ",\n";
558 ss << " \"type\": \"data\",\n";
559 ss << " \"dimensionality\": {\n";
560 ss << " \"header\": [" << "\"n_years\"" << "],\n";
561 ss << " \"dimensions\": [" << ymax << "]\n},\n";
562 ss << " \"value\": [";
563 for (size_t i = 0; i < landings_data.size() - 1; i++) {
564 ss << landings_data[i] << ", ";
565 }
566 ss << landings_data[landings_data.size() - 1] << "],\n";
567 ss << "\"uncertainty\": [ ";
568 for (size_t i = 0; i < uncertainty.size() - 1; i++) {
569 ss << uncertainty[i] << ", ";
570 }
571 ss << uncertainty[uncertainty.size() - 1] << "]\n";
572 ss << "}";
573 return ss.str();
574 }
575
576#ifdef TMB_MODEL
577
578 template <typename Type>
580 std::shared_ptr<fims_data_object::DataObject<Type>> data =
581 std::make_shared<fims_data_object::DataObject<Type>>(this->ymax);
582
583 data->id = this->id;
584
585 for (int y = 0; y < ymax; y++) {
586 data->at(y) = this->landings_data[y];
587 data->uncertainty[y] = this->uncertainty[y];
588 }
589
590 std::shared_ptr<fims_info::Information<Type>> info =
592
593 info->data_objects[this->id] = data;
594 return true;
595 }
596
601 virtual bool add_to_fims_tmb() {
602#ifdef TMBAD_FRAMEWORK
605#else
610#endif
611
612 return true;
613 }
614
615#endif
616};
617
618#endif
The Rcpp interface for AgeComp to instantiate the object from R: acomp <- methods::new(AgeComp).
Definition rcpp_data.hpp:91
RealVector uncertainty
The vector of age-composition uncertainty that is being passed from R.
Definition rcpp_data.hpp:111
virtual ~AgeCompDataInterface()
The destructor.
Definition rcpp_data.hpp:142
fims_int amax
The first dimension of the data, which relates to the number of age bins.
Definition rcpp_data.hpp:97
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_data.hpp:157
RealVector age_comp_data
The vector of age-composition data that is being passed from R.
Definition rcpp_data.hpp:106
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_data.hpp:148
AgeCompDataInterface(const AgeCompDataInterface &other)
Construct a new Age Comp Data Interface object.
Definition rcpp_data.hpp:132
AgeCompDataInterface(int ymax=0, int amax=0)
The constructor.
Definition rcpp_data.hpp:116
fims_int ymax
The second dimension of the data, which relates to the number of time steps or years.
Definition rcpp_data.hpp:102
Rcpp interface that serves as the parent class for Rcpp data interfaces. This type should be inherite...
Definition rcpp_data.hpp:19
virtual bool add_to_fims_tmb()
Adds the parameters to the TMB model.
Definition rcpp_data.hpp:78
virtual ~DataInterfaceBase()
The destructor.
Definition rcpp_data.hpp:68
DataInterfaceBase()
The constructor.
Definition rcpp_data.hpp:48
static uint32_t id_g
The static id of the DataInterfaceBase object.
Definition rcpp_data.hpp:32
uint32_t id
The local id of the DataInterfaceBase object.
Definition rcpp_data.hpp:37
virtual uint32_t get_id()
Get the ID for the child data interface objects to inherit.
Definition rcpp_data.hpp:73
Rcpp::NumericVector uncertainty
The vector of uncertainty that is being passed from R.
Definition rcpp_data.hpp:28
DataInterfaceBase(const DataInterfaceBase &other)
Construct a new Data Interface Base object.
Definition rcpp_data.hpp:60
static std::map< uint32_t, std::shared_ptr< DataInterfaceBase > > live_objects
The map associating the IDs of DataInterfaceBase to the objects. This is a live object,...
Definition rcpp_data.hpp:43
Rcpp::NumericVector observed_data
The vector of data that is being passed from R.
Definition rcpp_data.hpp:24
Base class for all interface objects.
Definition rcpp_interface_base.hpp:634
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:644
The Rcpp interface for Index to instantiate the object from R: fleet <- methods::new(Index).
Definition rcpp_data.hpp:366
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_data.hpp:424
fims_int ymax
An integer that specifies the second dimension of the data.
Definition rcpp_data.hpp:371
IndexDataInterface(int ymax=0)
The constructor.
Definition rcpp_data.hpp:385
RealVector index_data
The vector of index data that is being passed from R.
Definition rcpp_data.hpp:375
virtual ~IndexDataInterface()
The destructor.
Definition rcpp_data.hpp:409
RealVector uncertainty
The vector of index uncertainty that is being passed from R.
Definition rcpp_data.hpp:380
IndexDataInterface(const IndexDataInterface &other)
Construct a new Index Data Interface object.
Definition rcpp_data.hpp:400
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_data.hpp:415
The Rcpp interface for Landings to instantiate the object from R: fleet <- methods::new(Landings).
Definition rcpp_data.hpp:494
LandingsDataInterface(int ymax=0)
The constructor.
Definition rcpp_data.hpp:513
LandingsDataInterface(const LandingsDataInterface &other)
Construct a new Landings Data Interface object.
Definition rcpp_data.hpp:528
RealVector uncertainty
The vector of landings uncertainty that is being passed from R.
Definition rcpp_data.hpp:508
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_data.hpp:552
RealVector landings_data
The vector of landings data that is being passed from R.
Definition rcpp_data.hpp:503
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_data.hpp:543
fims_int ymax
An integer that specifies the second dimension of the data.
Definition rcpp_data.hpp:499
virtual ~LandingsDataInterface()
The destructor.
Definition rcpp_data.hpp:537
The Rcpp interface for LengthComp to instantiate the object from R: lcomp <- methods::new(LengthComp)...
Definition rcpp_data.hpp:231
fims_int lmax
The first dimension of the data, which relates to the number of length bins.
Definition rcpp_data.hpp:237
RealVector length_comp_data
The vector of length-composition data that is being passed from R.
Definition rcpp_data.hpp:246
fims_int ymax
The second dimension of the data, which relates to the number of time steps or years.
Definition rcpp_data.hpp:242
LengthCompDataInterface(const LengthCompDataInterface &other)
Construct a new Length Comp Data Interface object.
Definition rcpp_data.hpp:272
RealVector uncertainty
The vector of length-composition uncertainty that is being passed from R.
Definition rcpp_data.hpp:251
virtual ~LengthCompDataInterface()
The destructor.
Definition rcpp_data.hpp:282
LengthCompDataInterface(int ymax=0, int lmax=0)
The constructor.
Definition rcpp_data.hpp:256
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_data.hpp:297
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_data.hpp:288
An Rcpp interface class that defines the RealVector class.
Definition rcpp_interface_base.hpp:434
size_t size()
Returns the size of a RealVector.
Definition rcpp_interface_base.hpp:595
void resize(size_t size)
Resizes a RealVector to the desired length.
Definition rcpp_interface_base.hpp:602
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
A class that provides shared ownership of an integer value.
Definition rcpp_shared_primitive.hpp:24
static std::shared_ptr< Information< Type > > GetInstance()
Returns a singleton Information object for type T.
Definition information.hpp:238
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:279
The Rcpp interface to declare objects that are used ubiquitously throughout the Rcpp interface,...