32inline const Type exp(
const Type &x) {
43inline const Type log(
const Type &x) {
48inline const Type cos(
const Type &x) {
53inline const Type sqrt(
const Type &x) {
58inline const Type pow(
const Type &x,
const Type &y) {
59 return std::pow(x, y);
63inline const Type lgamma(
const Type &x) {
64 return std::lgamma(x);
67inline double Value(
const double &x) {
return x; }
79inline const Type pnorm(
const Type &x,
const Type &mean,
const Type &sd) {
80 const double z =
static_cast<double>(x - mean) /
81 (
static_cast<double>(sd) * std::sqrt(2.0));
82 return static_cast<Type
>(0.5 * (1.0 + std::erf(z)));
89inline double Value(
const TMBAD_FIMS_TYPE &x) {
return x.Value(); }
91inline double Value(
const double &x) {
return x; }
109inline const Type exp(
const Type &x) {
128inline const Type log(
const Type &x) {
147inline const Type cos(
const Type &x) {
165inline const Type sqrt(
const Type &x) {
184inline const Type pow(
const Type &x,
const Type &y) {
206inline const Type lgamma(
const Type &x) {
216inline const Type pnorm(
const Type &x,
const Type &mean,
const Type &sd) {
220 return ::pnorm(x, mean, sd);
243inline const Type
logistic(
const Type &inflection_point,
const Type &slope,
245 return static_cast<Type
>(1.0) /
246 (
static_cast<Type
>(1.0) +
247 exp(Type(-1.0) * slope * (x - inflection_point)));
261inline const Type
logit(
const Type &a,
const Type &b,
const Type &x) {
262 return -fims_math::log(b - x) + fims_math::log(x - a);
276inline const Type
inv_logit(
const Type &a,
const Type &b,
const Type &logit_x) {
277 return a + (b - a) / (
static_cast<Type
>(1.0) + fims_math::exp(-logit_x));
305 const Type &slope_asc,
306 const Type &inflection_point_desc,
307 const Type &slope_desc,
const Type &x) {
308 return (
static_cast<Type
>(1.0)) /
309 (
static_cast<Type
>(1.0) +
310 exp(Type(-1.0) * slope_asc * (x - inflection_point_asc))) *
311 (
static_cast<Type
>(1.0) /
312 (
static_cast<Type
>(1.0) +
313 exp(slope_desc * (x - inflection_point_desc))));
333const Type
ad_fabs(
const Type &x, Type C = 1e-5) {
334 return sqrt((x * x) + C);
356template <
typename Type>
357inline const Type
ad_min(
const Type &a,
const Type &b, Type C = 1e-5) {
379template <
typename Type>
380inline const Type
ad_max(
const Type &a,
const Type &b, Type C = 1e-5) {
405template <
typename Type>
409 const size_t n_ages = proportion_at_true_age.
size();
410 const size_t matrix_size = n_ages * n_ages;
411 const size_t matrix_offset =
412 (ageing_error.
size() == matrix_size) ? 0 : year * matrix_size;
415 for (
size_t true_age = 0; true_age < n_ages; true_age++) {
416 for (
size_t observed_age = 0; observed_age < n_ages; observed_age++) {
417 proportion_at_observed_age[observed_age] +=
418 proportion_at_true_age[true_age] *
419 ageing_error[matrix_offset + true_age * n_ages + observed_age];
422 return proportion_at_observed_age;
434T
sum(
const std::vector<T> &v) {
436 for (
size_t i = 0; i < v.size(); i++) {
453 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.
const Type logit(const Type &a, const Type &b, const Type &x)
A logit function for bounding of parameters.
Definition fims_math.hpp:261
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:406
T sum(const std::vector< T > &v)
Definition fims_math.hpp:434
const Type ad_min(const Type &a, const Type &b, Type C=1e-5)
Definition fims_math.hpp:357
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:304
const Type ad_max(const Type &a, const Type &b, Type C=1e-5)
Definition fims_math.hpp:380
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:276
const Type ad_fabs(const Type &x, Type C=1e-5)
Definition fims_math.hpp:333
const Type logistic(const Type &inflection_point, const Type &slope, const Type &x)
The general logistic function.
Definition fims_math.hpp:243
Establishes the FIMS Vector class.
An interface to the modeling platforms, e.g., TMB.