[ADMB Users] a conditional statement under PARAMETER_SECTION
Saang-Yoon
shyunuw at gmail.com
Sat Mar 19 13:15:23 PDT 2011
Hi, Jim and John.
Thank you VERY MUCH for your ideas and advice. It is a good idea to
turn on or off a parameter by switching the calculation phase between
a postive and negative integer values. Best Wishes,
Saang-Yoon
On Mar 19, 4:01 pm, John Sibert <sib... at hawaii.edu> wrote:
> If your code is generating compiler/linker errors you are probably
> referencing an undeclared variable (that is why you cannot put
> declarations inside a conditional block). So you if you really want to
> "ignore" a variable, you must completely banish if from your code. You
> can sometimes use conditional compilation for this purpose (ie #ifdef ).
> Otherwise, depending on what you really mean by "ignore", you could try
> something like this
>
> DATA_SECTION
>
> // declare some variables for later use in the PARAMETER_SECTION
> number sel_par_min
> number sel_par_max
> init_int ignore_sel_par // read int from the .dat file to control
> estimation at run time;
> // 1 to ignore; 0 to estimate
>
> LOCAL_CALCS
> // set default values
> sel_par_min = -5.0;
> sel_par_max = 5.0;
> sel_phz = 1; // or whatever phase you want
> // alternatively you could declare sel_phz to be an init_int and read
> it from the the .dat file
> if (ignore_sel_par)
> {
> // set sel_par_min and sel_par_max so their midpoint is the value
> you want for sel_par if you don't want 0.0
> sel_phz = -1; // forces the sel_par to NOT be active
> }
> END_CALCS
>
> PARAMETER_SECTION
> init_bounded_number(sel_par_min, sel_par_max, sel_phz);
>
> On 03/19/2011 09:14 AM, Saang-Yoon wrote:
>
>
>
>
>
> > Hello, Steve.
> > Thank you very much for your prompt response, which is helpful. By
> > the way, the conditional statement in your example is used below
> > "init_bounded_matrix_vector sel_par". Now if we want to ignore the
> > parameter vector, "sel_par" by an option, then we may want to put the
> > parameter declaration ("init_bounded_matrix_vector sel_par") under the
> > optional statement, which would lead to a compile/link error. I
> > wonder about how you or others get around in "one" TPL file. Again
> > thank you.
> > Saang-Yoon
>
> > On Mar 19, 2:35 pm, Steve Martell<s.mart... at fisheries.ubc.ca> wrote:
> >> Sanng-Yoon,
>
> >> Statements such as this work fine for me in the PARAMETER_SECTION
>
> >> //Selectivity parameters (A very complicated ragged array)
> >> init_bounded_matrix_vector sel_par(1,ngear,1,jsel_npar,1,isel_npar,-5.,5.,sel_phz);
> >> LOC_CALCS
> >> //initial values for logistic selectivity parameters
> >> //set phase to -1 for fixed selectivity.
> >> for(int k=1;k<=ngear;k++)
> >> {
> >> if( isel_type(k)==1 || isel_type(k)==6 )
> >> {
> >> sel_par(k,1,1) = log(ahat(k));
> >> sel_par(k,1,2) = log(ghat(k));
> >> }
> >> }
> >> END_CALCS
>
> >> On 2011-03-19, at 11:31 AM, Saang-Yoon wrote:
>
> >>> Hi, all.
> >>> Whenever I put a conditional statement (e.g., if - else) under
> >>> PARAMETER_SECTION, I run into an error. I wonder whether ADMB is
> >>> designed not to allow a conditional statement under PARAMETER_SECTION
> >>> ever. Sometimes I need to consider or ignore a parameter, depending
> >>> on a model assumption. If you were, how would you get around in
> >>> ADMB? Temporarily I make two TPL files (e.g., two EXE files) by the
> >>> assumption. But I suspect some of you may get around in "one" TPL
> >>> file (i.e., "one" EXE file).
> >>> Saang-Yoon
> >>> _______________________________________________
> >>> Users mailing list
> >>> Us... at admb-project.org
> >>>http://lists.admb-project.org/mailman/listinfo/users
> >> _______________________________________________
> >> Users mailing list
> >> Us... at admb-project.orghttp://lists.admb-project.org/mailman/listinfo/users
> > _______________________________________________
> > Users mailing list
> > Us... at admb-project.org
> >http://lists.admb-project.org/mailman/listinfo/users
>
> --
> John Sibert
> Emeritus Researcher, SOEST
> University of Hawaii at Manoa
>
> Visit the ADMB projecthttp://admb-project.org/
>
> _______________________________________________
> Users mailing list
> Us... at admb-project.orghttp://lists.admb-project.org/mailman/listinfo/users- Hide quoted text -
>
> - Show quoted text -
More information about the Users
mailing list