We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Clean up Lasso file, make examples work



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `examples/lasso/demo.py`
Content:
```
1 import numpy as np
2 import torch
3 import sys
4 
5 sys.path.append("../../")
6 
7 import heat as ht
8 from matplotlib import pyplot as plt
9 from sklearn import datasets
10 import heat.regression.lasso as lasso
11 import plotfkt
12 
13 # read scikit diabetes data set
14 diabetes = datasets.load_diabetes()
15 
16 # load diabetes dataset from hdf5 file
17 X = ht.load_hdf5("../../heat/datasets/data/diabetes.h5", dataset="x", split=0)
18 y = ht.load_hdf5("../../heat/datasets/data/diabetes.h5", dataset="y", split=0)
19 
20 # normalize dataset #DoTO this goes into the lasso fit routine soon as issue #106 is solved
21 X = X / ht.sqrt((ht.mean(X ** 2, axis=0)))
22 
23 # HeAT lasso instance
24 estimator = lasso.Lasso(max_iter=100)
25 
26 # List  lasso model parameters
27 theta_list = list()
28 
29 # Range of lambda values
30 lamda = np.logspace(0, 4, 10) / 10
31 
32 # compute the lasso path
33 for la in lamda:
34     estimator.lam = la
35     estimator.fit(X, y)
36     theta_list.append(estimator.theta.numpy().flatten())
37 
38 # Stack estimated model parameters into one numpy array
39 theta_lasso = np.stack(theta_list).T
40 
41 # Stack into numpy array
42 theta_lasso = np.stack(theta_list).T[1:, :]
43 
44 # plot lasso paths
45 plotfkt.plot_lasso_path(
46     lamda, theta_lasso, diabetes.feature_names, title="Lasso Paths - HeAT implementation"
47 )
48 
49 if X.is_distributed():
50     distributed = X.comm.rank
51 else:
52     distributed = False
53 
54 # plot only with first rank
55 if distributed is False:
56     plt.show()
57 elif distributed == 0:
58     plt.show()
59
```

Path: `setup.py`
Content:
```
1 from setuptools import setup, find_packages
2 import codecs
3 
4 
5 with codecs.open("README.md", "r", "utf-8") as handle:
6     long_description = handle.read()
7 
8 __version__ = None  # appeases flake, assignment in exec() below
9 with open("./heat/core/version.py") as handle:
10     exec(handle.read())
11 
12 setup(
13     name="heat",
14     packages=find_packages(exclude=("*tests*", "*benchmarks*")),
15     data_files=["README.md", "LICENSE"],
16     version=__version__,
17     description="A framework for high-performance data analytics and machine learning.",
18     long_description=long_description,
19     long_description_content_type="text/markdown",
20     author="Helmholtz Association",
21     author_email="martin.siggel@dlr.de",
22     url="https://github.com/helmholtz-analytics/heat",
23     keywords=["data", "analytics", "tensors", "distributed", "gpu"],
24     python_requires=">=3.7",
25     classifiers=[
26         "Development Status :: 4 - Beta",
27         "Programming Language :: Python :: 3.7",
28         "Programming Language :: Python :: 3.8",
29         "License :: OSI Approved :: MIT License",
30         "Intended Audience :: Science/Research",
31         "Topic :: Scientific/Engineering",
32     ],
33     install_requires=[
34         "mpi4py>=3.0.0",
35         "numpy>=1.13.0",
36         "torch>=1.7.0",
37         "scipy>=0.14.0",
38         "pillow>=6.0.0",
39         "torchvision>=0.8.0",
40     ],
41     extras_require={
42         "docutils": ["docutils>=0.16"],
43         "hdf5": ["h5py>=2.8.0"],
44         "netcdf": ["netCDF4>=1.5.6"],
45         "dev": ["pre-commit>=1.18.3"],
46     },
47 )
48
```

