32inline const Type exp(
const Type &x) {
40inline Type cond_exp_lt(
const Type &left,
const Type &right,
41 const Type &if_true,
const Type &if_false) {
42 return left < right ? if_true : if_false;
52inline const Type log(
const Type &x) {
57inline const Type cos(
const Type &x) {
62inline const Type sqrt(
const Type &x) {
67inline const Type pow(
const Type &x,
const Type &y) {
68 return std::pow(x, y);
72inline const Type lgamma(
const Type &x) {
73 return std::lgamma(x);
76inline double Value(
const double &x) {
return x; }
88inline const Type pnorm(
const Type &x,
const Type &mean,
const Type &sd) {
89 const double z =
static_cast<double>(x - mean) /
90 (
static_cast<double>(sd) * std::sqrt(2.0));
91 return static_cast<Type
>(0.5 * (1.0 + std::erf(z)));
98inline double Value(
const TMBAD_FIMS_TYPE &x) {
return x.Value(); }
100inline double Value(
const double &x) {
return x; }
118inline const Type exp(
const Type &x) {
128inline Type cond_exp_lt(
const Type &left,
const Type &right,
129 const Type &if_true,
const Type &if_false) {
130 return TMBad::CondExpLt(left, right, if_true, if_false);
146inline const Type log(
const Type &x) {
165inline const Type cos(
const Type &x) {
183inline const Type sqrt(
const Type &x) {
202inline const Type pow(
const Type &x,
const Type &y) {
224inline const Type lgamma(
const Type &x) {
234inline const Type pnorm(
const Type &x,
const Type &mean,
const Type &sd) {
238 return ::pnorm(x, mean, sd);
261inline const Type
logistic(
const Type &inflection_point,
const Type &slope,
263 return static_cast<Type
>(1.0) /
264 (
static_cast<Type
>(1.0) +
265 exp(Type(-1.0) * slope * (x - inflection_point)));
279inline const Type
logit(
const Type &a,
const Type &b,
const Type &x) {
280 return -fims_math::log(b - x) + fims_math::log(x - a);
294inline const Type
inv_logit(
const Type &a,
const Type &b,
const Type &logit_x) {
295 return a + (b - a) / (
static_cast<Type
>(1.0) + fims_math::exp(-logit_x));
323 const Type &slope_asc,
324 const Type &inflection_point_desc,
325 const Type &slope_desc,
const Type &x) {
326 return (
static_cast<Type
>(1.0)) /
327 (
static_cast<Type
>(1.0) +
328 exp(Type(-1.0) * slope_asc * (x - inflection_point_asc))) *
329 (
static_cast<Type
>(1.0) /
330 (
static_cast<Type
>(1.0) +
331 exp(slope_desc * (x - inflection_point_desc))));
353const Type
ad_fabs(
const Type &x, Type C = 1e-5) {
357 if (fims_math::Value(C) <= 0.0) {
358 throw std::invalid_argument(
"fims_math::ad_fabs: C is " +
360 ", which is not greater than 0.");
362 return sqrt((x * x) + C);
385template <
typename Type>
386inline const Type
ad_min(
const Type &a,
const Type &b, Type C = 1e-5) {
409template <
typename Type>
410inline const Type
ad_max(
const Type &a,
const Type &b, Type C = 1e-5) {
435template <
typename Type>
439 const size_t n_ages = proportion_at_true_age.
size();
440 const size_t matrix_size = n_ages * n_ages;
441 const size_t matrix_offset =
442 (ageing_error.
size() == matrix_size) ? 0 : year * matrix_size;
445 for (
size_t true_age = 0; true_age < n_ages; true_age++) {
446 for (
size_t observed_age = 0; observed_age < n_ages; observed_age++) {
447 proportion_at_observed_age[observed_age] +=
448 proportion_at_true_age[true_age] *
449 ageing_error[matrix_offset + true_age * n_ages + observed_age];
452 return proportion_at_observed_age;
464T
sum(
const std::vector<T> &v) {
466 for (
size_t i = 0; i < v.size(); i++) {
483 for (
size_t i = 0; i < v.
size(); i++) {
Definition fims_vector.hpp:27
size_type size() const
Returns the number of elements.
Definition fims_vector.hpp:299
Platform macros and the core FIMS logging system.
std::string to_string(T v)
Definition def.hpp:735
const Type logit(const Type &a, const Type &b, const Type &x)
A logit function for bounding of parameters.
Definition fims_math.hpp:279
fims::Vector< Type > apply_ageing_error(const fims::Vector< Type > &proportion_at_true_age, const fims::Vector< Type > &ageing_error, size_t year=0)
Converts values at true age, proportions or expected numbers, to values at observed age using an agei...
Definition fims_math.hpp:436
T sum(const std::vector< T > &v)
Definition fims_math.hpp:464
const Type ad_min(const Type &a, const Type &b, Type C=1e-5)
Definition fims_math.hpp:386
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)
The general double logistic function.
Definition fims_math.hpp:322
const Type ad_max(const Type &a, const Type &b, Type C=1e-5)
Definition fims_math.hpp:410
const Type inv_logit(const Type &a, const Type &b, const Type &logit_x)
An inverse logit function for bounding of parameters.
Definition fims_math.hpp:294
const Type ad_fabs(const Type &x, Type C=1e-5)
Definition fims_math.hpp:353
const Type logistic(const Type &inflection_point, const Type &slope, const Type &x)
The general logistic function.
Definition fims_math.hpp:261
Establishes the FIMS Vector class.
An interface to the modeling platforms, e.g., TMB.