[Developers] method set_initial_values(...) not working for param_init_number_vector

dave fournier davef at otter-rsch.com
Mon Jun 16 07:32:20 PDT 2014


On 06/16/2014 07:08 AM, William Stockhausen - NOAA Federal wrote:

If you post the code for a working example, I'll take a look at it.

without that it is impossible to know what the code really does.

      Dave



> Hi developers,
>
>  I'm running ADMB 11.1 on MacOSX and Windows 7. I'm trying to set the 
> initial values for a param_init_number_vector (p, say) from a dvector 
> (vls, say) in a function using the following:
>
> p.set_initial_value(vls);
>
> The actual function is:
>
> void setInitVals(BoundedNumberVectorInfo* pI, 
> param_init_bounded_number_vector& p){
> int np = pI->getSize();
>     if (np){
>         dvector vls = pI->getInitVals();
> p.set_initial_value(vls);
>     cout<<"vls = "<<vls<<endl;
> cout<<"p   = "<<p<<endl;
>     }
> }
>
> where pI is a pointer to an object whose method getInitVals() returns 
> a dvector.
>
> Everything compiles fine, but when I run the code,  the initial values 
> for p are not equal to vls (they're equal to the default initial 
> values) after running setInits.
>
> Fortunately this caused my code to produce some really strange results 
> so I realized there was a problem. Using the ADMB website, I tracked 
> down the following:
> The 'set_initial_value' method for param_init_bounded_number_vector is 
> defined in model45.cpp as
>
> 00008
> 00009  <http://www.admb-project.org/documentation/api/classparam__init__bounded__vector__vector.html#ad696a4660a01ad50266fcbafa7d3beb7>  void  param_init_bounded_vector_vector::set_initial_value  <http://www.admb-project.org/documentation/api/classparam__init__bounded__vector__vector.html#ad696a4660a01ad50266fcbafa7d3beb7>(
> 00010const  double_index_type  <http://www.admb-project.org/documentation/api/classdouble__index__type.html>& _it)
> 00011  {
> 00012it  <http://www.admb-project.org/documentation/api/classparam__init__bounded__vector__vector.html#a106e1b4f5049a08386645afbb658384b>=new  double_index_type  <http://www.admb-project.org/documentation/api/classdouble__index__type.html>(_it);
> 00013  }
> 00014
>
> and the conversion of a dvector to double_index_type is defined in 
> doublind.cpp as
> 00057
> 00062  <http://www.admb-project.org/documentation/api/classdouble__index__type.html#a70db7015028be71be42cbc4c37b59319>  double_index_type::double_index_type  <http://www.admb-project.org/documentation/api/classdouble__index__type.html#a2265b2e72fbd497b8cd4d4688398957a>(const  dvector  <http://www.admb-project.org/documentation/api/classdvector.html>& x)
> 00063   {
> 00064p  <http://www.admb-project.org/documentation/api/classdouble__index__type.html#ad1bebc88ffff9232f7502f2c764ee3f2>  =new  dvector_index  <http://www.admb-project.org/documentation/api/classdvector__index.html>((const  dvector  <http://www.admb-project.org/documentation/api/classdvector.html>&)(x));
> 00065   }
> 00066
>
> but the constructor for the dvector_index uses the copy constructor 
> for dvector
>
> 00184
> 00189  <http://www.admb-project.org/documentation/api/classdvector__index.html#aba2c20e6f7432a5b4441e828427ce6e7>  dvector_index::dvector_index  <http://www.admb-project.org/documentation/api/classdvector__index.html#aba2c20e6f7432a5b4441e828427ce6e7>(const  dvector  <http://www.admb-project.org/documentation/api/classdvector.html>& v) :dvector  <http://www.admb-project.org/documentation/api/classdvector.html>(v)
> 00190 {
> 00191 }
> 00192
>
> which makes a shallow copy of v. Not sure why this doesn't work, but 
> it doesn't.
>
> My immediate issue is that I want to put setInitVals(...) in a code 
> library--i.e., not in the tpl code and the usual methods for setting 
> the initial values (i.e., simple assignment by element) are private 
> and only work when the function is defined inside the tpl.
>
> I've also tried the set_initial_value(...) method in the tpl code but 
> it doesn't work there either. Setting the initial values 
> element-by-element in the tpl code does work, so the problem is not on 
> my end (e.g., the dvector vls is all 0's).
>
> Hope this is helpful.
>
> Buck Stockhausen
> ***************************************************
> * 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.
>
>
>
>
> _______________________________________________
> Developers mailing list
> 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/20140616/f93ea2f5/attachment-0001.html>


More information about the Developers mailing list