Crate concision_core

Crate concision_core 

Source
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 the anyhow crate 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 generation
  • serde: 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 Activate trait 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 Error type for the framework and provides a Result type alias for convenience.
models
this module works to provide a common interface for storing sets of parameters within a given model. The ModelParamsBase implementation generically captures the behavior of parameter storage, relying on the ParamsBase instance 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.
PadActionIter
An iterator over the variants of PadAction
Padding
Parameter
The Parameter struct represents a key-value pair used for configuration settings within the neural network framework.
ParamsBase
The ParamsBase implementation 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.
ParamsRef
StandardModelConfig
The StandardModelConfig struct is a standard implementation of the

Enums§

Deep
Error
The Error type enumerates various errors that can occur within the framework.
PadAction
PadMode
Shallow

Traits§

Abs
Activate
Activate is a higher-kinded trait that provides a mechanism to apply a function over the elements within a container or structure.
Activator
An Activator defines an interface for structural activation functions that can be applied onto various types.
ActivatorGradient
The ActivatorGradient trait extends the Activator trait 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
Apply is a composable binary operator generally used to apply some object or function onto the caller to produce some output.
ApplyGradient
A trait declaring basic gradient-related routines for a neural network
ApplyGradientExt
This trait extends the ApplyGradient trait by allowing for momentum-based optimization
ApplyMut
ApplyMut provides an interface for mutable containers that can apply a function onto their elements, modifying them in place.
ApplyOnce
The ApplyOnce trait consumes the container and applies the given function to every element before returning a new container with the results.
ArrayLike
AsBiasDim
The AsBiasDim trait is used to define a type that can be used to get the bias dimension of the parameters.
AsComplex
AsComplex defines an interface for converting a reference of some numerical type into a complex number.
Backward
The Backward trait establishes a common interface for completing a single backward step in a neural network or machine learning model.
BackwardStep
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
CrossEntropy
A trait for computing the cross-entropy loss of a tensor or array
Cubed
Decode
Decode defines a standard interface for decoding data.
Decrement
Decrement is a chainable trait that defines a decrement method, effectively removing a single unit from the original object to create another
DecrementAxis
The DecrementAxis is used as a unary operator for removing a single axis from a multidimensional array or tensor-like structure.
DecrementMut
The DecrementMut trait defines a decrement method that operates in place, modifying the original object.
DeepModelRepr
The DeepModelRepr trait for deep neural networks
DefaultLike
Dim
the Dim trait 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 the ndarray crate 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.
ExactDimParams
Exp
FillLike
FloorDiv
Forward
The Forward trait describes a common interface for objects designated to perform a single forward step in a neural network or machine learning model.
ForwardMut
ForwardOnce
A consuming implementation of forward propagation
GetBiasDim
Gradient
the Gradient trait 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.
HyperParamKey
Increment
The Increment
IncrementAxis
The IncrementAxis trait defines a method enabling an axis to increment itself, effectively adding a new axis to the array.
IncrementMut
InitWith
InitWith enables a container to
Initialize
Initialize provides a mechanism for initializing some object using a value of type T to produce another object.
IntoAxis
The IntoAxis trait is used to define a conversion routine that takes a type and wraps it in an Axis type.
IntoComplex
Trait for converting a type into a complex number.
Inverse
The Inverse trait generically establishes an interface for computing the inverse of a type, regardless of if its a tensor, scalar, or some other compatible type.
IsSquare
IsSquare is 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
LayoutExt
The LayoutExt trait 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 Loss trait 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, lhs and rhs, which can be of different types, X and Y respectively. 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 the lhs to be the predicted output and the rhs to be the actual output, but this is not a strict requirement. The trait also defines an associated type Output, which represents the type of the loss value returned by the loss method. 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
MapInto defines an interface for containers that can consume themselves to apply a given function onto each of their elements.
MapTo
MapTo establishes an interface for containers capable of applying a given function onto each of their elements, by reference.
MaskFill
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 MatMul trait defines an interface for matrix multiplication.
MatPow
The MatPow trait defines an interface for computing the power of some matrix
MeanAbsoluteError
A trait for computing the mean absolute error of a tensor or array
MeanSquaredError
A trait for computing the mean squared error of a tensor or array
Model
The Model trait 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
ModelExt
NdGradient
NdIter
NdIterMut
NdLike
NdTensor
NetworkConfig
The NetworkConfig trait defines an interface for compatible configurations within the framework, providing a layout and a key-value store to manage hyperparameters.
NetworkConsts
A trait defining common constants for neural networks.
NetworkDepth
The NetworkDepth trait is used to define the depth/kind of a neural network model.
NetworkParams
NeuralNetwork
The NeuralNetwork trait 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.
OnesLike
Pad
The Pad trait defines a padding operation for tensors.
PercentChange
The PercentChange trait establishes a binary operator for computing the percent change between two values where the caller is considered the original value.
PercentDiff
Compute the percentage difference between two values. The percentage difference is defined as:
Predict
The Predict trait 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 the Forward trait.
PredictWithConfidence
The PredictWithConfidence trait is an extension of the Predict trait, providing an additional method to obtain predictions along with a confidence score.
RawContext
RawHidden
The RawHidden trait for compatible representations of hidden layers
RawLayer
The RawLayer trait 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.
RawLayerMut
The RawLayerMut trait extends the RawLayer trait by providing mutable access to the layer’s parameters and additional methods for training the layer, such as backward propagation and parameter updates.
RawModelLayout
The RawModelLayout trait 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.
RawModelLayoutMut
The RawModelLayoutMut trait defines a mutable interface for objects capable of representing the layout; i.e. the number of input, hidden, and output features of
RawParams
The RawParams trait 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 RawStore trait is used to define an interface for key-value stores like hash-maps, dictionaries, and similar data structures.
RawStoreMut
RawStoreMut extends the RawStore trait by introducing various mutable operations and accessors for elements within the store.
RawTensor
RawTensorData
Root
The Root trait provides methods for computing the nth root of a number.
RoundTo
ScalarParams
The ScalarParams is a marker trait automatically implemented for
ScalarTensorData
A marker trait used to denote tensors that represent scalar values; more specifically, we consider any type implementing the RawTensorData type where the Elem associated type is the implementor itself a scalar value.
ShallowModelRepr
The ShallowModelRepr trait for shallow neural networks
Sine
Sinh
SquareRoot
Squared
Store
The Store trait is a more robust interface for key-value stores, building upon both RawStore and RawStoreMut traits by introducing an entry method for in-place manipulation of key-value pairs.
StoreEntry
The StoreEntry trait 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.
SummaryStatistics
This trait describes the fundamental methods of summary statistics. These include the mean, standard deviation, variance, and more.
Tan
Tanh
TensorBase
TensorParams
Train
This trait defines the training process for the network
Transpose
The Transpose trait generically establishes an interface for transposing a type
Unsqueeze
The Unsqueeze trait 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
ZerosLike

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 ParamsBase with a borrowed internal layout
DeepModelParams
a type alias for an owned representation of the DeepParamsBase generic of type A and the dimension D.
DeepParamsBase
a type alias for a deep representation of the ModelParamsBase using a vector of parameters as the hidden layers.
ModelParams
A type alias for an owned representation of the ModelParamsBase generic of type A and the dimension D.
Params
A type alias for a ParamsBase with an owned internal layout
ParamsView
A type alias for an immutable view of the parameters
ParamsViewMut
A type alias for a mutable view of the parameters
RawMutParams
A type alias for the ParamsBase whose elements are of type *mut A using a RawViewRepr layout
RawViewParams
A type alias for the ParamsBase whose elements are of type *const A using a RawViewRepr layout
Result
a type alias for a Result defined to use the custom Error as its error type.
ShallowModelParams
a type alias for an owned representation of the DeepParamsBase generic of type A and the dimension D.
ShallowParamsBase
a type alias for a shallow representation of the ModelParamsBase using a single ParamsBase instance as the hidden layer.