<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Mark,<div><br></div><div>Assuming the c11 extension is available, you could use default template parameters for you function.</div><div> </div><div><pre style="background-color: rgb(255, 255, 255); font-family: Monospaced; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; position: static; z-index: auto; "><span class="keyword-directive" style="color: rgb(0, 0, 230); ">template</span> <<span class="keyword-directive" style="color: rgb(0, 0, 230); ">typename</span> <span class="ST0" style="color: rgb(0, 0, 0); background-color: rgb(236, 235, 163); ">type1</span>, <span class="keyword-directive" style="color: rgb(0, 0, 230); ">typename</span> type2 = <span class="ST0" style="color: rgb(0, 0, 0); background-color: rgb(236, 235, 163); ">type1</span>, <span class="keyword-directive" style="color: rgb(0, 0, 230); ">typename</span> type3 = type2>
<span class="keyword-directive" style="color: rgb(0, 0, 230); ">const</span> <span class="ST0" style="color: rgb(0, 0, 0); background-color: rgb(236, 235, 163); ">type1</span> <span class="ST1" style="color: rgb(0, 0, 0); font-family: Monospaced; font-weight: bold; ">vonB</span>(<span class="keyword-directive" style="color: rgb(0, 0, 230); ">const</span> <span class="ST0" style="color: rgb(0, 0, 0); background-color: rgb(236, 235, 163); ">type1</span> &age, <span class="keyword-directive" style="color: rgb(0, 0, 230); ">const</span> type2 &Linf, <span class="keyword-directive" style="color: rgb(0, 0, 230); ">const</span> type2 &K, <span class="keyword-directive" style="color: rgb(0, 0, 230); ">const</span> type2 &t0)
</pre></div><div><br></div><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div><div>Matthew </div></div></span>
</div>
<br><div><div>On Jun 27, 2014, at 2:39 PM, <a href="mailto:developers-request@admb-project.org">developers-request@admb-project.org</a> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Send Developers mailing list submissions to<br><span class="Apple-tab-span" style="white-space:pre"> </span><a href="mailto:developers@admb-project.org">developers@admb-project.org</a><br><br>To subscribe or unsubscribe via the World Wide Web, visit<br><span class="Apple-tab-span" style="white-space:pre"> </span>http://lists.admb-project.org/mailman/listinfo/developers<br>or, via email, send a message with subject or body 'help' to<br><span class="Apple-tab-span" style="white-space:pre"> </span>developers-request@admb-project.org<br><br>You can reach the person managing the list at<br><span class="Apple-tab-span" style="white-space:pre"> </span>developers-owner@admb-project.org<br><br>When replying, please edit your Subject line so it is more specific<br>than "Re: Contents of Developers digest..."<br><br><br>Today's Topics:<br><br> 1. Template functions and documentation (Mark Maunder)<br> 2. Re: Template functions and documentation (Mark Maunder)<br> 3. Re: Template functions and documentation (Mark Maunder)<br><br><br>----------------------------------------------------------------------<br><br>Message: 1<br>Date: Fri, 27 Jun 2014 18:04:47 +0000<br>From: Mark Maunder <mmaunder@iattc.org><br>To: "developers@admb-project.org" <developers@admb-project.org><br>Cc: Alexandre Aires-Da-Silva <alexdasilva@iattc.org>,<span class="Apple-tab-span" style="white-space:pre"> </span>Carolina<br><span class="Apple-tab-span" style="white-space:pre"> </span>Minte-Vera <cminte@iattc.org><br>Subject: [Developers] Template functions and documentation<br>Message-ID:<br><span class="Apple-tab-span" style="white-space:pre"> </span><235aeee8-a6b0-4051-9f1d-82f8b382d2bc@MAIL1.lajolla.iattc.org><br>Content-Type: text/plain; charset="us-ascii"<br><br>Hi developers,<br><br>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".<br><br>Thanks,<br><br>Mark<br><br>/**<br>\defgroup CONTRIB Contributed libraries<br>*/<br><br>/**<br>\ingroup CONTRIB<br>\defgroup CAPAM CAPAM created functions<br>*/<br><br>#include <admodel.h><br><br>/** von Bertalanffy growth equation; constant objects.<br> \ingroup CAPAM<br> \brief Calculate the length from a given age based on the von Bertalanffy equation. Written by Mark Maunder.<br> \param age age of individual, \f$a\f$.<br> \param Linf asymptotic length, \f$L_inf\f$.<br> \param K growth rate, \f$K\f$.<br> \param t0 age at zero length, \f$t_0\f$.<br> \return length predicted length of individual. \f$L_inf*(1-exp(-K*(a-t0)))\f$.<br> */<br><br>template <typename type1, typename type1><br>//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<br>//type1 is probably a long<br>//type2 is probably a dvariable (either a model parameter (Linf K t0) or a derived variable (length))<br>//may need a type3, which is a dvar_vector if age and length are vectors, where type 1 will be a vector<br>type1 vonB(const type1 &age, const type2 &Linf, const type2 &K, const type2 &t0)<br>{<br> type2 length = Linf*(1.-mfexp(-K*(age-t0)));<br> return (length);<br>}<br><br><br>//is length a bad word to use<br>//do we use ingroup for both groups and subgroups in doxygen documentation<br>//should we use mfexp?<br>//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<br>//I couldn't work out how to put in the detailed description<br>//The equations did not work on my computer<br><br><br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <http://lists.admb-project.org/pipermail/developers/attachments/20140627/713f631e/attachment-0001.html><br><br>------------------------------<br><br>Message: 2<br>Date: Fri, 27 Jun 2014 18:29:17 +0000<br>From: Mark Maunder <mmaunder@iattc.org><br>To: dave fournier <davef@otter-rsch.com>,<br><span class="Apple-tab-span" style="white-space:pre"> </span>"developers@admb-project.org"<span class="Apple-tab-span" style="white-space:pre"> </span><developers@admb-project.org><br>Cc: Alexandre Aires-Da-Silva <alexdasilva@iattc.org>,<span class="Apple-tab-span" style="white-space:pre"> </span>Carolina<br><span class="Apple-tab-span" style="white-space:pre"> </span>Minte-Vera <cminte@iattc.org><br>Subject: Re: [Developers] Template functions and documentation<br>Message-ID:<br><span class="Apple-tab-span" style="white-space:pre"> </span><0a073d62-ef7d-470c-a971-91286f42ce6c@MAIL1.lajolla.iattc.org><br>Content-Type: text/plain; charset="us-ascii"<br><br>Thanks Dave,<br><br>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.<br><br>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.<br><br>Regards,<br><br>Mark<br><br>From: dave fournier [mailto:davef@otter-rsch.com]<br>Sent: Friday, June 27, 2014 11:11 AM<br>To: Mark Maunder; developers@admb-project.org<br>Cc: Alexandre Aires-Da-Silva; Carolina Minte-Vera<br>Subject: Re: [Developers] Template functions and documentation<br><br>On 06/27/2014 11:04 AM, Mark Maunder wrote:<br><br>Its hard to believe that Schnute and I figured out how to do this properly almost 34 years ago<br>using punch cards on a machine with 18K user memory. Someone really should figure out how to teach<br>people the importance of parameterizing nonlinear models in a stable fashion.<br><br><br><br>Hi developers,<br><br>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".<br><br>Thanks,<br><br>Mark<br><br>/**<br>\defgroup CONTRIB Contributed libraries<br>*/<br><br>/**<br>\ingroup CONTRIB<br>\defgroup CAPAM CAPAM created functions<br>*/<br><br>#include <admodel.h><br><br>/** von Bertalanffy growth equation; constant objects.<br> \ingroup CAPAM<br> \brief Calculate the length from a given age based on the von Bertalanffy equation. Written by Mark Maunder.<br> \param age age of individual, \f$a\f$.<br> \param Linf asymptotic length, \f$L_inf\f$.<br> \param K growth rate, \f$K\f$.<br> \param t0 age at zero length, \f$t_0\f$.<br> \return length predicted length of individual. \f$L_inf*(1-exp(-K*(a-t0)))\f$.<br> */<br><br>template <typename type1, typename type1><br>//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<br>//type1 is probably a long<br>//type2 is probably a dvariable (either a model parameter (Linf K t0) or a derived variable (length))<br>//may need a type3, which is a dvar_vector if age and length are vectors, where type 1 will be a vector<br>type1 vonB(const type1 &age, const type2 &Linf, const type2 &K, const type2 &t0)<br>{<br> type2 length = Linf*(1.-mfexp(-K*(age-t0)));<br> return (length);<br>}<br><br><br>//is length a bad word to use<br>//do we use ingroup for both groups and subgroups in doxygen documentation<br>//should we use mfexp?<br>//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<br>//I couldn't work out how to put in the detailed description<br>//The equations did not work on my computer<br><br><br><br><br><br><br>_______________________________________________<br><br>Developers mailing list<br><br>Developers@admb-project.org<mailto:Developers@admb-project.org><br><br>http://lists.admb-project.org/mailman/listinfo/developers<br><br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <http://lists.admb-project.org/pipermail/developers/attachments/20140627/e6203be5/attachment-0001.html><br><br>------------------------------<br><br>Message: 3<br>Date: Fri, 27 Jun 2014 18:39:01 +0000<br>From: Mark Maunder <mmaunder@iattc.org><br>To: dave fournier <davef@otter-rsch.com>,<br><span class="Apple-tab-span" style="white-space:pre"> </span>"developers@admb-project.org"<span class="Apple-tab-span" style="white-space:pre"> </span><developers@admb-project.org><br>Cc: Alexandre Aires-Da-Silva <alexdasilva@iattc.org>,<span class="Apple-tab-span" style="white-space:pre"> </span>Carolina<br><span class="Apple-tab-span" style="white-space:pre"> </span>Minte-Vera <cminte@iattc.org><br>Subject: Re: [Developers] Template functions and documentation<br>Message-ID:<br><span class="Apple-tab-span" style="white-space:pre"> </span><0e2a28ac-a7d5-4955-95bc-f75315446f05@MAIL1.lajolla.iattc.org><br>Content-Type: text/plain; charset="us-ascii"<br><br>Dave,<br><br>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.<br><br>Mark<br><br>From: dave fournier [mailto:davef@otter-rsch.com]<br>Sent: Friday, June 27, 2014 11:34 AM<br>To: Mark Maunder; developers@admb-project.org<br>Cc: Alexandre Aires-Da-Silva; Carolina Minte-Vera<br>Subject: Re: [Developers] Template functions and documentation<br><br>On 06/27/2014 11:29 AM, Mark Maunder wrote:<br><br>OK, so the asymptotic length is important. What is your point?<br><br> Dave<br><br>Thanks Dave,<br><br>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.<br><br>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.<br><br>Regards,<br><br>Mark<br><br>From: dave fournier [mailto:davef@otter-rsch.com]<br>Sent: Friday, June 27, 2014 11:11 AM<br>To: Mark Maunder; developers@admb-project.org<mailto:developers@admb-project.org><br>Cc: Alexandre Aires-Da-Silva; Carolina Minte-Vera<br>Subject: Re: [Developers] Template functions and documentation<br><br>On 06/27/2014 11:04 AM, Mark Maunder wrote:<br><br>Its hard to believe that Schnute and I figured out how to do this properly almost 34 years ago<br>using punch cards on a machine with 18K user memory. Someone really should figure out how to teach<br>people the importance of parameterizing nonlinear models in a stable fashion.<br><br><br><br><br>Hi developers,<br><br>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".<br><br>Thanks,<br><br>Mark<br><br>/**<br>\defgroup CONTRIB Contributed libraries<br>*/<br><br>/**<br>\ingroup CONTRIB<br>\defgroup CAPAM CAPAM created functions<br>*/<br><br>#include <admodel.h><br><br>/** von Bertalanffy growth equation; constant objects.<br> \ingroup CAPAM<br> \brief Calculate the length from a given age based on the von Bertalanffy equation. Written by Mark Maunder.<br> \param age age of individual, \f$a\f$.<br> \param Linf asymptotic length, \f$L_inf\f$.<br> \param K growth rate, \f$K\f$.<br> \param t0 age at zero length, \f$t_0\f$.<br> \return length predicted length of individual. \f$L_inf*(1-exp(-K*(a-t0)))\f$.<br> */<br><br>template <typename type1, typename type1><br>//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<br>//type1 is probably a long<br>//type2 is probably a dvariable (either a model parameter (Linf K t0) or a derived variable (length))<br>//may need a type3, which is a dvar_vector if age and length are vectors, where type 1 will be a vector<br>type1 vonB(const type1 &age, const type2 &Linf, const type2 &K, const type2 &t0)<br>{<br> type2 length = Linf*(1.-mfexp(-K*(age-t0)));<br> return (length);<br>}<br><br><br>//is length a bad word to use<br>//do we use ingroup for both groups and subgroups in doxygen documentation<br>//should we use mfexp?<br>//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<br>//I couldn't work out how to put in the detailed description<br>//The equations did not work on my computer<br><br><br><br><br><br><br><br>_______________________________________________<br><br>Developers mailing list<br><br>Developers@admb-project.org<mailto:Developers@admb-project.org><br><br>http://lists.admb-project.org/mailman/listinfo/developers<br><br><br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <http://lists.admb-project.org/pipermail/developers/attachments/20140627/0871a1a7/attachment.html><br><br>------------------------------<br><br>_______________________________________________<br>Developers mailing list<br>Developers@admb-project.org<br>http://lists.admb-project.org/mailman/listinfo/developers<br><br><br>End of Developers Digest, Vol 62, Issue 7<br>*****************************************<br></div></blockquote></div><br></body></html>