torch_openreml.covariance.IdentityMatrix¶
- class torch_openreml.covariance.IdentityMatrix(n, dtype=None, device=None)[source]¶
Bases:
MatrixFixed \(n \times n\) identity covariance matrix.
\[\symbf{V} = \symbf{I}_n\]This matrix has no trainable parameters, so
grad()always returns(None, []). It is typically used to represent independent, homoscedastic residuals.Initialize a fixed identity matrix of size
n x n.- Parameters:
n (int) – Matrix dimension.
dtype (torch.dtype, optional) – Desired dtype of the matrix. Defaults to the PyTorch default dtype.
device (torch.device, optional) – Desired device of the matrix. Defaults to the PyTorch default device.
Example:
import torch from torch_openreml.covariance import IdentityMatrix mat = IdentityMatrix(3) mat()
tensor([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])Methods
__call__(*args, **kwargs)Construct the matrix from a flat parameter tensor.
auto_grad([free_params])Compute the Jacobian of
build()with respect to free parameters using automatic differentiation.build_params([free_params, include_fixed, ...])Construct the full parameter tensor from free parameters.
get_intermediates(params)Retrieve cached intermediate computation results if still valid.
grad([free_params])Compute the Jacobian of
__call__()with respect to trainable parameters.manual_grad([free_params])Compute the Jacobian of
__call__()with respect to free parameters using a closed-form analytic expression.map_theta_to_dv(theta)An interface compatible with
torch_openreml.REMLthat maps parameters to the matrix Jacobian.map_theta_to_v(theta)An interface compatible with
torch_openreml.REMLthat maps parameters to a matrix.reset_intermediates()Clear the intermediate computation cache.
set_intermediates(params, intermediates)Cache intermediate computation results keyed by parameter hash.
trans_grad([free_params])Compute the element-wise derivative of the free parameter transforms.
Attributes
fixed_param_defaultsFixed parameter defaults.
fixed_param_indexIndex of fixed parameters.
fixed_param_namesFixed parameter names.
fixed_param_transTransforms for fixed parameters.
free_param_defaultsFree parameter defaults.
free_param_indexIndex of free parameters.
free_param_namesFree parameter names.
free_param_transTransforms for free parameters.
num_fixed_paramsTotal number of fixed parameters.
num_free_paramsTotal number of free parameters.
num_paramsTotal number of parameters.
param_defaultsParameter defaults.
param_namesParameter names.
param_specsParameter specifications.
param_transParameter transforms.
repr_dictKey-value pairs used to build the string representation.
shapeOutput matrix shape.
- __call__(*args, **kwargs)[source]¶
Construct the matrix from a flat parameter tensor.
Must be implemented by subclasses. Implementations should convert
free_paramsviabuild_params()to validate, include fixed parameters, and apply transforms before any computation.- Parameters:
free_params (torch.Tensor or dict) – Flat 1D parameter tensor or parameter dictionary. If omitted, default values are used. Default:
None.- Returns:
Constructed matrix of shape
shape.- Return type:
torch.Tensor