Skip to content

Commit 60b6a8e

Browse files
committed
Update README and formatting + new release
1 parent 58e5a9f commit 60b6a8e

File tree

4 files changed

+111
-23
lines changed

4 files changed

+111
-23
lines changed

README.md

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,91 @@
1-
# Hyperdimensional Computing Library
1+
<h1 align="center">
2+
<a href="https://mikeheddes.github.io/hdc-lib">Hyperdimensional Computing Library</a><br/>
23

3-
The `hdc` library is a comprehensive package for all hyperdimensional computing related tasks.
4+
</h1>
5+
<p align="center">
6+
<a href="https://github.com/mikeheddes/hdc-lib/blob/main/LICENSE">
7+
<img alt="GitHub license" src="https://img.shields.io/badge/license-MIT-orange.svg?style=flat" /></a>
8+
<a href="https://pypi.org/project/hdc/"><img alt="pypi version" src="https://img.shields.io/pypi/v/hdc.svg?style=flat&color=orange" /></a>
9+
<a href="https://github.com/mikeheddes/hdc-lib/actions/workflows/test.yml?query=branch%3Amain"><img alt="tests status" src="https://img.shields.io/github/workflow/status/mikeheddes/hdc-lib/Testing/main?label=tests&style=flat" /></a>
10+
<img alt="PRs Welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" />
11+
</p>
12+
13+
This is a Python library for Hyperdimensional Computing.
14+
15+
* **Easy-to-use:** This library makes it painless to develop a wide range of Hyperdimensional Computing (HDC) applications and algorithms. For someone new to the field we provide Pythonic abstractions and examples to get you started fast. For the experienced researchers we made the library modular by design, giving you endless flexibility to prototype new ideas in no-time.
16+
* **Performant:** The library is build on top of the high-performance PyTorch library, giving you optimized tensor execution without the headaches. Moreover, PyTorch makes it effortless to accelerate your code on a GPU.
417

518
## Installation
619

20+
The library is hosted on PyPi and Conda, use one of the following commands to install:
21+
722
```bash
8-
# Note: torch is a prerequisite of hdc, see: https://pytorch.org/get-started/locally/ for an installation guide.
923
pip install hdc
1024
```
1125

