# What is FELT Labs?

FELT Labs is a data science company that provides a suite of tools for working with private and distributed data. Our focus is on federated learning, which allows you to train machine learning models or perform data analytics across multiple datasets while preserving data privacy. We built our solution on top of Ocean Protocol, that creates tools for the web3 data economy. This means you can easily select and use datasets from Ocean. Our web application simplifies the entire training process, making it easy for users to get started quickly.

### Federated Learning and How FELT Works

Federated learning is a powerful technique that enables multiple parties to collaborate on training a single machine learning model while keeping their private data secure. For example, three separate companies might want to create a machine learning model to improve their product recommendations, but they don't want to share their data with each other. With federated learning, each company trains a local model on its own data. These local models are then combined to create a global model that's better than any of the local models individually, while ensuring that no sensitive data is revealed during the process.

{% hint style="info" %}
There are many applications where companies/individuals can make use of federated learning:

* Car manufactures working on self-driving tehcnology
* Hospitals developing AI to treat patients better
* Individuals sharing data from fitness tracking devices
* Ecommerce providing better products to customers
  {% endhint %}

FELT makes federated learning simple by providing its own algorithms for training and aggregating models. We rely on Ocean protocol to handle everything around data management. Our platform allows data scientists to easily select any compatible data published on Ocean and use it to train their models. They can choose our algorithms or create their own for their specific use case, and run them seamlessly through FELT. Meanwhile, data providers can set prices on their data and get paid for providing compute to their private data.

*There are multiple approaches to federated learning. At the moment, FELT implements only one of them, but we have plans to extend this in the future.*

### Benefits

Key benefits of FELT:

1. **Secure** - All data remains securely on the data provider machine. Access to data is protected by a blockchain network.
2. **Encrypted** - All trained models are encrypted and exchanged only between interested parties. This ensures that the models are kept confidential and that privacy is maintained throughout the process.
3. **Easy** - FELT makes the entire process of federated learning simple and easy to use. With our web application, data scientists can easily select compatible datasets from Ocean, choose their preferred algorithms, and train their models seamlessly.
4. **Rewards** - Data providers can set prices on their data and get paid for providing their data. This incentivizes data sharing and allows data providers to benefit from the use of their data.

By leveraging FELT's secure, encrypted, and easy-to-use platform, data scientists and data providers can unlock the power of federated learning and gain new insights from their data while maintaining privacy and security.

## Getting Started

**Have 2 minutes?**

{% embed url="<https://youtu.be/gRqWCdeTIDo>" %}
FELT Labs promotion video.
{% endembed %}

**Have 5 minutes?**

{% embed url="<https://www.youtube.com/watch?v=CFfmLdYtz4s&t=5s>" %}
Presentation of FELT Labs architecture
{% endembed %}

### Guides: Jump right in

Follow our handy guides to get started on the basics as quickly as possible:

{% content-ref url="/pages/Hz6nGYjiYXj0xjyUuIfz" %}
[Complete Getting Started](/guides/getting-started)
{% endcontent-ref %}

{% content-ref url="/pages/5jv61vz9iMTBwgOJ1jUm" %}
[Data Provider](/guides/data-provider)
{% endcontent-ref %}

### Fundamentals: Dive a little deeper

Learn the fundamentals of FELT to get a deeper understanding of our main features:

{% content-ref url="/pages/gdmUdBjKMvSnNr6tk6yH" %}
[Federated Learning](/fundamentals/federated-learning)
{% endcontent-ref %}

{% content-ref url="/pages/dNzFDaMZ6oFfkHdC1try" %}
[FELT Architecture](/fundamentals/felt-architecture)
{% endcontent-ref %}


# Roles

In FELT, we define two main roles: data scientist and data provider. The data provider is anyone publishing their data on Ocean Protocol. The data scientist is then a person who selects suitable datasets and starts the training. Data provider or data scientist can be any kind of entity (person, company, etc.) with the ability to publish data or start training.

### Data Scientist

{% hint style="info" %}
Data scientist trains ML models on the datasets.
{% endhint %}

