Neuro-Orbital Engine: Continuous-Control Spiking Neural Networks in a Custom N-Body Physics Environment
This project is a custom-built, continuous-control simulation engine written entirely in C. It integrates a Spiking Neural Network (SNN) with an N-Body gravitational physics simulator to train a satellite to achieve and maintain a stable orbit around a dynamic central star.
I intentionally avoided high-level game engines and machine learning frameworks. By building the physics and neural architectures from scratch, this project serves as a rigorous exercise in low-level state management, numerical integration, and the implementation of unsupervised reinforcement learning algorithms.
The engine is decoupled into three primary, continuous loops:
Instead of relying on standard Euler or Runge-Kutta methods, which tend to leak orbital energy over time, I implemented a 4th-Order Yoshida symplectic integrator. This algorithm evaluates the state of 100 interacting gravitational bodies across multiple sub-steps per frame, preserving the Hamiltonian energy of the system over extended time scales.
The satellite is piloted by a custom Leaky Integrate-and-Fire (LIF) neural network. The network takes continuous 1D sensory inputs (radial distance error and velocity) and encodes them into spike trains. I implemented a custom Reward-Modulated Hebbian Gaussian Spike-Timing-Dependent Plasticity (HG-STDP) algorithm. This allows the network to dynamically update its synaptic weights in real-time, learning orbital control through continuous environmental feedback rather than pre-calculated backpropagation.
A lightweight visualizer utilizing Raylib renders the multi-body system and overlays real-time telemetry, including control effort, orbital error, and spiking frequencies, directly from the memory buffers.
The most significant engineering work in this project occurred at the intersection of orbital mechanics and machine learning. Strapping a raw neural network to a highly sensitive dynamical system exposed several complex edge cases. Documenting these failures and their solutions was the core focus of the development process. there are a lot of issues in this right now but i hope i can improve them.
Standard Spike-Timing-Dependent Plasticity (STDP) is fundamentally designed for discrete, associative learning, making it highly unstable for continuous-control problems like orbital mechanics. To bridge the gap between spiking logic and continuous 3D physics, I implemented a custom Reward-Modulated Hebbian Gaussian STDP (HG-STDP).
This required two major mathematical departures from traditional SNN architecture:
Initial implementations attempted to reward the network by minimizing the temporal derivative of the system's Hamiltonian energy (
To correct this, I designed a spatially driven Gaussian reward function that provides a smooth, continuous gradient peaking exactly at the target orbital radius (
This raw reward is then normalized and passed through a low-pass temporal filter to create a stabilized reward trace (
The most critical mathematical challenge was the "Diagonal Lock" phenomenon. In a standard continuous STDP model, a firing neuron updates its downstream synapses uniformly. Because the satellite has three output thrusters (
To solve this, I decoupled the eligibility trace updates by introducing a uniform stochastic exploration variable,
Where
By modulating the trace with dimension-specific noise, the mathematical symmetry was broken. The network was forced to test independent directional thrusts, evaluating their success against the temporally delayed Gaussian reward trace. The final synaptic weight update is then governed by:
Where
- Language: C (C99)
- Libraries: Raylib, Math.h
- Core Concepts Applied: Manual memory management, matrix and vector mathematics, dynamical systems theory, unsupervised learning, and hardware-agnostic computation.
Ensure you have the GCC compiler and Raylib installed and configured on your system.
gcc main.c physics.c neural.c encoder.c reservoir.c -o neuro_orbital -O3 -lraylib -lm
./neuro_orbital