[CppAD] Avoid retaping when constant is changed
Brad Bell
bradbell at seanet.com
Wed Jun 28 08:04:42 EDT 2017
On 06/28/2017 04:51 AM, Hilario Tomé wrote:
> Thank you Brad for the answer, I thought of doing what you suggested,
> but I would later face the problem of having to manually trim the
> jacobian when I call the jacobian method of the adfun object, and also
> the extra computation not needed when computing the full jacobian, do
> you have any work around for this?
In the sparse case, you specify which elements of the Jacobian to
calculate; see subset on
https://www.coin-or.org/CppAD/Doc/sparse_jac.htm#subset
In the dense matrix case, and reverse mode, there is very little extra
work for computing derivatives w.r.t. extra variables. In the dense case
and forward mode, there is no need to include the extra variable during
the forward passes for the Jacobian. For this case, think of the
function JacobianFor in
https://github.com/coin-or/CppAD/blob/master/cppad/core/jacobian.hpp
as an example of how to compute the Jacobian and just exclude the
constant for the set of variables you are computing the paritals w.r..t
>
> Best,
>
> On Wed, Jun 28, 2017 at 1:43 PM, Brad Bell <bradbell at seanet.com
> <mailto:bradbell at seanet.com>> wrote:
>
> I would try the following approach:
>
> Use c (or any other name) to denote the constant (a scalar) and
> let n be the length of the vector x.
> Then do the following;
> Vector< AD<double> > a_xc(n+1);
> for(size_t j = 0; j < n; j++)
> a_xc[j] = x[j];
> a_xc[n] = c;
> Independent( a_xc );
> Vector< AD<double> > a_x(n);
> AD<double> a_c;
> for(size_t j = 0; j < n; j++)
> a_x[j] = a_xc[j];
> a_c = a_xc[n];
> In other words make c a variable. That way you can change is value
> when computing derivatives.
>
>
>
>
>
>
>
> On 06/28/2017 04:27 AM, Hilario Tomé wrote:
>>
>> Dear all,
>>
>> I would like to know if it's possible to record a pointer to an
>> external value in the tape. The use case is to have formulas like
>> y = constant*x. Once the ADfun object is created if I change the
>> value of constant I have to retape right now, and sometimes the
>> re-taping operation is to costly, especially if sparsity
>> operations are involved.
>>
>> Best,
>>
>>
>> --
>> Hilario.
>>
>>
>> _______________________________________________
>> CppAD mailing list
>> CppAD at list.coin-or.org <mailto:CppAD at list.coin-or.org>
>> https://list.coin-or.org/mailman/listinfo/cppad
>> <https://urldefense.proofpoint.com/v2/url?u=https-3A__list.coin-2Dor.org_mailman_listinfo_cppad&d=DwMDaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=GH3eJ7xA3ZBR9rQvT_fJhDgld4V8Nzy-5rXbR27Kb5c&m=1mBE6bNs5eNxiLDQVywSDTN4TIfnDxcxIe-wUHbDd80&s=sjbUY3bPGw7yzllPcFdDlP6RIXCLMUiM62_VWPzTCwU&e=>
> _______________________________________________ CppAD mailing list
> CppAD at list.coin-or.org <mailto:CppAD at list.coin-or.org>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__list.coin-2Dor.org_mailman_listinfo_cppad&d=DwICAg&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=GH3eJ7xA3ZBR9rQvT_fJhDgld4V8Nzy-5rXbR27Kb5c&m=1mBE6bNs5eNxiLDQVywSDTN4TIfnDxcxIe-wUHbDd80&s=sjbUY3bPGw7yzllPcFdDlP6RIXCLMUiM62_VWPzTCwU&e=
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__list.coin-2Dor.org_mailman_listinfo_cppad&d=DwICAg&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=GH3eJ7xA3ZBR9rQvT_fJhDgld4V8Nzy-5rXbR27Kb5c&m=1mBE6bNs5eNxiLDQVywSDTN4TIfnDxcxIe-wUHbDd80&s=sjbUY3bPGw7yzllPcFdDlP6RIXCLMUiM62_VWPzTCwU&e=>
>
>
> --
> Hilario.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cppad/attachments/20170628/3d6344eb/attachment-0001.html>
More information about the CppAD
mailing list