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

Johnoel Ancheta johnoel at hawaii.edu
Mon Jun 16 15:05:46 PDT 2014


Add fix with test case.

http://www.admb-project.org/redmine/projects/issues/repository/revisions/2104


On Mon, Jun 16, 2014 at 10:46 AM, Johnoel Ancheta <johnoel at hawaii.edu>
wrote:

> Working on this now...
>
>
> On Mon, Jun 16, 2014 at 8:13 AM, William Stockhausen - NOAA Federal <
> william.stockhausen at noaa.gov> wrote:
>
>> Here's Dave's solution to my problem (for some reason he wasn't able to
>> post to the developers list). His full solution is attached.
>>
>> ---------- Forwarded message ----------
>> From: dave fournier <davef at otter-rsch.com>
>> Date: Mon, Jun 16, 2014 at 10:00 AM
>> Subject: Re: [Developers] method set_initial_values(...) not working for
>> param_init_number_vector
>> To: William Stockhausen - NOAA Federal <william.stockhausen at noaa.gov>,
>> developers <developers at admb-project.org>
>>
>>
>>
>> It appears that this function was some duped code which was never
>> finished properly.
>> I think it should look like this at the top of the file model48.cpp.
>>
>> There may also be other set_initial_value functions which were not
>> finished.
>>
>>  void param_init_bounded_number_vector::set_initial_value(const
>> double_index_type& _it)
>>  {
>>    int mmin=indexmin();
>>    int mmax=indexmax();
>>    for (int i=mmin;i<=mmax;i++)
>>    {
>>      (*this)(i)=ad_double(_it(i));
>>    }
>>  }
>>
>>
>>
>>
>> On 06/16/2014 07:08 AM, William Stockhausen - NOAA Federal wrote:
>>
>> 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>(00010   const double_index_type <http://www.admb-project.org/documentation/api/classdouble__index__type.html>& _it)00011  {00012     it <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   {00064     p <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             *
>> * 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 listDevelopers at admb-project.orghttp://lists.admb-project.org/mailman/listinfo/developers
>>
>>
>>
>>
>> _______________________________________________
>> 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/0555f7d8/attachment.html>


More information about the Developers mailing list