Sparse Distributed Memory for Python
What is this?
This is a fast implementation of Pentti Kanerva's Sparse Distributed Memory (SDM). sdmlib is written in Python using numpy.
Installation
The package is available through PyPi:
pip install sdmlib
Using sdmlib
sdmlib is designed to operate on numpy arrays.
The Memory class
This class provides the main functionality of SDM.
| Parameter | Description |
|---|---|
N |
Length of addresses in bits |
M |
Number of hard addresses |
U |
Length of data in bits |
d |
Hamming radius of addresses considered "near" for reading and writing. If None, then it is computed using T |
T |
(Default: None) Number of data points to be written. Ignored if d is provided. If T is None then d must be provided. d and T cannot both be None |
seed |
Seed the random number generator (for reproducability) |
Example Usage
import numpy as np
from sdmlib import Memory
N = 256
M = 1000
U = 256
T = 100
addresses = np.random.randint(low=0, high=2, size=(T, N), dtype=np.uint8)
data = np.random.randint(low=0, high=2, size=(T, U), dtype=np.uint8)
mem = Memory(N=N, M=M, U=U, d=None, T=T)
for t in range(T):
mem.write(addresses[t], data[t])
error = 0
for t in range(T):
error += np.mean(data[t] != mem.read(addresses[t]))/T
print(f'Reconstruction error: {100*error:.2f}%')
Reconstruction error: 0.51%
The write method
Write a binary string to memory.
| Parameter | Description |
|---|---|
x |
Address. Binary numpy array of shape (N,) |
w |
Data. Binary numpy array of shape (U,) |
The read method
Read a binary string from memory.
| Parameter | Description |
|---|---|
x |
Address. Binary numpy array of shape (N,) |
| Returns | Description |
|---|---|
z |
Data. Binary numpy array of shape (U,) |
Metadata
Release files for sdmlib 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sdmlib-0.1.2.tar.gz | 2.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sdmlib-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.6 kB
Release files / sdmlib-0.1.2.tar.gz
| Download URL | sdmlib-0.1.2.tar.gz |
|---|---|
| Size | 2.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d5ebc5c85d7965a6b9a7e76188b1a63326a748ca17df2cbebf1bd5e423da2300
|
|
BLAKE2b-256 checksum How to use checksums |
b345eb609d5a13c57c0e8a6502617c10a8efb63852ea352833a61c1f2b9ffa7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.5
|
Release files / sdmlib-0.1.2-py3-none-any.whl
| Download URL | sdmlib-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a933f95ff730ccd8c611aba6dc77b57866ce0490c2fe8fac6f18b270994a57ee
|
|
BLAKE2b-256 checksum How to use checksums |
289c4121abdcb5725bdf00f46c7fdbd60d296c84663fa9aa3c46cce175c7abc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.5
|
Security for sdmlib 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.