[Developers] Developers Digest, Vol 62, Issue 7

Mark Maunder mmaunder at iattc.org
Fri Jun 27 12:17:01 PDT 2014


Matthew,

I understand using default arguments in a function, but using default parameter types in a template function, particularly ones that refer to other parameter types in the function call is a bit beyond my intuition. Can you please explain why this would be used?

Also, your example does not use type3.

Thanks,

Mark

From: developers-bounces at admb-project.org [mailto:developers-bounces at admb-project.org] On Behalf Of Matthew Supernaw
Sent: Friday, June 27, 2014 12:02 PM
To: developers at admb-project.org
Subject: Re: [Developers] Developers Digest, Vol 62, Issue 7

Hi Mark,

Assuming the c11 extension is available, you could use default template parameters for you function.


template <typename type1, typename type2 = type1, typename type3 = type2>

const type1 vonB(const type1 &age, const type2 &Linf, const type2 &K, const type2 &t0)

Matthew

On Jun 27, 2014, at 2:39 PM, developers-request at admb-project.org<mailto:developers-request at admb-project.org> wrote:


Send Developers mailing list submissions to
            developers at admb-project.org<mailto:developers at admb-project.org>

To subscribe or unsubscribe via the World Wide Web, visit
            http://lists.admb-project.org/mailman/listinfo/developers
or, via email, send a message with subject or body 'help' to
            developers-request at admb-project.org<mailto:developers-request at admb-project.org>

You can reach the person managing the list at
            developers-owner at admb-project.org<mailto:developers-owner at admb-project.org>

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Developers digest..."


Today's Topics:

  1. Template functions and documentation (Mark Maunder)
  2. Re: Template functions and documentation (Mark Maunder)
  3. Re: Template functions and documentation (Mark Maunder)


----------------------------------------------------------------------

Message: 1
Date: Fri, 27 Jun 2014 18:04:47 +0000
From: Mark Maunder <mmaunder at iattc.org<mailto:mmaunder at iattc.org>>
To: "developers at admb-project.org<mailto:developers at admb-project.org>" <developers at admb-project.org<mailto:developers at admb-project.org>>
Cc: Alexandre Aires-Da-Silva <alexdasilva at iattc.org<mailto:alexdasilva at iattc.org>>,     Carolina
            Minte-Vera <cminte at iattc.org<mailto:cminte at iattc.org>>
Subject: [Developers] Template functions and documentation
Message-ID:
            <235aeee8-a6b0-4051-9f1d-82f8b382d2bc at MAIL1.lajolla.iattc.org<mailto:235aeee8-a6b0-4051-9f1d-82f8b382d2bc at MAIL1.lajolla.iattc.org>>
Content-Type: text/plain; charset="us-ascii"

Hi developers,

I am in the process or putting together a model that will be used to evaluate several growth equations so I thought I better try to use the ADMB project "approved" approach for writing the functions. Below is a template function and documentation for the von Bertalanffy growth equation. I would appreciate any advice on doing this "correctly".

Thanks,

Mark

/**
\defgroup CONTRIB Contributed libraries
*/

/**
\ingroup CONTRIB
\defgroup CAPAM CAPAM created functions
*/

#include <admodel.h>

/**  von Bertalanffy growth equation; constant objects.
 \ingroup CAPAM
 \brief Calculate the length from a given age based on the von Bertalanffy equation. Written by Mark Maunder.
 \param age age of individual, \f$a\f$.
 \param Linf asymptotic length, \f$L_inf\f$.
 \param K growth rate, \f$K\f$.
 \param t0 age at zero length, \f$t_0\f$.
 \return length predicted length of individual. \f$L_inf*(1-exp(-K*(a-t0)))\f$.
 */

template <typename type1, typename type1>
//can have multiple types so that they are used below in variable definitions, they can differ between function calls, but remain the same within a function call
//type1 is probably a long
//type2 is probably a dvariable (either a model parameter (Linf K t0) or a derived variable (length))
//may need a type3, which is a dvar_vector if age and length are vectors, where type 1 will be a vector
type1 vonB(const type1 &age, const type2 &Linf, const type2 &K, const type2 &t0)
{
 type2 length = Linf*(1.-mfexp(-K*(age-t0)));
 return (length);
}


//is length a bad word to use
//do we use ingroup for both groups and subgroups in doxygen documentation
//should we use mfexp?
//what if age and length are vectors, but age is a vector and length is a dvar_vector, do we need to overload the type with one with three variable types
//I couldn't work out how to put in the detailed description
//The equations did not work on my computer


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/developers/attachments/20140627/713f631e/attachment-0001.html>

------------------------------

Message: 2
Date: Fri, 27 Jun 2014 18:29:17 +0000
From: Mark Maunder <mmaunder at iattc.org<mailto:mmaunder at iattc.org>>
To: dave fournier <davef at otter-rsch.com<mailto:davef at otter-rsch.com>>,
            "developers at admb-project.org<mailto:developers at admb-project.org>"       <developers at admb-project.org<mailto:developers at admb-project.org>>
