model.generic ============= .. py:module:: model.generic Attributes ---------- .. autoapisummary:: model.generic.w Classes ------- .. autoapisummary:: model.generic.GenericNN Functions --------- .. autoapisummary:: model.generic._validate_and_reformat_inputs model.generic.generate_layers Module Contents --------------- .. py:function:: _validate_and_reformat_inputs(weights: Union[torch.Tensor, List[torch.Tensor]], biases: Union[torch.Tensor, List[torch.Tensor]], act_fns: Union[torch.nn.Module, List[torch.nn.Module]]) -> Tuple Validates and reformats inputs. :param weights: Input weight tensors. :type weights: torch.Tensor | list[torch.Tensor] :param biases: Input bias tensors. :type biases: torch.Tensor | list[torch.Tensor] | NoneType :param act_fns: Activation functions. :type act_fns: torch.Tensor | list[torch.Tensor] | NoneType :returns: Tuple contianing the reformatted weights, biases, and activation functions. :rtype: tuple :raises TypeError: If inputs are not of the expected types. :raises AssertionError: If dimensions of input tensors are incorrect or mismatched. .. py:function:: generate_layers(weights: Union[torch.Tensor, List[torch.Tensor]], biases: Union[torch.Tensor, List[torch.Tensor]], act_fns: Union[torch.nn.Module, List[torch.nn.Module]]) -> List[torch.nn.Module] Creates linear layers and activation function to be used as inputs for nn.Sequential. :param weights: Weights for each linear layer. :type weights: torch.Tensor | list[torch.Tensor] :param biases: Bias for each linear layer. Length of weights and biases must match if list. :type biases: torch.Tensor | list[torch.Tensor] | NoneType :param act_fns: Activation for each linear layer. If activation Layer (i.e. not list) act_fns will be repeated for each linear layer. It is recommended to pass in the class rather than instance of activation Layer, as certain FA methods require no duplicate layers in the model. :type act_fns: nn.module.activation | list | NoneType .. py:class:: GenericNN(weights: torch.Tensor, biases: Optional[torch.Tensor] = None, act_fns: Optional[torch.nn.Module] = None) Bases: :py:obj:`torch.nn.Sequential` Class for creating custom neural network architectures using specified weights, biases, and activation functions. Inherits from: torch.nn.Sequential: Parent class for implementing neural networks with modules defined in a sequential manner. Initializes a GenericNN object. :param weights: Weights for each linear layer. :type weights: torch.Tensor | list[torch.Tensor] :param biases: Bias for each linear layer. Length of weights and biases must match if list. :type biases: torch.Tensor | list[torch.Tensor], optional :param act_fns: Activation for each linear layer. :type act_fns: nn.module.activation | list, optional .. py:data:: w