Dear Sebastien
Thanks for M_.NNZDerivatives,
1) However, M_.NNZDerivatives(2) ans = 119 should result in a Hessian matrix of 3*119, total 357 elements, however, as can be seen below, it finishes sparse at element 138 instead 357-1=356.Alternatively, if 119 it a total number of elements (including indices) then it should be divisible by 3. Can you explain me where is this discrepancy occurring form?
2) Also, in a related issue, if you, or anyone else, has no objections Re my previous email, would it be then possible to change the behaviour of the preprocessor and have the indices and values of the sparse Hessian from the mex file returned grouped together either 3 by 3 as per my example below (which would then also constitute a 3 column matrix by number of non-zero elements rows as per your email) or, if it is supposed to be a "3 row" matrix, then apart by the total number of non-zero Hessian values, that is,. rather than being apart by no-of-vars/equations as it seems to be the case now?
Best regards George
----- Original Message ----- From: "G. Perendia" george@perendia.orangehome.co.uk To: "List for Dynare developers" dev@dynare.org Sent: Friday, June 26, 2009 3:26 PM Subject: Re: [DynareDev] 2nd and 3rd model derivatives + k-order
Dear Sebastien
Am I right to assume from the enclosed sample from the new <mod>_dynamic.c sparse hessian that row and column indices and values are 10 position
apart
with other values in between ( i.e. apart by Number of variables which happens to be 10 in this case). That seems to me a bit confusing and I am wandering what to do when the number of non-zero values is not a multiply
of
or no of vars - i.e we are going to have zero values to pad the matrices
(as
in the example below, positions 119 and 129 are not populated and in model with 20 or more vars there will be a lot of padding).
v2[0]=1; v2[10]=78;
v2[20]=(-(T21*T16*params[4]*T94));
v2[1]=1;
v2[11]=158;
v2[21]=v2[20];
v2[2]=1;
v2[12]=73;
v2[22]=(-(T21*T16*y[9]*params[4]*T172));
.....
v2[118]=10;
v2[128]=109;
v2[138]=(1+params[6])*(1+params[6]-1)*pow(y[6],1+params[6]-1-1)/(1+params[6]
);
}
What is the advantage in grouping by no-of vars?
What would be disadvantage if we had indices and values grouped together
in
3 by 3 values? e.g.
v2[0]=1; v2[1]=78;
v2[2]=(-(T21*T16*params[4]*T94));
...
Best regards
George
----- Original Message ----- From: "Sébastien Villemot" sebastien.villemot@ens.fr To: dev@dynare.org Cc: "Pablo Winant" pablo.winant@gmail.com Sent: Thursday, June 25, 2009 11:09 AM Subject: [DynareDev] 2nd and 3rd model derivatives + k-order
Hi everyone,
In the preprocessor, I have applied (in r2787) a change suggested by Pablo Winant: it consists in optimizing the way that the sparse matrices for 2nd and 3rd derivatives (g2 and g3) are constructed in dynamic (and sometimes static) model files. Thanks to Pablo for his very helpful patch.
First, note that this breaks the USE_DLL option at order 2. Since we are going to drop this option in the future, I'm not planning to fix this.
Second, a change needs to be made in the k-order library: the matrix for 2nd order derivatives of the dynamic model, as returned by the MEX file, has changed. It is now a 3 columns matrix, which contain only the non-null derivatives of the Hessian. Each line represents a non-zero element: column 1 is the row index of the non-zero element in the Hessian, column 2 is its column index, and column 3 is its value. Note that this is the format required by Matlab sparse() function.
Best,
-- Sébastien Villemot
Dev mailing list Dev@dynare.org http://www.dynare.org/cgi-bin/mailman/listinfo/dev
"G. Perendia" george@perendia.orangehome.co.uk a écrit :
- However,
M_.NNZDerivatives(2) ans = 119 should result in a Hessian matrix of 3*119, total 357 elements, however, as can be seen below, it finishes sparse at element 138 instead 357-1=356.Alternatively, if 119 it a total number of elements (including indices) then it should be divisible by 3. Can you explain me where is this discrepancy occurring form?
Sorry it was my mistake. The v2 matrix in the C file was not correctly constructed. This should now be fixed.
- Also, in a related issue, if you, or anyone else, has no objections Re my
previous email, would it be then possible to change the behaviour of the preprocessor and have the indices and values of the sparse Hessian from the mex file returned grouped together either 3 by 3 as per my example below (which would then also constitute a 3 column matrix by number of non-zero elements rows as per your email) or, if it is supposed to be a "3 row" matrix, then apart by the total number of non-zero Hessian values, that is,. rather than being apart by no-of-vars/equations as it seems to be the case now?
The matrix v2 has 3 columns. In the C file, it is constructed in column major order (which is Fortran and MATLAB's internal representation). For a n-by-3 matrix stored in a vector, the first n elements are the first columns, the next n elements the second, and the last n elements the third.
Put it otherwise, the (i,j) element has index (i-1)+(j-1)*n in the vector.
The other convention is row major order, where element (i,j) has index (j-1)+3*(i-1); we don't use it since it is not MATLAB's internal representation.
Please let me know if you need more explanations or if you discover another bug.
Best,
Thanks Sebastien
we now have all 3*NNZD(2) = 3*119=357 matrix elements and they are NNZD(2) (i.e. the total number of non-zero Hessian elements) apart rather than no-of-vars apart as they used to be.
Is there a reason that M_.NNZDerivatives is 3x3 matrix rather than 3x1 vector, i..e. M_.NNZDerivatives ans = 47 0 0 119 0 0 0 0 0
Best regards George
----- Original Message ----- From: "Sébastien Villemot" sebastien.villemot@ens.fr To: dev@dynare.org Sent: Monday, June 29, 2009 10:31 AM Subject: Re: [DynareDev] 2nd and 3rd model derivatives + k-order
"G. Perendia" george@perendia.orangehome.co.uk a écrit :
- However,
M_.NNZDerivatives(2) ans = 119 should result in a Hessian matrix of 3*119, total 357 elements, however, as can be seen below, it finishes sparse at element 138 instead 357-1=356.Alternatively, if 119 it a total number of elements (including indices) then it should be divisible by 3. Can you explain me where is
this
discrepancy occurring form?
Sorry it was my mistake. The v2 matrix in the C file was not correctly constructed. This should now be fixed.
- Also, in a related issue, if you, or anyone else, has no objections Re
my
previous email, would it be then possible to change the behaviour of the preprocessor and have the indices and values of the sparse Hessian from
the
mex file returned grouped together either 3 by 3 as per my example below (which would then also constitute a 3 column matrix by number of non-zero elements rows as per your email) or, if it is supposed to be a "3 row" matrix, then apart by the total number of non-zero Hessian values, that
is,.
rather than being apart by no-of-vars/equations as it seems to be the case now?
The matrix v2 has 3 columns. In the C file, it is constructed in column major order (which is Fortran and MATLAB's internal representation). For a n-by-3 matrix stored in a vector, the first n elements are the first columns, the next n elements the second, and the last n elements the third.
Put it otherwise, the (i,j) element has index (i-1)+(j-1)*n in the vector.
The other convention is row major order, where element (i,j) has index (j-1)+3*(i-1); we don't use it since it is not MATLAB's internal representation.
Please let me know if you need more explanations or if you discover another bug.
Best,
"G. Perendia" george@perendia.orangehome.co.uk a écrit :
Is there a reason that M_.NNZDerivatives is 3x3 matrix rather than 3x1 vector, i..e. M_.NNZDerivatives ans = 47 0 0 119 0 0 0 0 0
This should now be fixed.