Cc: Alexandre Aires-Da-Silva <alexdasilva at iattc.org<mailto:alexdasilva at iattc.org>>,     Carolina
            Minte-Vera <cminte at iattc.org<mailto:cminte at iattc.org>>
Subject: Re: [Developers] Template functions and documentation
Message-ID:
            <0a073d62-ef7d-470c-a971-91286f42ce6c at MAIL1.lajolla.iattc.org<mailto:0a073d62-ef7d-470c-a971-91286f42ce6c at MAIL1.lajolla.iattc.org>>
Content-Type: text/plain; charset="us-ascii"

Thanks Dave,

We will probably use a reparameterization like this when we do the analysis. Right now I am trying to get the function coding structure sorted out before I write too much code.

If you have a growth curve that is quite linear for the first few ages and then bends over quickly, that would be useful. We have been applying the Richards curve, but I think we might need to do better. The issue is that the asymptotic length is quite important when fitting to length composition data, but we often don't have much age (or tagging) data for old fish. So, the asymptotic length is controlled by the shape of the growth curve and the fit to the young and intermediate aged fish.

Regards,

Mark

From: dave fournier [mailto:davef at otter-rsch.com]
Sent: Friday, June 27, 2014 11:11 AM
To: Mark Maunder; developers at admb-project.org<mailto:developers at admb-project.org>
Cc: Alexandre Aires-Da-Silva; Carolina Minte-Vera
Subject: Re: [Developers] Template functions and documentation

On 06/27/2014 11:04 AM, Mark Maunder wrote:

Its hard to believe that Schnute and I figured out how to do this properly almost 34 years ago
using punch cards on a machine with 18K user memory.  Someone really should figure out how to teach
people the importance of parameterizing nonlinear models in a stable fashion.



Hi developers,

I am in the process or putting together a model that will be used to evaluate several growth equations so I thought I better try to use the ADMB project "approved" approach for writing the functions. Below is a template function and documentation for the von Bertalanffy growth equation. I would appreciate any advice on doing this "correctly".

Thanks,

Mark

/**
\defgroup CONTRIB Contributed libraries
*/

/**
\ingroup CONTRIB
\defgroup CAPAM CAPAM created functions
*/

#include <admodel.h>

/**  von Bertalanffy growth equation; constant objects.
 \ingroup CAPAM
 \brief Calculate the length from a given age based on the von Bertalanffy equation. Written by Mark Maunder.
 \param age age of individual, \f$a\f$.
 \param Linf asymptotic length, \f$L_inf\f$.
 \param K growth rate, \f$K\f$.
 \param t0 age at zero length, \f$t_0\f$.
 \return length predicted length of individual. \f$L_inf*(1-exp(-K*(a-t0)))\f$.
 */

template <typename type1, typename type1>
//can have multiple types so that they are used below in variable definitions, they can differ between function calls, but remain the same within a function call
//type1 is probably a long
//type2 is probably a dvariable (either a model parameter (Linf K t0) or a derived variable (length))
//may need a type3, which is a dvar_vector if age and length are vectors, where type 1 will be a vector
type1 vonB(const type1 &age, const type2 &Linf, const type2 &K, const type2 &t0)
{
 type2 length = Linf*(1.-mfexp(-K*(age-t0)));
 return (length);
}


//is length a bad word to use
//do we use ingroup for both groups and subgroups in doxygen documentation
//should we use mfexp?
//what if age and length are vectors, but age is a vector and length is a dvar_vector, do we need to overload the type with one with three variable types
//I couldn't work out how to put in the detailed description
//The equations did not work on my computer






_______________________________________________

Developers mailing list

Developers at admb-project.org<mailto:Developers at admb-project.org<mailto:Developers at admb-project.org%3cmailto:Developers at admb-project.org>>

http://lists.admb-project.org/mailman/listinfo/developers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/developers/attachments/20140627/e6203be5/attachment-0001.html>

------------------------------

Message: 3
Date: Fri, 27 Jun 2014 18:39:01 +0000
From: Mark Maunder <mmaunder at iattc.org<mailto:mmaunder at iattc.org>>
To: dave fournier <davef at otter-rsch.com<mailto:davef at otter-rsch.com>>,
            "developers at admb-project.org<mailto:developers at admb-project.org>"       <developers at admb-project.org<mailto:developers at admb-project.org>>
Cc: Alexandre Aires-Da-Silva <alexdasilva at iattc.org<mailto:alexdasilva at iattc.org>>,     Carolina
            Minte-Vera <cminte at iattc.org<mailto:cminte at iattc.org>>
