A biomimetic neural network implementation inspired by the growth patterns, resource allocation, and adaptive behaviors of fungal mycelium networks.
The Mycelium Network provides an innovative approach to neural networks that mimics the decentralized, adaptive properties of fungal mycelium. Unlike traditional neural networks with fixed architectures, mycelium networks can grow, adapt, and reshape themselves based on environmental factors and the tasks they're solving.
Key features include:
- Dynamic growth: Networks can add new nodes and connections during operation
- Resource allocation: Nodes distribute resources based on their utility
- Chemical signaling: Communication between nodes via signal propagation
- Environmental awareness: Networks operate within simulated environments that can contain resources and obstacles
- Enhanced ecosystem: Complex multi-organism environment with plants, herbivores, and decomposers
- Machine learning integration: Reinforcement learning and transfer learning capabilities
- Adaptive specialization: Nodes can specialize for different functions based on environmental conditions
Prototype Demo Visualizations from Wiki
# Clone the repository
git clone https://github.com/yourusername/mycelium_network.git
cd mycelium_network
# Setup a virtual environment (required)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run a quick test to verify the environment is set up correctly
python quick_test.py
Important: You must activate the virtual environment before running any scripts or tests. The project relies on specific package versions and paths, so running outside the virtual environment will likely result in errors.
mycelium_network/
βββ examples/ # Example scripts and utilities
β βββ enhanced_demo.py # Demo for enhanced environment
β βββ ecosystem_demo.py # Demo for ecosystem simulation
β βββ ml_integration_demo.py # Demo for machine learning capabilities
β βββ reorganized/ # Organized examples by category
β β βββ advanced/ # Advanced utilization examples
β β βββ basic/ # Basic task examples
β β βββ utils/ # Utility functions
β β βββ visualization/ # Visualization examples
βββ mycelium/ # Core package
β βββ __init__.py # Package initialization
β βββ environment.py # Environment implementation
β βββ network.py # Network implementation
β βββ node.py # Node implementation
β βββ enhanced/ # Enhanced components
β β βββ __init__.py
β β βββ rich_environment.py # Advanced environment implementation
β β βββ adaptive_network.py # Adaptive network implementation
β β βββ resource.py # Enhanced resource types
β β βββ ecosystem/ # Ecosystem simulation
β β β βββ __init__.py
β β β βββ ecosystem.py # Full ecosystem implementation
β β β βββ interaction.py # Organism interaction registry
β β β βββ organisms/ # Individual organism types
β β β β βββ base.py # Base organism class
β β β β βββ plant.py # Plant organisms
β β β β βββ herbivore.py # Herbivore organisms
β β β β βββ decomposer.py # Decomposer organisms
β β βββ ml/ # Machine learning components
β β β βββ __init__.py
β β β βββ reinforcement.py # Reinforcement learning
β β β βββ transfer.py # Transfer learning
β βββ tasks/ # Task-specific implementations
β βββ __init__.py
β βββ anomaly_detector.py
β βββ classifier.py
β βββ regressor.py
βββ tools/ # Utility tools
β βββ profile_performance.py # Performance profiling tool
βββ visualizations/ # Generated visualizations from demos
β βββ ecosystem_simulation.png # Ecosystem demo visualization
β βββ rl_training_results.png # ML demo visualization
βββ requirements.txt # Project dependencies
βββ README.md # This documentation
βββ venv/ # Virtual environment (after setup)
Follow these steps to get started with Mycelium Network:
-
Setup the environment as described in the Installation section.
-
Run one of the example scripts to see the network in action:
# Make sure to activate the virtual environment first
source venv/bin/activate # On Windows: venv\Scripts\activate
# Run the enhanced environment demo
python examples/enhanced_demo.py
# Run the ecosystem simulation demo
python examples/ecosystem_demo.py
# This will save a visualization plot to: visualizations/ecosystem_simulation.png
# Run the machine learning integration demo
python examples/ml_integration_demo.py
# This will save a visualization plot to: visualizations/rl_training_results.png
# Run a basic classification example using the Iris dataset
python examples/reorganized/basic/classification_example.py
- Create your own implementation based on the examples:
from mycelium import MyceliumClassifier, Environment
# Create an environment
env = Environment(dimensions=4)
# Initialize and train a classifier
classifier = MyceliumClassifier(
input_size=4,
num_classes=2,
hidden_nodes=20,
environment=env
)
# Train the classifier
history = classifier.fit(X_train, y_train, epochs=15)
# Make predictions
predictions = classifier.predict(X_test)
The Environment
class provides the spatial context for the mycelium network:
from mycelium import Environment
# Create an environment with 2D space
env = Environment(dimensions=2)
# Add resources and obstacles
env.add_resource((0.3, 0.7), 1.5)
env.add_obstacle((0.5, 0.5), 0.1)
The enhanced RichEnvironment
provides a more sophisticated environment model:
from mycelium.enhanced.rich_environment import RichEnvironment
from mycelium.enhanced.resource import ResourceType
# Create a 3D environment with terrain layers
env = RichEnvironment(dimensions=3, size=1.0, name="Demo Environment")
# Add diverse resource types
env.add_nutrient_cluster((0.5, 0.5, 0.6), 0.2, ResourceType.CARBON, 2.0)
env.add_nutrient_cluster((0.3, 0.3, 0.65), 0.15, ResourceType.WATER, 1.5)
# Create seasonal cycle
env.create_seasonal_cycle(year_length=24.0, intensity=0.7)
# Update environment over time
env.update(delta_time=0.5)
The ecosystem module provides a complex simulation of interacting organisms:
from mycelium.enhanced.rich_environment import RichEnvironment
from mycelium.enhanced.ecosystem.ecosystem import Ecosystem
# Create a rich environment
environment = RichEnvironment(dimensions=3, size=1.0)
# Create an ecosystem
ecosystem = Ecosystem(environment)
# Populate with organisms
ecosystem.populate_randomly(
num_plants=15,
num_herbivores=6,
num_decomposers=4
)
# Run simulation
for i in range(30):
stats = ecosystem.update(delta_time=0.5)
print(f"Population: {stats['population']['total']} organisms")
The AdvancedMyceliumNetwork
is the core component that implements the network functionality:
from mycelium import AdvancedMyceliumNetwork, Environment
# Create an environment
env = Environment(dimensions=3)
# Create a network
network = AdvancedMyceliumNetwork(
environment=env,
input_size=3,
output_size=1,
initial_nodes=20
)
# Process inputs through the network
outputs = network.forward([0.5, 0.7, 0.3])
The enhanced AdaptiveMyceliumNetwork
adapts to environmental conditions:
from mycelium.enhanced.rich_environment import RichEnvironment
from mycelium.enhanced.adaptive_network import AdaptiveMyceliumNetwork
# Create a rich environment
env = RichEnvironment(dimensions=3)
# Create an adaptive network
network = AdaptiveMyceliumNetwork(
environment=env,
input_size=2,
output_size=1,
initial_nodes=10
)
# Process inputs and adapt to environment
for i in range(10):
outputs = network.forward([0.7, 0.3])
# Check adaptation levels
stats = network.get_specialization_statistics()
print(f"Temperature adaptation: {stats['adaptation']['temperature_adaptation']:.3f}")
The ML components provide reinforcement learning and transfer learning capabilities:
from mycelium.enhanced.rich_environment import RichEnvironment
from mycelium.enhanced.adaptive_network import AdaptiveMyceliumNetwork
from mycelium.enhanced.ml.reinforcement import ReinforcementLearner
from mycelium.enhanced.ml.transfer import TransferNetwork
# Create networks and environments
env1 = RichEnvironment()
env2 = RichEnvironment()
source_network = AdaptiveMyceliumNetwork(environment=env1)
target_network = AdaptiveMyceliumNetwork(environment=env2)
# Transfer knowledge between networks
transfer = TransferNetwork(similarity_threshold=0.5)
result = transfer.transfer_knowledge(source_network, target_network)
print(f"Knowledge transfer success: {result['success']}")
The project includes a performance profiling tool to identify bottlenecks:
# Run the performance profiling tool
python tools/profile_performance.py
Networks can adapt to changing environmental conditions:
# Create environment with changing conditions
env = RichEnvironment(dimensions=2)
# Create an adaptive network
network = AdaptiveMyceliumNetwork(environment=env)
# Simulate changing conditions
env.factors.temperature = 0.8 # Hot environment
env.factors.moisture = 0.2 # Dry environment
env.update(delta_time=0.5)
# Run network with adaptation
for i in range(10):
outputs = network.forward([0.5, 0.5])
print(f"Temperature adaptation: {network.temperature_adaptation:.2f}")
-
ImportError: No module named 'mycelium'
- Make sure you're running the examples from the main directory
- Check that the virtual environment is activated
-
ValueError: Expected {input_size} inputs, got {len(inputs)}
- Ensure your input vectors match the dimensionality of the network
-
Memory issues with large ecosystems
- Reduce the number of organisms in the simulation
- Consider running on a machine with more memory
-
Permission denied when saving plots
- Visualization plots are saved to the 'visualizations/' directory in the repository
- Make sure your user has write permissions to this directory
- If issues persist, run the script with appropriate permissions or modify the save path in the demo scripts
We're actively developing the following features:
-
Performance Optimizations
- Implement spatial indexing for faster resource lookups
- Optimize node connection algorithms
- Add parallel processing for network updates
-
Extended Ecosystem
- Add more organism types (e.g., carnivores, symbiotic organisms)
- Implement more complex food webs and energy flows
- Create visualization tools for ecosystem monitoring
-
Advanced Learning Capabilities
- Implement deep reinforcement learning integration
- Add evolutionary algorithms for network optimization
- Develop species-level adaptation using genetic algorithms
-
Visualization and Monitoring
- Create interactive 3D visualizations for networks and ecosystems
- Implement real-time monitoring dashboards
- Add export tools for analysis in other software
-
Application Development
- Create specialized adapters for common AI tasks
- Implement model comparison tools
- Develop example applications for real-world problems
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License