Skip to content

Commit

Permalink
Merge branch 'main' into 494-questionhelp-why-is-populationspawning_b…
Browse files Browse the repository at this point in the history
…iomass-indexed-by-age-in-test
  • Loading branch information
Bai-Li-NOAA authored Nov 3, 2023
2 parents 9267058 + 2b679d3 commit 42e66a2
Show file tree
Hide file tree
Showing 68 changed files with 1,219 additions and 1,303 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-checklist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name: Add a comment with reviewer checklist when PR opened
on:
pull_request:

types: [opened]
jobs:
pr-checklist:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/run-googletest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# Use windows-2019 instead of windows-latest to avoid using Mingw-w64
os: [ubuntu-latest, macos-latest, windows-2019]
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

Expand Down
12 changes: 6 additions & 6 deletions R/create_rcpp_interface_object.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' model = "LogisticSelectivity",
#' base_class = "SelectivityInterfaceBase",
#' container = "selectivity_models",
#' parameters = c("slope", "median"),
#' parameters = c("slope", "inflection_point"),
#' evaluate_parameter = "x",
#' evaluate_parameter_type = "double"
#' )
Expand Down Expand Up @@ -69,7 +69,7 @@ create_fims_rcpp_interface <- function(interface_name = character(),

if (!is.null(evaluate_parameter)) {
cat(paste0(" virtual double evaluate(", evaluate_parameter_type, " ", evaluate_parameter, ") {\n"))
cat(paste0(" fims::", model, "<double> object;\n"))
cat(paste0(" fims_popdy::", model, "<double> object;\n"))
for (i in 1:length(parameters)) {
cat(paste0(" object.", parameters[i], " = this->", parameters[i], ".value;\n"))
}
Expand All @@ -78,20 +78,20 @@ create_fims_rcpp_interface <- function(interface_name = character(),

cat(" virtual bool add_to_fims_tmb(){\n")
for (i in 1:4) {
cat(paste0(" std::shared_ptr<fims::Information<", types[i]))
cat(paste0(" std::shared_ptr<fims_info::Information<", types[i]))
cat(paste("> >", itypes[i]))
cat(" =\n")
cat(" fims::Information<")
cat(" fims_info::Information<")
cat(types[i])
cat(">::GetInstance();\n\n")
cat(" std::shared_ptr<fims::")
cat(" std::shared_ptr<fims_popdy::")
cat(model)
cat("<")
cat(types[i])
cat("> > ")
cat(mtypes[i])
cat(" =\n")
cat(" std::make_shared<fims::")
cat(" std::make_shared<fims_popdy::")
cat(model)
cat("<")
cat(types[i])
Expand Down
6 changes: 3 additions & 3 deletions inst/include/common/data_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@

#include "model_object.hpp"

namespace fims {
namespace fims_data_object {

/**
* Container to hold user supplied data.
*/
template <typename Type>
struct DataObject : public fims::FIMSObject<Type> {
struct DataObject : public fims_model_object::FIMSObject<Type> {
static uint32_t id_g; /*!< id of the Data Object >*/
std::vector<Type> data; /*!< vector of the data >*/
size_t dimensions; /*!< dimension of the Data object >*/
Expand Down Expand Up @@ -225,6 +225,6 @@ struct DataObject : public fims::FIMSObject<Type> {
template <typename Type>
uint32_t DataObject<Type>::id_g = 0;

} // namespace fims
} // namespace fims_data_object

#endif
24 changes: 22 additions & 2 deletions inst/include/common/def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,27 @@
#include <memory>
#include <vector>

std::ofstream FIMS_LOG("fims.log"); /**< Log file */
// The following rows initialize default log files for outputing model progress
// comments used to assist in diagnosing model issues and tracking progress.
// These files will only be created if a logs folder is added to the root model
// directory.
std::ofstream FIMS_LOG("logs/fims.log"); /**< Generic log file */
std::ofstream INFO_LOG("logs/info.log"); /**< Information.hpp log file */
std::ofstream ERROR_LOG("logs/error.log"); /**< Error tracking log file */
std::ofstream DATA_LOG("logs/data.log"); /**< Data input tracking log file */
std::ofstream MODEL_LOG("logs/model.log"); /**< Model.hpp log file */
std::ofstream FLEET_LOG("logs/fleet.log"); /**< Fleet module log file */
std::ofstream POPULATION_LOG(
"logs/population.log"); /**< Populations module log file */
std::ofstream RECRUITMENT_LOG(
"logs/recruitment.log"); /**< Recruitment module log file */
std::ofstream GROWTH_LOG("logs/growth.log"); /**< Growth module log file */
std::ofstream MATURITY_LOG(
"logs/maturity.log"); /**< Maturity module log file */
std::ofstream SELECTIVITY_LOG(
"logs/selectivity.log"); /**< Selectivity module log file */
std::ofstream DEBUG_LOG(
"logs/debug/debug.log"); /**< Development debugging log file */

#ifdef TMB_MODEL
// simplify access to singletons
Expand Down Expand Up @@ -58,7 +78,7 @@ std::map<std::string, std::ofstream> fims_log::FIMS_LOGS;
* @brief Default trait. These are "T" specific
* traits that depend on modeling platform.
*/
template <typename T>
template <typename Type>
struct ModelTraits {
typedef double real_t; /**< The real type */
typedef double variable_t; /**< The variable type */
Expand Down
107 changes: 56 additions & 51 deletions inst/include/common/fims_math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@

#include "../interface/interface.hpp"

namespace fims {
namespace fims_math {
#ifdef STD_LIB
/**
* @brief The exponential function.
*
* @param x value to exponentiate. Please use fims::exp<double>(x) if x is an
* integer.
* @param x value to exponentiate. Please use fims_math::exp<double>(x) if x is
* an integer.
* @return the exponentiated value
*/
template <class T>
inline const T exp(const T &x) {
template <class Type>
inline const Type exp(const Type &x) {
return std::exp(x);
}

/**
* @brief The natural log function (base e)
* @param x the value to take the log of. Please use fims::log<double>(x) if x
* is an integer.
* @param x the value to take the log of. Please use fims_math::log<double>(x)
* if x is an integer.
* @return
*/
template <class T>
inline const T log(const T &x) {
template <class Type>
inline const Type log(const Type &x) {
return std::log(x);
}
#endif
Expand All @@ -54,12 +54,12 @@ inline const T log(const T &x) {
* @brief The exponential function.
* The code cannot be tested using the compilation flag
* -DTMB_MODEL through CMake and Google Test
* @param x value to exponentiate. Please use fims::exp<double>(x) if x is an
* integer.
* @param x value to exponentiate. Please use fims_math::exp<double>(x) if x is
* an integer.
* @return the exponentiated value
*/
template <class T>
inline const T exp(const T &x) {
template <class Type>
inline const Type exp(const Type &x) {
using ::exp;
return exp(x);
}
Expand All @@ -73,12 +73,12 @@ inline const double exp(const double &x) {
* @brief The natural log function (base e)
* The code cannot be tested using the compilation flag
* -DTMB_MODEL through CMake and Google Test.
* @param x the value to take the log of. Please use fims::log<double>(x) if x
* is an integer.
* @param x the value to take the log of. Please use fims_math::log<double>(x)
* if x is an integer.
* @return the log of the value
*/
template <class T>
inline const T log(const T &x) {
template <class Type>
inline const Type log(const Type &x) {
return log(x);
}

Expand All @@ -92,16 +92,17 @@ inline const double log(const double &x) {
/**
* @brief The general logistic function
*
* \f$ \frac{1.0}{ 1.0 + exp(-1.0 * slope (x - median))} \f$
* \f$ \frac{1.0}{ 1.0 + exp(-1.0 * slope (x - inflection_point))} \f$
*
* @param median the median (inflection point) of the logistic function
* @param inflection_point the inflection point of the logistic function
* @param slope the slope of the logistic function
* @param x the index the logistic function should be evaluated at
* @return
*/
template <class T>
inline const T logistic(const T &median, const T &slope, const T &x) {
return (1.0) / (1.0 + exp(-1.0 * slope * (x - median)));
template <class Type>
inline const Type logistic(const Type &inflection_point, const Type &slope,
const Type &x) {
return (1.0) / (1.0 + exp(-1.0 * slope * (x - inflection_point)));
}

/**
Expand All @@ -114,9 +115,9 @@ inline const T logistic(const T &median, const T &slope, const T &x) {
* @return the parameter in real space
*
*/
template <class T>
inline const T logit(const T &a, const T &b, const T &x) {
return -fims::log(b - x) + fims::log(x - a);
template <class Type>
inline const Type logit(const Type &a, const Type &b, const Type &x) {
return -fims_math::log(b - x) + fims_math::log(x - a);
}

/**
Expand All @@ -129,36 +130,39 @@ inline const T logit(const T &a, const T &b, const T &x) {
* @return the parameter in bounded space
*
*/
template <class T>
inline const T inv_logit(const T &a, const T &b, const T &logit_x) {
return a + (b - a) / (1 + fims::exp(-logit_x));
template <class Type>
inline const Type inv_logit(const Type &a, const Type &b, const Type &logit_x) {
return a + (b - a) / (1.0 + fims_math::exp(-logit_x));
}

/**
* @brief The general double logistic function
*
* \f$ \frac{1.0}{ 1.0 + exp(-1.0 * slope_{asc} (x - median_{asc}))}
* \left(1-\frac{1.0}{ 1.0 + exp(-1.0 * slope_{desc} (x - median_{desc}))}
* \right)\f$
* \f$ \frac{1.0}{ 1.0 + exp(-1.0 * slope_{asc} (x - inflection_point_{asc}))}
* \left(1-\frac{1.0}{ 1.0 + exp(-1.0 * slope_{desc} (x -
* inflection_point_{desc}))} \right)\f$
*
* @param median_asc the median (inflection point) of the ascending limb of the
* @param inflection_point_asc the inflection point of the ascending limb of the
* double logistic function
* @param slope_asc the slope of the ascending limb of the double logistic
* function
* @param median_desc the median (inflection point) of the descending limb of
* the double logistic function, where median_desc > median_asc
* @param inflection_point_desc the inflection point of the descending limb of
* the double logistic function, where inflection_point_desc >
* inflection_point_asc
* @param slope_desc the slope of the descending limb of the double logistic
* function
* @param x the index the logistic function should be evaluated at
* @return
*/

template <class T>
inline const T double_logistic(const T &median_asc, const T &slope_asc,
const T &median_desc, const T &slope_desc,
const T &x) {
return (1.0) / (1.0 + exp(-1.0 * slope_asc * (x - median_asc))) *
(1.0 - (1.0) / (1.0 + exp(-1.0 * slope_desc * (x - median_desc))));
template <class Type>
inline const Type double_logistic(const Type &inflection_point_asc,
const Type &slope_asc,
const Type &inflection_point_desc,
const Type &slope_desc, const Type &x) {
return (1.0) / (1.0 + exp(-1.0 * slope_asc * (x - inflection_point_asc))) *
(1.0 -
(1.0) / (1.0 + exp(-1.0 * slope_desc * (x - inflection_point_desc))));
}

/**
Expand All @@ -174,17 +178,17 @@ inline const T double_logistic(const T &median_asc, const T &slope_asc,
* @param C default = 1e-5
* @return
*/
template <class T>
const T ad_fabs(const T &x, T C = 1e-5) {
template <class Type>
const Type ad_fabs(const Type &x, Type C = 1e-5) {
return sqrt((x * x) + C); //, .5);
}

/**
*
* Returns the minimum between a and b in a continuous manner using:
*
* (a + b - fims::ad_fabs(a - b))*.5;
* Reference: \ref fims::ad_fabs()
* (a + b - fims_math::ad_fabs(a - b))*.5;
* Reference: \ref fims_math::ad_fabs()
*
* This is an approximation with minimal error.
*
Expand All @@ -193,16 +197,17 @@ const T ad_fabs(const T &x, T C = 1e-5) {
* @param C default = 1e-5
* @return
*/
template <typename T>
inline const T ad_min(const T &a, const T &b, T C = 1e-5) {
return (a + b - fims::ad_fabs(a - b, C)) * .5;

template <typename Type>
inline const Type ad_min(const Type &a, const Type &b, Type C = 1e-5) {
return (a + b - fims_math::ad_fabs(a - b, C)) * 0.5;
}

/**
* Returns the maximum between a and b in a continuous manner using:
*
* (a + b + fims::ad_fabs(a - b)) *.5;
* Reference: \ref fims::ad_fabs()
* (a + b + fims_math::ad_fabs(a - b)) *.5;
* Reference: \ref fims_math::ad_fabs()
* This is an approximation with minimal error.
*
* @param a
Expand All @@ -212,9 +217,9 @@ inline const T ad_min(const T &a, const T &b, T C = 1e-5) {
*/
template <typename Type>
inline const Type ad_max(const Type &a, const Type &b, Type C = 1e-5) {
return (a + b + fims::ad_fabs(a - b, C)) * static_cast<Type>(.5);
return (a + b + fims_math::ad_fabs(a - b, C)) * static_cast<Type>(.5);
}

} // namespace fims
} // namespace fims_math

#endif /* FIMS_MATH_HPP */
Loading

0 comments on commit 42e66a2

Please sign in to comment.