FIMS  v0.8.1
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() {
213
214 return true;
215 }
216
217#endif
218};
219
225 public:
245
250 this->lmax = lmax;
251 this->ymax = ymax;
252 this->length_comp_data.resize(lmax * ymax);
253 this->uncertainty.resize(lmax * ymax);
255 std::make_shared<LengthCompDataInterface>(*this);
258 }
259
271
276
281 virtual uint32_t get_id() { return this->id; }
282
290 virtual std::string to_json() {
291 std::stringstream ss;
292
293 ss << "{\n";
294 ss << " \"name\": \"LengthComp\",\n";
295 ss << " \"id\":" << this->id << ",\n";
296 ss << " \"type\": \"data\",\n";
297 ss << " \"dimensionality\": {\n";
298 ss << " \"header\": [" << "\"n_lengths\", \"n_years\"" << "],\n";
299 ss << " \"dimensions\": [" << lmax << ", " << ymax << "]\n},\n";
300 ss << " \"value\": [";
301 for (size_t i = 0; i < length_comp_data.size() - 1; i++) {
302 ss << length_comp_data[i] << ", ";
303 }
304 ss << length_comp_data[length_comp_data.size() - 1] << "],\n";
305 ss << "\"uncertainty\": [ ";
306 for (size_t i = 0; i < uncertainty.size() - 1; i++) {
307 ss << uncertainty[i] << ", ";
308 }
309 ss << uncertainty[uncertainty.size() - 1] << "]\n";
310 ss << "}";
311 return ss.str();
312 }
313
314#ifdef TMB_MODEL
315 template <typename Type>
317 std::shared_ptr<fims_data_object::DataObject<Type>> length_comp_data =
318 std::make_shared<fims_data_object::DataObject<Type>>(this->ymax,
319 this->lmax);
320 length_comp_data->id = this->id;
321 for (int y = 0; y < ymax; y++) {
322 for (int l = 0; l < lmax; l++) {
323 int i_length_year = y * lmax + l;
324 length_comp_data->at(y, l) = this->length_comp_data[i_length_year];
325 length_comp_data->uncertainty[i_length_year] =
326 this->uncertainty[i_length_year];
327 }
328 }
329 std::shared_ptr<fims_info::Information<Type>> info =
331 info->data_objects[this->id] = length_comp_data;
332 return true;
333 }
334
339 virtual bool add_to_fims_tmb() {
342
343 return true;
344 }
345#endif
346};
347
353 public:
367
372 this->ymax = ymax;
373 this->index_data.resize(ymax);
374 this->uncertainty.resize(ymax);
376 std::make_shared<IndexDataInterface>(*this);
379 }
380
391
396
401 virtual uint32_t get_id() { return this->id; }
402
410 virtual std::string to_json() {
411 std::stringstream ss;
412
413 ss << "{\n";
414 ss << " \"name\": \"Index\",\n";
415 ss << " \"id\": " << this->id << ",\n";
416 ss << " \"type\": \"data\",\n";
417 ss << " \"dimensionality\": {\n";
418 ss << " \"header\": [" << "\"n_years\"" << "],\n";
419 ss << " \"dimensions\": [" << ymax << "]\n},\n";
420 ss << " \"value\": [";
421 for (size_t i = 0; i < index_data.size() - 1; i++) {
422 ss << index_data[i] << ", ";
423 }
424 ss << index_data[index_data.size() - 1] << "],\n";
425 ss << "\"uncertainty\": [ ";
426 for (size_t i = 0; i < uncertainty.size() - 1; i++) {
427 ss << uncertainty[i] << ", ";
428 }
429 ss << uncertainty[uncertainty.size() - 1] << "]\n";
430 ss << "}";
431 return ss.str();
432 }
433
434#ifdef TMB_MODEL
435
436 template <typename Type>
438 std::shared_ptr<fims_data_object::DataObject<Type>> data =
439 std::make_shared<fims_data_object::DataObject<Type>>(this->ymax);
440
441 data->id = this->id;
442
443 for (int y = 0; y < ymax; y++) {
444 data->at(y) = this->index_data[y];
445 data->uncertainty[y] = this->uncertainty[y];
446 }
447
448 std::shared_ptr<fims_info::Information<Type>> info =
450
451 info->data_objects[this->id] = data;
452 return true;
453 }
454
459 virtual bool add_to_fims_tmb() {
462
463 return true;
464 }
465
466#endif
467};
468
474 public:
488
493 this->ymax = ymax;
494 this->landings_data.resize(ymax);
495 this->uncertainty.resize(ymax);
497 std::make_shared<LandingsDataInterface>(*this);
500 }
501
512
517
522 virtual uint32_t get_id() { return this->id; }
523
531 virtual std::string to_json() {
532 std::stringstream ss;
533
534 ss << "{\n";
535 ss << " \"name\": \"Landings\",\n";
536 ss << " \"id\": " << this->id << ",\n";
537 ss << " \"type\": \"data\",\n";
538 ss << " \"dimensionality\": {\n";
539 ss << " \"header\": [" << "\"n_years\"" << "],\n";
540 ss << " \"dimensions\": [" << ymax << "]\n},\n";
541 ss << " \"value\": [";
542 for (size_t i = 0; i < landings_data.size() - 1; i++) {
543 ss << landings_data[i] << ", ";
544 }
545 ss << landings_data[landings_data.size() - 1] << "],\n";
546 ss << "\"uncertainty\": [ ";
547 for (size_t i = 0; i < uncertainty.size() - 1; i++) {
548 ss << uncertainty[i] << ", ";
549 }
550 ss << uncertainty[uncertainty.size() - 1] << "]\n";
551 ss << "}";
552 return ss.str();
553 }
554
555#ifdef TMB_MODEL
556
557 template <typename Type>
559 std::shared_ptr<fims_data_object::DataObject<Type>> data =
560 std::make_shared<fims_data_object::DataObject<Type>>(this->ymax);
561
562 data->id = this->id;
563
564 for (int y = 0; y < ymax; y++) {
565 data->at(y) = this->landings_data[y];
566 data->uncertainty[y] = this->uncertainty[y];
567 }
568
569 std::shared_ptr<fims_info::Information<Type>> info =
571
572 info->data_objects[this->id] = data;
573 return true;
574 }
575
580 virtual bool add_to_fims_tmb() {
583
584 return true;
585 }
586
587#endif
588};
589
590#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:574
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:584
The Rcpp interface for Index to instantiate the object from R: fleet <- methods::new(Index).
Definition rcpp_data.hpp:352
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_data.hpp:410
fims_int ymax
An integer that specifies the second dimension of the data.
Definition rcpp_data.hpp:357
IndexDataInterface(int ymax=0)
The constructor.
Definition rcpp_data.hpp:371
RealVector index_data
The vector of index data that is being passed from R.
Definition rcpp_data.hpp:361
virtual ~IndexDataInterface()
The destructor.
Definition rcpp_data.hpp:395
RealVector uncertainty
The vector of index uncertainty that is being passed from R.
Definition rcpp_data.hpp:366
IndexDataInterface(const IndexDataInterface &other)
Construct a new Index Data Interface object.
Definition rcpp_data.hpp:386
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_data.hpp:401
The Rcpp interface for Landings to instantiate the object from R: fleet <- methods::new(Landings).
Definition rcpp_data.hpp:473
LandingsDataInterface(int ymax=0)
The constructor.
Definition rcpp_data.hpp:492
LandingsDataInterface(const LandingsDataInterface &other)
Construct a new Landings Data Interface object.
Definition rcpp_data.hpp:507
RealVector uncertainty
The vector of landings uncertainty that is being passed from R.
Definition rcpp_data.hpp:487
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_data.hpp:531
RealVector landings_data
The vector of landings data that is being passed from R.
Definition rcpp_data.hpp:482
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_data.hpp:522
fims_int ymax
An integer that specifies the second dimension of the data.
Definition rcpp_data.hpp:478
virtual ~LandingsDataInterface()
The destructor.
Definition rcpp_data.hpp:516
The Rcpp interface for LengthComp to instantiate the object from R: lcomp <- methods::new(LengthComp)...
Definition rcpp_data.hpp:224
fims_int lmax
The first dimension of the data, which relates to the number of length bins.
Definition rcpp_data.hpp:230
RealVector length_comp_data
The vector of length-composition data that is being passed from R.
Definition rcpp_data.hpp:239
fims_int ymax
The second dimension of the data, which relates to the number of time steps or years.
Definition rcpp_data.hpp:235
LengthCompDataInterface(const LengthCompDataInterface &other)
Construct a new Length Comp Data Interface object.
Definition rcpp_data.hpp:265
RealVector uncertainty
The vector of length-composition uncertainty that is being passed from R.
Definition rcpp_data.hpp:244
virtual ~LengthCompDataInterface()
The destructor.
Definition rcpp_data.hpp:275
LengthCompDataInterface(int ymax=0, int lmax=0)
The constructor.
Definition rcpp_data.hpp:249
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_data.hpp:290
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_data.hpp:281
An Rcpp interface class that defines the RealVector class.
Definition rcpp_interface_base.hpp:374
size_t size()
Returns the size of a RealVector.
Definition rcpp_interface_base.hpp:535
void resize(size_t size)
Resizes a RealVector to the desired length.
Definition rcpp_interface_base.hpp:542
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
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:239
The Rcpp interface to declare objects that are used ubiquitously throughout the Rcpp interface,...