Table of Contents

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

T

The numeric type used for calculations (float or double).

Inheritance
HyperbolicLinearLayer<T>
Implements
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

inputFeatures int

Number of input features.

outputFeatures int

Number of output features.

curvature double

Curvature of hyperbolic space (default -1).

activationFunction IActivationFunction<T>

Optional activation function.

Properties

InputFeatures

Gets the number of input features.

public int InputFeatures { get; }

Property Value

int

OutputFeatures

Gets the number of output features.

public int OutputFeatures { get; }

Property Value

int

ParameterCount

Gets the total number of trainable parameters.

public override int ParameterCount { get; }

Property Value

int

SupportsGpuExecution

Gets a value indicating whether this layer supports GPU execution.

protected override bool SupportsGpuExecution { get; }

Property Value

bool

SupportsJitCompilation

Gets whether this layer supports JIT compilation. Hyperbolic operations use TensorOperations for JIT compilation.

public override bool SupportsJitCompilation { get; }

Property Value

bool

SupportsTraining

Gets whether this layer supports training.

public override bool SupportsTraining { get; }

Property Value

bool

Methods

Backward(Tensor<T>)

public override Tensor<T> Backward(Tensor<T> outputGradient)

Parameters

outputGradient Tensor<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

outputGradient IGpuTensor<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

inputNodes List<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:

  1. Project input to Poincare ball
  2. 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

input Tensor<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

inputs IGpuTensor<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

parameters Vector<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

learningRate T

The 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

config IGpuOptimizerConfig

GPU optimizer configuration specifying the optimizer type and hyperparameters.