Skip to content

Commit

Permalink
Added ToJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
msupernaw committed Jul 18, 2024
1 parent 91a48bf commit 1133b52
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 24 additions & 2 deletions inst/include/interface/rcpp/rcpp_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ void Finalize() {
}
}

/**
* @brief Extracts derived quantities from model objects.
*/
void ToJSON() {
std::stringstream ss;
ss<<"[\n";
size_t length = FIMSRcppInterfaceBase::fims_interface_objects.size();
for (size_t i = 0; i < length-1;i++) {
ss<<FIMSRcppInterfaceBase::fims_interface_objects[i]->to_json()<<",\n";
}

ss<<FIMSRcppInterfaceBase::fims_interface_objects[length-1]->to_json()<<"\n]";
return ss.str();
}

Rcpp::NumericVector get_fixed_parameters_vector() {
// base model
std::shared_ptr<fims_info::Information < TMB_FIMS_REAL_TYPE>> d0 =
Expand Down Expand Up @@ -464,6 +479,7 @@ RCPP_EXPOSED_CLASS(ParameterVector)
RCPP_MODULE(fims) {
Rcpp::function("CreateTMBModel", &CreateTMBModel);
Rcpp::function("Finalize", &Finalize);
Rcpp::function("ToJSON", &ToJSON);
Rcpp::function("get_fixed", &get_fixed_parameters_vector);
Rcpp::function("get_random", &get_random_parameters_vector);
Rcpp::function("clear", clear);
Expand Down Expand Up @@ -612,21 +628,27 @@ RCPP_MODULE(fims) {
.constructor()
.field("inflection_point",
&LogisticSelectivityInterface::inflection_point)
.field("estimated_inflection_point",
.field("estimated_inflection_point",
&LogisticSelectivityInterface::estimated_inflection_point)
.field("slope", &LogisticSelectivityInterface::slope)
.field("slope", &LogisticSelectivityInterface::slope)
.field("slope", &LogisticSelectivityInterface::slope)
.method("get_id", &LogisticSelectivityInterface::get_id)
.method("evaluate", &LogisticSelectivityInterface::evaluate);

Rcpp::class_<DoubleLogisticSelectivityInterface>("DoubleLogisticSelectivity")
.constructor()
.field("inflection_point_asc",
&DoubleLogisticSelectivityInterface::inflection_point_asc)
.field("estimated_inflection_point_asc",
&DoubleLogisticSelectivityInterface::estimated_inflection_point_asc)
.field("slope_asc", &DoubleLogisticSelectivityInterface::slope_asc)
.field("estimated_slope_asc", &DoubleLogisticSelectivityInterface::estimated_slope_asc)
.field("inflection_point_desc",
&DoubleLogisticSelectivityInterface::inflection_point_desc)
.field("estimated_inflection_point_desc",
&DoubleLogisticSelectivityInterface::estimated_inflection_point_desc)
.field("slope_desc", &DoubleLogisticSelectivityInterface::slope_desc)
.field("estimated_slope_desc", &DoubleLogisticSelectivityInterface::estimated_slope_desc)
.method("get_id", &DoubleLogisticSelectivityInterface::get_id)
.method("evaluate", &DoubleLogisticSelectivityInterface::evaluate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ class FIMSRcppInterfaceBase {
virtual void finalize() {

}

virtual std::string to_json(){

}
};
std::vector<FIMSRcppInterfaceBase *>
FIMSRcppInterfaceBase::fims_interface_objects;
Expand Down

0 comments on commit 1133b52

Please sign in to comment.