Expand description
This crate provides the core implementations for the cnc framework, defining various
traits, types, and utilities essential for building neural networks.
ParamsBase: A structure for defining the parameters within a neural network.Backward: This trait establishes a common interface for backward propagation.Forward: This trait denotes a single forward pass through a layer of a neural network
§Features
The crate is heavily feature-gate, enabling users to customize their experience based on their needs.
utils: Provides various utilities for developing machine learning models.
§Dependency-specific Features
Additionally, the crate provides various dependency-specific features that can be enabled:
anyhow: Enables the use of theanyhowcrate for error handling.approx: Enables approximate equality checks for floating-point numbers.complex: Enables complex number support.json: Enables JSON serialization and deserialization capabilities.rand: Enables random number generationserde: Enables serialization and deserialization capabilities.tracing: Enables tracing capabilities for debugging and logging.
Re-exports§
pub use super::layer::*;
Modules§
- activate
- this module provides the
Activatetrait alongside additional primitives and utilities for activating neurons within a neural network. - config
- This module is dedicated to establishing common interfaces for valid configuration objects while providing a standard implementation to quickly spin up a new model.
- error
- This module implements the core
Errortype for the framework and provides aResulttype alias for convenience. - models
- this module works to provide a common interface for storing sets of parameters within a
given model. The
ModelParamsBaseimplementation generically captures the behavior of parameter storage, relying on theParamsBaseinstance to represent individual layers within the network. - nn
- This module provides network specific implementations and traits supporting the development of neural network models.
- params
- In machine learning, each layer is composed of some set of neurons that process input data to produce some meaningful output. Each neuron typically has associated parameters, namely weights and biases, which are adjusted during training to optimize the model’s performance.
- utils
- Additional utilities for creating, manipulating, and managing tensors and models.
Structs§
- Dropout
- The Dropout layer is randomly zeroizes inputs with a given probability (
p). This regularization technique is often used to prevent overfitting. - PadAction
Iter - An iterator over the variants of PadAction
- Padding
- Parameter
- The
Parameterstruct represents a key-value pair used for configuration settings within the neural network framework. - Params
Base - The
ParamsBaseimplementation aims to provide a generic, n-dimensional weight and bias pair for a model (or layer). The object requires the bias tensor to be a single dimension smaller than the weights tensor. - Params
Ref - Standard
Model Config - The
StandardModelConfigstruct is a standard implementation of the
Enums§
- Deep
- Error
- The
Errortype enumerates various errors that can occur within the framework. - PadAction
- PadMode
- Shallow
Traits§
- Abs
- Activate
Activateis a higher-kinded trait that provides a mechanism to apply a function over the elements within a container or structure.- Activator
- An
Activatordefines an interface for structural activation functions that can be applied onto various types. - Activator
Gradient - The
ActivatorGradienttrait extends theActivatortrait to include a method for computing the gradient of the activation function. - Affine
- apply an affine transformation to a tensor;
affine transformation is defined as
mul * self + add - Apply
Applyis a composable binary operator generally used to apply some object or function onto the caller to produce some output.- Apply
Gradient - A trait declaring basic gradient-related routines for a neural network
- Apply
Gradient Ext - This trait extends the ApplyGradient trait by allowing for momentum-based optimization
- Apply
Mut ApplyMutprovides an interface for mutable containers that can apply a function onto their elements, modifying them in place.- Apply
Once - The
ApplyOncetrait consumes the container and applies the given function to every element before returning a new container with the results. - Array
Like - AsBias
Dim - The
AsBiasDimtrait is used to define a type that can be used to get the bias dimension of the parameters. - AsComplex
AsComplexdefines an interface for converting a reference of some numerical type into a complex number.- Backward
- The
Backwardtrait establishes a common interface for completing a single backward step in a neural network or machine learning model. - Backward
Step - Biased
- Clip
- A trait denoting objects capable of being clipped between some minimum and some maximum.
- ClipMut
- This trait enables tensor clipping; it is implemented for
ArrayBase - Codex
- Conjugate
- Cos
- Cosh
- Cross
Entropy - A trait for computing the cross-entropy loss of a tensor or array
- Cubed
- Decode
- Decode defines a standard interface for decoding data.
- Decrement
Decrementis a chainable trait that defines a decrement method, effectively removing a single unit from the original object to create another- Decrement
Axis - The
DecrementAxisis used as a unary operator for removing a single axis from a multidimensional array or tensor-like structure. - Decrement
Mut - The
DecrementMuttrait defines a decrement method that operates in place, modifying the original object. - Deep
Model Repr - The
DeepModelReprtrait for deep neural networks - Default
Like - Dim
- the
Dimtrait is used to define a type that can be used as a raw dimension. This trait is primarily used to provide abstracted, generic interpretations of the dimensions of thendarraycrate to ensure long-term compatibility. - DimConst
- DropOut
- Dropout randomly zeroizes elements with a given probability (
p). - Encode
- Encode defines a standard interface for encoding data.
- Exact
DimParams - Exp
- Fill
Like - Floor
Div - Forward
- The
Forwardtrait describes a common interface for objects designated to perform a single forward step in a neural network or machine learning model. - Forward
Mut - Forward
Once - A consuming implementation of forward propagation
- GetBias
Dim - Gradient
- the
Gradienttrait defines the gradient of a function, which is a function that takes an input and returns a delta, which is the change in the output with respect to the input. - Hyper
Param Key - Increment
- The
Increment - Increment
Axis - The
IncrementAxistrait defines a method enabling an axis to increment itself, effectively adding a new axis to the array. - Increment
Mut - Init
With InitWithenables a container to- Initialize
Initializeprovides a mechanism for initializing some object using a value of typeTto produce another object.- Into
Axis - The
IntoAxistrait is used to define a conversion routine that takes a type and wraps it in anAxistype. - Into
Complex - Trait for converting a type into a complex number.
- Inverse
- The
Inversetrait generically establishes an interface for computing the inverse of a type, regardless of if its a tensor, scalar, or some other compatible type. - IsSquare
IsSquareis a trait for checking if the layout, or dimensionality, of a tensor is square.- L1Norm
- a trait for computing the L1 norm of a tensor or array
- L2Norm
- a trait for computing the L2 norm of a tensor or array
- Layout
Ext - The
LayoutExttrait defines an interface for object capable of representing the layout; i.e. the number of input, hidden, and output features of a neural network model containing some number of hidden layers. - Loss
- The
Losstrait defines a common interface for any custom loss function implementations. This trait requires the implementor to define their algorithm for calculating the loss between two values,lhsandrhs, which can be of different types,XandYrespectively. These terms are used generically to allow for flexibility in the allowed types, such as tensors, scalars, or other data structures while clearly defining the “order” in which the operations are performed. It is most common to expect thelhsto be the predicted output and therhsto be the actual output, but this is not a strict requirement. The trait also defines an associated typeOutput, which represents the type of the loss value returned by thelossmethod. This allows for different loss functions to return different types of loss values, such as scalars or tensors, depending on the specific implementation of the loss function. - MapInto
MapIntodefines an interface for containers that can consume themselves to apply a given function onto each of their elements.- MapTo
MapToestablishes an interface for containers capable of applying a given function onto each of their elements, by reference.- Mask
Fill - This trait is used to fill an array with a value based on a mask. The mask is a boolean array of the same shape as the array.
- MatMul
- The
MatMultrait defines an interface for matrix multiplication. - MatPow
- The
MatPowtrait defines an interface for computing the power of some matrix - Mean
Absolute Error - A trait for computing the mean absolute error of a tensor or array
- Mean
Squared Error - A trait for computing the mean squared error of a tensor or array
- Model
- The
Modeltrait defines the core interface for all models; implementors will need to provide the type of configuration used by the model, the type of layout used by the model, and the type of parameters used by the model. The crate provides standard, or default, definitions of both the configuration and layout types, however, for - Model
Ext - NdGradient
- NdIter
- NdIter
Mut - NdLike
- NdTensor
- Network
Config - The
NetworkConfigtrait defines an interface for compatible configurations within the framework, providing a layout and a key-value store to manage hyperparameters. - Network
Consts - A trait defining common constants for neural networks.
- Network
Depth - The
NetworkDepthtrait is used to define the depth/kind of a neural network model. - Network
Params - Neural
Network - The
NeuralNetworktrait is used to define the network itself as well as each of its constituent parts. - Norm
- The Norm trait serves as a unified interface for various normalization routnines. At the moment, the trait provides L1 and L2 techniques.
- Ones
Like - Pad
- The
Padtrait defines a padding operation for tensors. - Percent
Change - The
PercentChangetrait establishes a binary operator for computing the percent change between two values where the caller is considered the original value. - Percent
Diff - Compute the percentage difference between two values. The percentage difference is defined as:
- Predict
- The
Predicttrait is designed as a model-specific interface for making predictions. In the future, we may consider opening the trait up allowing for an alternative implementation of the trait, but for now, it is simply implemented for all implementors of theForwardtrait. - Predict
With Confidence - The
PredictWithConfidencetrait is an extension of thePredicttrait, providing an additional method to obtain predictions along with a confidence score. - RawContext
- RawHidden
- The
RawHiddentrait for compatible representations of hidden layers - RawLayer
- The
RawLayertrait establishes a common interface for all layers within a given model. Implementors will need to define the type of parameters they utilize, as well as provide methods to access both the activation function and the parameters of the layer. - RawLayer
Mut - The
RawLayerMuttrait extends theRawLayertrait by providing mutable access to the layer’s parameters and additional methods for training the layer, such as backward propagation and parameter updates. - RawModel
Layout - The
RawModelLayouttrait defines a minimal interface for objects capable of representing the layout; i.e. the number of input, hidden, and output features of a neural network model containing some number of hidden layers. - RawModel
Layout Mut - The
RawModelLayoutMuttrait defines a mutable interface for objects capable of representing the layout; i.e. the number of input, hidden, and output features of - RawParams
- The
RawParamstrait is used to denote objects capable of being used as a paramater within a neural network or machine learning context. More over, it provides us with an ability to associate some generic element type with the parameter and thus allows us to consider so-called parameter spaces. If we allow a parameter space to simply be a collection of points then we can refine the definition downstream to consider specific interpolations, distributions, or manifolds. In other words, we are trying to construct a tangible configuration space for our models so that we can reason about optimization and training in a more formal manner. - RawStore
- The
RawStoretrait is used to define an interface for key-value stores like hash-maps, dictionaries, and similar data structures. - RawStore
Mut RawStoreMutextends theRawStoretrait by introducing various mutable operations and accessors for elements within the store.- RawTensor
- RawTensor
Data - Root
- The
Roottrait provides methods for computing the nth root of a number. - RoundTo
- Scalar
Params - The
ScalarParamsis a marker trait automatically implemented for - Scalar
Tensor Data - A marker trait used to denote tensors that represent scalar values; more specifically, we
consider any type implementing the
RawTensorDatatype where theElemassociated type is the implementor itself a scalar value. - Shallow
Model Repr - The
ShallowModelReprtrait for shallow neural networks - Sine
- Sinh
- Square
Root - Squared
- Store
- The
Storetrait is a more robust interface for key-value stores, building upon bothRawStoreandRawStoreMuttraits by introducing anentrymethod for in-place manipulation of key-value pairs. - Store
Entry - The
StoreEntrytrait establishes a common interface for all entries within a key-value store. These types enable in-place manipulation of key-value pairs by allowing for keys to point to empty or vacant slots within the store. - Summary
Statistics - This trait describes the fundamental methods of summary statistics. These include the mean, standard deviation, variance, and more.
- Tan
- Tanh
- Tensor
Base - Tensor
Params - Train
- This trait defines the training process for the network
- Transpose
- The
Transposetrait generically establishes an interface for transposing a type - Unsqueeze
- The
Unsqueezetrait establishes an interface for a routine that unsqueezes an array, by inserting a new axis at a specified position. This is useful for reshaping arrays to meet specific dimensional requirements. - Weighted
- A trait denoting an implementor with weights and associated methods
- Zeros
Like
Functions§
- calculate_
pattern_ similarity - Calculate similarity between two patterns
- clip_
gradient - Clip the gradient to a maximum value.
- clip_
inf_ nan - concat_
iter - Creates an n-dimensional array from an iterator of n dimensional arrays.
- extract_
bias_ dim - Extract a suitable dimension for a bias tensor from the given reference to the layout of the weight tensor.
- extract_
patterns - Extract common patterns from historical sequences
- floor_
div - divide two values and round down to the nearest integer.
- genspace
- hstack
- stack a 1D array into a 2D array by stacking them horizontally.
- inverse
- is_
similar_ pattern - Check if two patterns are similar enough to be considered duplicates
- layer_
norm - layer_
norm_ axis - linarr
- round_
to - Round the given value to the given number of decimal places.
- stack_
iter - Creates a larger array from an iterator of smaller arrays.
- tril
- Returns the lower triangular portion of a matrix.
- triu
- Returns the upper triangular portion of a matrix.
- vstack
- stack a 1D array into a 2D array by stacking them vertically.
Type Aliases§
- ArcParams
- A type alias for shared parameters
- CowParams
- A type alias for a
ParamsBasewith a borrowed internal layout - Deep
Model Params - a type alias for an owned representation of the
DeepParamsBasegeneric of typeAand the dimensionD. - Deep
Params Base - a type alias for a deep representation of the
ModelParamsBaseusing a vector of parameters as the hidden layers. - Model
Params - A type alias for an owned representation of the
ModelParamsBasegeneric of typeAand the dimensionD. - Params
- A type alias for a
ParamsBasewith an owned internal layout - Params
View - A type alias for an immutable view of the parameters
- Params
View Mut - A type alias for a mutable view of the parameters
- RawMut
Params - A type alias for the
ParamsBasewhose elements are of type*mut Ausing aRawViewReprlayout - RawView
Params - A type alias for the
ParamsBasewhose elements are of type*const Ausing aRawViewReprlayout - Result
- a type alias for a
Resultdefined to use the customErroras its error type. - Shallow
Model Params - a type alias for an owned representation of the
DeepParamsBasegeneric of typeAand the dimensionD. - Shallow
Params Base - a type alias for a shallow representation of the
ModelParamsBaseusing a singleParamsBaseinstance as the hidden layer.