Function and module reference¶
The context manager¶
- cadjn.init()¶
Returns a CADJN context manager object.
- Returns:
CADJN context manager object.
- Return type:
- class cadjn.CADJN¶
CADJN context manager.
This class loads the CADJN C library and creates handles for the necessary functions.
The most important methods are
init
, which creates CAdjNet neural net objects,load
, which creates CAdjNet neural net objects from files, andsave
, which saves CAdjNet neural net objects.- init(init)¶
Returns a CADJN context manager object.
- load(fname)¶
Returns a CADJN context manager object.
The neural network¶
- class cadjn.cadjn.CAdjNet(cadjn, net, data)¶
The CADJN neural net object.
- Hv(d_w, w, data, specs)¶
Compute a product of the Hessian of the scalar objective function
objw
given weights, data, and specs, with d_w. Also returns the gradient as withg
and the scalar objective value.- Parameters:
d_w (numpy.ndarray) – The derivative direction(s). A 2D array of shape [N, NDD], where N is the number of weights (
numel
) and NDD is some integer > 0. A single vector with shape [N] is also accepted.w (numpy.ndarray) – The network weights. The gradient returned is the derivative of the scalar objective function w.r.t. this parameter.
data (numpy.ndarray) – Data and specs to process, as for
objw
.specs (numpy.ndarray) – Data and specs to process, as for
objw
.
- Returns:
Product of the Hessian of the scalar objective function with d_w, a 2D array of shape [N, NDD] (N is
numel
), gradient of the scalar objective function, a vector of shape [N], and the scalar objective value.- Return type:
(numpy.ndarray, numpy.ndarray, float)
- Jv(d_w, w, data, specs)¶
Compute a product of the Jacobian of the vector objective function
objwv
given weights, data, and specs, with d_w. Also returns the vector objective value.- Parameters:
d_w (numpy.ndarray) – The derivative direction(s). A 2D array of shape [N, NDD], where N is the number of weights (
numel
) and NDD is some integer > 0. A single vector with shape [N] is also accepted.w (numpy.ndarray) – The network weights. The gradient returned is the derivative of the scalar objective function w.r.t. this parameter.
data (numpy.ndarray) – Data and specs to process, as for
objw
.specs (numpy.ndarray) – Data and specs to process, as for
objw
.
- Returns:
The Jacobian product with d_w, a 2D array of shape [M*J, NDD], where M is the number of samples (the leading dimension of data) and J is
numout
, and the vector objective value.- Return type:
(numpy.ndarray, numpy.ndarray)
- compute(data)¶
Compute the neural network response from data, which is a 2D array of input data, one per row.
- g(w, data, specs)¶
Compute the gradient of the scalar objective function
objw
given weights, data, and specs. Also returns the scalar objective value.
- getweights()¶
Set the weights of the neural network. The vector is a sequence of bias vectors and transfer matrixes according to the network configuration. Use
setweights
to set the weights.- Returns:
Vector of network weights, a 1D array of shape [N], where N is the number of weights (
numel
).- Return type:
numpy.ndarray
- obj(data, specs)¶
Compute the scalar objective (error) function of the neural network response from data, which is a 2D array of input data, one per row, given the specs, which is a 2D array of the intended response, one per row. The result is the result of
residual
evaluated by the objective function configured in the network.- Parameters:
- Returns:
Value of the network scalar objective function.
- Return type:
- objv(data, specs)¶
Compute the vector objective (error) function of the neural network response from data, which is a 2D array of input data, one per row, given the specs, which is a 2D array of the intended response, one per row. The result is the result of
residual
evaluated by the objective function configured in the network.- Parameters:
- Returns:
Value of the network vector objective function.
- Return type:
numpy.ndarray
- objw(w, data, specs)¶
Like
obj
, but applysetweights
before computation.- Parameters:
- Returns:
Value of the network scalar objective function.
- Return type:
- objwv(w, data, specs)¶
Like
objv
, but applysetweights
before computation.- Parameters:
- Returns:
Value of the network vector objective function.
- Return type:
numpy.ndarray
- residual(data, specs)¶
Compute the residual (error) of the neural network response from data, which is a 2D array of input data, one per row, given the specs, which is a 2D array of the intended response, one per row. The result is the result of
compute
minus the specs.- Parameters:
- Returns:
Residual of network response, a 2D array of shape [M, J], where J is the number of outputs (
numout
).- Return type:
numpy.ndarray
- setweights(w)¶
Set the weights of the neural network. The vector is a sequence of bias vectors and transfer matrixes according to the network configuration. Use
getweights
to get the current weights vector.
- vJ(d_w, w, data, specs)¶
Compute a product of d_w with the Jacobian of the vector objective function
objwv
given weights, data, and specs. Also returns the vector objective value.- Parameters:
d_w (numpy.ndarray) – The derivative direction(s). A 2D array of shape [NDD, M*J], where M is the number of samples (the leading dimension of data), J is
numout
and NDD is some integer > 0. A single vector with shape [M*J] is also accepted.w (numpy.ndarray) – The network weights. The gradient returned is the derivative of the scalar objective function w.r.t. this parameter.
data (numpy.ndarray) – Data and specs to process, as for
objw
.specs (numpy.ndarray) – Data and specs to process, as for
objw
.
- Returns:
The product of d_w with the Jacobian, a 2D array of shape [NDD, N], where N is
numel
and NDD is some integer > 0, and the vector objective value.- Return type:
(numpy.ndarray, numpy.ndarray)