FIMS  v0.11.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
14
20 public:
24 Rcpp::NumericVector observed_data;
28 Rcpp::NumericVector uncertainty;
32 static uint32_t id_g;
37 uint32_t id;
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
63 id(other.id) {}
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
86 public:
106
111 this->amax = amax;
112 this->ymax = ymax;
113 this->age_comp_data.resize(amax * ymax);
114 this->uncertainty.resize(amax * ymax);
116 std::make_shared<AgeCompDataInterface>(*this);
119 }
120
127 : DataInterfaceBase(other),
128 amax(other.amax),
129 ymax(other.ymax),
131 uncertainty(other.uncertainty) {}
132
137
142 virtual uint32_t get_id() { return this->id; }
143
151 virtual std::string to_json() {
152 std::stringstream ss;
153
154 ss << "{\n";
155 ss << " \"name\": \"AgeComp\",\n";
156 ss << " \"id\":" << this->id << ",\n";
157 ss << " \"type\": \"data\",\n";
158 ss << " \"dimensionality\": {\n";
159 ss << " \"header\": [" << "\"n_ages\", \"n_years\"" << "],\n";
160 ss << " \"dimensions\": [" << amax << ", " << ymax << "]\n},\n";
161 ss << " \"value\": [";
162 for (size_t i = 0; i < age_comp_data.size() - 1; i++) {
163 ss << age_comp_data[i] << ", ";
164 }
165 ss << age_comp_data[age_comp_data.size() - 1] << "],\n";
166 ss << "\"uncertainty\":[ ";
167 for (size_t i = 0; i < uncertainty.size() - 1; i++) {
168 ss << uncertainty[i] << ", ";
169 }
170 ss << uncertainty[uncertainty.size() - 1] << "]\n";
171 ss << "}";
172 return ss.str();
173 }
174
175#ifdef TMB_MODEL
176
177 template <typename Type>
178 bool add_to_fims_tmb_internal() {
179 std::shared_ptr<fims_data_object::DataObject<Type>> age_comp_data =
180 std::make_shared<fims_data_object::DataObject<Type>>(this->ymax,
181 this->amax);
182
183 age_comp_data->id = this->id;
184 for (int y = 0; y < ymax; y++) {
185 for (int a = 0; a < amax; a++) {
186 int i_age_year = y * amax + a;
187 age_comp_data->at(y, a) = this->age_comp_data[i_age_year];
188 age_comp_data->uncertainty[i_age_year] = this->uncertainty[i_age_year];
189 }
190 }
191
192 std::shared_ptr<fims_info::Information<Type>> info =
194
195 info->data_objects[this->id] = age_comp_data;
196
197 return true;
198 }
199
204 virtual bool add_to_fims_tmb() {
205 this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
206 this->add_to_fims_tmb_internal<TMBAD_FIMS_TYPE>();
207
208 return true;
209 }
210
211#endif
212};
213
219 public:
239
244 this->lmax = lmax;
245 this->ymax = ymax;
246 this->length_comp_data.resize(lmax * ymax);
247 this->uncertainty.resize(lmax * ymax);
249 std::make_shared<LengthCompDataInterface>(*this);
252 }
253
265
270
275 virtual uint32_t get_id() { return this->id; }
276
284 virtual std::string to_json() {
285 std::stringstream ss;
286
287 ss << "{\n";
288 ss << " \"name\": \"LengthComp\",\n";
289 ss << " \"id\":" << this->id << ",\n";
290 ss << " \"type\": \"data\",\n";
291 ss << " \"dimensionality\": {\n";
292 ss << " \"header\": [" << "\"n_lengths\", \"n_years\"" << "],\n";
293 ss << " \"dimensions\": [" << lmax << ", " << ymax << "]\n},\n";
294 ss << " \"value\": [";
295 for (size_t i = 0; i < length_comp_data.size() - 1; i++) {
296 ss << length_comp_data[i] << ", ";
297 }
298 ss << length_comp_data[length_comp_data.size() - 1] << "],\n";
299 ss << "\"uncertainty\": [ ";
300 for (size_t i = 0; i < uncertainty.size() - 1; i++) {
301 ss << uncertainty[i] << ", ";
302 }
303 ss << uncertainty[uncertainty.size() - 1] << "]\n";
304 ss << "}";
305 return ss.str();
306 }
307
308#ifdef TMB_MODEL
309 template <typename Type>
310 bool add_to_fims_tmb_internal() {
311 std::shared_ptr<fims_data_object::DataObject<Type>> length_comp_data =
312 std::make_shared<fims_data_object::DataObject<Type>>(this->ymax,
313 this->lmax);
314 length_comp_data->id = this->id;
315 for (int y = 0; y < ymax; y++) {
316 for (int l = 0; l < lmax; l++) {
317 int i_length_year = y * lmax + l;
318 length_comp_data->at(y, l) = this->length_comp_data[i_length_year];
319 length_comp_data->uncertainty[i_length_year] =
320 this->uncertainty[i_length_year];
321 }
322 }
323 std::shared_ptr<fims_info::Information<Type>> info =
325 info->data_objects[this->id] = length_comp_data;
326 return true;
327 }
328
333 virtual bool add_to_fims_tmb() {
334 this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
335 this->add_to_fims_tmb_internal<TMBAD_FIMS_TYPE>();
336
337 return true;
338 }
339#endif
340};
341
347 public:
361
366 this->ymax = ymax;
367 this->index_data.resize(ymax);
368 this->uncertainty.resize(ymax);
370 std::make_shared<IndexDataInterface>(*this);
373 }
374
381 : DataInterfaceBase(other),
382 ymax(other.ymax),
383 index_data(other.index_data),
384 uncertainty(other.uncertainty) {}
385
390
395 virtual uint32_t get_id() { return this->id; }
396
404 virtual std::string to_json() {
405 std::stringstream ss;
406
407 ss << "{\n";
408 ss << " \"name\": \"Index\",\n";
409 ss << " \"id\": " << this->id << ",\n";
410 ss << " \"type\": \"data\",\n";
411 ss << " \"dimensionality\": {\n";
412 ss << " \"header\": [" << "\"n_years\"" << "],\n";
413 ss << " \"dimensions\": [" << ymax << "]\n},\n";
414 ss << " \"value\": [";
415 for (size_t i = 0; i < index_data.size() - 1; i++) {
416 ss << index_data[i] << ", ";
417 }
418 ss << index_data[index_data.size() - 1] << "],\n";
419 ss << "\"uncertainty\": [ ";
420 for (size_t i = 0; i < uncertainty.size() - 1; i++) {
421 ss << uncertainty[i] << ", ";
422 }
423 ss << uncertainty[uncertainty.size() - 1] << "]\n";
424 ss << "}";
425 return ss.str();
426 }
427
428#ifdef TMB_MODEL
429
430 template <typename Type>
431 bool add_to_fims_tmb_internal() {
432 std::shared_ptr<fims_data_object::DataObject<Type>> data =
433 std::make_shared<fims_data_object::DataObject<Type>>(this->ymax);
434
435 data->id = this->id;
436
437 for (int y = 0; y < ymax; y++) {
438 data->at(y) = this->index_data[y];
439 data->uncertainty[y] = this->uncertainty[y];
440 }
441
442 std::shared_ptr<fims_info::Information<Type>> info =
444
445 info->data_objects[this->id] = data;
446 return true;
447 }
448
453 virtual bool add_to_fims_tmb() {
454 this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
455 this->add_to_fims_tmb_internal<TMBAD_FIMS_TYPE>();
456
457 return true;
458 }
459
460#endif
461};
462
468 public:
482
487 this->ymax = ymax;
488 this->catch_data.resize(ymax);
489 this->uncertainty.resize(ymax);
491 std::make_shared<CatchDataInterface>(*this);
494 }
495
502 : DataInterfaceBase(other),
503 ymax(other.ymax),
504 catch_data(other.catch_data),
505 uncertainty(other.uncertainty) {}
506
511
516 virtual uint32_t get_id() { return this->id; }
517
525 virtual std::string to_json() {
526 std::stringstream ss;
527
528 ss << "{\n";
529 ss << " \"name\": \"Catch\",\n";
530 ss << " \"id\": " << this->id << ",\n";
531 ss << " \"type\": \"data\",\n";
532 ss << " \"dimensionality\": {\n";
533 ss << " \"header\": [" << "\"n_years\"" << "],\n";
534 ss << " \"dimensions\": [" << ymax << "]\n},\n";
535 ss << " \"value\": [";
536 for (size_t i = 0; i < catch_data.size() - 1; i++) {
537 ss << catch_data[i] << ", ";
538 }
539 ss << catch_data[catch_data.size() - 1] << "],\n";
540 ss << "\"uncertainty\": [ ";
541 for (size_t i = 0; i < uncertainty.size() - 1; i++) {
542 ss << uncertainty[i] << ", ";
543 }
544 ss << uncertainty[uncertainty.size() - 1] << "]\n";
545 ss << "}";
546 return ss.str();
547 }
548
549#ifdef TMB_MODEL
550
551 template <typename Type>
552 bool add_to_fims_tmb_internal() {
553 std::shared_ptr<fims_data_object::DataObject<Type>> data =
554 std::make_shared<fims_data_object::DataObject<Type>>(this->ymax);
555
556 data->id = this->id;
557
558 for (int y = 0; y < ymax; y++) {
559 data->at(y) = this->catch_data[y];
560 data->uncertainty[y] = this->uncertainty[y];
561 }
562
563 std::shared_ptr<fims_info::Information<Type>> info =
565
566 info->data_objects[this->id] = data;
567 return true;
568 }
569
574 virtual bool add_to_fims_tmb() {
575 this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
576 this->add_to_fims_tmb_internal<TMBAD_FIMS_TYPE>();
577
578 return true;
579 }
580
581#endif
582};
583
584#endif
RealVector uncertainty
The vector of age-composition uncertainty that is being passed from R.
Definition rcpp_data.hpp:105
virtual ~AgeCompDataInterface()
The destructor.
Definition rcpp_data.hpp:136
fims_int amax
The first dimension of the data, which relates to the number of age bins.
Definition rcpp_data.hpp:91
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_data.hpp:151
RealVector age_comp_data
The vector of age-composition data that is being passed from R.
Definition rcpp_data.hpp:100
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_data.hpp:142
AgeCompDataInterface(const AgeCompDataInterface &other)
Construct a new Age Comp Data Interface object.
Definition rcpp_data.hpp:126
AgeCompDataInterface(int ymax=0, int amax=0)
The constructor.
Definition rcpp_data.hpp:110
fims_int ymax
The second dimension of the data, which relates to the number of time steps or years.
Definition rcpp_data.hpp:96
RealVector catch_data
The vector of catch data that is being passed from R.
Definition rcpp_data.hpp:476
CatchDataInterface(const CatchDataInterface &other)
Construct a new Catch Data Interface object.
Definition rcpp_data.hpp:501
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_data.hpp:525
virtual ~CatchDataInterface()
The destructor.
Definition rcpp_data.hpp:510
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_data.hpp:516
CatchDataInterface(int ymax=0)
The constructor.
Definition rcpp_data.hpp:486
fims_int ymax
An integer that specifies the second dimension of the data.
Definition rcpp_data.hpp:472
RealVector uncertainty
The vector of catch uncertainty that is being passed from R.
Definition rcpp_data.hpp:481
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
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:655
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:665
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_data.hpp:404
fims_int ymax
An integer that specifies the second dimension of the data.
Definition rcpp_data.hpp:351
IndexDataInterface(int ymax=0)
The constructor.
Definition rcpp_data.hpp:365
RealVector index_data
The vector of index data that is being passed from R.
Definition rcpp_data.hpp:355
virtual ~IndexDataInterface()
The destructor.
Definition rcpp_data.hpp:389
RealVector uncertainty
The vector of index uncertainty that is being passed from R.
Definition rcpp_data.hpp:360
IndexDataInterface(const IndexDataInterface &other)
Construct a new Index Data Interface object.
Definition rcpp_data.hpp:380
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_data.hpp:395
fims_int lmax
The first dimension of the data, which relates to the number of length bins.
Definition rcpp_data.hpp:224
RealVector length_comp_data
The vector of length-composition data that is being passed from R.
Definition rcpp_data.hpp:233
fims_int ymax
The second dimension of the data, which relates to the number of time steps or years.
Definition rcpp_data.hpp:229
LengthCompDataInterface(const LengthCompDataInterface &other)
Construct a new Length Comp Data Interface object.
Definition rcpp_data.hpp:259
RealVector uncertainty
The vector of length-composition uncertainty that is being passed from R.
Definition rcpp_data.hpp:238
virtual ~LengthCompDataInterface()
The destructor.
Definition rcpp_data.hpp:269
LengthCompDataInterface(int ymax=0, int lmax=0)
The constructor.
Definition rcpp_data.hpp:243
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_data.hpp:284
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_data.hpp:275
An Rcpp interface class that defines the RealVector class.
Definition rcpp_interface_base.hpp:431
void resize(size_t size)
Resizes a RealVector to the desired length.
Definition rcpp_interface_base.hpp:609
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:563
static std::shared_ptr< Information< Type > > GetInstance()
Returns a singleton Information object for type T.
Definition information.hpp:262
Code to store all objects that are created in FIMS because FIMS uses integer representation....
The Rcpp interface to declare objects that are used ubiquitously throughout the Rcpp interface,...
SharedInt fims_int
An alias for the SharedInt class.
Definition rcpp_shared_primitive.hpp:2107