A high-performance neuron activity simulation program with both standard and optimized implementations, designed for accuracy, performance, and easy verification.
- Standard Implementation: Faithful to problem specifications, ideal for small-scale data and verification
- Fast Implementation: Processes only active neurons, optimized for sparse graphs and large-scale cases
- Verification Mode: Compares outputs and execution times between standard and fast versions
- Benchmark Mode: Performance testing with large-scale randomly generated networks
git clone https://github.com/Lucasmotabr/neuron-simulation.git
cd neuron-simulationNo additional dependencies required - uses Python standard library only.
python3 q1.py --stdin < input_file.txtpython3 q1.py --stdin-fast < input_file.txtpython3 q1.py --verify-stdin < input_file.txtpython3 q1.py --bench-demoThe input file should follow this format:
M N
state_1 state_2 ... state_M
threshold_1 threshold_2 ... threshold_M
[connection_data]
Where:
M: Number of neuronsN: Number of simulation stepsstate_i: Initial state of neuron i (0 or 1)threshold_i: Activation threshold for neuron iconnection_data: Network connectivity information
- Implemented standard neuron simulation following problem specifications
- Process M neurons over N steps with signal transmission and state updates
- Verified correctness with small-scale test cases
- Added
--stdinoption for flexible input handling - Support for piped text files and direct file input
- Maintained backward compatibility
- Identified performance bottleneck with N up to 10^6 steps
- Implemented
fastmode utilizing inactive neuron properties - Achieved significant speedup for sparse networks
- Added
--verify-stdinfor output validation - Real-time comparison of standard vs. fast implementations
- Performance benchmarking capabilities
- Implemented
--bench-demofor large-scale testing - Automated generation of random network topologies
- Quantified performance improvements
The fast implementation shows significant improvements, especially for large sparse networks:
| Test Case | Neurons | Edges | Steps | Standard | Fast | Improvement |
|---|---|---|---|---|---|---|
| Small | 1,000 | 3,000 | 100 | 0.15s | 0.12s | 20% |
| Medium | 20,000 | 60,000 | 500 | 6.36s | 5.03s | 21% |
| Large | 200,000 | 600,000 | 1,500 | 158.15s | 124.71s | 21% |
$ python3 q1.py --stdin < input_q1_case1.txt
1 0 1 1 0 1 1 1 1$ python3 q1.py --verify-stdin < input_q1_case2.txt
BASE : 0 0 0 1 0 0 1 0 0 0 1 0 1 0
FAST : 0 0 0 1 0 0 1 0 0 0 1 0 1 0
MATCH: True
time baseline=0.036705s fast=0.031777s$ python3 q1.py --bench-demo
[Bench] M=200000, edges=600000, steps=1500
baseline: 158.145s
fast : 124.714s- Standard Simulator: Direct implementation of neuron update rules
- Fast Simulator: Optimized version tracking only active neurons
- Verification Engine: Automated testing and performance comparison
- Benchmark Generator: Creates test cases with configurable parameters
- Active Neuron Tracking: Only processes neurons that can affect the network state
- Sparse Graph Handling: Efficient representation for networks with low connectivity
- Memory Management: Reduced memory footprint for large-scale simulations
Run the verification suite:
# Test with provided examples
python3 q1.py --verify-stdin < test_cases/case1.txt
python3 q1.py --verify-stdin < test_cases/case2.txt
# Run performance benchmarks
python3 q1.py --bench-demo- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Original problem specification from competitive programming contest
- Optimization techniques inspired by sparse matrix algorithms
- Performance testing methodology based on scientific computing best practices
Built for high-performance neural network simulation