Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synapse.Tensors
Description
Module that provides mathematical base for neural networks.
This module implements Vec
and Mat
datatypes and provides
several useful function to work with them.
Most of typeclasses of this module are working with DType
type family.
That is to permit instances on types that are not exactly containers, but rather wrappers of containers,
and it allows imposing additional constraints on inner type.
The best example is Symbol
from Synapse.Autograd.
Synopsis
- type family DType f :: Type
- class Indexable f where
- class ElementwiseScalarOps f where
- (+.) :: Num (DType f) => f -> DType f -> f
- (-.) :: Num (DType f) => f -> DType f -> f
- (*.) :: Num (DType f) => f -> DType f -> f
- (/.) :: Fractional (DType f) => f -> DType f -> f
- (**.) :: Floating (DType f) => f -> DType f -> f
- elementsMin :: Ord (DType f) => f -> DType f -> f
- elementsMax :: Ord (DType f) => f -> DType f -> f
- class SingletonOps f where
- singleton :: DType f -> f
- isSingleton :: f -> Bool
- unSingleton :: f -> DType f
- extendSingleton :: f -> f -> f
- elementsSum :: Num (DType f) => f -> f
- elementsProduct :: Fractional (DType f) => f -> f
- mean :: Fractional (DType f) => f -> f
- norm :: Floating (DType f) => f -> f
- class VecOps f where
- class MatOps f where
DType
type family
type family DType f :: Type Source #
DType
type family allows to get type of element for any container of that type - even for nested ones!
Instances
type DType (SymbolMat a) Source # | |
Defined in Synapse.Autograd | |
type DType (SymbolVec a) Source # | |
Defined in Synapse.Autograd | |
type DType (Dataset a) Source # | |
Defined in Synapse.NN.Batching | |
type DType (Sample a) Source # | |
Defined in Synapse.NN.Batching | |
type DType (Dense a) Source # | |
Defined in Synapse.NN.Layers.Dense | |
type DType (Layer a) Source # | |
Defined in Synapse.NN.Layers.Layer | |
type DType (SequentialModel a) Source # | |
Defined in Synapse.NN.Models | |
type DType (SGD a) Source # | |
Defined in Synapse.NN.Optimizers | |
type DType (Mat a) Source # | |
Defined in Synapse.Tensors.Mat | |
type DType (Vec a) Source # | |
Defined in Synapse.Tensors.Vec |
Indexable
typeclass
class Indexable f where Source #
Indexable
typeclass provides indexing interface for datatypes.
Methods
unsafeIndex :: f -> Index f -> DType f Source #
Unsafe indexing.
(!) :: f -> Index f -> DType f infixl 9 Source #
Indexing with bounds checking.
(!?) :: f -> Index f -> Maybe (DType f) infixl 9 Source #
Safe indexing.
Container-scalar operations
class ElementwiseScalarOps f where Source #
ElementwiseScalarOps
typeclass allows containers over numerical values easily work with scalars by using elementwise operations.
This typeclass operates on DType
to permit instances on types that are not exactly containers, but rather wrappers of containers.
The best example is Symbol
from Synapse.Autograd.
Methods
(+.) :: Num (DType f) => f -> DType f -> f infixl 6 Source #
Adds given value to every element of the container.
(-.) :: Num (DType f) => f -> DType f -> f infixl 6 Source #
Subtracts given value from every element of the functor.
(*.) :: Num (DType f) => f -> DType f -> f infixl 7 Source #
Multiplies every element of the functor by given value.
(/.) :: Fractional (DType f) => f -> DType f -> f infixl 7 Source #
Divides every element of the functor by given value.
(**.) :: Floating (DType f) => f -> DType f -> f infixr 8 Source #
Exponentiates every element of the functor by given value.
elementsMin :: Ord (DType f) => f -> DType f -> f Source #
Applies min
operation with given value to every element.
elementsMax :: Ord (DType f) => f -> DType f -> f Source #
Applies max
operation with given value to every element.
Instances
class SingletonOps f where Source #
SingletonOps
typeclass provides operations that relate to singleton containers (scalars that are wrapped in said container).
All functions of that typeclass must return singletons (scalars that are wrapped in container).
This typeclass operates on DType
to permit instances on types that are not exactly containers, but rather wrappers of containers.
The best example is Symbol
from Synapse.Autograd.
Methods
singleton :: DType f -> f Source #
Initializes singleton container.
isSingleton :: f -> Bool Source #
Return true if container represents a singleton.
unSingleton :: f -> DType f Source #
Unwraps singleton container.
extendSingleton :: f -> f -> f Source #
elementsSum :: Num (DType f) => f -> f Source #
Sums all elements of container.
elementsProduct :: Fractional (DType f) => f -> f Source #
Multiplies all elements of container (Fractional
constraint is needed for efficient gradient calculation, although it may be overly restrictive in some situations).
mean :: Fractional (DType f) => f -> f Source #
Calculates the mean of all elements of container.
norm :: Floating (DType f) => f -> f Source #
Calculates the Frobenius norm of all elements of container.
Instances
Symbolic a => SingletonOps (SymbolMat a) Source # | |
Defined in Synapse.Autograd Methods singleton :: DType (SymbolMat a) -> SymbolMat a Source # isSingleton :: SymbolMat a -> Bool Source # unSingleton :: SymbolMat a -> DType (SymbolMat a) Source # extendSingleton :: SymbolMat a -> SymbolMat a -> SymbolMat a Source # elementsSum :: SymbolMat a -> SymbolMat a Source # elementsProduct :: SymbolMat a -> SymbolMat a Source # | |
Symbolic a => SingletonOps (SymbolVec a) Source # | |
Defined in Synapse.Autograd Methods singleton :: DType (SymbolVec a) -> SymbolVec a Source # isSingleton :: SymbolVec a -> Bool Source # unSingleton :: SymbolVec a -> DType (SymbolVec a) Source # extendSingleton :: SymbolVec a -> SymbolVec a -> SymbolVec a Source # elementsSum :: SymbolVec a -> SymbolVec a Source # elementsProduct :: SymbolVec a -> SymbolVec a Source # | |
SingletonOps (Mat a) Source # | |
Defined in Synapse.Tensors.Mat | |
SingletonOps (Vec a) Source # | |
Defined in Synapse.Tensors.Vec |
Specific container operations
VecOps
typeclass provides vector-specific operations.
This typeclass operates on DType
to permit instances on types that are not exactly containers, but rather wrappers of containers.
The best example is Symbol
from Synapse.Autograd.
MatOps
typeclass provides matrix-specific operations.
This typeclass operates on DType
to permit instances on types that are not exactly containers, but rather wrappers of containers.
The best example is Symbol
from Synapse.Autograd.
Methods
Transposes matrix.
addMatRow :: Num (DType f) => f -> f -> f Source #
Add matrix that represents row to every row of given matrix.
matMul :: Num (DType f) => f -> f -> f Source #
Mutiplies two matrices.