Path: `examples/classification/demo_knn.py`
Content:
```
1 import sys
2 import os
3 import random
4 
5 # Fix python path if run from terminal
6 curdir = os.path.dirname(os.path.abspath(__file__))
7 sys.path.insert(0, os.path.abspath(os.path.join(curdir, "../../")))
8 
9 import heat as ht
10 from heat.classification.kneighborsclassifier import KNeighborsClassifier
11 
12 # Load dataset from hdf5 file
13 X = ht.load_hdf5("../../heat/datasets/data/iris.h5", dataset="data", split=0)
14 
15 # Generate keys for the iris.h5 dataset
16 keys = []
17 for i in range(50):
18     keys.append(0)
19 for i in range(50, 100):
20     keys.append(1)
21 for i in range(100, 150):
22     keys.append(2)
23 Y = ht.array(keys, split=0)
24 
25 
26 def calculate_accuracy(new_y, verification_y):
27     """
28     Calculates the accuracy of classification/clustering-algorithms.
29     Note this only works with integer/discrete classes. For algorithms that give approximations an error function is
30     required.
31 
32     Parameters
33     ----------
34     new_y : ht.tensor of shape (n_samples, n_features), required
35         The new labels that where generated
36     verification_y : ht.tensor of shape (n_samples, n_features), required
37         Known labels
38 
39     Returns
40     ----------
41     float
42         the accuracy, number of properly labeled samples divided by amount of labels.
43     """
44 
45     if new_y.gshape != verification_y.gshape:
46         raise ValueError(
47             "Expecting results of same length, got {}, {}".format(
48                 new_y.gshape, verification_y.gshape
49             )
50         )
51 
52     count = ht.sum(ht.where(new_y == verification_y, 1, 0))
53 
54     return count / new_y.gshape[0]
55 
56 
57 def create_fold(dataset_x, dataset_y, size, seed=None):
58     """
59     Randomly splits the dataset into two parts for cross-validation.
60 
61     Parameters
62     ----------
63     dataset_x : ht.DNDarray
64         data vectors, required
65     dataset_y : ht.DNDarray
66         labels for dataset_x, required
67     size : int
68         the size of the split to create
69     seed: int, optional
70         seed for the random generator, allows deterministic testing
71 
72     Returns
73     ----------
74     fold_x : ht.DNDarray
75         DNDarray of shape (size,) containing data vectors from dataset_x
76     fold_y : ht.DNDarray
77         DNDarray of shape(size,) containing labels from dataset_y
78     verification_x : ht.DNDarray
79         DNDarray of shape(len(dataset_x - size),) containing all items from dataset_x not in fold_x
80     verification_y : ht.DNDarray
81         DNDarray of shape(len(dataset_y - size),) containing all items from dataset_y not in fold_y
82     """
83     assert len(dataset_y) == len(dataset_x)
84     assert size < len(dataset_x)
85 
86     data_length = len(dataset_x)
87 
88     if seed:
89         random.seed(seed)
90     indices = [i for i in range(data_length)]
91     random.shuffle(indices)
92 
93     data_indices = ht.array(indices[0:size], split=0)
94     verification_indices = ht.array(indices[size:], split=0)
95 
96     fold_x = ht.array(dataset_x[data_indices], is_split=0)
97     fold_y = ht.array(dataset_y[data_indices], is_split=0)
98     verification_y = ht.array(dataset_y[verification_indices], is_split=0)
99     verification_x = ht.array(dataset_x[verification_indices], is_split=0)
100 
101     # Balance arrays
102     fold_x.balance_()
103     fold_y.balance_()
104     verification_y.balance_()
105     verification_x.balance_()
106 
107     return fold_x, fold_y, verification_x, verification_y
108 
109 
110 def verify_algorithm(x, y, split_number, split_size, k, seed=None):
111     """
112     Parameters
113     ----------
114     x : ht.DNDarray
115         array containing data vectors
116     y : ht.DNDarray
117         array containing the labels for x (must be in same order)
118     split_number: int
119         the number of test iterations
120     split_size : int
121         the number of vectors used by the KNeighborsClassifier-Algorithm
122     k : int
123         The number of neighbours for KNeighborsClassifier-Algorithm
124     seed : int
125         Seed for the random generator used in creating folds. Used for deterministic testing purposes.
126     Returns
127     -------
128     accuracies : ht.DNDarray
129         array of shape (split_number,) containing the accuracy per run
130     """
131     assert len(x) == len(y)
132     assert split_size < len(x)
133     assert k < len(x)
134 
135     accuracies = []
136 
137     for split_index in range(split_number):
138         fold_x, fold_y, verification_x, verification_y = create_fold(x, y, split_size, seed)
139         classifier = KNeighborsClassifier(fold_x, fold_y, k)
140         result_y = classifier.predict(verification_x)
141         accuracies.append(calculate_accuracy(result_y, verification_y).item())
142     return accuracies
143 
144 
145 print(verify_algorithm(X, Y, 1, 30, 5, 1))
146
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/examples/classification/demo_knn.py b/examples/classification/demo_knn.py
--- a/examples/classification/demo_knn.py
+++ b/examples/classification/demo_knn.py
@@ -10,7 +10,7 @@
 from heat.classification.kneighborsclassifier import KNeighborsClassifier
 
 # Load dataset from hdf5 file
-X = ht.load_hdf5("../../heat/datasets/data/iris.h5", dataset="data", split=0)
+X = ht.load_hdf5("../../heat/datasets/iris.h5", dataset="data", split=0)
 
 # Generate keys for the iris.h5 dataset
 keys = []
diff --git a/examples/lasso/demo.py b/examples/lasso/demo.py
--- a/examples/lasso/demo.py
+++ b/examples/lasso/demo.py
@@ -1,8 +1,11 @@
 import numpy as np
 import torch
 import sys
+import os
 
-sys.path.append("../../")
+# Fix python path if run from terminal
+curdir = os.path.dirname(os.path.abspath(__file__))
+sys.path.insert(0, os.path.abspath(os.path.join(curdir, "../../")))
 
 import heat as ht
 from matplotlib import pyplot as plt
@@ -14,8 +17,8 @@
 diabetes = datasets.load_diabetes()
 
 # load diabetes dataset from hdf5 file
-X = ht.load_hdf5("../../heat/datasets/data/diabetes.h5", dataset="x", split=0)
-y = ht.load_hdf5("../../heat/datasets/data/diabetes.h5", dataset="y", split=0)
+X = ht.load_hdf5("../../heat/datasets/diabetes.h5", dataset="x", split=0)
+y = ht.load_hdf5("../../heat/datasets/diabetes.h5", dataset="y", split=0)
 
 # normalize dataset #DoTO this goes into the lasso fit routine soon as issue #106 is solved
 X = X / ht.sqrt((ht.mean(X ** 2, axis=0)))
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -43,5 +43,6 @@
         "hdf5": ["h5py>=2.8.0"],
         "netcdf": ["netCDF4>=1.5.6"],
         "dev": ["pre-commit>=1.18.3"],
+        "examples": ["scikit-learn>=0.24.0", "matplotlib>=3.1.0"],
     },
 )

{"golden_diff": "diff --git a/examples/classification/demo_knn.py b/examples/classification/demo_knn.py\n--- a/examples/classification/demo_knn.py\n+++ b/examples/classification/demo_knn.py\n@@ -10,7 +10,7 @@\n from heat.classification.kneighborsclassifier import KNeighborsClassifier\n \n # Load dataset from hdf5 file\n-X = ht.load_hdf5(\"../../heat/datasets/data/iris.h5\", dataset=\"data\", split=0)\n+X = ht.load_hdf5(\"../../heat/datasets/iris.h5\", dataset=\"data\", split=0)\n \n # Generate keys for the iris.h5 dataset\n keys = []\ndiff --git a/examples/lasso/demo.py b/examples/lasso/demo.py\n--- a/examples/lasso/demo.py\n+++ b/examples/lasso/demo.py\n@@ -1,8 +1,11 @@\n import numpy as np\n import torch\n import sys\n+import os\n \n-sys.path.append(\"../../\")\n+# Fix python path if run from terminal\n+curdir = os.path.dirname(os.path.abspath(__file__))\n+sys.path.insert(0, os.path.abspath(os.path.join(curdir, \"../../\")))\n \n import heat as ht\n from matplotlib import pyplot as plt\n@@ -14,8 +17,8 @@\n diabetes = datasets.load_diabetes()\n \n # load diabetes dataset from hdf5 file\n-X = ht.load_hdf5(\"../../heat/datasets/data/diabetes.h5\", dataset=\"x\", split=0)\n-y = ht.load_hdf5(\"../../heat/datasets/data/diabetes.h5\", dataset=\"y\", split=0)\n+X = ht.load_hdf5(\"../../heat/datasets/diabetes.h5\", dataset=\"x\", split=0)\n+y = ht.load_hdf5(\"../../heat/datasets/diabetes.h5\", dataset=\"y\", split=0)\n \n # normalize dataset #DoTO this goes into the lasso fit routine soon as issue #106 is solved\n X = X / ht.sqrt((ht.mean(X ** 2, axis=0)))\ndiff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -43,5 +43,6 @@\n         \"hdf5\": [\"h5py>=2.8.0\"],\n         \"netcdf\": [\"netCDF4>=1.5.6\"],\n         \"dev\": [\"pre-commit>=1.18.3\"],\n+        \"examples\": [\"scikit-learn>=0.24.0\", \"matplotlib>=3.1.0\"],\n     },\n )\n", "issue": "Clean up Lasso file, make examples work\n\r\n\n", "before_files": [{"content": "import numpy as np\nimport torch\nimport sys\n\nsys.path.append(\"../../\")\n\nimport heat as ht\nfrom matplotlib import pyplot as plt\nfrom sklearn import datasets\nimport heat.regression.lasso as lasso\nimport plotfkt\n\n# read scikit diabetes data set\ndiabetes = datasets.load_diabetes()\n\n# load diabetes dataset from hdf5 file\nX = ht.load_hdf5(\"../../heat/datasets/data/diabetes.h5\", dataset=\"x\", split=0)\ny = ht.load_hdf5(\"../../heat/datasets/data/diabetes.h5\", dataset=\"y\", split=0)\n\n# normalize dataset #DoTO this goes into the lasso fit routine soon as issue #106 is solved\nX = X / ht.sqrt((ht.mean(X ** 2, axis=0)))\n\n# HeAT lasso instance\nestimator = lasso.Lasso(max_iter=100)\n\n# List  lasso model parameters\ntheta_list = list()\n\n# Range of lambda values\nlamda = np.logspace(0, 4, 10) / 10\n\n# compute the lasso path\nfor la in lamda:\n    estimator.lam = la\n    estimator.fit(X, y)\n    theta_list.append(estimator.theta.numpy().flatten())\n\n# Stack estimated model parameters into one numpy array\ntheta_lasso = np.stack(theta_list).T\n\n# Stack into numpy array\ntheta_lasso = np.stack(theta_list).T[1:, :]\n\n# plot lasso paths\nplotfkt.plot_lasso_path(\n    lamda, theta_lasso, diabetes.feature_names, title=\"Lasso Paths - HeAT implementation\"\n)\n\nif X.is_distributed():\n    distributed = X.comm.rank\nelse:\n    distributed = False\n\n# plot only with first rank\nif distributed is False:\n    plt.show()\nelif distributed == 0:\n    plt.show()\n", "path": "examples/lasso/demo.py"}, {"content": "from setuptools import setup, find_packages\nimport codecs\n\n\nwith codecs.open(\"README.md\", \"r\", \"utf-8\") as handle:\n    long_description = handle.read()\n\n__version__ = None  # appeases flake, assignment in exec() below\nwith open(\"./heat/core/version.py\") as handle:\n    exec(handle.read())\n\nsetup(\n    name=\"heat\",\n    packages=find_packages(exclude=(\"*tests*\", \"*benchmarks*\")),\n    data_files=[\"README.md\", \"LICENSE\"],\n    version=__version__,\n    description=\"A framework for high-performance data analytics and machine learning.\",\n    long_description=long_description,\n    long_description_content_type=\"text/markdown\",\n    author=\"Helmholtz Association\",\n    author_email=\"martin.siggel@dlr.de\",\n    url=\"https://github.com/helmholtz-analytics/heat\",\n    keywords=[\"data\", \"analytics\", \"tensors\", \"distributed\", \"gpu\"],\n    python_requires=\">=3.7\",\n    classifiers=[\n        \"Development Status :: 4 - Beta\",\n        \"Programming Language :: Python :: 3.7\",\n        \"Programming Language :: Python :: 3.8\",\n        \"License :: OSI Approved :: MIT License\",\n        \"Intended Audience :: Science/Research\",\n        \"Topic :: Scientific/Engineering\",\n    ],\n    install_requires=[\n        \"mpi4py>=3.0.0\",\n        \"numpy>=1.13.0\",\n        \"torch>=1.7.0\",\n        \"scipy>=0.14.0\",\n        \"pillow>=6.0.0\",\n        \"torchvision>=0.8.0\",\n    ],\n    extras_require={\n        \"docutils\": [\"docutils>=0.16\"],\n        \"hdf5\": [\"h5py>=2.8.0\"],\n        \"netcdf\": [\"netCDF4>=1.5.6\"],\n        \"dev\": [\"pre-commit>=1.18.3\"],\n    },\n)\n", "path": "setup.py"}, {"content": "import sys\nimport os\nimport random\n\n# Fix python path if run from terminal\ncurdir = os.path.dirname(os.path.abspath(__file__))\nsys.path.insert(0, os.path.abspath(os.path.join(curdir, \"../../\")))\n\nimport heat as ht\nfrom heat.classification.kneighborsclassifier import KNeighborsClassifier\n\n# Load dataset from hdf5 file\nX = ht.load_hdf5(\"../../heat/datasets/data/iris.h5\", dataset=\"data\", split=0)\n\n# Generate keys for the iris.h5 dataset\nkeys = []\nfor i in range(50):\n    keys.append(0)\nfor i in range(50, 100):\n    keys.append(1)\nfor i in range(100, 150):\n    keys.append(2)\nY = ht.array(keys, split=0)\n\n\ndef calculate_accuracy(new_y, verification_y):\n    \"\"\"\n    Calculates the accuracy of classification/clustering-algorithms.\n    Note this only works with integer/discrete classes. For algorithms that give approximations an error function is\n    required.\n\n    Parameters\n    ----------\n    new_y : ht.tensor of shape (n_samples, n_features), required\n        The new labels that where generated\n    verification_y : ht.tensor of shape (n_samples, n_features), required\n        Known labels\n\n    Returns\n    ----------\n    float\n        the accuracy, number of properly labeled samples divided by amount of labels.\n    \"\"\"\n\n    if new_y.gshape != verification_y.gshape:\n        raise ValueError(\n            \"Expecting results of same length, got {}, {}\".format(\n                new_y.gshape, verification_y.gshape\n            )\n        )\n\n    count = ht.sum(ht.where(new_y == verification_y, 1, 0))\n\n    return count / new_y.gshape[0]\n\n\ndef create_fold(dataset_x, dataset_y, size, seed=None):\n    \"\"\"\n    Randomly splits the dataset into two parts for cross-validation.\n\n    Parameters\n    ----------\n    dataset_x : ht.DNDarray\n        data vectors, required\n    dataset_y : ht.DNDarray\n        labels for dataset_x, required\n    size : int\n        the size of the split to create\n    seed: int, optional\n        seed for the random generator, allows deterministic testing\n\n    Returns\n    ----------\n    fold_x : ht.DNDarray\n        DNDarray of shape (size,) containing data vectors from dataset_x\n    fold_y : ht.DNDarray\n        DNDarray of shape(size,) containing labels from dataset_y\n    verification_x : ht.DNDarray\n        DNDarray of shape(len(dataset_x - size),) containing all items from dataset_x not in fold_x\n    verification_y : ht.DNDarray\n        DNDarray of shape(len(dataset_y - size),) containing all items from dataset_y not in fold_y\n    \"\"\"\n    assert len(dataset_y) == len(dataset_x)\n    assert size < len(dataset_x)\n\n    data_length = len(dataset_x)\n\n    if seed:\n        random.seed(seed)\n    indices = [i for i in range(data_length)]\n    random.shuffle(indices)\n\n    data_indices = ht.array(indices[0:size], split=0)\n    verification_indices = ht.array(indices[size:], split=0)\n\n    fold_x = ht.array(dataset_x[data_indices], is_split=0)\n    fold_y = ht.array(dataset_y[data_indices], is_split=0)\n    verification_y = ht.array(dataset_y[verification_indices], is_split=0)\n    verification_x = ht.array(dataset_x[verification_indices], is_split=0)\n\n    # Balance arrays\n    fold_x.balance_()\n    fold_y.balance_()\n    verification_y.balance_()\n    verification_x.balance_()\n\n    return fold_x, fold_y, verification_x, verification_y\n\n\ndef verify_algorithm(x, y, split_number, split_size, k, seed=None):\n    \"\"\"\n    Parameters\n    ----------\n    x : ht.DNDarray\n        array containing data vectors\n    y : ht.DNDarray\n        array containing the labels for x (must be in same order)\n    split_number: int\n        the number of test iterations\n    split_size : int\n        the number of vectors used by the KNeighborsClassifier-Algorithm\n    k : int\n        The number of neighbours for KNeighborsClassifier-Algorithm\n    seed : int\n        Seed for the random generator used in creating folds. Used for deterministic testing purposes.\n    Returns\n    -------\n    accuracies : ht.DNDarray\n        array of shape (split_number,) containing the accuracy per run\n    \"\"\"\n    assert len(x) == len(y)\n    assert split_size < len(x)\n    assert k < len(x)\n\n    accuracies = []\n\n    for split_index in range(split_number):\n        fold_x, fold_y, verification_x, verification_y = create_fold(x, y, split_size, seed)\n        classifier = KNeighborsClassifier(fold_x, fold_y, k)\n        result_y = classifier.predict(verification_x)\n        accuracies.append(calculate_accuracy(result_y, verification_y).item())\n    return accuracies\n\n\nprint(verify_algorithm(X, Y, 1, 30, 5, 1))\n", "path": "examples/classification/demo_knn.py"}], "after_files": [{"content": "import numpy as np\nimport torch\nimport sys\nimport os\n\n# Fix python path if run from terminal\ncurdir = os.path.dirname(os.path.abspath(__file__))\nsys.path.insert(0, os.path.abspath(os.path.join(curdir, \"../../\")))\n\nimport heat as ht\nfrom matplotlib import pyplot as plt\nfrom sklearn import datasets\nimport heat.regression.lasso as lasso\nimport plotfkt\n\n# read scikit diabetes data set\ndiabetes = datasets.load_diabetes()\n\n# load diabetes dataset from hdf5 file\nX = ht.load_hdf5(\"../../heat/datasets/diabetes.h5\", dataset=\"x\", split=0)\ny = ht.load_hdf5(\"../../heat/datasets/diabetes.h5\", dataset=\"y\", split=0)\n\n# normalize dataset #DoTO this goes into the lasso fit routine soon as issue #106 is solved\nX = X / ht.sqrt((ht.mean(X ** 2, axis=0)))\n\n# HeAT lasso instance\nestimator = lasso.Lasso(max_iter=100)\n\n# List  lasso model parameters\ntheta_list = list()\n\n# Range of lambda values\nlamda = np.logspace(0, 4, 10) / 10\n\n# compute the lasso path\nfor la in lamda:\n    estimator.lam = la\n    estimator.fit(X, y)\n    theta_list.append(estimator.theta.numpy().flatten())\n\n# Stack estimated model parameters into one numpy array\ntheta_lasso = np.stack(theta_list).T\n\n# Stack into numpy array\ntheta_lasso = np.stack(theta_list).T[1:, :]\n\n# plot lasso paths\nplotfkt.plot_lasso_path(\n    lamda, theta_lasso, diabetes.feature_names, title=\"Lasso Paths - HeAT implementation\"\n)\n\nif X.is_distributed():\n    distributed = X.comm.rank\nelse:\n    distributed = False\n\n# plot only with first rank\nif distributed is False:\n    plt.show()\nelif distributed == 0:\n    plt.show()\n", "path": "examples/lasso/demo.py"}, {"content": "from setuptools import setup, find_packages\nimport codecs\n\n\nwith codecs.open(\"README.md\", \"r\", \"utf-8\") as handle:\n    long_description = handle.read()\n\n__version__ = None  # appeases flake, assignment in exec() below\nwith open(\"./heat/core/version.py\") as handle:\n    exec(handle.read())\n\nsetup(\n    name=\"heat\",\n    packages=find_packages(exclude=(\"*tests*\", \"*benchmarks*\")),\n    data_files=[\"README.md\", \"LICENSE\"],\n    version=__version__,\n    description=\"A framework for high-performance data analytics and machine learning.\",\n    long_description=long_description,\n    long_description_content_type=\"text/markdown\",\n    author=\"Helmholtz Association\",\n    author_email=\"martin.siggel@dlr.de\",\n    url=\"https://github.com/helmholtz-analytics/heat\",\n    keywords=[\"data\", \"analytics\", \"tensors\", \"distributed\", \"gpu\"],\n    python_requires=\">=3.7\",\n    classifiers=[\n        \"Development Status :: 4 - Beta\",\n        \"Programming Language :: Python :: 3.7\",\n        \"Programming Language :: Python :: 3.8\",\n        \"License :: OSI Approved :: MIT License\",\n        \"Intended Audience :: Science/Research\",\n        \"Topic :: Scientific/Engineering\",\n    ],\n    install_requires=[\n        \"mpi4py>=3.0.0\",\n        \"numpy>=1.13.0\",\n        \"torch>=1.7.0\",\n        \"scipy>=0.14.0\",\n        \"pillow>=6.0.0\",\n        \"torchvision>=0.8.0\",\n    ],\n    extras_require={\n        \"docutils\": [\"docutils>=0.16\"],\n        \"hdf5\": [\"h5py>=2.8.0\"],\n        \"netcdf\": [\"netCDF4>=1.5.6\"],\n        \"dev\": [\"pre-commit>=1.18.3\"],\n        \"examples\": [\"scikit-learn>=0.24.0\", \"matplotlib>=3.1.0\"],\n    },\n)\n", "path": "setup.py"}, {"content": "import sys\nimport os\nimport random\n\n# Fix python path if run from terminal\ncurdir = os.path.dirname(os.path.abspath(__file__))\nsys.path.insert(0, os.path.abspath(os.path.join(curdir, \"../../\")))\n\nimport heat as ht\nfrom heat.classification.kneighborsclassifier import KNeighborsClassifier\n\n# Load dataset from hdf5 file\nX = ht.load_hdf5(\"../../heat/datasets/iris.h5\", dataset=\"data\", split=0)\n\n# Generate keys for the iris.h5 dataset\nkeys = []\nfor i in range(50):\n    keys.append(0)\nfor i in range(50, 100):\n    keys.append(1)\nfor i in range(100, 150):\n    keys.append(2)\nY = ht.array(keys, split=0)\n\n\ndef calculate_accuracy(new_y, verification_y):\n    \"\"\"\n    Calculates the accuracy of classification/clustering-algorithms.\n    Note this only works with integer/discrete classes. For algorithms that give approximations an error function is\n    required.\n\n    Parameters\n    ----------\n    new_y : ht.tensor of shape (n_samples, n_features), required\n        The new labels that where generated\n    verification_y : ht.tensor of shape (n_samples, n_features), required\n        Known labels\n\n    Returns\n    ----------\n    float\n        the accuracy, number of properly labeled samples divided by amount of labels.\n    \"\"\"\n\n    if new_y.gshape != verification_y.gshape:\n        raise ValueError(\n            \"Expecting results of same length, got {}, {}\".format(\n                new_y.gshape, verification_y.gshape\n            )\n        )\n\n    count = ht.sum(ht.where(new_y == verification_y, 1, 0))\n\n    return count / new_y.gshape[0]\n\n\ndef create_fold(dataset_x, dataset_y, size, seed=None):\n    \"\"\"\n    Randomly splits the dataset into two parts for cross-validation.\n\n    Parameters\n    ----------\n    dataset_x : ht.DNDarray\n        data vectors, required\n    dataset_y : ht.DNDarray\n        labels for dataset_x, required\n    size : int\n        the size of the split to create\n    seed: int, optional\n        seed for the random generator, allows deterministic testing\n\n    Returns\n    ----------\n    fold_x : ht.DNDarray\n        DNDarray of shape (size,) containing data vectors from dataset_x\n    fold_y : ht.DNDarray\n        DNDarray of shape(size,) containing labels from dataset_y\n    verification_x : ht.DNDarray\n        DNDarray of shape(len(dataset_x - size),) containing all items from dataset_x not in fold_x\n    verification_y : ht.DNDarray\n        DNDarray of shape(len(dataset_y - size),) containing all items from dataset_y not in fold_y\n    \"\"\"\n    assert len(dataset_y) == len(dataset_x)\n    assert size < len(dataset_x)\n\n    data_length = len(dataset_x)\n\n    if seed:\n        random.seed(seed)\n    indices = [i for i in range(data_length)]\n    random.shuffle(indices)\n\n    data_indices = ht.array(indices[0:size], split=0)\n    verification_indices = ht.array(indices[size:], split=0)\n\n    fold_x = ht.array(dataset_x[data_indices], is_split=0)\n    fold_y = ht.array(dataset_y[data_indices], is_split=0)\n    verification_y = ht.array(dataset_y[verification_indices], is_split=0)\n    verification_x = ht.array(dataset_x[verification_indices], is_split=0)\n\n    # Balance arrays\n    fold_x.balance_()\n    fold_y.balance_()\n    verification_y.balance_()\n    verification_x.balance_()\n\n    return fold_x, fold_y, verification_x, verification_y\n\n\ndef verify_algorithm(x, y, split_number, split_size, k, seed=None):\n    \"\"\"\n    Parameters\n    ----------\n    x : ht.DNDarray\n        array containing data vectors\n    y : ht.DNDarray\n        array containing the labels for x (must be in same order)\n    split_number: int\n        the number of test iterations\n    split_size : int\n        the number of vectors used by the KNeighborsClassifier-Algorithm\n    k : int\n        The number of neighbours for KNeighborsClassifier-Algorithm\n    seed : int\n        Seed for the random generator used in creating folds. Used for deterministic testing purposes.\n    Returns\n    -------\n    accuracies : ht.DNDarray\n        array of shape (split_number,) containing the accuracy per run\n    \"\"\"\n    assert len(x) == len(y)\n    assert split_size < len(x)\n    assert k < len(x)\n\n    accuracies = []\n\n    for split_index in range(split_number):\n        fold_x, fold_y, verification_x, verification_y = create_fold(x, y, split_size, seed)\n        classifier = KNeighborsClassifier(fold_x, fold_y, k)\n        result_y = classifier.predict(verification_x)\n        accuracies.append(calculate_accuracy(result_y, verification_y).item())\n    return accuracies\n\n\nprint(verify_algorithm(X, Y, 1, 30, 5, 1))\n", "path": "examples/classification/demo_knn.py"}]}