Skip to content

bluebbberry/MLTorrent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MLTorrent 🌐🧠

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.

MLTorrent Demo React Machine Learning

🚀 Features

  • 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

🎯 Technical Implementation

Core Components

  • 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

Architecture

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   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)    │
                    └─────────────────┘

📋 Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • Modern web browser (Chrome, Firefox, Safari, Edge)

🛠️ Installation

1. Clone the repository

git clone https://github.com/yourusername/mltorrent.git
cd mltorrent

2. Install dependencies

npm install

3. Start the development server

npm start

4. Open your browser

Navigate to http://localhost:3000 to see MLTorrent in action!

📁 Project Structure

mltorrent/
├── public/
│   ├── index.html
│   └── favicon.ico
├── src/
│   ├── components/
│   │   └── MLTorrent.jsx     # Main component
│   ├── App.js
│   ├── App.css
│   └── index.js
├── package.json
├── README.md
└── .gitignore

🎮 How to Use

Basic Demo Flow

  1. Start Training: Click the "Start Training" button to begin distributed learning
  2. Watch Network Activity: Observe real-time model sharing between peers
  3. Monitor Accuracy: See the global model accuracy improve over time
  4. Peer Behavior: Notice peers going online/offline and their contribution scores
  5. Reset: Use the "Reset" button to start a new training session

Key Metrics to Watch

  • 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

🔬 Technical Details

Machine Learning Algorithm

The system uses a Linear Classifier with Sigmoid Activation for binary classification:

prediction = sigmoid(w₁x₁ + w₂x₂ + bias)

Federated Learning Process

  1. Data Sharding: 1000 samples distributed across 5 peers
  2. Local Training: Each peer trains on its private data shard
  3. Model Aggregation: Global model created via weighted averaging
  4. Gossip Distribution: Peers randomly share model updates
  5. Convergence: Global accuracy improves through collaboration

Dataset

  • 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

🚧 Development

Available Scripts

# Start development server
npm start

# Build for production
npm run build

# Run tests
npm test

# Eject (not recommended)
npm run eject

Adding New Features

The codebase is modular and easy to extend:

  • New ML Algorithms: Modify the SimpleLinearClassifier class
  • Different Datasets: Update the generateTrainingData function
  • More Peers: Adjust the peer initialization logic
  • Network Protocols: Enhance the gossip protocol implementation

🌟 Future Enhancements

  • 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

🤝 Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • 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

About

BitTorrent for machine learning. Implementation of https://dl.acm.org/doi/full/10.1145/3703790.3703813 for general machine learning (not just IoT setting)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published