Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed <T> to <Type> #487

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions inst/extdata/TMB_tests/distributions/test_dlnorm_distribution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
/**
* @brief Model class defines and returns negative log-likelihood (nll)
*
* @tparam T
* @tparam Type
*/
template <typename T>
template <typename Type>
class Model {
using DataVector = typename ModelTraits<T>::DataVector;
using DataVector = typename ModelTraits<Type>::DataVector;
public:
DataVector logy; /*!< observation */
T meanlog; /*!< mean of the distribution of log(x) */
T sdlog; /*!< standard deviation of the distribution of log(x) */
Type meanlog; /*!< mean of the distribution of log(x) */
Type sdlog; /*!< standard deviation of the distribution of log(x) */

// Initiate pointer to link .cpp to .hpp
static Model<T>* instance;
static Model<Type>* instance;

/** @brief Constructor.
*/
Expand All @@ -35,23 +35,23 @@
/**
* @brief Create new singleton class
*
* @return Model<T>*
* @return Model<Type>*
*/
static Model<T>* getInstance(){
return Model<T>::instance;
static Model<Type>* getInstance(){
return Model<Type>::instance;
}

/**
* @brief Function that calculates the negative log-likelihood given the data and parameters
*
* @return negative log-likelihood (nll)
*/
T evaluate(){
Type evaluate(){

T nll = 0;
Type nll = 0;
int i;
int n = logy.size();
fims::Dlnorm<T> nll_dlnorm;
fims::Dlnorm<Type> nll_dlnorm;
nll_dlnorm.meanlog = meanlog;
nll_dlnorm.sdlog = sdlog;
for(i =0; i < n; i++){
Expand All @@ -65,10 +65,10 @@
/**
* @brief Create new instance of Model
*
* @tparam T
* @tparam Type
*/
template<class T>
Model<T>* Model<T>::instance = new Model<T>();
template<class Type>
Model<Type>* Model<Type>::instance = new Model<Type>();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
/**
* @brief Model class defines and returns negative log-likelihood (nll)
*
* @tparam T
* @tparam Type
*/
template <typename T>
template <typename Type>
class Model {
using Vector = typename ModelTraits<T>::EigenVector;
using Vector = typename ModelTraits<Type>::EigenVector;
public:
Vector x; /*!< Vector of length K of integers */
Vector p; /*!< Vector of length K, specifying the probability for the K classes (note, unlike in R these must sum to 1). */

// Initiate pointer to link .cpp to .hpp
static Model<T>* instance;
static Model<Type>* instance;

/** @brief Constructor.
*/
Expand All @@ -34,21 +34,21 @@
/**
* @brief Create new singleton class
*
* @return Model<T>*
* @return Model<Type>*
*/
static Model<T>* getInstance(){
return Model<T>::instance;
static Model<Type>* getInstance(){
return Model<Type>::instance;
}

/**
* @brief Function that calculates the negative log-likelihood given the data and parameters
*
* @return negative log-likelihood (nll)
*/
T evaluate(){
Type evaluate(){

T nll = 0;
fims::Dmultinom<T> nll_dmultinom;
Type nll = 0;
fims::Dmultinom<Type> nll_dmultinom;
nll_dmultinom.x = x;
nll_dmultinom.p = p;
nll -= nll_dmultinom.evaluate(true);
Expand All @@ -59,10 +59,10 @@
/**
* @brief Create new instance of Model
*
* @tparam T
* @tparam Type
*/
template<class T>
Model<T>* Model<T>::instance = new Model<T>();
template<class Type>
Model<Type>* Model<Type>::instance = new Model<Type>();
}


Expand Down
30 changes: 15 additions & 15 deletions inst/extdata/TMB_tests/distributions/test_dnorm_distribution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
/**
* @brief Model class defines and returns negative log-likelihood (nll)
*
* @tparam T
* @tparam Type
*/
template <typename T>
template <typename Type>
class Model {
using DataVector = typename ModelTraits<T>::DataVector;
using DataVector = typename ModelTraits<Type>::DataVector;
public:
DataVector y; /*!< observation */
T mean; /*!< mean of the normal distribution */
T sd; /*!< standard deviation of the normal distribution, must be strictly positive.*/
Type mean; /*!< mean of the normal distribution */
Type sd; /*!< standard deviation of the normal distribution, must be strictly positive.*/

// Initiate pointer to link .cpp to .hpp
static Model<T>* instance;
static Model<Type>* instance;

/** @brief Constructor.
*/
Expand All @@ -35,23 +35,23 @@
/**
* @brief Create new singleton class
*
* @return Model<T>*
* @return Model<Type>*
*/
static Model<T>* getInstance(){
return Model<T>::instance;
static Model<Type>* getInstance(){
return Model<Type>::instance;
}

/**
* @brief Function that calculates the negative log-likelihood given the data and parameters
*
* @return negative log-likelihood (nll)
*/
T evaluate(){
Type evaluate(){

T nll = 0;
Type nll = 0;
int i;
int n = y.size();
fims::Dnorm<T> nll_dnorm;
fims::Dnorm<Type> nll_dnorm;
nll_dnorm.mean = mean;
nll_dnorm.sd = sd;
for(i =0; i < n; i++){
Expand All @@ -65,10 +65,10 @@
/**
* @brief Create new instance of Model
*
* @tparam T
* @tparam Type
*/
template<class T>
Model<T>* Model<T>::instance = new Model<T>();
template<class Type>
Model<Type>* Model<Type>::instance = new Model<Type>();
}


Expand Down
32 changes: 16 additions & 16 deletions inst/extdata/TMB_tests/distributions/test_fleet_acomp_nll.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
/**
* @brief Model class defines and returns negative log-likelihood (nll)
*
* @tparam T
* @tparam Type
*/
template <typename T>
template <typename Type>
class Model {

using Vector = typename ModelTraits<T>::EigenVector;
using Vector = typename ModelTraits<Type>::EigenVector;
public:
Vector x; /*!< Vector of length K of integers */
Vector p; /*!< Vector of length K, specifying the probability for the K classes (note, unlike in R these must sum to 1). */

// Initiate pointer to link .cpp to .hpp
static Model<T>* instance;
static Model<Type>* instance;


::objective_function<T> *of;
::objective_function<Type> *of;

/** @brief Constructor.
*/
Expand All @@ -38,28 +38,28 @@
/**
* @brief Create new singleton class
*
* @return Model<T>*
* @return Model<Type>*
*/
static Model<T>* getInstance(){
return Model<T>::instance;
static Model<Type>* getInstance(){
return Model<Type>::instance;
}

/**
* @brief Function that calculates the negative log-likelihood given the data and parameters
*
* @return negative log-likelihood (nll)
*/
T evaluate(){
Type evaluate(){

T nll = 0.0;
Type nll = 0.0;
int n = x.size();

fims::FleetAgeCompNLL<T> nll_fac;
fims::FleetAgeCompNLL<Type> nll_fac;
nll_fac.catch_numbers_at_age.resize(n);
nll_fac.nyears = 1;
nll_fac.nages = 10;
std::shared_ptr<fims::DataObject<T>> age_comp_data =
std::make_shared<fims::DataObject<T>>(10, 1);
std::shared_ptr<fims::DataObject<Type>> age_comp_data =
std::make_shared<fims::DataObject<Type>>(10, 1);

nll_fac.observed_agecomp_data = age_comp_data;
Vector obs;
Expand All @@ -86,10 +86,10 @@
/**
* @brief Create new instance of Model
*
* @tparam T
* @tparam Type
*/
template<class T>
Model<T>* Model<T>::instance = new Model<T>();
template<class Type>
Model<Type>* Model<Type>::instance = new Model<Type>();
}


Expand Down
36 changes: 18 additions & 18 deletions inst/extdata/TMB_tests/distributions/test_fleet_index_nll.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
/**
* @brief Model class defines and returns negative log-likelihood (nll)
*
* @tparam T
* @tparam Type
*/
template <typename T>
template <typename Type>
class Model {
using DataVector = typename ModelTraits<T>::DataVector;
using Vector = typename ModelTraits<T>::EigenVector;
using DataVector = typename ModelTraits<Type>::DataVector;
using Vector = typename ModelTraits<Type>::EigenVector;
public:
DataVector y; /*!< observation */
Vector mean; /*!< expected fleet index */
T logsd; /*!< standard deviation of the fleet observation error, must be strictly positive.*/
Type logsd; /*!< standard deviation of the fleet observation error, must be strictly positive.*/

// Initiate pointer to link .cpp to .hpp
static Model<T>* instance;
static Model<Type>* instance;

::objective_function<T> *of;
::objective_function<Type> *of;

/** @brief Constructor.
*/
Expand All @@ -38,27 +38,27 @@
/**
* @brief Create new singleton class
*
* @return Model<T>*
* @return Model<Type>*
*/
static Model<T>* getInstance(){
return Model<T>::instance;
static Model<Type>* getInstance(){
return Model<Type>::instance;
}

/**
* @brief Function that calculates the negative log-likelihood given the data and parameters
*
* @return negative log-likelihood (nll)
*/
T evaluate(){
Type evaluate(){

T nll = 0;
Type nll = 0;
int n = y.size();

fims::FleetIndexNLL<T> nll_fleet_index;
fims::FleetIndexNLL<Type> nll_fleet_index;
nll_fleet_index.log_obs_error = logsd;

std::shared_ptr<fims::DataObject<T>> index_data =
std::make_shared<fims::DataObject<T>>(n);
std::shared_ptr<fims::DataObject<Type>> index_data =
std::make_shared<fims::DataObject<Type>>(n);
nll_fleet_index.observed_index_data = index_data;

nll_fleet_index.expected_index.resize(n);
Expand All @@ -80,10 +80,10 @@
/**
* @brief Create new instance of Model
*
* @tparam T
* @tparam Type
*/
template<class T>
Model<T>* Model<T>::instance = new Model<T>();
template<class Type>
Model<Type>* Model<Type>::instance = new Model<Type>();
}


Expand Down
6 changes: 3 additions & 3 deletions inst/include/common/fims_math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ inline const T ad_min(const T &a, const T &b, T C = 1e-5) {
* @param C default = 1e-5
* @return
*/
template <typename T>
inline const T ad_max(const T &a, const T &b, T C = 1e-5) {
return (a + b + fims::ad_fabs(a - b, C)) * static_cast<T>(.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);
}

} // namespace fims
Expand Down
Loading
Loading