I developed this simple environment where a ball falls and bounces, obeying the free fall of gravity. The floor position is not included in the observation space. Can the model learn to predict the next state of this environment, for example, the bouncing of the ball when it hits the ground?
Target
25% Lower MAE
with balanced datasets
Chart
3 Datasets
20K, 14.7K balanced, 14.7K unbalanced
Check
Validated CGLSTM
IEEE PRML 2024
Watch the environment in action: hidden floor challenge demonstrated
2. Research Motivation
Why This Was Needed
When transitioning from discrete to continuous action spaces in SocNavGym, I observed that as action choices increased from 4 to 16, prediction errors became more pronounced. This highlighted the need for more robust sequential learning models that could handle incomplete state information.
I developed FallingBallEnv as a controlled testing ground to explore fundamental challenges in temporal prediction before applying methods to complex environments like SocNavGym. It isolates the core challenge of learning from incomplete observations, allowing for focused investigation of sequential learning capabilities without the complexity of social navigation dynamics.
Research Design
To study the impact of data distribution on model performance, I created three distinct datasets:
Full Dataset: 20,000 episodes (unbalanced, with bounce events underrepresented)
Balanced Dataset: 14,700 episodes with equal representation of bounce and free-fall windows
Unbalanced Subset: 14,700 episodes randomly sampled without balancing (control group)
The balanced dataset ensured models were exposed to bounce events more frequently, improving their ability to learn bounce dynamics effectively.
3. The Challenge
What Makes This Hard?
In FallingBallEnv, the floor position is deliberately hidden from the observation space (see Key Innovation section). Models only receive:
Ball’s position (x, y)
Ball’s velocity (vx, vy)
The challenge: Can your model learn to infer where the floor is from the ball’s trajectory alone?
Why This Matters
This tests whether models can:
Learn implicit physics - Infer boundary conditions from observations
Handle incomplete information - Make predictions with missing state data
Generalize patterns - Learn bounce dynamics without explicit floor coordinates
4. Key Innovation
What Makes This Unique
Unlike most Gym environments that reveal all state information, FallingBallEnv deliberately omits the floor position from the observation space. This creates a controlled test of sequential learning where models must infer boundary conditions from trajectory patterns alone.
Hidden State: Floor position (y_floor) - deliberately excluded
Learning Challenge: Infer floor position from trajectory observations
Controlled Complexity: Simple physics simulation with complex learning requirement
5. Results & Performance
Balanced Dataset Impact
Key Finding: Balanced Dataset Impact
The balanced dataset (equal representation of bounce and free-fall windows) resulted in a 25% reduction in MAE compared to the unbalanced dataset, highlighting the importance of balanced training data for learning transition events like bounces.
Model Performance Comparison
Model
MAE (k=1)
MAE (k=3)
MAE (k=5)
MAE (k=10)
Time (s)
Params
Vanilla LSTM
1.643×10⁻⁴
1.705×10⁻⁴
1.730×10⁻⁴
4.696×10⁻³
0.00108
84,419
GRU
1.737×10⁻⁴
1.677×10⁻⁴
2.114×10⁻⁴
4.793×10⁻³
0.00091
63,363
Transformer
9.138×10⁻⁵
7.189×10⁻⁵
8.910×10⁻⁵
1.528×10⁻³
0.01417
1,125,059
CGLSTM
3.558×10⁻⁵
4.302×10⁻⁵
2.341×10⁻⁵
1.360×10⁻³
0.00325
104,771
Note: MAE = Mean Absolute Error, k = prediction horizon (steps ahead). Lower is better. Results from balanced dataset.
Key Performance Findings
CGLSTM Achievements:
Best MAE across all prediction horizons (k=1, 3, 5, 10)
78% lower MAE than Transformer at k=1
77% lower MAE than Vanilla LSTM at k=1
79% lower MAE than GRU at k=1
77% faster than Transformer in prediction time
25% lower MAE with balanced dataset compared to unbalanced
6. Visual Demo
Figure 1: Environment Visualization
Ball falling and bouncing in FallingBallEnv. Yellow circle = current state. The floor position is not included in the observation space.
Figure 2: Prediction Comparison
Sky blue = actual future, blue = CGLSTM prediction, red = errors, gray = perfect alignment.
Figure 3: CGLSTM Performance
Detailed results showing CGLSTM's superior accuracy across prediction horizons (k=1, 3, 5, 10).
7. Experimental Setup
Models Tested
Vanilla LSTM: Baseline recurrent architecture
GRU: Gated Recurrent Unit (simpler than LSTM)
RAU: Recurrent Attention Unit
Transformer: Encoder-only architecture
CGLSTM: Cosine-Gated LSTM (proposed model)
Hyperparameters
Hidden Size: 128 units
Batch Size: 128
Learning Rate: 1×10⁻³ (0.001)
Optimizer: Adam
Epochs: Variable (early stopping applied)
Random Seeds: 3 different seeds per model (results averaged)
Evaluation Metrics
Mean Absolute Error (MAE): Primary metric
Mean Squared Error (MSE): Secondary metric
Prediction Time: Inference speed comparison
Visual Validation: Qualitative assessment of predictions
8. Technical Specifications
Observation Space
Dimensions: 4D continuous vector [x, y, vx, vy]
Components:
x: Horizontal position (continuous)
y: Vertical position (continuous)
vx: Horizontal velocity (continuous)
vy: Vertical velocity (continuous)
Important: Floor position (y_floor) is deliberately excluded from observations (see Key Innovation section)
Action Space
Type: None (prediction/forecasting task)
Purpose: Used for next-state prediction, not control
Environment Parameters
Gravity: Standard gravitational acceleration (customizable)
Energy Loss: Reduced velocity after bounce (coefficient: typically 0.7-0.9)
Ball Radius: Customizable (default: varies by initial conditions)
Floor Height: Variable (not disclosed to model in observation space)
Episode Length: Variable (depends on initial conditions)
Episode Termination
Episode ends when ball position goes outside boundaries
Episode can be manually truncated at maximum steps
Key Features
Simplified Physics: Gravity simulation with customizable parameters
Limited Observation Space: Only ball’s (x,y) coordinates and velocity (floor position excluded)
Bouncing Mechanism: Ball bounces off floor with reduced velocity (energy loss)
Render Support: Visualize ball motion for analysis
OpenAI Gym Compatible: Standard interface for RL algorithm integration
Controlled Complexity: Focuses on prediction rather than complex physics simulation
9. Installation & Usage
Installation
# Clone the repository
git clone https://github.com/goodluckoguzie/falling_ball_env.git
cd falling_ball_env
# Install dependencies
pip install-e.# or
pip install gymnasium numpy opencv-python
Quick Start Example
importgymnasiumasgymfromfalling_ball_envimportFallingBallEnv# Create environment
env=FallingBallEnv()# Reset environment
obs,info=env.reset()print(f"Observation: {obs}")# [x, y, vx, vy]
print(f"Notice: Floor position is NOT in observations!")print(f"Challenge: Can your model infer where the ball will bounce?")# The model must learn the hidden floor position
# from the ball's trajectory alone
# Run episode
forstepinrange(100):# For prediction task, no action needed
# Instead, predict next observation
obs,reward,terminated,truncated,info=env.step(None)# Render visualization
env.render()ifterminatedortruncated:obs,info=env.reset()env.close()
Customization
# Create environment with custom parameters
env=FallingBallEnv(gravity=9.81,# Gravitational acceleration
energy_loss=0.8,# Velocity reduction after bounce (0.7-0.9)
floor_height=0.0,# Floor position (not in observation!)
initial_y_range=(5,10),# Initial y position range
ball_radius=0.5# Ball radius
)
FallingBallEnv provided crucial insights into sequential learning that informed the development and validation of CGLSTM. Results demonstrated that CGLSTM’s cosine similarity gating mechanism significantly improves prediction accuracy in temporal tasks, establishing a foundation for applying the model to more complex social navigation scenarios.
LiteSocNavGym - Lightweight version for faster iteration
Comparison with Other Environments:
Unlike standard Gym environments (CartPole, MountainCar, etc.), FallingBallEnv deliberately omits state information to test implicit physics learning (see Key Innovation section). This makes it unique for evaluating sequential learning models that must infer hidden dynamics.
13. FAQ
Q: Why is the floor position hidden?
A: This design tests whether models can learn implicit physics from observations alone. Unlike most Gym environments that reveal all state information, FallingBallEnv requires models to infer hidden boundary conditions from trajectory patterns (see Key Innovation section).
Q: How does this compare to other Gym environments?
A: Most Gym environments (CartPole, MountainCar, etc.) reveal all state information. FallingBallEnv uniquely tests learning of implicit physics by hiding the floor position, creating a controlled test of sequential learning capabilities (see Key Innovation section).
Q: Can I use this for my research?
A: Yes! The environment is open-source and available on GitHub. It’s particularly useful for:
Testing sequential learning models
Evaluating physics-informed learning approaches
Benchmarking model architectures
Teaching sequential learning concepts
Q: What makes this environment challenging?
A: The hidden floor position forces models to learn implicit physics from trajectory observations alone. This tests whether models can infer boundary conditions without explicit state information.
Q: How do I get started?
A: Clone the repository, install dependencies, and check out the Quick Start example in the Installation & Usage section above.
Q: What datasets were used?
A: Three datasets were created:
Full Dataset: 20,000 episodes (unbalanced)
Balanced Dataset: 14,700 episodes with equal bounce/free-fall representation
A: Vanilla LSTM, GRU, RAU, Transformer, and CGLSTM (proposed model). CGLSTM achieved the best performance across all metrics.
14. Citation & Resources
Citation
If you use FallingBallEnv in your research, please cite:
BibTeX:
@software{fallingballenv2023,title={FallingBallEnv: A Custom Gym Environment for Sequential Learning Validation},author={Oguzie, Goodluck},year={2023},url={https://github.com/goodluckoguzie/falling_ball_env},note={Used in: Oguzie, G. (2024). Cosine-Gated LSTM for Sequential Learning.
In 2024 IEEE 5th International Conference on Pattern Recognition and Machine Learning (PRML), pp. 8-15.
PhD Thesis: Enhancing Robot Social Navigation with Reinforcement Learning and Advanced Predictive Models,
Aston University, 2024, Chapter 6}}
APA:
Oguzie, G. (2023). FallingBallEnv: A Custom Gym Environment for Sequential Learning Validation [Computer software].
GitHub. https://github.com/goodluckoguzie/falling_ball_env