Distributed Machine Learning via P2P Networks
MLTorrent is a proof-of-concept implementation that demonstrates how BitTorrent-inspired peer-to-peer protocols can be used for distributed machine learning. This MVP showcases federated learning with gossip protocols, where multiple peers collaboratively train a global model while keeping their data private.
- Real Federated Learning: Actual machine learning training across distributed peers
- P2P Network Simulation: 5 peers with different data shards and network behaviors
- Gossip Protocol: BitTorrent-inspired model sharing and synchronization
- Privacy-Preserving: No raw data sharing between peers
- Real-time Visualization: Live network activity and training progress
- Interactive Demo: Perfect for presentations and technical demos
- Federated Averaging: Combines peer models using contribution-weighted averaging
- Gossip Protocol: Peers randomly share model updates with each other
- Linear Classifier: Simple but effective model for 2D classification
- Data Sharding: Training data distributed across peers
- Trust System: Peer reputation and contribution scoring
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Peer 1 │ │ Peer 2 │ │ Peer 3 │
│ SmartHome │◄──►│ IoT Device │◄──►│ Edge Device │
│ Local Model │ │ Local Model │ │ Local Model │
│ Data Shard │ │ Data Shard │ │ Data Shard │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
└───────────────────────┼───────────────────────┘
│
┌─────────────────┐
│ Global Model │
│ (Federated │
│ Averaging) │
└─────────────────┘
- Node.js (v16 or higher)
- npm or yarn
- Modern web browser (Chrome, Firefox, Safari, Edge)
git clone https://github.com/yourusername/mltorrent.git
cd mltorrentnpm installnpm startNavigate to http://localhost:3000 to see MLTorrent in action!
mltorrent/
├── public/
│ ├── index.html
│ └── favicon.ico
├── src/
│ ├── components/
│ │ └── MLTorrent.jsx # Main component
│ ├── App.js
│ ├── App.css
│ └── index.js
├── package.json
├── README.md
└── .gitignore
- Start Training: Click the "Start Training" button to begin distributed learning
- Watch Network Activity: Observe real-time model sharing between peers
- Monitor Accuracy: See the global model accuracy improve over time
- Peer Behavior: Notice peers going online/offline and their contribution scores
- Reset: Use the "Reset" button to start a new training session
- Global Model Accuracy: Shows overall performance of the federated model
- Epoch Count: Number of training rounds completed
- Active Peers: Currently participating nodes in the network
- Data Shared: Total model updates exchanged between peers
- Network Activity: Real-time model fragment transfers
The system uses a Linear Classifier with Sigmoid Activation for binary classification:
prediction = sigmoid(w₁x₁ + w₂x₂ + bias)- Data Sharding: 1000 samples distributed across 5 peers
- Local Training: Each peer trains on its private data shard
- Model Aggregation: Global model created via weighted averaging
- Gossip Distribution: Peers randomly share model updates
- Convergence: Global accuracy improves through collaboration
- Type: 2D Binary Classification
- Size: 1000 samples total
- Distribution: 200 samples per peer
- Features: (x₁, x₂) coordinates
- Labels: Binary classification based on x₁ + x₂ > 0
# Start development server
npm start
# Build for production
npm run build
# Run tests
npm test
# Eject (not recommended)
npm run ejectThe codebase is modular and easy to extend:
- New ML Algorithms: Modify the
SimpleLinearClassifierclass - Different Datasets: Update the
generateTrainingDatafunction - More Peers: Adjust the peer initialization logic
- Network Protocols: Enhance the gossip protocol implementation
- Real P2P Networking: Implement actual WebRTC connections
- Advanced ML Models: Support for neural networks and deep learning
- Blockchain Integration: Add cryptocurrency incentives for participation
- Real IoT Integration: Connect to actual smart home devices
- Advanced Privacy: Implement differential privacy and homomorphic encryption
- Mobile App: React Native version for mobile devices
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a 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.
- Inspired by BitTorrent's decentralized architecture
- Built on React and modern web technologies
- Federated learning concepts from research papers
- P2P networking principles from distributed systems
Made with ❤️ for the future of decentralized AI