Class HyperbolicLinearLayer<T>
- Namespace
- AiDotNet.NeuralNetworks.Layers
- Assembly
- AiDotNet.dll
Represents a fully connected layer operating in hyperbolic (Poincare ball) space.
public class HyperbolicLinearLayer<T> : LayerBase<T>, ILayer<T>, IJitCompilable<T>, IDiagnosticsProvider, IWeightLoadable<T>, IDisposable
Type Parameters
TThe numeric type used for calculations (float or double).
- Inheritance
-
LayerBase<T>HyperbolicLinearLayer<T>
- Implements
-
ILayer<T>
- Inherited Members
Remarks
A hyperbolic linear layer performs linear transformations in hyperbolic space using Mobius operations. This is particularly useful for learning hierarchical representations where tree-like structures need to be embedded.
For Beginners: This layer works in hyperbolic space instead of flat Euclidean space.
Benefits of hyperbolic layers:
- Naturally represents hierarchical data (trees, graphs, taxonomies)
- Can embed large hierarchies with low distortion
- Fewer dimensions needed for complex hierarchical structures
The layer uses the Poincare ball model where all points are inside a unit ball. Points near the center are "higher" in the hierarchy, points near the edge are "lower".
Constructors
HyperbolicLinearLayer(int, int, double, IActivationFunction<T>?)
Initializes a new instance of the HyperbolicLinearLayer.
public HyperbolicLinearLayer(int inputFeatures, int outputFeatures, double curvature = -1, IActivationFunction<T>? activationFunction = null)
Parameters
inputFeaturesintNumber of input features.
outputFeaturesintNumber of output features.
curvaturedoubleCurvature of hyperbolic space (default -1).
activationFunctionIActivationFunction<T>Optional activation function.
Properties
InputFeatures
Gets the number of input features.
public int InputFeatures { get; }
Property Value
OutputFeatures
Gets the number of output features.
public int OutputFeatures { get; }
Property Value
ParameterCount
Gets the total number of trainable parameters.
public override int ParameterCount { get; }
Property Value
SupportsGpuExecution
Gets a value indicating whether this layer supports GPU execution.
protected override bool SupportsGpuExecution { get; }
Property Value
SupportsJitCompilation
Gets whether this layer supports JIT compilation. Hyperbolic operations use TensorOperations for JIT compilation.
public override bool SupportsJitCompilation { get; }
Property Value
SupportsTraining
Gets whether this layer supports training.
public override bool SupportsTraining { get; }
Property Value
Methods
Backward(Tensor<T>)
public override Tensor<T> Backward(Tensor<T> outputGradient)
Parameters
outputGradientTensor<T>Gradient from the next layer.
Returns
- Tensor<T>
Gradient to pass to the previous layer.
BackwardGpu(IGpuTensor<T>)
Performs the backward pass on GPU for the hyperbolic linear layer. Computes gradients using Riemannian geometry in the Poincaré ball model.
public override IGpuTensor<T> BackwardGpu(IGpuTensor<T> outputGradient)
Parameters
outputGradientIGpuTensor<T>The GPU tensor containing the gradient of the loss with respect to the output.
Returns
- IGpuTensor<T>
The GPU tensor containing the gradient of the loss with respect to the input.
ExportComputationGraph(List<ComputationNode<T>>)
Exports the layer's forward pass as a JIT-compilable computation graph.
public override ComputationNode<T> ExportComputationGraph(List<ComputationNode<T>> inputNodes)
Parameters
inputNodesList<ComputationNode<T>>List to populate with input computation nodes.
Returns
- ComputationNode<T>
The output computation node.
Remarks
The exported computation graph uses TensorOperations.HyperbolicLinear which implements:
- Project input to Poincare ball
- For each output: exp_origin(weight) → Mobius add with input → Mobius add with bias → distance from origin The curvature is captured at export time.
Forward(Tensor<T>)
Performs the forward pass through the layer.
public override Tensor<T> Forward(Tensor<T> input)
Parameters
inputTensor<T>Input tensor with shape [inputFeatures] or [batch, inputFeatures].
Returns
- Tensor<T>
Output tensor with shape [outputFeatures] or [batch, outputFeatures].
ForwardGpu(params IGpuTensor<T>[])
Performs the GPU-accelerated forward pass for hyperbolic linear transformation.
public override IGpuTensor<T> ForwardGpu(params IGpuTensor<T>[] inputs)
Parameters
inputsIGpuTensor<T>[]The GPU tensor inputs. First element is the input activation.
Returns
- IGpuTensor<T>
A GPU tensor containing the hyperbolic transformation output.
Remarks
The hyperbolic layer operates in Poincare ball space using Mobius operations. This uses GPU kernels for the entire forward pass, keeping data GPU-resident.
GetParameters()
Gets all trainable parameters as a single vector.
public override Vector<T> GetParameters()
Returns
- Vector<T>
A vector containing all weights and biases.
ResetState()
Resets the internal state of the layer.
public override void ResetState()
SetParameters(Vector<T>)
Sets all trainable parameters from a single vector.
public override void SetParameters(Vector<T> parameters)
Parameters
parametersVector<T>A vector containing all parameters to set.
UpdateParameters(T)
Updates the parameters of the layer using the calculated gradients.
public override void UpdateParameters(T learningRate)
Parameters
learningRateTThe learning rate to use for the update.
Remarks
Uses Riemannian gradient descent (exponential map of negative gradient).
UpdateParametersGpu(IGpuOptimizerConfig)
Updates parameters using GPU-based optimizer.
public override void UpdateParametersGpu(IGpuOptimizerConfig config)
Parameters
configIGpuOptimizerConfigGPU optimizer configuration specifying the optimizer type and hyperparameters.