LagrangianNeuralNetwork<T>

Models & Types · AiDotNet.PhysicsInformed.ScientificML

Implements Lagrangian Neural Networks (LNN) for learning mechanical systems.

Inheritance: NeuralNetworkBase<T> → LagrangianNeuralNetwork<T>

How It Works

For Beginners: Lagrangian Neural Networks learn physics using the Lagrangian formulation of mechanics.

Lagrangian Mechanics: Alternative to Hamiltonian mechanics, uses the Lagrangian: L(q, q̇) = T - V = Kinetic Energy - Potential Energy

Equations of Motion (Euler-Lagrange): d/dt(∂L/∂q̇) - ∂L/∂q = 0

Where:

  • q = generalized coordinates (positions)
  • q̇ = generalized velocities
  • T = kinetic energy (usually ½m q̇²)
  • V = potential energy (depends on q)

Why Lagrangian vs. Hamiltonian?

  • Lagrangian: Uses (q, q̇) - position and velocity
  • Hamiltonian: Uses (q, p) - position and momentum
  • Lagrangian often more intuitive for mechanical systems
  • Both give same physics, different formulations

How LNN Works:

  1. Neural network learns L(q, q̇)
  2. Compute ∂L/∂q and ∂L/∂q̇ using automatic differentiation
  3. Apply Euler-Lagrange equation to get acceleration q̈
  4. Guaranteed to conserve energy and satisfy principle of least action

Applications:

  • Robotics (manipulator dynamics)
  • Biomechanics (human motion)
  • Aerospace (satellite dynamics)
  • Any mechanical system

Example

var lnn = new LagrangianNeuralNetwork<float>();
float[] acceleration = lnn.ComputeAcceleration(
    new float[] { 1.0f, 0.5f }, new float[] { 0.1f, -0.2f });

Constructors

Constructor Summary
LagrangianNeuralNetwork() Creates a default LagrangianNeuralNetwork with a 2D configuration space.
LagrangianNeuralNetwork(NeuralNetworkArchitecture<T> architecture, int configurationDim, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, LagrangianNeuralNetworkOptions options)

Properties

Property Summary
TrainingObjectiveKind TrainingObjectiveKind { get; }
bool SupportsTraining { get; } Serializes Lagrangian-specific data.

Methods

Method Summary
ModelMetadata<T> GetModelMetadata() Gets metadata about the Lagrangian network.
T ComputeLagrangian(Vector<T> q, Vector<T> qDot) Computes the Lagrangian L(q, q̇) = T - V.
Tensor<T> Forward(Tensor<T> input) Performs a forward pass through the network.
Tensor<T> ForwardForTraining(Tensor<T> input)
Vector<T> ComputeAcceleration(Vector<T> q, Vector<T> qDot) Computes acceleration using Euler-Lagrange equation.