[Developers] libraries of functions

Mark Maunder mmaunder at iattc.org
Wed Aug 13 15:26:20 PDT 2014


So we need a copy constructor defined for a double to a prevariable. We probably also need a copy constructor defined for an int to a prevariable

What about a dvector[1], an ivector[1], or higher dimensions to a prevariable?

Then we could define the library functions as prevariables. Are there any disadvantages to this?

Mark

From: William Stockhausen - NOAA Federal [mailto:william.stockhausen at noaa.gov]
Sent: Wednesday, August 13, 2014 1:46 PM
To: Mark Maunder
Cc: Steve Martell; developers at admb-project.org
Subject: Re: [Developers] libraries of functions

I think dvariable works with a double because it has a "copy constructor" defined for a double (so you can do something like "dvariable dv(0.124);" in your code. The compiler knows how to convert a double to a dvariable when you pass a double as the 1st input to Richards(const dvariable&,...) [note that your code calling this function w/ a double wouldn't compile if you didn't have the "const" there because c++ only constructs temporary variables (the resulting dvariable) when they are declared consts (and thus don't modify them in the function body)]. Passing a double as 1st input to Richards(const prevariable&,...) wouldn't work because prevariable doesn't have a copy constructor defined for a double, so the compiler doesn't know how to convert a double to a temporary prevariable&. Passing a dvariable to the latter function is no problem because a dvariable is already a prevariable because it's a derived class of prevariable.

Where you'll get in trouble with Richards(const dvariable&,...) is when you try Richards(dvarvector[1],...) where dvarvector is a dvar_vector, because the operation dvarvector[1] returns a prevariable, not a dvariable!  You're also out of luck with dvar3_array(i,j) [returns a prevariable] and I suspect most/all of the dvar array operations that return a single element.

Buck

***************************************************
* Dr. William T. Stockhausen                      *
***************************************************
* Resource Ecology and Fisheries Management       *
* Alaska Fisheries Science Center                 *
* National Marine Fisheries Service               *
* National Oceanic and Atmospheric Administration *
* 7600 Sand Point Way N.E.                        *
* Seattle, Washington 98115-6349                  *
***************************************************
* email: William.Stockhausen at noaa.gov<mailto:William.Stockhausen at noaa.gov>             *
* voice: 206-526-4241 fax: 206-526-6723           *
* web  : http://www.afsc.noaa.gov                 *
***************************************************
All models are wrong, some are useful.--G.E.P. Box
Beware of geeks bearing equations.    --W. Buffett
***************************************************
Disclaimer: The opinions expressed above are personal
and do not necessarily reflect official NOAA policy.


On Wed, Aug 13, 2014 at 9:45 AM, Mark Maunder <mmaunder at iattc.org<mailto:mmaunder at iattc.org>> wrote:
Thanks Buck.

However dvariable works for a double but a prevariable does not (nor does a named_dvariable, whatever that is). The error I get using prevariables is

no matching function for call to 'Richards(double&, named_dvariable&, named_dvariable&, param_init_number&, named_dvariable&)


From: William Stockhausen - NOAA Federal [mailto:william.stockhausen at noaa.gov<mailto:william.stockhausen at noaa.gov>]
Sent: Tuesday, August 12, 2014 1:59 PM
To: Mark Maunder
Cc: Steve Martell; developers at admb-project.org<mailto:developers at admb-project.org>

Subject: Re: [Developers] libraries of functions

If you redefine all the dvariables in the function signature as prevariables, you may be ok (as long as you don't try passing in a double, which the last error in your error output seems to be indicating). This is because (if I followed things correctly in the online documentation):

     param_init_number inherits from named_dvariable, which inherits from dvariable, which inherits from prevariable.

which you can partly see from the "Class Hierarchy" entry regarding prevariable on the online documentation (although param_init_number is missing). It would be a nice feature in the documentation if you could see the class hierarchy tree starting from the most-derived (param_init_number, in this case) to the base class(es).

Buck

***************************************************
* Dr. William T. Stockhausen                      *
***************************************************
* Resource Ecology and Fisheries Management       *
* Alaska Fisheries Science Center                 *
* National Marine Fisheries Service               *
* National Oceanic and Atmospheric Administration *
* 7600 Sand Point Way N.E.                        *
* Seattle, Washington 98115-6349                  *
***************************************************
* email: William.Stockhausen at noaa.gov<mailto:William.Stockhausen at noaa.gov>             *
* voice: 206-526-4241<tel:206-526-4241> fax: 206-526-6723<tel:206-526-6723>           *
* web  : http://www.afsc.noaa.gov                 *
***************************************************
All models are wrong, some are useful.--G.E.P. Box
Beware of geeks bearing equations.    --W. Buffett
***************************************************
Disclaimer: The opinions expressed above are personal
and do not necessarily reflect official NOAA policy.

On Tue, Aug 12, 2014 at 12:51 PM, Mark Maunder <mmaunder at iattc.org<mailto:mmaunder at iattc.org>> wrote:
Any comments on the use of templates messing up the various forms of dvariable and the automatic translation between the different forms of dvariable (sorry for not using the right terminology). I think the beneficial use of templates for functions in ADMB might be a redherring.

Mark

From: developers-bounces at admb-project.org<mailto:developers-bounces at admb-project.org> [mailto:developers-bounces at admb-project.org<mailto:developers-bounces at admb-project.org>] On Behalf Of Steve Martell
Sent: Tuesday, August 12, 2014 12:46 PM
To: William Stockhausen - NOAA Federal
Cc: developers at admb-project.org<mailto:developers at admb-project.org>

Subject: Re: [Developers] libraries of functions

My bad

Should have been

FUNCTION dvariable Richards(...)

S
On Aug 12, 2014, at 12:40 PM, William Stockhausen - NOAA Federal <william.stockhausen at noaa.gov<mailto:william.stockhausen at noaa.gov>> wrote:

I don't think your suggestion will work, Steve (he said without having tried it). If I understand things correctly (going out on a looong limb here), "FUNCTION" is an identifier to the tpl2cpp translator that what follows is a function that 1) whose signature should be added to the model_parameters class declaration in tpl_name.htp and 2) whose implementation should be added to tpl_name.cpp.

A nice (but probably tough to implement) feature in tpl2cpp would be the ability to put the following:

FUNCTION dvariable model_parameters::Richards(const dvariable &age, const dvariable &Linf, const dvariable &K, const dvariable &t0, const dvariable &p)
    dvariable Length=Linf*pow((1+(1/p)*exp(-K*(age-t0))),-p);
    return(Length);

into a file (functions.cxx, say) and be able to "include" that text in the tpl you're converting to cpp at a stage in the process before FUNCTIONs get converted to cpp equivalents. If such a feature is currently available, I haven't found it.

Buck
On Mon, Aug 11, 2014 at 3:59 PM, Steve Martell <martell.steve at gmail.com<mailto:martell.steve at gmail.com>> wrote:
Try:
FUNCTION dvariable model_parameters::Richards(const dvariable &age, const dvariable &Linf, const dvariable &K, const dvariable &t0, const dvariable &p)
{
  {
    dvariable Length=Linf*pow((1+(1/p)*exp(-K*(age-t0))),-p);
    return(Length);
  }
}

On Aug 11, 2014, at 3:49 PM, Mark Maunder <mmaunder at iattc.org<mailto:mmaunder at iattc.org>> wrote:

Why do I get an error if I put the following function in the file CAPAM_Growth.hpp and include it using #include<CAPAM_Growth.hpp> but if I put it in the tpl using the FUNCTION section I do not? The translator appears to just put it in the cpp with no changes

dvariable model_parameters::Richards(const dvariable &age, const dvariable &Linf, const dvariable &K, const dvariable &t0, const dvariable &p)
{
  {
    dvariable Length=Linf*pow((1+(1/p)*exp(-K*(age-t0))),-p);
    return(Length);
  }
}

The errors I get are

In file included from igm.cpp:3:0:
./CAPAM_Growth.hpp:130:142: error: invalid use of incomplete type 'struct model_parameters'
c:/ADMB/admb101-gcc452-win32\include/admodel.h:107:9: error: forward declaration of 'struct model_parameters'
igm.cpp: In member function 'virtual void model_parameters::userfunction()':
igm.cpp:127:46: error: no matching function for call to 'Richards(prevariable, named_dvariable&, named_dvariable&, param_init_number&, named_dvariable&)'
igm.cpp:128:58: error: no matching function for call to 'Richards(prevariable&, named_dvariable&, named_dvariable&, param_init_number&, named_dvariable&)'
igm.cpp:139:49: error: no matching function for call to 'Richards(double&, named_dvariable&, named_dvariable&, param_init_number&, named_dvariable&)'




The selectivity special issue of the journal Fisheries Research is now published
http://www.sciencedirect.com/science/journal/01657836/158/supp/C


The Stock Synthesis special issue of the journal Fisheries Research
http://www.sciencedirect.com/science/journal/01657836/142

Mark Maunder
Head of the Stock Assessment Program
Inter-American  Tropical Tuna Commission
8901 La Jolla Shores Dr.
La Jolla, CA  92037-1508, USA

Tel: (858) 546-7027<tel:%28858%29%20546-7027>
Fax: (858) 546-7133<tel:%28858%29%20546-7133>
mmaunder at iattc.org<mailto:mmaunder at iattc.org>
http://www.fisheriesstockassessment.com/TikiWiki/tiki-index.php?page=Mark+Maunder

Visit the Center for the Advancement of Population Assessment Methodology at
http://www.capamresearch.org/

Visit the AD Model Builder project at
 http://admb-project.org/

See the following website for information on fisheries stock assessment http://www.fisheriesstockassessment.com/



--
You received this message because you are subscribed to the Google Groups "admb-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to admb-users+unsubscribe at googlegroups.com<mailto:admb-users+unsubscribe at googlegroups.com>.
To post to this group, send email to admb-users at googlegroups.com<mailto:admb-users at googlegroups.com>.
Visit this group at http://groups.google.com/group/admb-users.
For more options, visit https://groups.google.com/d/optout.


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

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


________________________________

This internet e-mail message, and any files transmitted with it, contains confidential, privileged information that is intended only for the addressee. If you have received this e-mail message in error, please call us at (206) 634-1838<tel:%28206%29%20634-1838> collect if necessary) and ask to speak to the message sender. Nothing in this e-mail or the act of transmitting it, is to be construed as a waiver of any rights or privileges enjoyed by the sender or the International Pacific Halibut Commission pursuant to the International Organizations Immunities Act, 22 U.S.C. Sec. 288 et seq.


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


More information about the Developers mailing list