diff --git a/blades/aggregators/__init__.py b/blades/aggregators/__init__.py index 4cfbda3..d246a55 100644 --- a/blades/aggregators/__init__.py +++ b/blades/aggregators/__init__.py @@ -6,12 +6,12 @@ __all__ = [ "Mean", - "Median", - "Trimmedmean", - "GeoMed", - "DnC", - "Clippedclustering", - "Signguard", - "Multikrum", - "Centeredclipping", + # "Median", + # "Trimmedmean", + # "GeoMed", + # "DnC", + # "Clippedclustering", + # "Signguard", + # "Multikrum", + # "Centeredclipping", ] diff --git a/blades/aggregators/aggregators.py b/blades/aggregators/aggregators.py index 757f409..3c2793a 100644 --- a/blades/aggregators/aggregators.py +++ b/blades/aggregators/aggregators.py @@ -17,16 +17,29 @@ def _median(inputs: List[torch.Tensor]): class Mean(object): + """Computes the ``sample mean`` over the updates from all give clients.""" + def __call__(self, inputs: List[torch.Tensor]): return _mean(inputs) class Median(object): + """Partitioner that uses Dirichlet distribution to allocate samples to + clients.""" + def __call__(self, inputs: List[torch.Tensor]): + """A robust aggregator from paper `Byzantine-robust distributed + learning: + + Towards optimal statistical rates.`_. + It computes the coordinate-wise median of the given set of clients + """ return _median(inputs) class Trimmedmean(object): + """A robust aggregator.""" + def __init__(self, num_byzantine: int, *, filter_frac=1.0): if filter_frac > 1.0 or filter_frac < 0.0: raise ValueError(f"filter_frac should be in [0.0, 1.0], got {filter_frac}.") diff --git a/blades/aggregators/clippedclustering.py b/blades/aggregators/clippedclustering.py index 77ceed4..7134307 100644 --- a/blades/aggregators/clippedclustering.py +++ b/blades/aggregators/clippedclustering.py @@ -10,9 +10,14 @@ class Clippedclustering(object): - def __init__(self, agg="mean", max_tau=1e5, linkage="average") -> None: - super(Clippedclustering, self).__init__() - + """Clipped clustering aggregator.""" + + # def __init__(self, agg="mean", max_tau=1e5, linkage="average") -> None: + def __init__(self): + agg = "mean" + max_tau = 1e5 + linkage = "average" + # def __init__(self, agg="mean", max_tau=1e5, linkage="average") -> None: assert linkage in ["average", "single"] self.tau = max_tau self.linkage = linkage diff --git a/blades/aggregators/signguard.py b/blades/aggregators/signguard.py index c34405a..ae9633c 100644 --- a/blades/aggregators/signguard.py +++ b/blades/aggregators/signguard.py @@ -9,11 +9,10 @@ class Signguard(object): - r"""A robust aggregator from paper `Xu et al. + """A robust aggregator from paper `Xu et al. SignGuard: Byzantine-robust + Federated Learning through Collaborative Malicious Gradient Filtering. - SignGuard: Byzantine-robust Federated - Learning through Collaborative Malicious Gradient - Filtering `_. + `_. """ def __init__(self, agg="mean", max_tau=1e5, linkage="average") -> None: diff --git a/docs/requirements.txt b/docs/requirements.txt index a867e2b..358f918 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,3 +1,9 @@ git+https://github.com/fedlib/blades_sphinx_theme.git +lxml_html_clean +m2r2 nbsphinx +nbsphinx-link numpy>=1.19.5 +sphinx==5.1.1 +sphinx_autodoc_typehints +sphinx_gallery diff --git a/docs/source/_examples/_examples_jupyter.zip b/docs/source/_examples/_examples_jupyter.zip new file mode 100644 index 0000000..18a9e36 Binary files /dev/null and b/docs/source/_examples/_examples_jupyter.zip differ diff --git a/docs/source/_examples/_examples_python.zip b/docs/source/_examples/_examples_python.zip new file mode 100644 index 0000000..9573c5b Binary files /dev/null and b/docs/source/_examples/_examples_python.zip differ diff --git a/docs/source/_examples/customize_attack.ipynb b/docs/source/_examples/customize_attack.ipynb new file mode 100644 index 0000000..fe5b68c --- /dev/null +++ b/docs/source/_examples/customize_attack.ipynb @@ -0,0 +1,43 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# Customize Attack\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import ray\nfrom ray import tune\nfrom ray.tune.stopper import MaximumIterationStopper\n\nfrom blades.algorithms.fedavg import FedavgConfig, Fedavg\nfrom fedlib.trainers import TrainerConfig\n\n\nfrom fedlib.trainers import Trainer\nfrom fedlib.clients import ClientCallback\nfrom blades.adversaries import Adversary\n\n\nclass LabelFlipAdversary(Adversary):\n def on_trainer_init(self, trainer: Trainer):\n class LabelFlipCallback(ClientCallback):\n def on_train_batch_begin(self, data, target):\n return data, 10 - 1 - target\n\n for client in self.clients:\n client.to_malicious(callbacks_cls=LabelFlipCallback, local_training=True)\n\n\nclass ExampleFedavgConfig(FedavgConfig):\n def __init__(self, algo_class=None):\n \"\"\"Initializes a FedavgConfig instance.\"\"\"\n super().__init__(algo_class=algo_class or ExampleFedavg)\n\n self.dataset_config = {\n \"type\": \"FashionMNIST\",\n \"num_clients\": 10,\n \"train_batch_size\": 32,\n }\n self.global_model = \"cnn\"\n self.num_malicious_clients = 1\n self.adversary_config = {\"type\": LabelFlipAdversary}\n\n\nclass ExampleFedavg(Fedavg):\n @classmethod\n def get_default_config(cls) -> TrainerConfig:\n return ExampleFedavgConfig()\n\n\nif __name__ == \"__main__\":\n ray.init()\n\n config_dict = (\n ExampleFedavgConfig()\n .resources(\n num_gpus_for_driver=0.0,\n num_cpus_for_driver=1,\n num_remote_workers=0,\n num_gpus_per_worker=0.0,\n )\n .to_dict()\n )\n print(config_dict)\n tune.run(\n ExampleFedavg,\n config=config_dict,\n stop=MaximumIterationStopper(100),\n )" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.14" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/docs/source/_examples/customize_attack.py b/docs/source/_examples/customize_attack.py new file mode 100644 index 0000000..6afb7df --- /dev/null +++ b/docs/source/_examples/customize_attack.py @@ -0,0 +1,70 @@ +""" +Customize Attack +================== + +""" + + +import ray +from ray import tune +from ray.tune.stopper import MaximumIterationStopper + +from blades.algorithms.fedavg import FedavgConfig, Fedavg +from fedlib.trainers import TrainerConfig + + +from fedlib.trainers import Trainer +from fedlib.clients import ClientCallback +from blades.adversaries import Adversary + + +class LabelFlipAdversary(Adversary): + def on_trainer_init(self, trainer: Trainer): + class LabelFlipCallback(ClientCallback): + def on_train_batch_begin(self, data, target): + return data, 10 - 1 - target + + for client in self.clients: + client.to_malicious(callbacks_cls=LabelFlipCallback, local_training=True) + + +class ExampleFedavgConfig(FedavgConfig): + def __init__(self, algo_class=None): + """Initializes a FedavgConfig instance.""" + super().__init__(algo_class=algo_class or ExampleFedavg) + + self.dataset_config = { + "type": "FashionMNIST", + "num_clients": 10, + "train_batch_size": 32, + } + self.global_model = "cnn" + self.num_malicious_clients = 1 + self.adversary_config = {"type": LabelFlipAdversary} + + +class ExampleFedavg(Fedavg): + @classmethod + def get_default_config(cls) -> TrainerConfig: + return ExampleFedavgConfig() + + +if __name__ == "__main__": + ray.init() + + config_dict = ( + ExampleFedavgConfig() + .resources( + num_gpus_for_driver=0.0, + num_cpus_for_driver=1, + num_remote_workers=0, + num_gpus_per_worker=0.0, + ) + .to_dict() + ) + print(config_dict) + tune.run( + ExampleFedavg, + config=config_dict, + stop=MaximumIterationStopper(100), + ) diff --git a/docs/source/_examples/customize_attack.rst b/docs/source/_examples/customize_attack.rst new file mode 100644 index 0000000..d4748af --- /dev/null +++ b/docs/source/_examples/customize_attack.rst @@ -0,0 +1,114 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "_examples/customize_attack.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + :ref:`Go to the end ` + to download the full example code. + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr__examples_customize_attack.py: + + +Customize Attack +================== + +.. GENERATED FROM PYTHON SOURCE LINES 6-71 + +.. code-block:: Python + + + + import ray + from ray import tune + from ray.tune.stopper import MaximumIterationStopper + + from blades.algorithms.fedavg import FedavgConfig, Fedavg + from fedlib.trainers import TrainerConfig + + + from fedlib.trainers import Trainer + from fedlib.clients import ClientCallback + from blades.adversaries import Adversary + + + class LabelFlipAdversary(Adversary): + def on_trainer_init(self, trainer: Trainer): + class LabelFlipCallback(ClientCallback): + def on_train_batch_begin(self, data, target): + return data, 10 - 1 - target + + for client in self.clients: + client.to_malicious(callbacks_cls=LabelFlipCallback, local_training=True) + + + class ExampleFedavgConfig(FedavgConfig): + def __init__(self, algo_class=None): + """Initializes a FedavgConfig instance.""" + super().__init__(algo_class=algo_class or ExampleFedavg) + + self.dataset_config = { + "type": "FashionMNIST", + "num_clients": 10, + "train_batch_size": 32, + } + self.global_model = "cnn" + self.num_malicious_clients = 1 + self.adversary_config = {"type": LabelFlipAdversary} + + + class ExampleFedavg(Fedavg): + @classmethod + def get_default_config(cls) -> TrainerConfig: + return ExampleFedavgConfig() + + + if __name__ == "__main__": + ray.init() + + config_dict = ( + ExampleFedavgConfig() + .resources( + num_gpus_for_driver=0.0, + num_cpus_for_driver=1, + num_remote_workers=0, + num_gpus_per_worker=0.0, + ) + .to_dict() + ) + print(config_dict) + tune.run( + ExampleFedavg, + config=config_dict, + stop=MaximumIterationStopper(100), + ) + + +.. _sphx_glr_download__examples_customize_attack.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: customize_attack.ipynb ` + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: customize_attack.py ` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/_examples/customize_attack_codeobj.pickle b/docs/source/_examples/customize_attack_codeobj.pickle new file mode 100644 index 0000000..0d2cbb5 Binary files /dev/null and b/docs/source/_examples/customize_attack_codeobj.pickle differ diff --git a/docs/source/_examples/images/sphx_glr_plot_comparing_aggregation_schemes_001.png b/docs/source/_examples/images/sphx_glr_plot_comparing_aggregation_schemes_001.png new file mode 100644 index 0000000..41b595b Binary files /dev/null and b/docs/source/_examples/images/sphx_glr_plot_comparing_aggregation_schemes_001.png differ diff --git a/docs/source/_examples/images/thumb/sphx_glr_customize_attack_thumb.png b/docs/source/_examples/images/thumb/sphx_glr_customize_attack_thumb.png new file mode 100644 index 0000000..8a5fed5 Binary files /dev/null and b/docs/source/_examples/images/thumb/sphx_glr_customize_attack_thumb.png differ diff --git a/docs/source/_examples/images/thumb/sphx_glr_plot_comparing_aggregation_schemes_thumb.png b/docs/source/_examples/images/thumb/sphx_glr_plot_comparing_aggregation_schemes_thumb.png new file mode 100644 index 0000000..aa2ccbd Binary files /dev/null and b/docs/source/_examples/images/thumb/sphx_glr_plot_comparing_aggregation_schemes_thumb.png differ diff --git a/docs/source/_examples/images/thumb/sphx_glr_toy_example_thumb.png b/docs/source/_examples/images/thumb/sphx_glr_toy_example_thumb.png new file mode 100644 index 0000000..8a5fed5 Binary files /dev/null and b/docs/source/_examples/images/thumb/sphx_glr_toy_example_thumb.png differ diff --git a/docs/source/_examples/index.rst b/docs/source/_examples/index.rst new file mode 100644 index 0000000..f88ed59 --- /dev/null +++ b/docs/source/_examples/index.rst @@ -0,0 +1,99 @@ +:orphan: + +Examples +========== + +Below is a gallery of examples + + + +.. raw:: html + +
+ +.. thumbnail-parent-div-open + +.. raw:: html + +
+ +.. only:: html + + .. image:: /_examples/images/thumb/sphx_glr_toy_example_thumb.png + :alt: + + :ref:`sphx_glr__examples_toy_example.py` + +.. raw:: html + +
A Toy Example
+
+ + +.. raw:: html + +
+ +.. only:: html + + .. image:: /_examples/images/thumb/sphx_glr_customize_attack_thumb.png + :alt: + + :ref:`sphx_glr__examples_customize_attack.py` + +.. raw:: html + +
Customize Attack
+
+ + +.. raw:: html + +
+ +.. only:: html + + .. image:: /_examples/images/thumb/sphx_glr_plot_comparing_aggregation_schemes_thumb.png + :alt: + + :ref:`sphx_glr__examples_plot_comparing_aggregation_schemes.py` + +.. raw:: html + +
Comparing Buitd-in Aggregation Schemes
+
+ + +.. thumbnail-parent-div-close + +.. raw:: html + +
+ + +.. toctree:: + :hidden: + + /_examples/toy_example + /_examples/customize_attack + /_examples/plot_comparing_aggregation_schemes + + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-gallery + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download all examples in Python source code: _examples_python.zip ` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download all examples in Jupyter notebooks: _examples_jupyter.zip ` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/_examples/plot_comparing_aggregation_schemes.ipynb b/docs/source/_examples/plot_comparing_aggregation_schemes.ipynb new file mode 100644 index 0000000..fb32f67 --- /dev/null +++ b/docs/source/_examples/plot_comparing_aggregation_schemes.ipynb @@ -0,0 +1,50 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# Comparing Buitd-in Aggregation Schemes\nThis example demonstrates the comparison of eight built-in aggregation schemes.\nWe draw 100 samples from two normal distributions with different mean and co-variance.\nThe samples are then aggregated using the built-in aggregation rules.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\nimport numpy as np\nimport torch\n\nfrom blades.aggregators import (\n Clippedclustering,\n DnC,\n GeoMed,\n Mean,\n Median,\n Multikrum,\n Trimmedmean,\n)\n\nplt.rcParams[\"axes.linewidth\"] = 1.5 # set the value globally\nplt.rcParams[\"font.weight\"] = \"bold\"\nplt.rcParams[\"font.size\"] = 16\nplt.rcParams[\"axes.labelweight\"] = \"bold\"\n\nnp.random.seed(1)\nsz = 40\nsample_sz = 80\n\nmean = np.array((0, 0))\ncov = [[20, 0], [0, 20]]\nbenign = np.random.multivariate_normal(mean, cov, 60)\nmean = np.array((30, 30))\ncov = [[60, 0], [0, 60]]\noutliers = np.concatenate([np.random.multivariate_normal(mean, cov, 40)])\nall_data = np.concatenate([benign, outliers])\n\nall_data_tensor = torch.Tensor(np.concatenate([benign, outliers]))\n\nall_data_tensor = [tensor for tensor in all_data_tensor]\n\naggs = [\n Mean(),\n Multikrum(len(outliers), 10),\n GeoMed(),\n Median(),\n DnC(num_byzantine=len(outliers)),\n Trimmedmean(num_byzantine=len(outliers)),\n Clippedclustering(),\n]\n\n# sphinx_gallery_thumbnail_number = 1\nfig, axs = plt.subplots(figsize=(8, 8))\n\nax = axs\nax.scatter(\n benign[:, 0],\n benign[:, 1],\n s=sample_sz,\n alpha=0.6,\n color=\"r\",\n linewidths=0.2,\n edgecolors=\"black\",\n)\nax.scatter(\n outliers[:, 0],\n outliers[:, 1],\n s=sample_sz,\n color=[0.0, 0.7, 0.0, 1.0],\n linewidths=0.2,\n edgecolors=\"black\",\n)\n\n\ndef plot_agg(ax, agg):\n target = agg(all_data_tensor).cpu().detach().numpy()\n ax.scatter(\n target[0],\n target[1],\n s=sz * 3,\n label=type(agg).__name__,\n linewidths=0.3,\n edgecolors=\"black\",\n )\n\n\nlist(map(lambda agg: plot_agg(ax, agg), aggs))\nax.set_xticks([])\nax.set_yticks([])\nax.legend()\n\nfig.tight_layout(pad=0.0, w_pad=0.6, h_pad=0.5)\nplt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In this example, the results of Mean deviated away by the\noutliers. All the other are inside the range of benign data.\n\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.14" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/docs/source/_examples/plot_comparing_aggregation_schemes.py b/docs/source/_examples/plot_comparing_aggregation_schemes.py new file mode 100644 index 0000000..10b0cc2 --- /dev/null +++ b/docs/source/_examples/plot_comparing_aggregation_schemes.py @@ -0,0 +1,99 @@ +""" +Comparing Buitd-in Aggregation Schemes +========================================== +This example demonstrates the comparison of eight built-in aggregation schemes. +We draw 100 samples from two normal distributions with different mean and co-variance. +The samples are then aggregated using the built-in aggregation rules. +""" + +import matplotlib.pyplot as plt +import numpy as np +import torch + +from blades.aggregators import ( + Clippedclustering, + DnC, + GeoMed, + Mean, + Median, + Multikrum, + Trimmedmean, +) + +plt.rcParams["axes.linewidth"] = 1.5 # set the value globally +plt.rcParams["font.weight"] = "bold" +plt.rcParams["font.size"] = 16 +plt.rcParams["axes.labelweight"] = "bold" + +np.random.seed(1) +sz = 40 +sample_sz = 80 + +mean = np.array((0, 0)) +cov = [[20, 0], [0, 20]] +benign = np.random.multivariate_normal(mean, cov, 60) +mean = np.array((30, 30)) +cov = [[60, 0], [0, 60]] +outliers = np.concatenate([np.random.multivariate_normal(mean, cov, 40)]) +all_data = np.concatenate([benign, outliers]) + +all_data_tensor = torch.Tensor(np.concatenate([benign, outliers])) + +all_data_tensor = [tensor for tensor in all_data_tensor] + +aggs = [ + Mean(), + Multikrum(len(outliers), 10), + GeoMed(), + Median(), + DnC(num_byzantine=len(outliers)), + Trimmedmean(num_byzantine=len(outliers)), + Clippedclustering(), +] + +# sphinx_gallery_thumbnail_number = 1 +fig, axs = plt.subplots(figsize=(8, 8)) + +ax = axs +ax.scatter( + benign[:, 0], + benign[:, 1], + s=sample_sz, + alpha=0.6, + color="r", + linewidths=0.2, + edgecolors="black", +) +ax.scatter( + outliers[:, 0], + outliers[:, 1], + s=sample_sz, + color=[0.0, 0.7, 0.0, 1.0], + linewidths=0.2, + edgecolors="black", +) + + +def plot_agg(ax, agg): + target = agg(all_data_tensor).cpu().detach().numpy() + ax.scatter( + target[0], + target[1], + s=sz * 3, + label=type(agg).__name__, + linewidths=0.3, + edgecolors="black", + ) + + +list(map(lambda agg: plot_agg(ax, agg), aggs)) +ax.set_xticks([]) +ax.set_yticks([]) +ax.legend() + +fig.tight_layout(pad=0.0, w_pad=0.6, h_pad=0.5) +plt.show() + +# %% +# In this example, the results of Mean deviated away by the +# outliers. All the other are inside the range of benign data. diff --git a/docs/source/_examples/plot_comparing_aggregation_schemes.py.md5 b/docs/source/_examples/plot_comparing_aggregation_schemes.py.md5 new file mode 100644 index 0000000..7eaea69 --- /dev/null +++ b/docs/source/_examples/plot_comparing_aggregation_schemes.py.md5 @@ -0,0 +1 @@ +1e88e3a32d3569e7f4471fe953ba14e1 \ No newline at end of file diff --git a/docs/source/_examples/plot_comparing_aggregation_schemes.rst b/docs/source/_examples/plot_comparing_aggregation_schemes.rst new file mode 100644 index 0000000..ab19f81 --- /dev/null +++ b/docs/source/_examples/plot_comparing_aggregation_schemes.rst @@ -0,0 +1,162 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "_examples/plot_comparing_aggregation_schemes.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + :ref:`Go to the end ` + to download the full example code. + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr__examples_plot_comparing_aggregation_schemes.py: + + +Comparing Buitd-in Aggregation Schemes +========================================== +This example demonstrates the comparison of eight built-in aggregation schemes. +We draw 100 samples from two normal distributions with different mean and co-variance. +The samples are then aggregated using the built-in aggregation rules. + +.. GENERATED FROM PYTHON SOURCE LINES 8-97 + +.. code-block:: Python + + + import matplotlib.pyplot as plt + import numpy as np + import torch + + from blades.aggregators import ( + Clippedclustering, + DnC, + GeoMed, + Mean, + Median, + Multikrum, + Trimmedmean, + ) + + plt.rcParams["axes.linewidth"] = 1.5 # set the value globally + plt.rcParams["font.weight"] = "bold" + plt.rcParams["font.size"] = 16 + plt.rcParams["axes.labelweight"] = "bold" + + np.random.seed(1) + sz = 40 + sample_sz = 80 + + mean = np.array((0, 0)) + cov = [[20, 0], [0, 20]] + benign = np.random.multivariate_normal(mean, cov, 60) + mean = np.array((30, 30)) + cov = [[60, 0], [0, 60]] + outliers = np.concatenate([np.random.multivariate_normal(mean, cov, 40)]) + all_data = np.concatenate([benign, outliers]) + + all_data_tensor = torch.Tensor(np.concatenate([benign, outliers])) + + all_data_tensor = [tensor for tensor in all_data_tensor] + + aggs = [ + Mean(), + Multikrum(len(outliers), 10), + GeoMed(), + Median(), + DnC(num_byzantine=len(outliers)), + Trimmedmean(num_byzantine=len(outliers)), + Clippedclustering(), + ] + + # sphinx_gallery_thumbnail_number = 1 + fig, axs = plt.subplots(figsize=(8, 8)) + + ax = axs + ax.scatter( + benign[:, 0], + benign[:, 1], + s=sample_sz, + alpha=0.6, + color="r", + linewidths=0.2, + edgecolors="black", + ) + ax.scatter( + outliers[:, 0], + outliers[:, 1], + s=sample_sz, + color=[0.0, 0.7, 0.0, 1.0], + linewidths=0.2, + edgecolors="black", + ) + + + def plot_agg(ax, agg): + target = agg(all_data_tensor).cpu().detach().numpy() + ax.scatter( + target[0], + target[1], + s=sz * 3, + label=type(agg).__name__, + linewidths=0.3, + edgecolors="black", + ) + + + list(map(lambda agg: plot_agg(ax, agg), aggs)) + ax.set_xticks([]) + ax.set_yticks([]) + ax.legend() + + fig.tight_layout(pad=0.0, w_pad=0.6, h_pad=0.5) + plt.show() + + + + +.. image-sg:: /_examples/images/sphx_glr_plot_comparing_aggregation_schemes_001.png + :alt: plot comparing aggregation schemes + :srcset: /_examples/images/sphx_glr_plot_comparing_aggregation_schemes_001.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 98-100 + +In this example, the results of Mean deviated away by the +outliers. All the other are inside the range of benign data. + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** (0 minutes 1.304 seconds) + + +.. _sphx_glr_download__examples_plot_comparing_aggregation_schemes.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_comparing_aggregation_schemes.ipynb ` + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_comparing_aggregation_schemes.py ` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/_examples/plot_comparing_aggregation_schemes_codeobj.pickle b/docs/source/_examples/plot_comparing_aggregation_schemes_codeobj.pickle new file mode 100644 index 0000000..a298a1f Binary files /dev/null and b/docs/source/_examples/plot_comparing_aggregation_schemes_codeobj.pickle differ diff --git a/docs/source/_examples/sg_execution_times.rst b/docs/source/_examples/sg_execution_times.rst new file mode 100644 index 0000000..ddc7070 --- /dev/null +++ b/docs/source/_examples/sg_execution_times.rst @@ -0,0 +1,43 @@ + +:orphan: + +.. _sphx_glr__examples_sg_execution_times: + + +Computation times +================= +**00:01.304** total execution time for 3 files **from _examples**: + +.. container:: + + .. raw:: html + + + + + + + + .. list-table:: + :header-rows: 1 + :class: table table-striped sg-datatable + + * - Example + - Time + - Mem (MB) + * - :ref:`sphx_glr__examples_plot_comparing_aggregation_schemes.py` (``plot_comparing_aggregation_schemes.py``) + - 00:01.304 + - 0.0 + * - :ref:`sphx_glr__examples_customize_attack.py` (``customize_attack.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr__examples_toy_example.py` (``toy_example.py``) + - 00:00.000 + - 0.0 diff --git a/docs/source/_examples/toy_example.ipynb b/docs/source/_examples/toy_example.ipynb new file mode 100644 index 0000000..7469a49 --- /dev/null +++ b/docs/source/_examples/toy_example.ipynb @@ -0,0 +1,43 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# A Toy Example\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import ray\nfrom ray import tune\nfrom ray.tune.stopper import MaximumIterationStopper\n\nfrom blades.algorithms.fedavg import FedavgConfig, Fedavg\nfrom fedlib.trainers import TrainerConfig\n\n\nclass ExampleFedavgConfig(FedavgConfig):\n def __init__(self, algo_class=None):\n \"\"\"Initializes a FedavgConfig instance.\"\"\"\n super().__init__(algo_class=algo_class or ExampleFedavg)\n\n self.dataset_config = {\n \"type\": \"FashionMNIST\",\n \"num_clients\": 4,\n \"train_batch_size\": 32,\n }\n self.global_model = \"cnn\"\n\n\nclass ExampleFedavg(Fedavg):\n def __init__(self, config=None, logger_creator=None, **kwargs):\n super().__init__(config, logger_creator, **kwargs)\n\n @classmethod\n def get_default_config(cls) -> TrainerConfig:\n return ExampleFedavgConfig()\n\n\nif __name__ == \"__main__\":\n ray.init()\n\n config_dict = (\n ExampleFedavgConfig()\n .resources(\n num_gpus_for_driver=0.5,\n num_cpus_for_driver=1,\n num_remote_workers=0,\n num_gpus_per_worker=0.5,\n )\n .to_dict()\n )\n print(config_dict)\n tune.run(\n ExampleFedavg,\n config=config_dict,\n stop=MaximumIterationStopper(100),\n )" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.14" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/examples/fedavg_tune.py b/docs/source/_examples/toy_example.py similarity index 94% rename from examples/fedavg_tune.py rename to docs/source/_examples/toy_example.py index 63b37ed..a3aea75 100644 --- a/examples/fedavg_tune.py +++ b/docs/source/_examples/toy_example.py @@ -1,3 +1,10 @@ +""" +A Toy Example +================== + +""" + + import ray from ray import tune from ray.tune.stopper import MaximumIterationStopper @@ -13,7 +20,7 @@ def __init__(self, algo_class=None): self.dataset_config = { "type": "FashionMNIST", - "num_clients": 10, + "num_clients": 4, "train_batch_size": 32, } self.global_model = "cnn" diff --git a/docs/source/_examples/toy_example.rst b/docs/source/_examples/toy_example.rst new file mode 100644 index 0000000..24dfbfa --- /dev/null +++ b/docs/source/_examples/toy_example.rst @@ -0,0 +1,100 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "_examples/toy_example.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + :ref:`Go to the end ` + to download the full example code. + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr__examples_toy_example.py: + + +A Toy Example +================== + +.. GENERATED FROM PYTHON SOURCE LINES 6-57 + +.. code-block:: Python + + + + import ray + from ray import tune + from ray.tune.stopper import MaximumIterationStopper + + from blades.algorithms.fedavg import FedavgConfig, Fedavg + from fedlib.trainers import TrainerConfig + + + class ExampleFedavgConfig(FedavgConfig): + def __init__(self, algo_class=None): + """Initializes a FedavgConfig instance.""" + super().__init__(algo_class=algo_class or ExampleFedavg) + + self.dataset_config = { + "type": "FashionMNIST", + "num_clients": 4, + "train_batch_size": 32, + } + self.global_model = "cnn" + + + class ExampleFedavg(Fedavg): + def __init__(self, config=None, logger_creator=None, **kwargs): + super().__init__(config, logger_creator, **kwargs) + + @classmethod + def get_default_config(cls) -> TrainerConfig: + return ExampleFedavgConfig() + + + if __name__ == "__main__": + ray.init() + + config_dict = ( + ExampleFedavgConfig() + .resources( + num_gpus_for_driver=0.5, + num_cpus_for_driver=1, + num_remote_workers=0, + num_gpus_per_worker=0.5, + ) + .to_dict() + ) + print(config_dict) + tune.run( + ExampleFedavg, + config=config_dict, + stop=MaximumIterationStopper(100), + ) + + +.. _sphx_glr_download__examples_toy_example.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: toy_example.ipynb ` + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: toy_example.py ` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/_examples/toy_example_codeobj.pickle b/docs/source/_examples/toy_example_codeobj.pickle new file mode 100644 index 0000000..5cba767 Binary files /dev/null and b/docs/source/_examples/toy_example_codeobj.pickle differ diff --git a/docs/source/_templates/autosummary/class.rst b/docs/source/_templates/autosummary/class.rst new file mode 100644 index 0000000..8792675 --- /dev/null +++ b/docs/source/_templates/autosummary/class.rst @@ -0,0 +1,2300 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

{{ fullname | escape | underline }}

+
+

{{ module }}

+
+
+

{{ objname }}

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + diff --git a/docs/source/_templates/autosummary/inherited_class.rst b/docs/source/_templates/autosummary/inherited_class.rst new file mode 100644 index 0000000..c96c8a6 --- /dev/null +++ b/docs/source/_templates/autosummary/inherited_class.rst @@ -0,0 +1,2300 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/inherited_class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
9 lines (7 loc) · 187 Bytes

inherited_class.rst

File metadata and controls

9 lines (7 loc) · 187 Bytes

{{ fullname | escape }}

+
+

{{ module }}

+
+
+

{{ objname }}

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + diff --git a/docs/source/_templates/autosummary/only_class.rst b/docs/source/_templates/autosummary/only_class.rst new file mode 100644 index 0000000..9677986 --- /dev/null +++ b/docs/source/_templates/autosummary/only_class.rst @@ -0,0 +1,1644 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/only_class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + diff --git a/docs/source/conf.py b/docs/source/conf.py index 4e6504c..bdaaf77 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -2,7 +2,6 @@ import sys import blades_sphinx_theme - project = "blades" copyright = "2023, Shenghui Li" author = "Shenghui Li" @@ -10,17 +9,34 @@ sys.path.append(osp.join(osp.dirname(blades_sphinx_theme.__file__), "extension")) +example_path = osp.abspath("../../examples") + +print(example_path) +sys.path.insert(0, example_path) # 添加 example 目录到路径 +sys.path.insert(0, osp.abspath("../../blades/aggregators")) # 添加 example 目录到路径 + +# sys.path.insert(0, os.path.abspath("/Users/sheli564/Desktop/blades/src/blades")) +# sys.path.insert(0, os.path.abspath("/Users/sheli564/Desktop/blades/")) + + extensions = [ "sphinx.ext.autodoc", + "sphinx_autodoc_typehints", "sphinx.ext.autosummary", + "sphinx.ext.doctest", + "sphinx.ext.extlinks", "sphinx.ext.intersphinx", "sphinx.ext.mathjax", "sphinx.ext.napoleon", "sphinx.ext.viewcode", "nbsphinx", + "sphinx_gallery.gen_gallery", + "sphinx_gallery.load_style", "blades_sphinx", + "m2r2", ] + templates_path = ["_templates"] exclude_patterns = [] @@ -45,6 +61,13 @@ "torch": ("https://pytorch.org/docs/master", None), } +sphinx_gallery_conf = { + "line_numbers": False, + "ignore_pattern": "/todo_", + "examples_dirs": "../../examples", # path to your example scripts + "gallery_dirs": "_examples", # path to where to save gallery generated output +} + # def setup(app): # def rst_jinja_render(app, _, source): # rst_context = {'torch_geometric': torch_geometric} diff --git a/docs/source/generated/blades.aggregators.Centeredclipping.rst b/docs/source/generated/blades.aggregators.Centeredclipping.rst new file mode 100644 index 0000000..b53ca4c --- /dev/null +++ b/docs/source/generated/blades.aggregators.Centeredclipping.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

blades.aggregators.Centeredclipping +===================================

+
+

blades.aggregators

+
+
+

Centeredclipping

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + diff --git a/docs/source/generated/blades.aggregators.Clippedclustering.rst b/docs/source/generated/blades.aggregators.Clippedclustering.rst new file mode 100644 index 0000000..1b68e91 --- /dev/null +++ b/docs/source/generated/blades.aggregators.Clippedclustering.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

blades.aggregators.Clippedclustering +====================================

+
+

blades.aggregators

+
+
+

Clippedclustering

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + diff --git a/docs/source/generated/blades.aggregators.DnC.rst b/docs/source/generated/blades.aggregators.DnC.rst new file mode 100644 index 0000000..3efb571 --- /dev/null +++ b/docs/source/generated/blades.aggregators.DnC.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

blades.aggregators.DnC +======================

+
+

blades.aggregators

+
+
+

DnC

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + diff --git a/docs/source/generated/blades.aggregators.GeoMed.rst b/docs/source/generated/blades.aggregators.GeoMed.rst new file mode 100644 index 0000000..981f4b6 --- /dev/null +++ b/docs/source/generated/blades.aggregators.GeoMed.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

blades.aggregators.GeoMed +=========================

+
+

blades.aggregators

+
+
+

GeoMed

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + diff --git a/docs/source/generated/blades.aggregators.Mean.rst b/docs/source/generated/blades.aggregators.Mean.rst new file mode 100644 index 0000000..bcfb128 --- /dev/null +++ b/docs/source/generated/blades.aggregators.Mean.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

blades.aggregators.Mean +=======================

+
+

blades.aggregators

+
+
+

Mean

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + diff --git a/docs/source/generated/blades.aggregators.Median.rst b/docs/source/generated/blades.aggregators.Median.rst new file mode 100644 index 0000000..242b3c5 --- /dev/null +++ b/docs/source/generated/blades.aggregators.Median.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

blades.aggregators.Median +=========================

+
+

blades.aggregators

+
+
+

Median

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + diff --git a/docs/source/generated/blades.aggregators.Multikrum.rst b/docs/source/generated/blades.aggregators.Multikrum.rst new file mode 100644 index 0000000..0bf64ab --- /dev/null +++ b/docs/source/generated/blades.aggregators.Multikrum.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

blades.aggregators.Multikrum +============================

+
+

blades.aggregators

+
+
+

Multikrum

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + diff --git a/docs/source/generated/blades.aggregators.Signguard.rst b/docs/source/generated/blades.aggregators.Signguard.rst new file mode 100644 index 0000000..9af80f5 --- /dev/null +++ b/docs/source/generated/blades.aggregators.Signguard.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

blades.aggregators.Signguard +============================

+
+

blades.aggregators

+
+
+

Signguard

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + diff --git a/docs/source/generated/blades.aggregators.Trimmedmean.rst b/docs/source/generated/blades.aggregators.Trimmedmean.rst new file mode 100644 index 0000000..c31c922 --- /dev/null +++ b/docs/source/generated/blades.aggregators.Trimmedmean.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

blades.aggregators.Trimmedmean +==============================

+
+

blades.aggregators

+
+
+

Trimmedmean

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + diff --git a/docs/source/generated/fedlib.aggregators.Centeredclipping.rst b/docs/source/generated/fedlib.aggregators.Centeredclipping.rst new file mode 100644 index 0000000..de5fc98 --- /dev/null +++ b/docs/source/generated/fedlib.aggregators.Centeredclipping.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.aggregators.Centeredclipping +===================================

+
+

fedlib.aggregators

+
+
+

Centeredclipping

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/generated/fedlib.aggregators.Clippedclustering.rst b/docs/source/generated/fedlib.aggregators.Clippedclustering.rst new file mode 100644 index 0000000..6b969a3 --- /dev/null +++ b/docs/source/generated/fedlib.aggregators.Clippedclustering.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.aggregators.Clippedclustering +====================================

+
+

fedlib.aggregators

+
+
+

Clippedclustering

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/generated/fedlib.aggregators.DnC.rst b/docs/source/generated/fedlib.aggregators.DnC.rst new file mode 100644 index 0000000..55809dc --- /dev/null +++ b/docs/source/generated/fedlib.aggregators.DnC.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.aggregators.DnC +======================

+
+

fedlib.aggregators

+
+
+

DnC

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/generated/fedlib.aggregators.GeoMed.rst b/docs/source/generated/fedlib.aggregators.GeoMed.rst new file mode 100644 index 0000000..e808956 --- /dev/null +++ b/docs/source/generated/fedlib.aggregators.GeoMed.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.aggregators.GeoMed +=========================

+
+

fedlib.aggregators

+
+
+

GeoMed

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/generated/fedlib.aggregators.Mean.rst b/docs/source/generated/fedlib.aggregators.Mean.rst new file mode 100644 index 0000000..d6ec523 --- /dev/null +++ b/docs/source/generated/fedlib.aggregators.Mean.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.aggregators.Mean +=======================

+
+

fedlib.aggregators

+
+
+

Mean

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/generated/fedlib.aggregators.Median.rst b/docs/source/generated/fedlib.aggregators.Median.rst new file mode 100644 index 0000000..fafc7f1 --- /dev/null +++ b/docs/source/generated/fedlib.aggregators.Median.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.aggregators.Median +=========================

+
+

fedlib.aggregators

+
+
+

Median

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/generated/fedlib.aggregators.Multikrum.rst b/docs/source/generated/fedlib.aggregators.Multikrum.rst new file mode 100644 index 0000000..427f19f --- /dev/null +++ b/docs/source/generated/fedlib.aggregators.Multikrum.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.aggregators.Multikrum +============================

+
+

fedlib.aggregators

+
+
+

Multikrum

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/generated/fedlib.aggregators.Signguard.rst b/docs/source/generated/fedlib.aggregators.Signguard.rst new file mode 100644 index 0000000..6cd3c53 --- /dev/null +++ b/docs/source/generated/fedlib.aggregators.Signguard.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.aggregators.Signguard +============================

+
+

fedlib.aggregators

+
+
+

Signguard

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/generated/fedlib.aggregators.Trimmedmean.rst b/docs/source/generated/fedlib.aggregators.Trimmedmean.rst new file mode 100644 index 0000000..f2554b5 --- /dev/null +++ b/docs/source/generated/fedlib.aggregators.Trimmedmean.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.aggregators.Trimmedmean +==============================

+
+

fedlib.aggregators

+
+
+

Trimmedmean

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/generated/fedlib.datasets.DatasetPartitioner.rst b/docs/source/generated/fedlib.datasets.DatasetPartitioner.rst new file mode 100644 index 0000000..8ff242e --- /dev/null +++ b/docs/source/generated/fedlib.datasets.DatasetPartitioner.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.datasets.DatasetPartitioner +==================================

+
+

fedlib.datasets

+
+
+

DatasetPartitioner

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/generated/fedlib.datasets.DirichletPartitioner.rst b/docs/source/generated/fedlib.datasets.DirichletPartitioner.rst new file mode 100644 index 0000000..03e735c --- /dev/null +++ b/docs/source/generated/fedlib.datasets.DirichletPartitioner.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.datasets.DirichletPartitioner +====================================

+
+

fedlib.datasets

+
+
+

DirichletPartitioner

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/generated/fedlib.datasets.IIDPartitioner.rst b/docs/source/generated/fedlib.datasets.IIDPartitioner.rst new file mode 100644 index 0000000..eb6ae8b --- /dev/null +++ b/docs/source/generated/fedlib.datasets.IIDPartitioner.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.datasets.IIDPartitioner +==============================

+
+

fedlib.datasets

+
+
+

IIDPartitioner

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/generated/fedlib.datasets.ShardPartitioner.rst b/docs/source/generated/fedlib.datasets.ShardPartitioner.rst new file mode 100644 index 0000000..556720c --- /dev/null +++ b/docs/source/generated/fedlib.datasets.ShardPartitioner.rst @@ -0,0 +1,2302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fedlib/docs/source/_templates/autosummary/class.rst at main · fedlib/fedlib · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + fedlib + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + +

Latest commit

 

History

History
7 lines (5 loc) · 134 Bytes

class.rst

File metadata and controls

7 lines (5 loc) · 134 Bytes

fedlib.datasets.ShardPartitioner +================================

+
+

fedlib.datasets

+
+
+

ShardPartitioner

+
+
+
+ + + + +
+ +
+ +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2024 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/docs/source/install/installation.rst b/docs/source/get_started/installation.rst similarity index 100% rename from docs/source/install/installation.rst rename to docs/source/get_started/installation.rst diff --git a/docs/source/get_started/key_concepts.rst b/docs/source/get_started/key_concepts.rst new file mode 100644 index 0000000..67657e7 --- /dev/null +++ b/docs/source/get_started/key_concepts.rst @@ -0,0 +1,5 @@ +Key Concepts +============= + + +yodayoda diff --git a/docs/source/get_started/overview.rst b/docs/source/get_started/overview.rst new file mode 100644 index 0000000..90228ef --- /dev/null +++ b/docs/source/get_started/overview.rst @@ -0,0 +1,204 @@ +Overview +============= + + +.. raw:: html + + + +.. + .. image:: https://img.shields.io/github/last-commit/lishenghui/blades/master?logo=Github + :alt: GitHub last commit (branch) + :target: https://github.com/lishenghui/blades + .. image:: https://github.com/lishenghui/blades/actions/workflows/unit-tests.yml/badge.svg?branch=master + :alt: GitHub Workflow Status (with event) + + .. container:: badges + + .. image:: https://img.shields.io/github/last-commit/lishenghui/blades/master?logo=Github + :alt: GitHub last commit (branch) + :target: https://github.com/lishenghui/blades + + .. image:: https://github.com/lishenghui/blades/actions/workflows/unit-tests.yml/badge.svg?branch=master + :alt: GitHub Workflow Status (with event) + + .. image:: https://img.shields.io/badge/Pytorch-2.0-brightgreen?logo=pytorch&logoColor=red + :alt: Static Badge + :target: https://pytorch.org/get-started/pytorch-2.0/ + + .. image:: https://img.shields.io/badge/Ray-2.8-brightgreen?logo=ray&logoColor=blue + :alt: Static Badge + :target: https://docs.ray.io/en/releases-2.8.0/ + + .. image:: https://readthedocs.org/projects/blades/badge/?version=latest + :target: https://blades.readthedocs.io/en/latest/?badge=latest + :alt: Documentation Status + + .. image:: https://img.shields.io/github/license/lishenghui/blades?logo=apache&logoColor=red + :alt: GitHub + :target: https://github.com/lishenghui/blades/blob/master/LICENSE + + .. image:: https://img.shields.io/badge/arXiv-2206.05359-red?logo=arxiv&style=flat-square&link=https%3A%2F%2Farxiv.org%2Fpdf%2F2206.05359.pdf + :alt: Static Badge + :target: https://arxiv.org/pdf/2206.05359.pdf + + +.. raw:: html + +

+ Blades Logo +

+ +Installation +================================================== + +.. code-block:: bash + + git clone https://github.com/lishenghui/blades + cd blades + pip install -v -e . + # "-v" means verbose, or more output + # "-e" means installing a project in editable mode, + # thus any local modifications made to the code will take effect without reinstallation. + + +.. code-block:: bash + + cd blades/blades + python train.py file ./tuned_examples/fedsgd_cnn_fashion_mnist.yaml + + +**Blades** internally calls `ray.tune `_; therefore, the experimental results are output to its default directory: ``~/ray_results``. + +Experiment Results +================================================== + +.. image:: https://github.com/lishenghui/blades/blob/master/docs/source/images/fashion_mnist.png + +.. image:: https://github.com/lishenghui/blades/blob/master/docs/source/images/cifar10.png + + + + +Cluster Deployment +=================== + +To run **blades** on a cluster, you only need to deploy ``Ray cluster`` according to the `official guide `_. + + +Built-in Implementations +================================================== +In detail, the following strategies are currently implemented: + + + +Attacks +--------- + +General Attacks +^^^^^^^^^^^^^^^^^ ++--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------+ +| Strategy | Description | Sourse | ++====================+==========================================================================================================================================================================================================+===========================================================================================================+ +| **Noise** | Put random noise to the updates. | `Sourse `_ | ++--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------+ +| **Labelflipping** | `Fang et al. Local Model Poisoning Attacks to Byzantine-Robust Federated Learning `_, *USENIX Security' 20* | `Sourse `_ | ++--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------+ +| **Signflipping** | `Li et al. RSA: Byzantine-Robust Stochastic Aggregation Methods for Distributed Learning from Heterogeneous Datasets `_, *AAAI' 19* | `Sourse `_ | ++--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------+ +| **ALIE** | `Baruch et al. A little is enough: Circumventing defenses for distributed learning `_ *NeurIPS' 19* | `Sourse `_ | ++--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------+ +| **IPM** | `Xie et al. Fall of empires: Breaking byzantine- tolerant sgd by inner product manipulation `_, *UAI' 20* | `Sourse `_ | ++--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------+ + +Adaptive Attacks +^^^^^^^^^^^^^^^^^ ++--------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+ +| Strategy | Description | Sourse | ++==========================+=====================================================================================================================================================================================+=================================================================================================================+ +| **DistanceMaximization** | `Shejwalkar et al. Manipulating the byzantine: Optimizing model poisoning attacks and defenses for federated learning `_, *NDSS' 21* | `Sourse `_ | ++--------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+ + + +.. | **FangAttack** | `Fang et al. Local Model Poisoning Attacks to Byzantine-Robust Federated Learning `_, *USENIX Security' 20* | `Sourse `_ | +.. +--------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+ + + +Defenses +--------- + +Robust Aggregation +^^^^^^^^^^^^^^^^^^^ + ++-----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+ +| Strategy | Descriptions | Source | ++=======================+=============================================================================================================================================================================================================================================================+==========================================================================================================+ +| **MultiKrum** | `Blanchard et al. Machine Learning with Adversaries: Byzantine Tolerant Gradient Descent `_, *NIPS'17* | `Source `_ | ++-----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+ +| **GeoMed** | `Chen et al. Distributed Statistical Machine Learning in Adversarial Settings: Byzantine Gradient Descent `_, *POMACS'18* | `Source `_ | ++-----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+ +| **Median** | `Yin et al. Byzantine-robust distributed learning: Towards optimal statistical rates `_, *ICML'18* | `Source `_ | ++-----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+ +| **TrimmedMean** | `Yin et al. Byzantine-robust distributed learning: Towards optimal statistical rates `_, *ICML'18* | `Source `_ | ++-----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+ +| **CenteredClipping** | `Karimireddy et al. Learning from History for Byzantine Robust Optimization `_, *ICML'21* | `Source `_ | ++-----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+ +| **Clustering** | `Sattler et al. On the byzantine robustness of clustered federated learning `_, *ICASSP'20* | `Source `_ | ++-----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+ +| **ClippedClustering** | `Li et al. An Experimental Study of Byzantine-Robust Aggregation Schemes in Federated Learning `_, *IEEE TBD'23* | `Source `_ | ++-----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+ +| **DnC** | `Shejwalkar et al. Manipulating the Byzantine: Optimizing Model Poisoning Attacks and Defenses for Federated Learning `_, *NDSS'21* | `Source `_ | ++-----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+ +| **SignGuard** | `Xu et al. SignGuard: Byzantine-robust Federated Learning through Collaborative Malicious Gradient Filtering `_, *ICDCS'22* | `Source `_ | ++-----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+ + + +Data Partitioners: +================================================== + +Dirichlet Partitioner +---------------------- + +.. image:: https://github.com/lishenghui/blades/blob/master/docs/source/images/dirichlet_partition.png + +Sharding Partitioner +---------------------- + +.. image:: https://github.com/lishenghui/blades/blob/master/docs/source/images/shard_partition.png + + +Citation +========= + +Please cite our `paper `_ (and the respective papers of the methods used) if you use this code in your own work: + +:: + + @inproceedings{li2024blades, + title={Blades: A Unified Benchmark Suite for Byzantine Attacks and Defenses in Federated Learning}, + author={Li, Shenghui and Ngai, Edith and Ye, Fanghua and Ju, Li and Zhang, Tianru and Voigt, Thiemo}, + booktitle={2024 IEEE/ACM Ninth International Conference on Internet-of-Things Design and Implementation (IoTDI)}, + year={2024} + } diff --git a/docs/source/get_started/quickstart.rst b/docs/source/get_started/quickstart.rst new file mode 100644 index 0000000..6887aaf --- /dev/null +++ b/docs/source/get_started/quickstart.rst @@ -0,0 +1,5 @@ +Quick Start +============= + + +yodayoda diff --git a/docs/source/index.rst b/docs/source/index.rst index 5bda28c..cdea8ef 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -19,16 +19,32 @@ and :ray:`null` `Ray `_ to study the state-of-the-art attacks an .. toctree:: :maxdepth: 1 - :caption: Install Blades + :caption: Getting Started - install/installation + get_started/installation + get_started/overview + get_started/key_concepts + get_started/quickstart + + +.. toctree:: + :maxdepth: 1 + :caption: Example Gallery + + _examples/index + +.. toctree:: + :maxdepth: 1 + :caption: Package Reference + + modules/datasets + modules/aggregators .. toctree:: :maxdepth: 2 :caption: Contents: - Indices and tables ================== diff --git a/docs/source/modules/aggregators.rst b/docs/source/modules/aggregators.rst new file mode 100644 index 0000000..8ebb6ca --- /dev/null +++ b/docs/source/modules/aggregators.rst @@ -0,0 +1,18 @@ +Aggregators +============= + +.. contents:: aggratators + :local: + +Aggregators +------------- + +.. currentmodule:: fedlib.aggregators + +.. autosummary:: + :nosignatures: + :toctree: ../generated + + {% for name in fedlib.aggregators.classes %} + {{ name }} + {% endfor %} diff --git a/docs/source/modules/datasets.rst b/docs/source/modules/datasets.rst new file mode 100644 index 0000000..6aafa37 --- /dev/null +++ b/docs/source/modules/datasets.rst @@ -0,0 +1,18 @@ +Datasets +========== + +.. contents:: Contents + :local: + +Partitioners +------------- + +.. currentmodule:: fedlib.datasets + +.. autosummary:: + :nosignatures: + :toctree: ../generated + + {% for name in fedlib.datasets.all_partitioners %} + {{ name }} + {% endfor %} diff --git a/docs/source/references/aggregators.rst b/docs/source/references/aggregators.rst new file mode 100644 index 0000000..fb9e7ac --- /dev/null +++ b/docs/source/references/aggregators.rst @@ -0,0 +1,27 @@ +Aggregators +============ + +.. currentmodule:: sphinx + +.. autosummary:: + + environment.BuildEnvironment + util.relative_uri + + +.. currentmodule:: blades + +.. automodule:: blades.aggregators.Mean + :members: + :show-inheritance: + :member-order: bysource + +.. automodule:: aggregators.Median + :members: + :show-inheritance: + :member-order: bysource + +.. automodule:: blades.aggregators.Clippedclustering + :members: + :show-inheritance: + :member-order: bysource diff --git a/docs/source/references/api_reference.rst b/docs/source/references/api_reference.rst new file mode 100644 index 0000000..12f838f --- /dev/null +++ b/docs/source/references/api_reference.rst @@ -0,0 +1,10 @@ + +API Reference +=================== + +.. toctree:: + :maxdepth: 3 + :caption: Contents: + :titlesonly: + + aggregators diff --git a/docs/source/sg_execution_times.rst b/docs/source/sg_execution_times.rst new file mode 100644 index 0000000..bea63de --- /dev/null +++ b/docs/source/sg_execution_times.rst @@ -0,0 +1,43 @@ + +:orphan: + +.. _sphx_glr_sg_execution_times: + + +Computation times +================= +**00:01.304** total execution time for 3 files **from all galleries**: + +.. container:: + + .. raw:: html + + + + + + + + .. list-table:: + :header-rows: 1 + :class: table table-striped sg-datatable + + * - Example + - Time + - Mem (MB) + * - :ref:`sphx_glr__examples_plot_comparing_aggregation_schemes.py` (``../../examples/plot_comparing_aggregation_schemes.py``) + - 00:01.304 + - 0.0 + * - :ref:`sphx_glr__examples_customize_attack.py` (``../../examples/customize_attack.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr__examples_toy_example.py` (``../../examples/toy_example.py``) + - 00:00.000 + - 0.0 diff --git a/examples/README.rst b/examples/README.rst new file mode 100644 index 0000000..1cf8a0b --- /dev/null +++ b/examples/README.rst @@ -0,0 +1,4 @@ +Examples +========== + +Below is a gallery of examples diff --git a/examples/customize_attack.py b/examples/customize_attack.py new file mode 100644 index 0000000..6afb7df --- /dev/null +++ b/examples/customize_attack.py @@ -0,0 +1,70 @@ +""" +Customize Attack +================== + +""" + + +import ray +from ray import tune +from ray.tune.stopper import MaximumIterationStopper + +from blades.algorithms.fedavg import FedavgConfig, Fedavg +from fedlib.trainers import TrainerConfig + + +from fedlib.trainers import Trainer +from fedlib.clients import ClientCallback +from blades.adversaries import Adversary + + +class LabelFlipAdversary(Adversary): + def on_trainer_init(self, trainer: Trainer): + class LabelFlipCallback(ClientCallback): + def on_train_batch_begin(self, data, target): + return data, 10 - 1 - target + + for client in self.clients: + client.to_malicious(callbacks_cls=LabelFlipCallback, local_training=True) + + +class ExampleFedavgConfig(FedavgConfig): + def __init__(self, algo_class=None): + """Initializes a FedavgConfig instance.""" + super().__init__(algo_class=algo_class or ExampleFedavg) + + self.dataset_config = { + "type": "FashionMNIST", + "num_clients": 10, + "train_batch_size": 32, + } + self.global_model = "cnn" + self.num_malicious_clients = 1 + self.adversary_config = {"type": LabelFlipAdversary} + + +class ExampleFedavg(Fedavg): + @classmethod + def get_default_config(cls) -> TrainerConfig: + return ExampleFedavgConfig() + + +if __name__ == "__main__": + ray.init() + + config_dict = ( + ExampleFedavgConfig() + .resources( + num_gpus_for_driver=0.0, + num_cpus_for_driver=1, + num_remote_workers=0, + num_gpus_per_worker=0.0, + ) + .to_dict() + ) + print(config_dict) + tune.run( + ExampleFedavg, + config=config_dict, + stop=MaximumIterationStopper(100), + ) diff --git a/examples/plot_comparing_aggregation_schemes.py b/examples/plot_comparing_aggregation_schemes.py new file mode 100644 index 0000000..10b0cc2 --- /dev/null +++ b/examples/plot_comparing_aggregation_schemes.py @@ -0,0 +1,99 @@ +""" +Comparing Buitd-in Aggregation Schemes +========================================== +This example demonstrates the comparison of eight built-in aggregation schemes. +We draw 100 samples from two normal distributions with different mean and co-variance. +The samples are then aggregated using the built-in aggregation rules. +""" + +import matplotlib.pyplot as plt +import numpy as np +import torch + +from blades.aggregators import ( + Clippedclustering, + DnC, + GeoMed, + Mean, + Median, + Multikrum, + Trimmedmean, +) + +plt.rcParams["axes.linewidth"] = 1.5 # set the value globally +plt.rcParams["font.weight"] = "bold" +plt.rcParams["font.size"] = 16 +plt.rcParams["axes.labelweight"] = "bold" + +np.random.seed(1) +sz = 40 +sample_sz = 80 + +mean = np.array((0, 0)) +cov = [[20, 0], [0, 20]] +benign = np.random.multivariate_normal(mean, cov, 60) +mean = np.array((30, 30)) +cov = [[60, 0], [0, 60]] +outliers = np.concatenate([np.random.multivariate_normal(mean, cov, 40)]) +all_data = np.concatenate([benign, outliers]) + +all_data_tensor = torch.Tensor(np.concatenate([benign, outliers])) + +all_data_tensor = [tensor for tensor in all_data_tensor] + +aggs = [ + Mean(), + Multikrum(len(outliers), 10), + GeoMed(), + Median(), + DnC(num_byzantine=len(outliers)), + Trimmedmean(num_byzantine=len(outliers)), + Clippedclustering(), +] + +# sphinx_gallery_thumbnail_number = 1 +fig, axs = plt.subplots(figsize=(8, 8)) + +ax = axs +ax.scatter( + benign[:, 0], + benign[:, 1], + s=sample_sz, + alpha=0.6, + color="r", + linewidths=0.2, + edgecolors="black", +) +ax.scatter( + outliers[:, 0], + outliers[:, 1], + s=sample_sz, + color=[0.0, 0.7, 0.0, 1.0], + linewidths=0.2, + edgecolors="black", +) + + +def plot_agg(ax, agg): + target = agg(all_data_tensor).cpu().detach().numpy() + ax.scatter( + target[0], + target[1], + s=sz * 3, + label=type(agg).__name__, + linewidths=0.3, + edgecolors="black", + ) + + +list(map(lambda agg: plot_agg(ax, agg), aggs)) +ax.set_xticks([]) +ax.set_yticks([]) +ax.legend() + +fig.tight_layout(pad=0.0, w_pad=0.6, h_pad=0.5) +plt.show() + +# %% +# In this example, the results of Mean deviated away by the +# outliers. All the other are inside the range of benign data. diff --git a/examples/toy_example.py b/examples/toy_example.py new file mode 100644 index 0000000..a3aea75 --- /dev/null +++ b/examples/toy_example.py @@ -0,0 +1,56 @@ +""" +A Toy Example +================== + +""" + + +import ray +from ray import tune +from ray.tune.stopper import MaximumIterationStopper + +from blades.algorithms.fedavg import FedavgConfig, Fedavg +from fedlib.trainers import TrainerConfig + + +class ExampleFedavgConfig(FedavgConfig): + def __init__(self, algo_class=None): + """Initializes a FedavgConfig instance.""" + super().__init__(algo_class=algo_class or ExampleFedavg) + + self.dataset_config = { + "type": "FashionMNIST", + "num_clients": 4, + "train_batch_size": 32, + } + self.global_model = "cnn" + + +class ExampleFedavg(Fedavg): + def __init__(self, config=None, logger_creator=None, **kwargs): + super().__init__(config, logger_creator, **kwargs) + + @classmethod + def get_default_config(cls) -> TrainerConfig: + return ExampleFedavgConfig() + + +if __name__ == "__main__": + ray.init() + + config_dict = ( + ExampleFedavgConfig() + .resources( + num_gpus_for_driver=0.5, + num_cpus_for_driver=1, + num_remote_workers=0, + num_gpus_per_worker=0.5, + ) + .to_dict() + ) + print(config_dict) + tune.run( + ExampleFedavg, + config=config_dict, + stop=MaximumIterationStopper(100), + )