Subject: Re: [Developers] Template functions and documentation
Message-ID:
            <0e2a28ac-a7d5-4955-95bc-f75315446f05 at MAIL1.lajolla.iattc.org<mailto:0e2a28ac-a7d5-4955-95bc-f75315446f05 at MAIL1.lajolla.iattc.org>>
Content-Type: text/plain; charset="us-ascii"

Dave,

The point is that the asymptotic length is controlled by the shape of the growth curve and the fit to the young and intermediate aged fish. For example, if you fit a vonB only to young fish that show linear growth you get a very large Linf. The more flexible Richards curve does better, but I don't think it bends over fast enough for the data I have. I have created a composite growth model that is linear for young fish and vonB for old fish, but I was wondering if there is a better model out there that I don't know about.

Mark

From: dave fournier [mailto:davef at otter-rsch.com]
Sent: Friday, June 27, 2014 11:34 AM
To: Mark Maunder; developers at admb-project.org<mailto:developers at admb-project.org>
Cc: Alexandre Aires-Da-Silva; Carolina Minte-Vera
Subject: Re: [Developers] Template functions and documentation

On 06/27/2014 11:29 AM, Mark Maunder wrote:

OK,  so the asymptotic length is important.  What is your point?

   Dave

Thanks Dave,

We will probably use a reparameterization like this when we do the analysis. Right now I am trying to get the function coding structure sorted out before I write too much code.

If you have a growth curve that is quite linear for the first few ages and then bends over quickly, that would be useful. We have been applying the Richards curve, but I think we might need to do better. The issue is that the asymptotic length is quite important when fitting to length composition data, but we often don't have much age (or tagging) data for old fish. So, the asymptotic length is controlled by the shape of the growth curve and the fit to the young and intermediate aged fish.

Regards,

Mark

From: dave fournier [mailto:davef at otter-rsch.com]
Sent: Friday, June 27, 2014 11:11 AM
To: Mark Maunder; developers at admb-project.org<mailto:developers at admb-project.org<mailto:developers at admb-project.org%3cmailto:developers at admb-project.org>>
Cc: Alexandre Aires-Da-Silva; Carolina Minte-Vera
Subject: Re: [Developers] Template functions and documentation

On 06/27/2014 11:04 AM, Mark Maunder wrote:

Its hard to believe that Schnute and I figured out how to do this properly almost 34 years ago
using punch cards on a machine with 18K user memory.  Someone really should figure out how to teach
people the importance of parameterizing nonlinear models in a stable fashion.




Hi developers,

I am in the process or putting together a model that will be used to evaluate several growth equations so I thought I better try to use the ADMB project "approved" approach for writing the functions. Below is a template function and documentation for the von Bertalanffy growth equation. I would appreciate any advice on doing this "correctly".

Thanks,

Mark

/**
\defgroup CONTRIB Contributed libraries
*/

/**
\ingroup CONTRIB
\defgroup CAPAM CAPAM created functions
*/

#include <admodel.h>

/**  von Bertalanffy growth equation; constant objects.
 \ingroup CAPAM
 \brief Calculate the length from a given age based on the von Bertalanffy equation. Written by Mark Maunder.
 \param age age of individual, \f$a\f$.
 \param Linf asymptotic length, \f$L_inf\f$.
 \param K growth rate, \f$K\f$.
 \param t0 age at zero length, \f$t_0\f$.
 \return length predicted length of individual. \f$L_inf*(1-exp(-K*(a-t0)))\f$.
 */

template <typename type1, typename type1>
//can have multiple types so that they are used below in variable definitions, they can differ between function calls, but remain the same within a function call
//type1 is probably a long
//type2 is probably a dvariable (either a model parameter (Linf K t0) or a derived variable (length))
//may need a type3, which is a dvar_vector if age and length are vectors, where type 1 will be a vector
type1 vonB(const type1 &age, const type2 &Linf, const type2 &K, const type2 &t0)
{
 type2 length = Linf*(1.-mfexp(-K*(age-t0)));
 return (length);
}


//is length a bad word to use
//do we use ingroup for both groups and subgroups in doxygen documentation
//should we use mfexp?
//what if age and length are vectors, but age is a vector and length is a dvar_vector, do we need to overload the type with one with three variable types
//I couldn't work out how to put in the detailed description
//The equations did not work on my computer







_______________________________________________

Developers mailing list

Developers at admb-project.org<mailto:Developers at admb-project.org<mailto:Developers at admb-project.org%3cmailto:Developers at admb-project.org>>

http://lists.admb-project.org/mailman/listinfo/developers


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/developers/attachments/20140627/0871a1a7/attachment.html>

------------------------------

_______________________________________________
Developers mailing list
Developers at admb-project.org<mailto:Developers at admb-project.org>
http://lists.admb-project.org/mailman/listinfo/developers


End of Developers Digest, Vol 62, Issue 7
*****************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/developers/attachments/20140627/1f86f39b/attachment-0001.html>


More information about the Developers mailing list