ADMB Handy operations and functions

advertisement
ADMB Handy operations and functions (aka ADMB cheat sheet)
Compiled by C.V. Minte-Vera [2000]
Let V,X,Y be vectors and vi,wi,yi be the elements of the vectors.
Let M,N,A be matrices and mij, nij, aij be the elements of the matrices.
Let nu be a scalar [number].
Matrix and vector operations
Operation
Sum of two vectors
Sum of scalar to a vector
Sum of two matrices
Sum of a scalar to a matrix
Subtract two vectors
Subtract a scalar from a vector
Subtract a scalar from a matrix
Subtract two matrices
Vector dot product
Outer product of two vectors
Multiply a scalar by a vector
Multiply a vector by a scalar
Multiply a scalar by a matrix
Multiply a vector by a matrix
Multiply a matrix by a vector
Multiply two matrices
Division of vector by scalar
Division of scalar by a vector
Division of a matrix by a scalar
Math notation
vi=xi+yi
vi=xi+nu
aij=mij+nij
aij=mij+nu
vi=xi-yi
vi=xi-nu
vi=xi-nu
aij=mij-nij
nu=xi*yi
mij=xi*yj
xi=nu*yi
xi=yi*nu
mij=nu*aij
xj=i yi*mij
xi=j mij*yi
aij=k mik * nkj
yi=xi/nu
yi=nu/xi
mij=aij/nu
ADMB slow code
V=X+Y
V = X + nu
A=M+N
A = M +nu
V=X-Y
V=X-nu
A=M-nu
A=M-N
nu=X*Y
M=outer_prod(X,Y)
X=nu*Y
X=Y*nu
A=nu*M
X=Y*M
X=M*Y
A=M*N
Y=X/nu
Y=nu/X
M=N/nu
ADMB fast code
X+=Y
X+=nu
M+=nu
X-=Y
X-=nu
M-=nu
M-=N
Y*=nu
M*=nu
X/=nu
Element –wise (e-w) operations in a matrix or vector object
Operation [need objects of the Mathematical notation
ADMB code
same dimension]
Vectors e-w multiplication
vi=xi*yi
V=elem_prod (X,Y)
Vectors e-w division
vi=xi/yi
V=elem_div(X,Y)
Matrices e-w multiplication
mij=aij*nij
M=elem_prod(A,N)
Matrices e-w division
mij=aij/nij
M=elem_div(A,N)
Other matrix or vector operations
Operation
Norm of a vector
Norm square of a vector
Norm of a matrix
Norm square of a matrix
Sum over elements of a vector
Row sums of a matrix object
Column sum of a matrix object
Concatenation
Mathematical notation
nu=sqrt(i vi^2)
nu=(i vi^2)
nu=sqrt(ij mij^2)
nu=(ij mij^2)
nu= i vi
xi=j mij
yj=i mij
X=(x1,x2,x3), Y=(y1,y2)
V=( x1,x2,x3,y1,y2)
ADMB code
nu=norm(V)
nu=norm2(V)
nu=norm(M)
nu=norm2(M)
nu=sum(V)
X=rowsum(M)
Y=colsum(M)
V=X&Y
Other matrix or vector operations
Determinant (must be a square matrix cols=rows)
Logarithm of the determinant? (must be a square
matrix cols=rows), sgn is an integer
Not explained in the manual, but used in the codes.
Inverse (must be a square matrix cols=rows)
Minimum value of a vector object
Maximum value of a vector object
Eigenvalues of a symmetric matrix
Eigenvectors of a symmetric matrix
Identity matrix function
Useful functions
Function
current_phase( )
last_phase( )
Active(Par)
mceval_phase()
bolinha.initialize()
nu=det(M)
nu=ln_det(M,sgn)
N=inv(M)
nu=min(V)
nu=max(V)
V=Eigenvalues (M)
N=eigenvectors(M)
M=identity_matrix(int min, int max)
Action
return an integer that is the value of the current phase
return a binary: “true” if the current phase is the last phase and “false”
(=0) otherwise
return a binary: “true” if the parameter Par is active in the current
phase and “false” (=0) otherwise
return a binary: “true” if the current phase is the mceval phase and
“false” (=0) otherwise
Initializes (sets all elements equal to zero) the object bolinha
Download