A data scientist is the person picking datasets and analyzing them or running machine learning on them. The process of training can be started through FELT application: [app.feltlabs.ai](https://app.feltlabs.ai/). In the application, the data scientist can start the training simply with 3 steps - pick datasets, pick algorithm to run on those datasets and specify optional parameters. In order to be able to run the training, the data scientist must pay the necessary fees for training algorithms and purchasing compute access to the data from data providers. After that, they can monitor training progress and download the final global model.

For more details, read:

{% content-ref url="/pages/Hz6nGYjiYXj0xjyUuIfz" %}
[Complete Getting Started](/guides/getting-started)
{% endcontent-ref %}

### Data Provider

{% hint style="info" %}
The data provider owns private data and provides compute access to them via the Ocean Protocol.
{% endhint %}

Data providers are data owners. They can publish their data on Ocean protocol and make them available for computation. By doing that, they can also specify the price for using their data. They can control which algorithms can be used on top of their data (e.g. FELT local training algorithm).

For more details, read:

{% content-ref url="/pages/5jv61vz9iMTBwgOJ1jUm" %}
[Data Provider](/guides/data-provider)
{% endcontent-ref %}


# History

FELT originated as an idea for Chainlink Fall Hackathon 2021. Back then, we were calling ourselves a FELToken. The original platform worked as an independent solution using its own smart contracts. Below is the submission video from Chainlink Hackathon 2021 during which FELT started:

{% embed url="<https://youtu.be/3TFzvjnEDAA>" %}
First presentation of FELT
{% endembed %}

## FELToken MVP

The next months after starting, we spend working on our first MVP.

{% embed url="<https://youtu.be/uoBl2yeO7hY>" %}
Presentation of usage of FELT MVP
{% endembed %}

## Articles About FELT Labs

{% embed url="<https://medium.com/blockchain-biz/half-year-with-web3-start-up-ae3cc89574ee>" %}


# Complete Getting Started

From creating project to model training.

In this guide, we will use a sample problem to go over all steps necessary for federated learning with FELT. This process consists of:

1. Initial setup
2. Preparing datasets
3. Starting local training
4. Aggregating results from local training
5. Using final model

{% embed url="<https://youtu.be/xLcIxxA_9Rs>" %}
Video tutorial following similar structure as this guide.
{% endembed %}

## Initial Setup

### Web3 Wallet

For this guide you need an ethereum address. We recommened using MetaMask wallet:

{% embed url="<https://metamask.io/download>" %}
Follow the instuctions here to download MetaMask
{% endembed %}

For this guide we will be using Polygon Mumbai test network.

*In case you don't have `Polygon Mumbai` network in your MetaMask, you can add it by following* [*this guide*](https://docs.polygon.technology/docs/develop/metamask/config-polygon-on-metamask/)*.*

### Transaction Fees

Right now, the app is deployed on the Polygon Mumbai testnet. First, you will need some MATIC tokens to pay for the transaction fees. You can obtain these using a Polygon faucet. Just visit the following link and paste your wallet address:

{% embed url="<https://faucet.polygon.technology>" %}
Head to this site to obtain MATIC tokens for paying transaction fees.
{% endembed %}

You will also need OCEAN tokens to pay for datasets and algorithms. You can collect them through OCEAN faucet by submitting your wallet address here:

{% embed url="<https://faucet.mumbai.oceanprotocol.com/>" %}
OCEAN token faucet for mumbai network.
{% endembed %}

## Preparing datasets

For the demonstration of federated learning, let’s imagine two towns collaborating on analyzing housing data. The data might contain sensitive information. Therefore, they can’t fully disclose the data. Each town publishes its dataset on Ocean, allowing only computation over data without direct access. **We will try to predict a house price based on house parameters** (size in square feet, number of bedrooms, bathrooms, material, etc.). Below you can see a demonstration of our data ([original data file](https://github.com/ywchiu/riii/blob/cba34bb9342cb0d283b531f5dc502fc15688078a/data/house-prices.csv)).

{% embed url="<https://gist.github.com/Breta01/4c61088296fdeee2481cf33379d0a31e#file-house-prices-example-csv>" %}
Example of house prices dataset. The target column we want to predict (prices) is the last. In data published on Ocean, we also need to remove the header row.
{% endembed %}

We already have the data published on Ocean (using the Mumbai chain) as the following assets, which we will use in this guide:

* [did:op:3632e8584837f2eac04d85466c0cebd8b8cb2673b472a82a310175da9730042a](https://market.oceanprotocol.com/asset/did:op:3632e8584837f2eac04d85466c0cebd8b8cb2673b472a82a310175da9730042a)
* [did:op:cad4a81c9a8e1c1071ccf3e9dea6f8f42d58e100fa3ddf2950c8f0da9e0dda46](https://market.oceanprotocol.com/asset/did:op:cad4a81c9a8e1c1071ccf3e9dea6f8f42d58e100fa3ddf2950c8f0da9e0dda46)

### Data Format <a href="#id-6b53" id="id-6b53"></a>

In this guide we will be using FELT algorithms. For that we need to have data in the correct data format. Right now, we support only **CSV format**. With the following rules:

* CSV contains only numerical data
* CSV doesn't contain the header row
* All datasets used during training must have the same number of columns

You can check this file [`house-prices-part1.csv`](https://gist.github.com/Breta01/a8482d3cae0c257e9a7394ca72fdb281) which is used in this article. For more details about publishing your datasets on the Ocean marketplace, please read:

{% embed url="<https://docs.oceanprotocol.com/using-ocean-market/marketplace-publish-data-asset>" %}

{% hint style="info" %}
If you are using your data, don’t forget to allow the “Local Training — FELT” algorithm or just all published algorithms.
{% endhint %}

## Starting Local Training <a href="#id-901e" id="id-901e"></a>

Now that we have our data ready. It’s time to start the training! Head to the [app.feltoken.ai](https://app.feltoken.ai/). Before you begin, you need to sign in to FELT.

Then you will select between training on single dataset or on multiple datasets. For our case we will use the **multiple datasets** option. In the first step you will fill in the name of training (you can pick an arbitrary one) and search for our datasets with following dids:

```
did:op:3632e8584837f2eac04d85466c0cebd8b8cb2673b472a82a310175da9730042a
did:op:cad4a81c9a8e1c1071ccf3e9dea6f8f42d58e100fa3ddf2950c8f0da9e0dda46
```

<figure><img src="/files/iyRfyOGw6KPYvui8yRXb" alt=""><figcaption><p>Screenshot of how the form should look before you go to next step.</p></figcaption></figure>

Then you proceed to the next step, where you select the algorithm you want to run. Pick `Local Training - FELT (DEV)`

<figure><img src="/files/LlUfzAxHviFWCzbGAjSo" alt=""><figcaption><p>Select the algorithm.</p></figcaption></figure>

In the final step you customize parameters of the algoritm. FELT algorithm lets you pick from different models and customize their parameters. Right now, you can pick from scikit-learn models or analytics (mean, variance...). For our case we can pick any regression model, for example **Ridge regression**.

One of the most important options is to pick **target column index**. This is the index representing column which we want to predict. Setting value to -1 will use the last column. You can click on submit once you select you hyperparameters.

<figure><img src="/files/A09IYveGq5mFsQ5IAFOa" alt=""><figcaption><p>Picking parameters for the selected model. Target column set to -1 means that we want to predict the last column.</p></figcaption></figure>

### Approving Transactions <a href="#id-4d63" id="id-4d63"></a>

Once you hit **Submit** button, you will see the summary and then 2 options how to start the traing. Each option is further described here:

{% content-ref url="/pages/nXtoAri8r3vQJoKn0Gv6" %}
[Start Training](/guides/start-training)
{% endcontent-ref %}

For this guide, we will be using browser flow without auto-sign. You will have to approve a few transactions using MetaMask to start the training. Make sure that you connected your Metamask and that you are connected to `Polygon Mumbai` test network. Here is the list of all transactions you will have to confirm:

1. Approve OCEAN token spend to purchase the dataset
2. Purchase the dataset *(now approve and purchase are separate transactions)*
3. Approve OCEAN token spend to purchase FELT algorithm for training
4. Purchase the algorithm
5. Sign request to start the compute job (training)

We are starting the training on two datasets; therefore, you will have to approve those transactions twice.

<figure><img src="/files/ew0vwrUxVK6HllpSuitw" alt=""><figcaption><p>Screenshot from starting training and approving transactions through MetaMask.</p></figcaption></figure>

## Starting Aggregation <a href="#id-78b8" id="id-78b8"></a>

Once you start the local training, you can go to [launched jobs page](https://app.feltlabs.ai/jobs) (you can use **Launched jobs** button). Here you can monitor the progress.

Once both jobs finish, you can start the aggregation. On right side of each local training you have check box which you can use to select which local trainings should be aggregated (you need to select at least 2). After selecting jobs to aggregate, you can click **Aggregate** button and start the aggregation.

<figure><img src="/files/m6nbIgcSYIaVHREm6Mik" alt=""><figcaption><p>Displaying job status; selecting jobs to aggregate and starting the aggregation.</p></figcaption></figure>

After starting the aggregation, the progress bar will pop up. You will have to approve the following transactions:

1. Sign URLs to access local models
2. Approve OCEAN token to pay for provider fees
3. Order dataset for the compute job
4. Approve OCEAN token spend to purchase FELT algorithm for aggregation
5. Purchase the algorithm
6. Sign request to start the compute job (aggregation)

<figure><img src="/files/OlFZ5FslNDUspiLU44e8" alt=""><figcaption></figcaption></figure>

## Use Final Model <a href="#id-93d9" id="id-93d9"></a>

You can watch aggregation progress. Once it finishes, you will see the **Download final model** button. You will sign the request and download the final model (in our case `final-model-House Prices.json`). The file is not a standard machine learning file format. You will have to use the FELT library to import it.

First, you have to install the [FELT python library](https://github.com/FELT-Labs/feltlabs.py) using pip (it requires **Python 3.9 or newer**):

```
pip install feltlabs
```

Then you can load the model using `feltlabs.model.load_model(model_path)` function. This function will take the path of the model file as an argument and return the model object.

When using the federated learning option and importing the model using `load_model(...)` function. The function returns the model, which can be used as a standard [scikit-learn model](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html) object. The model can then be used for prediction using the function `model.predict(data)`. You can check the following code for sample usage:

{% embed url="<https://gist.github.com/Breta01/96f9c3783e18260bb6b512b1c3f94a68#file-felt-load-model-py>" %}

That’s it. You just trained your first model on a distributed dataset! Now it’s up to your imagination to find projects where you can use this technology.

## Conclusion

These should be the main parts for getting started with the FELT. In the following guides, you might find more detailed instructions for specific tasks.


# Single or Multi Dataset Training

When opening [the FELT application](https://app.feltlabs.ai/), you will have the option to select between **single** and **multi**-dataset training. This will determine the following process of training.

<figure><img src="/files/EwrByJZrOawzuIZPGOX9" alt=""><figcaption><p>Initial screen of FELT applicationa when selecting between single and multiple datasets option.</p></figcaption></figure>

## Starting Training

The start of the training is the same for both options. The only difference is that in the case of the single dataset training, you pick just one dataset, and for multiple datasets, you pick at least two. The rest of the training setup is the same, you will pick a model, select hyperparameters, and start training. Once the training starts, you can go to [the Launched jobs section](https://app.feltlabs.ai/jobs) of the application to view the results. That's the part where things start to differ.

## Single Dataset

When viewing the results of single dataset training. You will see only one compute job. When the training finishes, you can download the result and use it right away. Therefore training on a single dataset is generally faster as it requires starting just one compute job to get the results.

<figure><img src="/files/pB7tCiLLVXONPlEi8KrI" alt=""><figcaption><p>Screenshot from job status for single dataset training.</p></figcaption></figure>

## Multiple Datasets

The situation is different for multiple datasets training. In this case, we run compute job on each dataset separately. We call this **local training**. The results of local training can't be used directly, and you can't view them in the application. Instead, you have to select local trainings (using checkboxes on the right) and click on **aggregate**. The aggregation will combine these local jobs into the final model, which you can then download in the **Aggregation** section. If you have a lot of datasets, you can run multiple aggregations. Each job can aggregate different datasets together.

<figure><img src="/files/2BTAoRKCcaZ5UfLF2EYS" alt=""><figcaption><p>Status for training on multiple datasets. The results from local training have to be aggregated into the final model.</p></figcaption></figure>


# Start Training

Ways how to start training in FELT.

FELT provides 3 ways how to start the training:

* Browser flow with wallet signing
* Browser flow with Auto-Sign
* Python flow

Let's go through each of them.

## Browser flow with wallet signing

Any transaction on a blockchain has to be approved through your wallet. This ensures higher security, but it can slow things down when needing to approve multiple transactions.

## Browser flow with Auto-Sign

Instead of manually signing transactions, you can use the Auto-Sign feature. This feature will automatically sign all transactions using separated account. This makes the training process smoother.

### How to setup Auto-Sign

To setup Auto-Sign, go to your FELT [account page](https://app.feltlabs.ai/account):

1. Connect your MetaMask account using **Connect Wallet** button.
2. Click on **Setup Auto-Sign** button
3. You will be given a randomly generated private key. If you want, you can also paste your own private key.
4. Fill in the password which is used to encrypt the private key and click **Submit**

Now you see that a new account was generated for you. The current balance is zero. You have to use the **top-up** button to add Matic and Ocean to this account.

1. Select the amount of Matic/Ocean and click **Top Up**
2. **Confirm** the transaction using MetaMask

This will transfer the funds from your MetaMask account to the account used for automation. You can also use **Withdraw All** button to get all funds back to your MetaMask account.

Now you can start training using Auto-Sign. For that you just need to activate it by providing the password you used to encrypt the private key.

{% hint style="danger" %}
Do not lose your password. If you lose it, you will not be able to restore the account. We also recommend to backup the private key.
{% endhint %}

### Storing the Account

The account is stored encrypted by the password in our database. Next time you would like to use this account you will just activate it by providing a password. Be aware that if you lose the password, you are not able to restore the account.

## Python flow

Python flow is the most seamless and secure way how to start training. It allows you to use any wallet account. This account is not shared with anyone. It is used to automatically sign transactions through python.

Instruction how to set it up can be found here:

{% embed url="<https://github.com/FELT-Labs/python-flow>" %}


# Data Provider

A data provider is someone who publishes data on Ocean Protocol. They can choose to use a trusted Ocean provider or run their own. When publishing data, they set various parameters, such as the name, description, and price of the dataset.

If you are publishing private data, you only provide compute access and not download access. Therefore, you need to specify which algorithms can run on your data. To allow FELT algorithm, you need to ensure that your data are in the correct format for the algorithm to load the data and train models.

In general, data scientists need to be aware of format of the data and its schema so they can create a meaningful algorithm. On the other hand, data providers need to be awere of the algorithm that data scientist wants to run. If data provider wants to allow this algorithm to be run on their data, they need to specify it when publishing to Ocean (or later by editing the metadata).

### Data provider vs Ocean provider

To prevent any confusion between these two terms, the data provider is the entity owning the data. Ocean provider is code that is running on some machine. Ocean provider code interacts with Ocean smart contracts, handles the dataset purchases, and runs the computation with data.

Therefore, when data providers decide to publish data on Ocean, they must pick some Ocean provider which will manage the data access for them. Data providers can either pick some public Ocean provider or run their own instance of Ocean provider in order to reach the maximum security of the data.

*Keep in mind that once you publish your data, the Ocean provider code has full access to your data. Hence you must trust the entity running the Ocean provider (you can also be the one running the Ocean provider).*

### Data Format for using FELT algorithm

If you want to use FELT algorithm with your own data, you first need to have data in the correct data format. Right now, we support only **CSV format**. With the following rules:

* CSV contains only numerical data
* CSV doesn't contain the header row
* All datasets used during training must have the same number of columns

You can check this file [`house-prices-part1.csv`](https://gist.github.com/Breta01/a8482d3cae0c257e9a7394ca72fdb281) as an example.

### Publishing data

Publishing data can be done through Ocean marketplace. The web application will walk you through the whole process. For more details, please read:

{% embed url="<https://docs.oceanprotocol.com/using-ocean-market/marketplace-publish-data-asset>" %}

Alternatively, you can use their libraries - [ocean.py](https://github.com/oceanprotocol/ocean.py) or [ocean.js](https://github.com/oceanprotocol/ocean.js)

Don't forget to allow algorithms to run on your data.


# Using FELT Algorithms

We provide algorithms that you can use to train scikit-learn models and perform data analytics on CSV data. The general workflow of using the FELT application is described in the following:

{% content-ref url="/pages/Hz6nGYjiYXj0xjyUuIfz" %}
[Complete Getting Started](/guides/getting-started)
{% endcontent-ref %}

If you need an algorithm for your specific use case, see the following section:

{% content-ref url="/pages/ForOOnkJTOhRENBZGBIl" %}
[Creating Custom Algorithms](/guides/creating-custom-algorithms)
{% endcontent-ref %}

## Supported models

We are extending the list of supported models. If you request a certain model, we will try to prioritize adding it to our application.

{% embed url="<https://github.com/FELT-Labs/feltlabs.py/issues>" %}
Here you can create issue - requesting model type
{% endembed %}

### Scikit-learn models

* Regression:
  * [Linear Regression](https://scikit-learn.org/stable/modules/linear_model.html#ordinary-least-squares)
  * [Ridge Regression](https://scikit-learn.org/stable/modules/linear_model.html#ridge-regression-and-classification)
  * [Lasso Regression](https://scikit-learn.org/stable/modules/linear_model.html#lasso)
  * [Elastic-Net](https://scikit-learn.org/stable/modules/linear_model.html#elastic-net)
  * [LARS Lasso](https://scikit-learn.org/stable/modules/linear_model.html#lars-lasso)
* Classification:
  * [SGD Classifier](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDClassifier.html#sklearn.linear_model.SGDClassifier)
  * [Logistic Regression](https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression)
* Clustering:
  * [Nearest Centroid Classifier](https://scikit-learn.org/stable/modules/neighbors.html#nearest-centroid-classifier)
* Neural Networks:
  * [MLP Classifier](https://scikit-learn.org/stable/modules/neural_networks_supervised.html#classification)
  * [MLP Regressor](https://scikit-learn.org/stable/modules/neural_networks_supervised.html#regression)

### Data analytics

* Mean
* Sum
* Variance
* Standard deviation

### TensorFlow models

Coming soon

## Using Final Models

FELT is using custom format (based on JSON) for storing and exchanging the models. When you finish the training, you will download your final model file (e.g. `final-model-House Prices.json`).

In order to use it, you have to install the [FELT python library](https://github.com/FELT-Labs/feltlabs.py) using pip (it requires **Python 3.9 or newer**, the Python 3.9 is recommended):

```
pip install feltlabs
```

Then you can load the model using `feltlabs.model.load_model(model_path)` function. This function will take the path of the model file as an argument and return the model object. Right now, we support two types of models: federated learning and federated analytics. The behaviour of each is slightly different.

#### Federated Learning - Scikit-learn Model

When using the federated learning option and importing the model using `load_model(...)` function, the function returns the model, which can be used as a standard [scikit-learn model](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html) object. The model can then be used for prediction using the function `model.predict(data)`. You can check the following code for sample usage:

{% embed url="<https://gist.github.com/Breta01/96f9c3783e18260bb6b512b1c3f94a68#file-felt-load-model-py>" %}

#### Federated Analytics Models

Similarly to federated learning models, these models can be loaded using `load_model(...)` a function. This time you don't have to pass any data to the model, and you can obtain calculated value (of sum, mean, variance, or std) using the `model.predict(None)` function. See the example below:

```python
from feltlabs.model import load_model

# Load model
model = load_model("final-model-mean.json")
# Call predict function without any input
mean = model.predict(None)
print(mean)
# This will print the value of mean calculated by the model
```

### Converting FELT format to Python Pickle format

You can convert the FELT model format into a standard pickle file. This file will then contain a pickled object of scikit-learn model. FELT library provides an easy command for that. After installing `feltlabs.py` library, you can run:

```
felt-export --input "final-model-House Prices.json" --output "model.pkl"
```

Then you can use the created file as follows:

```python
import pickle

with open('model.pkl', 'rb') as f:
    model = pickle.load(object, f)
    
# See the above code example for data definition
model.predict(data)
```


# Creating Custom Algorithms

FELT Labs currently offers one algorithm that can be used to train certain types of machine learning models or perform data analytics on CSV data. However, if you have a specific use case that requires a different algorithm, we offer two options.

First option, you can tell us what you need and we can create a custom algorithm for you. Once the algorithm is developed, you will be able to easily run it on your data. To request a custom algorithm, you can reach out to us on our Discord channel and provide us with the details of your use case.

Second option, you can build your own algorithm. This page provides information how to do that. We encourage you to let us know if you decide to build your own algorithm, so that we can assist you and ensure that the final product meets your needs.

Overall, our goal is to provide flexible options for using our platform and to ensure that specific data analysis and machine learning objectives could be achieved, whether that involves using our pre-existing algorithm or developing a custom solution.

## How to Build a Custom Algorithm

To create algorithms that are tailored to your specific use case, you will need to develop two separate algorithms: one for local training and another for aggregation. The local training algorithm runs on the data iteself, computing intermediate results. Those results are then aggregated with the aggregation algorithm.

We provide a simple example of what such a pair of algorithms looks like in our GitHub repository, which you can find here:

{% embed url="<https://github.com/FELT-Labs/base-algorithm>" %}
Simple example to demonstrate how algorithms should look like
{% endembed %}

You can also check out the implementation of our existing algorithms here:

{% embed url="<https://github.com/FELT-Labs/feltlabs.py/tree/main/feltlabs/algorithm>" %}
FELT Labs algorithms
{% endembed %}

Once you have developed your algorithms, you will need to publish them as two separate algorithm assets on the Ocean Protocol. Instructions for doing so can be found at the following link:

{% embed url="<https://docs.oceanprotocol.com/using-ocean-market/marketplace-publish-data-asset>" %}
Tutorial to publish assets using the Ocean Market
{% endembed %}

After you have developed and published your algorithms, you can use them on our platform. In step 2 (choose algorithm) use "Use s custom algorithm" and fill the dids of your algorithms. In step 3 you will be able to provide any additional parameters in form of a JSON object (optional).

Do you want your algorithms to be listed? Let us know and we will review them. By listing your algorithms on our platform, you make it available to other users who may benefit from them. Plus when others are using your algorithms, you are receiving a passive income.

Our goal is to help you create algorithms that meet your specific needs and to foster collaboration and innovation in the data science community. If you have any questions don't hesitate to reach out to us.


# Federated Learning

Federated learning is a powerful technique that enables multiple parties to collaborate on training a single machine learning model while keeping their private data secure. For example, three separate companies might want to create a machine learning model to improve their product recommendations, but they don't want to share their data with each other. With federated learning, each company trains a local model on its own data. These local models are then combined to create a global model that's better than any of the local models individually, while ensuring that no sensitive data is revealed during the process.

{% hint style="info" %}
There are many applications where companies/individuals can make use of federated learning:

* Car manufacturers sharing self-driving data
* Hospitals developing AI to treat patients better
* Individuals sharing data from fitness tracking devices
* Ecommerce providing better products to customers
  {% endhint %}

FELT makes federated learning simple by providing its own algorithms for training and aggregating models. We rely on Ocean protocol to handle everything around data management. Our platform allows data scientists to easily select any compatible data published on Ocean and use it to train their models. They can choose our algorithms or create their own for their specific use case, and run them seamlessly through FELT. Meanwhile, data providers can set prices on their data and get paid for providing compute to their private data.

*There are multiple approaches to federated learning. At the moment, FELT implements only one of them, but we have plans to extend this in the future.*


# FELT Architecture

FELT consists of two main components: FELT application and algorithms. You can find the application at [app.feltlabs.ai](https://app.feltlabs.ai/). This page exaplains how our algorithms work and how we ensure secure encrypted exchange of results. However FELT also provides an option to run your own algorithm so this guide can help you understand how to create your own.

<figure><img src="/files/Uwsc5GKRAwFUlHht8iAS" alt=""><figcaption><p>The FELT application is interacting with Ocean protocol. It starts compute jobs and retrieve results.</p></figcaption></figure>

### Video presentation

{% embed url="<https://www.youtube.com/watch?v=CFfmLdYtz4s>" %}
Video from one of our presentations. Presenting FELT architecture.
{% endembed %}

## Algorithms

Algorithms are assets published on Ocean protocol. In general, algorithms are Docker containers that receive dataset(s) from Ocean protocol, execute some code and return results. This is possible using Ocean [compute-to-data](https://oceanprotocol.com/technology/compute-to-data) technology. FELT uses two main algorithms:

* **Local training algorithm** - for training machine learning models on data
* **Aggregation algorithm** - for combining outputs of local training into a single output

Both algorithms use the same Docker container, which you can find here: [FELT Labs - Docker Hub](https://hub.docker.com/r/feltlabs/feltlabs-py). The only difference between them is the entry command which starts the training or aggregation. The Docker container is a basic Python container with `feltlabs` library. For more details about this container, you can check the feltlabs-py repository:

{% embed url="<https://github.com/FELT-Labs/feltlabs.py>" %}

### Local Training Algorithm

The local training algorithm is for training machine learning models on Ocean datasets. We have a **single** algorithm for training any type of model. After a user picks datasets and a model type in the application, the application starts the local training algorithm on each dataset separately (if data are at different Ocean providers).

{% hint style="info" %}
In order to run this dataset, the dataset author must first approve to run this algorithm.
{% endhint %}

Consequently, each local training algorithm receives a data and model type definition (JSON object). Based on the model definition, the algorithm initializes the model and trains it on the data.

<figure><img src="/files/rwnotJah59UPfGEak1SC" alt=""><figcaption><p>For each dataset we start compute job which outputs the local model.</p></figcaption></figure>

Once the training finishes, the algorithm outputs an encrypted model. The model is encrypted in the following way:

1. Algorithm adds random noise to the model. The random noise is known by user who started the training.
2. Algorithm encrypts the model using the aggregation public key. Only the aggregation algorithm knows the private key to encrypt the model.

These two steps ensure greater privacy of the data. Encryption using an aggregation key ensures that the user can't access the local model directly, but it must first run the aggregation of multiple models. Aggregation provides greater privacy for the local data, keeping only global information.

On the other hand, the aggregation algorithm receives models with random values. Therefore aggregation algorithm can't steal the local models because the true values of the models are hidden.

### Aggregation Algorithm

Once the local training finishes, a user can pick models from local training and start the aggregation. The aggregation algorithm first decrypts the models and performs the aggregation. At the moment, we do the aggregation by averaging over model weights (more types of aggregation will be possible in the future).

<figure><img src="/files/o4nIABRVPNRpZoDYvCzx" alt=""><figcaption><p>The algorithm takes outputs of local training and creates one single model out of them.</p></figcaption></figure>

The aggregation algorithm owns a private key, which is used for decrypting outputs of local training. However, the aggregation doesn't know the random noise which was added to models, so the true values of model parameters are kept secret. The aggregation then outputs one final model (we call this **global model**).

The user then can download the final model through the FELT web application. When downloading the model, the information about random noise is added to the model file. The random noise is then automatically removed when loading the model. Therefore the downloaded model file can be used independently on the user.


# For Bussines

There are many different use cases for FELT in business. We could split them into a few basic categories:

## Secure Data Analysis

As a company, you often have a lot of data, and you want to hire a company to help you with analyzing data, creating prediction models, and solving different problems. The issue is that your data can be sensitive, and you don't want to face issues with providing your data to an analysis company. In that case, you can use FELT and Ocean protocol to provide your data as a compute asset. Data scientists will be able to train models, but they won't be able to directly see or copy your data. All data will remain under your control.

## Secure Collaboration

Maybe you want to collaborate with some other company. Get an advantage against the competition by collaborating on creating prediction models. But still, you don't want to put full trust in the other company and share sensitive data with them. In that case, you can use FELT run data analysis on datasets of both companies without revealing the data itself.

Examples of such cases:

* E-commerce data combined across shops
* Market data and private signals about stocks
* Sensory data from self-driving cars, IoT devices
* Any data you have

{% hint style="info" %}
Interested in more? Feel free to contact us at <support@feltlabs.ai>
{% endhint %}


# For Researches

There are different ways how to get started with FELT. To start, we recommend going through:

{% content-ref url="/pages/Hz6nGYjiYXj0xjyUuIfz" %}
[Complete Getting Started](/guides/getting-started)
{% endcontent-ref %}

This guide should give you an idea of the basic workflow of FELT and how to use it.

## Local Experiments

If you want to quickly experiment with the FELT library and training models in a federated setting locally. You can explore our demo using MNIST dataset. This code demonstrates how to locally run and evaluate different models using FELT.

{% embed url="<https://github.com/FELT-Labs/mnist-demo>" %}

You can also check out our anomaly detection demo on manufacturing data.

{% embed url="<https://github.com/FELT-Labs/anomaly-detection>" %}


# FAQ

### How does the exchange of the model work?

We use compute jobs provided by Ocean protocol. The results of the compute job (models) are stored at data provider machine. And it is accessed via URLs that must be signed by the person who started the compute job.

### Where to report issues?

In case you find any issues, you can create an issue in our project repository:

{% embed url="<https://github.com/FELT-Labs/feltlabs.py/issues>" %}

### Need personalised solution? Want to contact core developers?

We recommend contacting us via Discord:

{% embed url="<https://discord.com/invite/G4ZFfstsV2>" %}

Or you can send us at email: <support@feltlabs.ai>


# Helpful links

Twitter: <https://twitter.com/FELT_labs>

Discord:

{% embed url="<https://discord.com/invite/G4ZFfstsV2>" %}

GitHub:

{% embed url="<https://github.com/FELT-Labs>" %}


