# Generalized Coordinates in Active Inference ## Overview Generalized coordinates are a fundamental concept in continuous-time active inference that allows for a richer representation of dynamical systems by explicitly incorporating higher-order temporal derivatives into the state space. ## Mathematical Foundation ### Basic Definition A state x in generalized coordinates is represented as a vector of temporal derivatives: ``` x̃ = [x, x', x'', ..., x^(n)] ``` where: - x is the state value - x' is the first temporal derivative (velocity) - x'' is the second temporal derivative (acceleration) - etc. ### Shift Operator The shift operator D maps between orders of motion: ``` D[x, x', x''] = [x', x'', 0] ``` With factorial scaling for Taylor series: ``` D[x, x', x''] = [1!x', 2!x'', 0] ``` ## Role in Active Inference ### 1. Belief Representation Beliefs about states are represented in generalized coordinates: ``` q(x̃) = N(μ̃, Σ̃) ``` where: - μ̃ is the vector of means across orders - Σ̃ is the precision (inverse covariance) matrix ### 2. Dynamics The generalized motion of states follows: ``` dx̃/dt = Dx̃ - ∂F/∂x̃ ``` where: - D is the shift operator - F is the variational free energy - ∂F/∂x̃ are the gradients in generalized coordinates ### 3. Prediction Predictions in generalized coordinates allow for: - Smooth trajectories - Velocity matching - Acceleration matching - Higher-order consistency ## Implementation Details ### 1. State Representation ```python class ContinuousState: belief_means: np.ndarray # Shape: [n_states, n_orders] belief_precisions: np.ndarray # Shape: [n_states, n_orders] ``` ### 2. Shift Operator ```python def create_shift_operator(n_orders): D = np.zeros((n_orders, n_orders)) for i in range(n_orders - 1): D[i, i+1] = factorial(i+1) / factorial(i) return D ``` ### 3. Free Energy The free energy includes terms for all orders: ``` F = Σᵢ (prediction_errorᵢ)²/2σᵢ² ``` where i runs over all orders of motion. ## Advantages 1. **Smooth Dynamics**: Natural handling of continuous trajectories 2. **Rich Predictions**: Incorporation of velocity and acceleration 3. **Temporal Consistency**: Enforced across multiple orders 4. **Uncertainty Propagation**: Through all orders of motion ## Visualization 1. **State Space**: Plot of position vs. velocity 2. **Generalized Coordinates**: Multiple plots for each order 3. **Prediction Errors**: Across all orders of motion 4. **Taylor Expansions**: Showing predictive power ## References 1. Friston, K. J., et al. (2008). DEM: A variational treatment of dynamic systems. 2. Buckley, C. L., et al. (2017). The free energy principle for action and perception: A mathematical review. 3. Baltieri, M., & Buckley, C. L. (2019). Generalized synchronization through learning in coupled dynamical systems.