12-
## Creating a new release
26+
```bash
27+
conda install -c conda-forge hdc
28+
```
29+
30+
## Documentation
31+
32+
You can find the library's documentation [on the website](https://mikeheddes.github.io/hdc-lib).
33+
34+
## Examples
35+
36+
We have several examples [in the repository](/examples/). Here is a simple one to get you started:
37+
38+
```python
39+
import hdc
40+
import torch
41+
42+
d = 10000 # number of dimensions
43+
44+
### create a hypervector for each symbol
45+
# keys for each field of the dictionary: fruit, weight, and season
46+
keys = hdc.functional.random_hv(3, d)
47+
# fruits are: apple, lemon, mango
48+
fruits = hdc.functional.random_hv(3, d)
49+
# there are 10 weight levels
50+
weights = hdc.functional.level_hv(10, d)
51+
# the for seasons: winter, spring, summer, fall
52+
seasons = hdc.functional.circular_hv(4, d)
53+
54+
# map a float between min, max to an index of size 10
55+
# we map the 10 weight levels between 0 to 200 grams
56+
weight_index = hdc.functional.value_to_index(149.0, 0, 200, 10)
57+
58+
values = torch.stack([
59+
fruits[0],
60+
weights[weight_index],
61+
seasons[3],
62+
])
63+
# creates a dictionary:
64+
# record = key[0] * value[0] + key[1] * value[1] + key[2] * value[2]
65+
record = hdc.functional.struct(keys, values)
66+
67+
#### Similar Python code
68+
#
69+
# record = dict(
70+
# fruit="apple",
71+
# weight=149.0,
72+
# season="fall"
73+
# )
74+
#
75+
```
76+
77+
This example creates a hypervector that represents the record of a fruit, storing its species, weight, and growing season as one hypervector. This is achieved by combining the atomic information units into a structure (similar to a Python dictionary).
78+
79+
You will notice that we first declare all the symbols which are used to represent information. Note the type of hypervector used for each type of information, the fruits and keys use random hypervectors as they represent unrelated information whereas the weights and seasons use level and circular-hypervectors because they have linear and circular-correlations, respectively.
80+
81+
## Contributing
82+
83+
### Creating a New Release
84+
85+
- A GitHub release triggers a GitHub action that builds the library and publishes it to PyPi and Conda in addition to the documentation website.
86+
- Before creating a new GitHub release, increment the version number in [setup.py](/setup.py) using [semantic versioning](https://semver.org).
87+
- When creating a new GitHub release, set the tag to be "v{version number}", e.g., v1.5.2, and provide a clear description of the changes.
1388

14-
- Before creating a new release, increment the version number by 0.1 to have the workflow update the PyPi documentation.
15-
- On creating a new release, set the tag to be "v{version number}". Example: v0.5
89+
### License
1690

17-
New release should update both the PyPi library as well as documentation website.
91+
This library is [MIT licensed](./LICENSE).

hdc/datasets/airfoil_self_noise.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import math
88
from .utils import download_file, unzip_file
99

10+
1011
class AirfoilSelfNoise(data.Dataset):
1112
"""NASA data set <https://archive.ics.uci.edu/ml/datasets/airfoil+self-noise>`_, obtained from a series of aerodynamic and acoustic tests of two and three-dimensional airfoil blade sections conducted in an anechoic wind tunnel.
1213
@@ -21,6 +22,7 @@ class AirfoilSelfNoise(data.Dataset):
2122
target_transform (callable, optional): A function/transform that takes in the
2223
target and transforms it.
2324
"""
25+
2426
def __init__(
2527
self,
2628
root: str,
@@ -69,22 +71,25 @@ def __getitem__(self, index: int) -> Tuple[torch.FloatTensor, torch.FloatTensor]
6971
label = self.target_transform(label)
7072

7173
return sample, label
72-
74+
7375
def _check_integrity(self) -> bool:
7476
if not os.path.isdir(self.root):
7577
return False
76-
78+
7779
# Check if root directory contains the required data file
78-
has_data_file = os.path.isfile(os.path.join(self.root, "airfoil_self_noise.dat"))
80+
has_data_file = os.path.isfile(
81+
os.path.join(self.root, "airfoil_self_noise.dat")
82+
)
7983
if has_data_file:
8084
return True
81-
85+
8286
return False
8387

8488
def _load_data(self):
8589
file_name = "airfoil_self_noise.dat"
86-
data = pd.read_csv(os.path.join(self.root, file_name),
87-
delim_whitespace=True, header=None)
90+
data = pd.read_csv(
91+
os.path.join(self.root, file_name), delim_whitespace=True, header=None
92+
)
8893
self.data = torch.tensor(data.values[:, :-1], dtype=torch.float)
8994
self.targets = torch.tensor(data.values[:, -1], dtype=torch.float)
9095

@@ -94,13 +99,10 @@ def download(self):
9499
if self._check_integrity():
95100
print("Files already downloaded and verified")
96101
return
97-
102+
98103
zip_file_path = os.path.join(self.root, "airfoil_self_noise.dat")
99104

100105
download_file(
101106
"https://archive.ics.uci.edu/ml/machine-learning-databases/00291/airfoil_self_noise.dat",
102-
zip_file_path)
103-
104-
105-
106-
107+
zip_file_path,
108+
)

hdc/datasets/pamap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def _load_data(self):
230230
features = torch.tensor(data.values, dtype=torch.long)
231231
clean_labels = torch.cat((clean_labels, labels))
232232
clean_features = torch.cat((clean_features, features))
233-
233+
234234
self.data = clean_features
235235
self.targets = clean_labels
236236

setup.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
"""A setuptools based setup module.
2+
See:
3+
https://packaging.python.org/guides/distributing-packages-using-setuptools/
4+
https://github.com/pypa/sampleproject
5+
"""
16
from setuptools import setup
27

38
setup(
49
name="hdc",
5-
version="0.4",
6-
description="A python library for hyperdimensional computing",
10+
version="0.5.0",
11+
description="Python library for Hyperdimensional Computing",
12+
long_description=open("README.md").read(),
13+
long_description_content_type="text/markdown",
714
url="https://github.com/mikeheddes/hdc-lib",
815
license="MIT",
16+
install_requires=open("requirements.txt").readlines(),
917
packages=["hdc"],
10-
zip_safe=False,
18+
python_requires=">=3.6, <4",
19+
project_urls={
20+
"Source": "https://github.com/mikeheddes/hdc-lib/",
21+
"Documentation": "https://mikeheddes.github.io/hdc-lib/",
22+
},
1123
)

0 commit comments

Comments
 (0)