This is the official implementation of elephant activation function, a new class of activation function that can generates both sparse outputs and sparse gradients, introduced in Efficient Reinforcement Learning by Reducing Forgetting with Elephant Activation Functions.
We show that by simply replacing classical activation functions with elephant activation functions in the neural networks of value-based reinforcement learning algorithms, we can significantly improve the resilience of neural networks to catastrophic forgetting, thus making reinforcement learning more sample-efficient and memory-efficient.
Table of Contents
- Python: ==3.11
 - Jax: ==0.4.23
 - PyTorch: ==2.0.1
 - MuJoCo: ==2.3.6
 - Gymnasium: 
pip install 'gymnasium[box2d,mujoco]==0.29.1' - Gym Games: >=2.0.0.
 - Others: 
pip install -r requirements.txt. 
All hyperparameters including parameters for grid search are stored in a configuration file in directory configs. To run an experiment, a configuration index is first used to generate a configuration dict corresponding to this specific configuration index. Then we run an experiment defined by this configuration dict. All results including log files are saved in directory logs. Please refer to the code for details.
For example, run the experiment with configuration file mc_dqn.json and configuration index 1:
python main.py --config_file ./configs/mc_dqn.json --config_idx 1First, we calculate the number of total combinations in a configuration file (e.g. mc_dqn.json):
python utils/sweeper.pyThe output will be:
Number of total combinations in mc_dqn.json: 240
Then we run through all configuration indexes from 1 to 240. The simplest way is using a bash script:
for index in {1..240}
do
  python main.py --config_file ./configs/mc_dqn.json --config_idx $index
doneParallel is usually a better choice to schedule a large number of jobs:
parallel --eta --ungroup python main.py --config_file ./configs/mc_dqn.json --config_idx {1} ::: $(seq 1 240)Any configuration index that has the same remainder (divided by the number of total combinations) should have the same configuration dict. So for multiple runs, we just need to add the number of total combinations to the configuration index. For example, 3 runs for configuration index 1:
for index in 1 241 481
do
  python main.py --config_file ./configs/mc_dqn.json --config_idx $index
doneOr a simpler way:
parallel --eta --ungroup python main.py --config_file ./configs/mc_dqn.json --config_idx {1} ::: $(seq 1 240 720)To replicate the results in the papar, simply run
bash run.shTo analyze the experimental results, just run:
python analysis/*.py
Inside analysis/*.py, unfinished_index will print out the configuration indexes of unfinished jobs based on the existence of the result file. memory_info will print out the memory usage information and generate a histogram to show the distribution of memory usages in directory logs/mc_dqn/0. Similarly, time_info will print out the time information and generate a histogram to show the distribution of time in directory logs/mc_dqn/0. Finally, analyze will generate csv files that store training and test results. Please check folder analysis for more details. More functions are available in utils/plotter.py.
If you find this work useful to your research, please cite our paper.
@article{lan2025efficient,
  title={Efficient Reinforcement Learning by Reducing Forgetting with Elephant Activation Functions},
  author={Lan, Qingfeng and Vasan, Gautham and Mahmood, A. Rupam},
  journal={arXiv preprint arXiv:2509.19159},
  year={2025}
}
