├── .github ├── pull_request_template.md └── workflows │ ├── format.yml │ ├── publish.yml │ └── test.yml ├── .gitignore ├── .readthedocs.yaml ├── CITATION.cff ├── LICENSE ├── README.md ├── conda └── meta.yaml ├── dev-requirements.txt ├── docs ├── .gitignore ├── _static │ └── css │ │ └── custom.css ├── _templates │ ├── class.rst │ ├── class_classifier.rst │ ├── class_dataset.rst │ └── function.rst ├── classification.rst ├── classifiers.rst ├── conf.py ├── datasets.rst ├── docutils.conf ├── embeddings.rst ├── getting_started.rst ├── images │ ├── basis-hvs.png │ ├── torchhd-logo.png │ └── torchhd-logo.svg ├── index.rst ├── memory.rst ├── models.rst ├── requirements.txt ├── structures.rst ├── torchhd.rst └── utils.rst ├── examples ├── README.md ├── UCI_benchmark_intRVFL.py ├── classifiers.py ├── emg_hand_gestures.py ├── fractional_power_encoding_kernels.ipynb ├── graphhd.py ├── hd_hashing.py ├── language_recognition.py ├── learning_with_hrr.py ├── mnist.py ├── mnist_hugging_face.py ├── mnist_nonlinear.py ├── random_projection.py ├── reghd.py └── voicehd.py ├── setup.py └── torchhd ├── __init__.py ├── classifiers.py ├── datasets ├── __init__.py ├── abalone.py ├── acute_inflammation.py ├── acute_nephritis.py ├── adult.py ├── airfoil_self_noise.py ├── annealing.py ├── arrhythmia.py ├── audiology_std.py ├── balance_scale.py ├── balloons.py ├── bank.py ├── beijing_air_quality.py ├── blood.py ├── breast_cancer.py ├── breast_cancer_wisc.py ├── breast_cancer_wisc_diag.py ├── breast_cancer_wisc_prog.py ├── breast_tissue.py ├── car.py ├── cardiotocography_10clases.py ├── cardiotocography_3clases.py ├── ccpp.py ├── chess_krvk.py ├── chess_krvkp.py ├── congressional_voting.py ├── conn_bench_sonar_mines_rocks.py ├── conn_bench_vowel_deterding.py ├── connect_4.py ├── contrac.py ├── credit_approval.py ├── cylinder_bands.py ├── dataset.py ├── dermatology.py ├── echocardiogram.py ├── ecoli.py ├── emg_hand_gestures.py ├── energy_y1.py ├── energy_y2.py ├── european_languages.py ├── fertility.py ├── flags.py ├── glass.py ├── haberman_survival.py ├── hayes_roth.py ├── heart_cleveland.py ├── heart_hungarian.py ├── heart_switzerland.py ├── heart_va.py ├── hepatitis.py ├── hill_valley.py ├── horse_colic.py ├── ilpd_indian_liver.py ├── image_segmentation.py ├── ionosphere.py ├── iris.py ├── isolet.py ├── led_display.py ├── lenses.py ├── letter.py ├── libras.py ├── low_res_spect.py ├── lung_cancer.py ├── lymphography.py ├── magic.py ├── mammographic.py ├── miniboone.py ├── molec_biol_promoter.py ├── molec_biol_splice.py ├── monks_1.py ├── monks_2.py ├── monks_3.py ├── mushroom.py ├── musk_1.py ├── musk_2.py ├── nursery.py ├── oocytes_merluccius_nucleus_4d.py ├── oocytes_merluccius_states_2f.py ├── oocytes_trisopterus_nucleus_2f.py ├── oocytes_trisopterus_states_5b.py ├── optical.py ├── ozone.py ├── page_blocks.py ├── pamap.py ├── parkinsons.py ├── pendigits.py ├── pima.py ├── pittsburg_bridges_material.py ├── pittsburg_bridges_rel_l.py ├── pittsburg_bridges_span.py ├── pittsburg_bridges_t_or_d.py ├── pittsburg_bridges_type.py ├── planning.py ├── plant_margin.py ├── plant_shape.py ├── plant_texture.py ├── post_operative.py ├── primary_tumor.py ├── ringnorm.py ├── seeds.py ├── semeion.py ├── soybean.py ├── spambase.py ├── spect.py ├── spectf.py ├── statlog_australian_credit.py ├── statlog_german_credit.py ├── statlog_heart.py ├── statlog_image.py ├── statlog_landsat.py ├── statlog_shuttle.py ├── statlog_vehicle.py ├── steel_plates.py ├── synthetic_control.py ├── teaching.py ├── thyroid.py ├── tic_tac_toe.py ├── titanic.py ├── trains.py ├── twonorm.py ├── ucihar.py ├── utils.py ├── vertebral_column_2clases.py ├── vertebral_column_3clases.py ├── wall_following.py ├── waveform.py ├── waveform_noise.py ├── wine.py ├── wine_quality_red.py ├── wine_quality_white.py ├── yeast.py └── zoo.py ├── embeddings.py ├── functional.py ├── memory.py ├── models.py ├── structures.py ├── tensors ├── __init__.py ├── base.py ├── basemcr.py ├── bsbc.py ├── bsc.py ├── cgr.py ├── fhrr.py ├── hrr.py ├── map.py ├── mcr.py └── vtb.py ├── tests ├── __init__.py ├── basis_hv │ ├── __init__.py │ ├── test_base_tensor.py │ ├── test_circular_hv.py │ ├── test_empty_hv.py │ ├── test_identity_hv.py │ ├── test_level_hv.py │ └── test_random_hv.py ├── structures │ ├── __init__.py │ ├── test_distinct_sequence.py │ ├── test_fsa.py │ ├── test_graph.py │ ├── test_hashtable.py │ ├── test_memory.py │ ├── test_multiset.py │ ├── test_sequence.py │ └── test_tree.py ├── test_datasets.py ├── test_embeddings.py ├── test_encodings.py ├── test_memory.py ├── test_models.py ├── test_operations.py ├── test_similarities.py ├── test_utilities.py └── utils.py ├── types.py ├── utils.py └── version.py /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Description 4 | 5 | 6 | 7 | 8 | 9 | ## Checklist 10 | - [ ] I added/updated documentation for the changes. 11 | - [ ] I have thoroughly tested the changes. 12 | -------------------------------------------------------------------------------- /.github/workflows/format.yml: -------------------------------------------------------------------------------- 1 | # Uses Black to reformat the Python code on the all but the main branch. 2 | 3 | name: Format 4 | 5 | on: 6 | push: 7 | branches: 8 | - '**' # matches every branch 9 | - '!main' # excludes master 10 | 11 | permissions: 12 | contents: write 13 | 14 | jobs: 15 | format: 16 | runs-on: ubuntu-latest 17 | steps: 18 | # Checkout the main branch 19 | - uses: actions/checkout@v3 20 | 21 | # Setup Python environment 22 | - uses: actions/setup-python@v3 23 | 24 | # Install black 25 | - name: Install black 26 | run: pip install black 27 | 28 | # Execute black in check mode 29 | - name: Black 30 | id: black 31 | run: echo ::set-output name=format::$(black --check --quiet . || echo "true") 32 | 33 | # Execute black and commit the change to the main branch 34 | - name: Commit to the main branch 35 | if: steps.black.outputs.format == 'true' 36 | run: | 37 | black . 38 | git config --global user.name 'github-actions[bot]' 39 | git config --global user.email 'github-actions[bot]@users.noreply.github.com' 40 | git commit -am "[github-action] formatting fixes" 41 | git push 42 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | pypi: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v3 15 | - name: Set up Python 16 | uses: actions/setup-python@v3 17 | with: 18 | python-version: 3.12 19 | - name: Install dependencies 20 | run: | 21 | python -m pip install --upgrade pip 22 | pip install setuptools wheel 23 | pip install build --user 24 | - name: Build package 25 | run: >- 26 | python -m build --sdist --wheel --outdir dist/ 27 | - name: Publish distribution to PyPI 28 | uses: pypa/gh-action-pypi-publish@release/v1 29 | with: 30 | password: ${{ secrets.PYPI_TOKEN }} 31 | 32 | anaconda: 33 | runs-on: ubuntu-latest 34 | steps: 35 | - uses: actions/checkout@v3 36 | - name: Set up Python 37 | uses: actions/setup-python@v3 38 | with: 39 | python-version: 3.12 40 | - name: Add conda to system path 41 | run: | 42 | # $CONDA is an environment variable pointing to the root of the miniconda directory 43 | echo $CONDA/bin >> $GITHUB_PATH 44 | - name: Install dependencies 45 | run: | 46 | sudo apt-get update && sudo apt-get install openssl curl 47 | conda install -y python=3.12 anaconda-client conda-build conda-verify 48 | python -m pip install --upgrade pip 49 | pip install setuptools wheel build 50 | - name: Publish distribution to Anaconda 51 | env: 52 | ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }} 53 | run: | 54 | mkdir ./conda-build # create the artifact dir 55 | 56 | # Get the version of the library 57 | export TORCHHD_VERSION=$(python -c "with open('torchhd/version.py') as f: exec(f.read()); print(__version__)") 58 | 59 | # Build for noarch platform 60 | conda-build -c pytorch --output-folder ./conda-build ./conda 61 | 62 | # Upload noarch version of torchhd to anaconda 63 | anaconda upload -u torchhd --label main ./conda-build/noarch/torchhd-*.conda 64 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | 8 | permissions: 9 | contents: read 10 | 11 | jobs: 12 | test: 13 | name: Test with Python ${{ matrix.python-version }} on ${{ matrix.os }} 14 | runs-on: ${{ matrix.os }} 15 | timeout-minutes: 20 16 | strategy: 17 | matrix: 18 | python-version: ['3.10', '3.11', '3.12'] 19 | os: [ubuntu-latest, windows-latest, macos-latest] 20 | 21 | steps: 22 | - uses: actions/checkout@v3 23 | - name: Use Python ${{ matrix.python-version }} 24 | uses: actions/setup-python@v3 25 | with: 26 | python-version: ${{ matrix.python-version }} 27 | - name: Install dependencies 28 | run: | 29 | python -m pip install --upgrade pip 30 | pip install . 31 | pip install -r dev-requirements.txt 32 | - name: Lint with flake8 33 | run: | 34 | # stop the build if there are Python syntax errors or undefined names 35 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 36 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 37 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 38 | - name: Test with pytest 39 | run: | 40 | pytest 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Common dataset directory 2 | data/ 3 | 4 | # Editor generated files 5 | .vs/ 6 | .vscode/ 7 | 8 | # Byte-compiled / optimized / DLL files 9 | __pycache__/ 10 | *.py[cod] 11 | *$py.class 12 | 13 | # C extensions 14 | *.so 15 | 16 | # Distribution / packaging 17 | .Python 18 | build/ 19 | develop-eggs/ 20 | dist/ 21 | downloads/ 22 | eggs/ 23 | .eggs/ 24 | lib/ 25 | lib64/ 26 | parts/ 27 | sdist/ 28 | var/ 29 | wheels/ 30 | pip-wheel-metadata/ 31 | share/python-wheels/ 32 | *.egg-info/ 33 | .installed.cfg 34 | *.egg 35 | MANIFEST 36 | 37 | # PyInstaller 38 | # Usually these files are written by a python script from a template 39 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 40 | *.manifest 41 | *.spec 42 | 43 | # Installer logs 44 | pip-log.txt 45 | pip-delete-this-directory.txt 46 | 47 | # Unit test / coverage reports 48 | htmlcov/ 49 | .tox/ 50 | .nox/ 51 | .coverage 52 | .coverage.* 53 | .cache 54 | nosetests.xml 55 | coverage.xml 56 | *.cover 57 | *.py,cover 58 | .hypothesis/ 59 | .pytest_cache/ 60 | 61 | # Translations 62 | *.mo 63 | *.pot 64 | 65 | # Django stuff: 66 | *.log 67 | local_settings.py 68 | db.sqlite3 69 | db.sqlite3-journal 70 | 71 | # Flask stuff: 72 | instance/ 73 | .webassets-cache 74 | 75 | # Scrapy stuff: 76 | .scrapy 77 | 78 | # Sphinx documentation 79 | docs/_build/ 80 | 81 | # PyBuilder 82 | target/ 83 | 84 | # Jupyter Notebook 85 | .ipynb_checkpoints 86 | 87 | # IPython 88 | profile_default/ 89 | ipython_config.py 90 | 91 | # pyenv 92 | .python-version 93 | 94 | # pipenv 95 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 96 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 97 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 98 | # install all needed dependencies. 99 | #Pipfile.lock 100 | 101 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 102 | __pypackages__/ 103 | 104 | # Celery stuff 105 | celerybeat-schedule 106 | celerybeat.pid 107 | 108 | # SageMath parsed files 109 | *.sage.py 110 | 111 | # Environments 112 | .env 113 | .venv 114 | env/ 115 | venv/ 116 | ENV/ 117 | env.bak/ 118 | venv.bak/ 119 | 120 | # Spyder project settings 121 | .spyderproject 122 | .spyproject 123 | 124 | # Rope project settings 125 | .ropeproject 126 | 127 | # mkdocs documentation 128 | /site 129 | 130 | # mypy 131 | .mypy_cache/ 132 | .dmypy.json 133 | dmypy.json 134 | 135 | # Pyre type checker 136 | .pyre/ 137 | 138 | # MacOS 139 | .DS_Store -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Set the version of Python and other tools you might need 9 | build: 10 | os: ubuntu-20.04 11 | tools: 12 | python: "3.9" 13 | # You can also specify other tool versions: 14 | # nodejs: "16" 15 | # rust: "1.55" 16 | # golang: "1.17" 17 | 18 | # Build documentation in the docs/ directory with Sphinx 19 | sphinx: 20 | configuration: docs/conf.py 21 | 22 | # If using Sphinx, optionally build your docs in additional formats such as PDF 23 | formats: all 24 | 25 | # Optionally declare the Python requirements required to build your docs 26 | python: 27 | install: 28 | - requirements: docs/requirements.txt -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use this code for your research, please cite our paper." 3 | authors: 4 | - family-names: "Heddes" 5 | given-names: "Mike" 6 | orcid: "https://orcid.org/0000-0002-9276-458X" 7 | - family-names: "Nunes" 8 | given-names: "Igor" 9 | - family-names: "Vergés" 10 | given-names: "Pere" 11 | - family-names: "Kleyko" 12 | given-names: "Denis" 13 | - family-names: "Abraham" 14 | given-names: "Danny" 15 | - family-names: "Givargis" 16 | given-names: "Tony" 17 | - family-names: "Nicolau" 18 | given-names: "Alexandru" 19 | - family-names: "Veidenbaum" 20 | given-names: "Alex" 21 | title: "Torchhd: An Open Source Python Library to Support Research on Hyperdimensional Computing and Vector Symbolic Architectures" 22 | url: "https://github.com/hyperdimensional-computing/torchhd" 23 | preferred-citation: 24 | type: article 25 | authors: 26 | - family-names: "Heddes" 27 | given-names: "Mike" 28 | orcid: "https://orcid.org/0000-0002-9276-458X" 29 | - family-names: "Nunes" 30 | given-names: "Igor" 31 | - family-names: "Vergés" 32 | given-names: "Pere" 33 | - family-names: "Kleyko" 34 | given-names: "Denis" 35 | - family-names: "Abraham" 36 | given-names: "Danny" 37 | - family-names: "Givargis" 38 | given-names: "Tony" 39 | - family-names: "Nicolau" 40 | given-names: "Alexandru" 41 | - family-names: "Veidenbaum" 42 | given-names: "Alex" 43 | title: "Torchhd: An Open Source Python Library to Support Research on Hyperdimensional Computing and Vector Symbolic Architectures" 44 | journal: "Journal of Machine Learning Research" 45 | start: 1 # First page number 46 | end: 10 # Last page number 47 | volume: 24 48 | year: 2023 49 | url: http://jmlr.org/papers/v24/23-0300.html -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /conda/meta.yaml: -------------------------------------------------------------------------------- 1 | {% set name = "torch-hd" %} 2 | 3 | package: 4 | name: torchhd 5 | version: {{ TORCHHD_VERSION }} 6 | 7 | source: 8 | path: ../ 9 | 10 | build: 11 | noarch: python 12 | number: 0 13 | script: "{{ PYTHON }} -m pip install . -vv" 14 | 15 | requirements: 16 | host: 17 | - pip 18 | - python>=3.6,<3.13 19 | run: 20 | - python>=3.6,<3.13 21 | - pytorch 22 | - scipy 23 | - pandas 24 | - requests 25 | - openpyxl 26 | - tqdm 27 | 28 | test: 29 | imports: 30 | - torchhd 31 | - torchhd.functional 32 | - torchhd.embeddings 33 | - torchhd.structures 34 | - torchhd.models 35 | - torchhd.memory 36 | - torchhd.datasets 37 | 38 | about: 39 | home: https://github.com/hyperdimensional-computing/torchhd 40 | license: MIT 41 | license_file: LICENSE 42 | summary: Torchhd is a Python library for Hyperdimensional Computing 43 | dev_url: https://github.com/hyperdimensional-computing/torchhd 44 | doc_url: https://torchhd.readthedocs.io 45 | -------------------------------------------------------------------------------- /dev-requirements.txt: -------------------------------------------------------------------------------- 1 | torch>=1.9.0 2 | torchvision 3 | scipy 4 | pandas 5 | requests 6 | numpy 7 | flake8 8 | pytest 9 | black 10 | tqdm 11 | openpyxl 12 | coverage 13 | gdown -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | # auto generated files 2 | generated/ -------------------------------------------------------------------------------- /docs/_templates/class.rst: -------------------------------------------------------------------------------- 1 | .. role:: hidden 2 | :class: hidden-section 3 | .. currentmodule:: {{ module }} 4 | 5 | 6 | {{ name | underline}} 7 | 8 | .. autoclass:: {{ name }} 9 | :members: 10 | :special-members: 11 | :exclude-members: __weakref__, __init__ -------------------------------------------------------------------------------- /docs/_templates/class_classifier.rst: -------------------------------------------------------------------------------- 1 | .. role:: hidden 2 | :class: hidden-section 3 | .. currentmodule:: {{ module }} 4 | 5 | 6 | {{ name | underline}} 7 | 8 | .. autoclass:: {{ name }} 9 | :members: fit, predict, accuracy 10 | :special-members: __call__ 11 | -------------------------------------------------------------------------------- /docs/_templates/class_dataset.rst: -------------------------------------------------------------------------------- 1 | .. role:: hidden 2 | :class: hidden-section 3 | .. currentmodule:: {{ module }} 4 | 5 | 6 | {{ name | underline}} 7 | 8 | .. autoclass:: {{ name }} 9 | :members: 10 | __getitem__, 11 | {% if "category_name" in methods %} category_name {% endif %} 12 | :special-members: -------------------------------------------------------------------------------- /docs/_templates/function.rst: -------------------------------------------------------------------------------- 1 | .. role:: hidden 2 | :class: hidden-section 3 | .. currentmodule:: {{ module }} 4 | 5 | 6 | {{ name | underline}} 7 | 8 | .. autofunction:: {{ name }} -------------------------------------------------------------------------------- /docs/classifiers.rst: -------------------------------------------------------------------------------- 1 | .. _models: 2 | 3 | torchhd.classifiers 4 | ======================= 5 | 6 | .. currentmodule:: torchhd.classifiers 7 | 8 | .. autosummary:: 9 | :nosignatures: 10 | :toctree: generated/ 11 | :template: class_classifier.rst 12 | 13 | Classifier 14 | Vanilla 15 | AdaptHD 16 | OnlineHD 17 | NeuralHD 18 | DistHD 19 | CompHD 20 | SparseHD 21 | QuantHD 22 | LeHDC 23 | IntRVFL 24 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | import os 14 | import sys 15 | 16 | sys.path.insert(0, os.path.abspath("../")) 17 | 18 | 19 | # -- Project information ----------------------------------------------------- 20 | 21 | project = "Torchhd" 22 | copyright = "2022, Mike Heddes, Igor Nunes, Dheyay Desai, Pere Vergés" 23 | author = "Mike Heddes, Igor Nunes, Dheyay Desai, Pere Vergés" 24 | 25 | 26 | # -- General configuration --------------------------------------------------- 27 | 28 | # Add any Sphinx extension module names here, as strings. They can be 29 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 30 | # ones. 31 | 32 | extensions = [ 33 | "sphinx.ext.githubpages", 34 | "sphinx.ext.napoleon", 35 | "sphinx.ext.autodoc", 36 | "sphinx.ext.autosummary", 37 | "sphinx.ext.viewcode", 38 | "sphinx_rtd_theme", 39 | ] 40 | # Add any paths that contain templates here, relative to this directory. 41 | templates_path = ["_templates"] 42 | 43 | # List of patterns, relative to source directory, that match files and 44 | # directories to ignore when looking for source files. 45 | # This pattern also affects html_static_path and html_extra_path. 46 | exclude_patterns = [] 47 | 48 | # maps functions with a class name that is indistinguishable when case is 49 | # ignore to another filename 50 | autosummary_filename_map = { 51 | "torchhd.memory.Hopfield": "hopfield-class", 52 | "torchhd.memory.hopfield": "hopfield-function", 53 | } 54 | 55 | 56 | # -- Options for HTML output ------------------------------------------------- 57 | 58 | # The theme to use for HTML and HTML Help pages. See the documentation for 59 | # a list of builtin themes. 60 | 61 | html_theme = "sphinx_rtd_theme" 62 | html_theme_path = ["_themes"] 63 | 64 | html_logo = "images/torchhd-logo.svg" 65 | 66 | html_theme_options = { 67 | "logo_only": True, 68 | "display_version": True, 69 | "prev_next_buttons_location": "bottom", 70 | "style_nav_header_background": "white", 71 | } 72 | 73 | # Add any paths that contain custom static files (such as style sheets) here, 74 | # relative to this directory. They are copied after the builtin static files, 75 | # so a file named "default.css" will overwrite the builtin "default.css". 76 | html_static_path = ["_static"] 77 | 78 | html_css_files = [ 79 | "css/custom.css", 80 | ] 81 | -------------------------------------------------------------------------------- /docs/datasets.rst: -------------------------------------------------------------------------------- 1 | .. _datasets: 2 | 3 | torchhd.datasets 4 | ================ 5 | 6 | The Torchhd library provides many popular built-in datasets to work with. 7 | 8 | .. currentmodule:: torchhd.datasets 9 | 10 | .. automodule:: torchhd.datasets 11 | :members: 12 | :exclude-members: download, process, processed_file_names, raw_file_names, num_classes, DatasetFourFold, DatasetTrainTest, CollectionDataset 13 | 14 | 15 | Base classes 16 | ------------------------ 17 | 18 | .. autosummary:: 19 | :toctree: generated/ 20 | :template: class_dataset.rst 21 | 22 | CollectionDataset 23 | DatasetFourFold 24 | DatasetTrainTest 25 | -------------------------------------------------------------------------------- /docs/docutils.conf: -------------------------------------------------------------------------------- 1 | [restructuredtext parser] 2 | tab_width: 4 -------------------------------------------------------------------------------- /docs/embeddings.rst: -------------------------------------------------------------------------------- 1 | .. _embeddings: 2 | 3 | torchhd.embeddings 4 | ================== 5 | 6 | .. currentmodule:: torchhd.embeddings 7 | 8 | .. autosummary:: 9 | :toctree: generated/ 10 | :template: class.rst 11 | 12 | Empty 13 | Identity 14 | Random 15 | Level 16 | Thermometer 17 | Circular 18 | Projection 19 | Sinusoid 20 | Density 21 | FractionalPower -------------------------------------------------------------------------------- /docs/images/basis-hvs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyperdimensional-computing/torchhd/9d73e1bd1f169d718340dfd40aa1aa976faa3851/docs/images/basis-hvs.png -------------------------------------------------------------------------------- /docs/images/torchhd-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyperdimensional-computing/torchhd/9d73e1bd1f169d718340dfd40aa1aa976faa3851/docs/images/torchhd-logo.png -------------------------------------------------------------------------------- /docs/images/torchhd-logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to the Torchhd documentation! 2 | ===================================== 3 | 4 | Torchhd is a Python library dedicated to *Hyperdimensional Computing* also known as *Vector Symbolic Architectures*. 5 | 6 | .. toctree:: 7 | :glob: 8 | :maxdepth: 1 9 | :caption: Tutorials 10 | 11 | getting_started 12 | classification 13 | 14 | .. toctree:: 15 | :maxdepth: 2 16 | :caption: Package Reference: 17 | 18 | torchhd 19 | embeddings 20 | structures 21 | models 22 | classifiers 23 | memory 24 | datasets 25 | utils 26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/memory.rst: -------------------------------------------------------------------------------- 1 | .. _memory: 2 | 3 | torchhd.memory 4 | ================== 5 | 6 | .. currentmodule:: torchhd.memory 7 | 8 | .. autosummary:: 9 | :toctree: generated/ 10 | :template: class.rst 11 | 12 | SparseDistributed 13 | Hopfield 14 | 15 | .. autosummary:: 16 | :toctree: generated/ 17 | :template: function.rst 18 | 19 | hopfield 20 | modern_hopfield 21 | attention -------------------------------------------------------------------------------- /docs/models.rst: -------------------------------------------------------------------------------- 1 | .. _models: 2 | 3 | torchhd.models 4 | ================== 5 | 6 | .. currentmodule:: torchhd.models 7 | 8 | .. autosummary:: 9 | :toctree: generated/ 10 | :template: class.rst 11 | 12 | Centroid 13 | IntRVFL -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | torch 2 | torchvision 3 | pandas 4 | scipy 5 | requests 6 | tqdm 7 | numpy 8 | openpyxl 9 | sphinx 10 | sphinx-rtd-theme -------------------------------------------------------------------------------- /docs/structures.rst: -------------------------------------------------------------------------------- 1 | .. _structures: 2 | 3 | torchhd.structures 4 | ================== 5 | 6 | .. currentmodule:: torchhd.structures 7 | 8 | This module provides class-based implementations of HDC data structures. 9 | 10 | .. autosummary:: 11 | :toctree: generated/ 12 | :template: class.rst 13 | 14 | Memory 15 | Multiset 16 | HashTable 17 | BundleSequence 18 | BindSequence 19 | Graph 20 | Tree 21 | FiniteStateAutomata -------------------------------------------------------------------------------- /docs/torchhd.rst: -------------------------------------------------------------------------------- 1 | .. _functional: 2 | 3 | torchhd 4 | ========================= 5 | 6 | .. currentmodule:: torchhd 7 | 8 | This module consists of the basic hypervector generation functions and operations used on hypervectors. 9 | 10 | Basis-hypervector sets 11 | ---------------------------------- 12 | 13 | .. autosummary:: 14 | :toctree: generated/ 15 | :template: function.rst 16 | 17 | empty 18 | identity 19 | random 20 | level 21 | thermometer 22 | circular 23 | 24 | 25 | Operations 26 | -------------------- 27 | 28 | .. autosummary:: 29 | :toctree: generated/ 30 | :template: function.rst 31 | 32 | bind 33 | bundle 34 | permute 35 | inverse 36 | negative 37 | normalize 38 | cleanup 39 | randsel 40 | multirandsel 41 | create_random_permute 42 | resonator 43 | ridge_regression 44 | soft_quantize 45 | hard_quantize 46 | 47 | 48 | Similarities 49 | ------------------------ 50 | 51 | .. autosummary:: 52 | :toctree: generated/ 53 | :template: function.rst 54 | 55 | cosine_similarity 56 | dot_similarity 57 | hamming_similarity 58 | 59 | 60 | Encodings 61 | ------------------------ 62 | 63 | .. autosummary:: 64 | :toctree: generated/ 65 | :template: function.rst 66 | 67 | multiset 68 | multibind 69 | bundle_sequence 70 | bind_sequence 71 | hash_table 72 | cross_product 73 | ngrams 74 | graph 75 | 76 | 77 | VSA Models 78 | ------------------------ 79 | 80 | .. autosummary:: 81 | :toctree: generated/ 82 | :template: class.rst 83 | 84 | VSATensor 85 | BSCTensor 86 | MAPTensor 87 | HRRTensor 88 | FHRRTensor 89 | BSBCTensor 90 | BaseMCRTensor 91 | MCRTensor 92 | CGRTensor 93 | VTBTensor 94 | 95 | 96 | Utilities 97 | ------------------------ 98 | 99 | .. autosummary:: 100 | :toctree: generated/ 101 | :template: function.rst 102 | 103 | ensure_vsa_tensor 104 | map_range 105 | value_to_index 106 | index_to_value 107 | -------------------------------------------------------------------------------- /docs/utils.rst: -------------------------------------------------------------------------------- 1 | .. _utils: 2 | 3 | torchhd.utils 4 | ================== 5 | 6 | .. currentmodule:: torchhd.utils 7 | 8 | This module provides plotting functions for hypervector similarities. 9 | 10 | .. autosummary:: 11 | :toctree: generated/ 12 | :template: function.rst 13 | 14 | plot_similarity 15 | plot_pair_similarity 16 | 17 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | To run the examples in this folder, first clone the repository then install Torchhd using `pip install .`. Some examples require additional dependencies which are specified at the top of each script. -------------------------------------------------------------------------------- /examples/classifiers.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torchhd 3 | from torchhd.datasets.isolet import ISOLET 4 | 5 | classifiers = [ 6 | "Vanilla", 7 | "AdaptHD", 8 | "OnlineHD", 9 | "NeuralHD", 10 | "DistHD", 11 | "CompHD", 12 | "SparseHD", 13 | "QuantHD", 14 | "LeHDC", 15 | "IntRVFL", 16 | ] 17 | 18 | device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 19 | print("Using {} device".format(device)) 20 | 21 | DIMENSIONS = 1024 # number of hypervector dimensions 22 | BATCH_SIZE = 12 # for GPUs with enough memory we can process multiple images at ones 23 | 24 | train_ds = ISOLET("../data", train=True, download=True) 25 | train_ld = torch.utils.data.DataLoader(train_ds, batch_size=BATCH_SIZE, shuffle=True) 26 | 27 | test_ds = ISOLET("../data", train=False, download=True) 28 | test_ld = torch.utils.data.DataLoader(test_ds, batch_size=BATCH_SIZE, shuffle=False) 29 | 30 | num_features = train_ds[0][0].size(-1) 31 | num_classes = len(train_ds.classes) 32 | 33 | std, mean = torch.std_mean(train_ds.data, dim=0, keepdim=False) 34 | 35 | 36 | def transform(sample): 37 | return (sample - mean) / std 38 | 39 | 40 | train_ds.transform = transform 41 | test_ds.transform = transform 42 | 43 | params = { 44 | "Vanilla": {}, 45 | "AdaptHD": { 46 | "epochs": 10, 47 | }, 48 | "OnlineHD": { 49 | "epochs": 10, 50 | }, 51 | "NeuralHD": { 52 | "epochs": 10, 53 | "regen_freq": 5, 54 | }, 55 | "DistHD": { 56 | "epochs": 10, 57 | "regen_freq": 5, 58 | }, 59 | "CompHD": {}, 60 | "SparseHD": { 61 | "epochs": 10, 62 | }, 63 | "QuantHD": { 64 | "epochs": 10, 65 | }, 66 | "LeHDC": { 67 | "epochs": 10, 68 | }, 69 | "IntRVFL": {}, 70 | } 71 | 72 | for classifier in classifiers: 73 | print() 74 | print(classifier) 75 | 76 | model_cls = getattr(torchhd.classifiers, classifier) 77 | model: torchhd.classifiers.Classifier = model_cls( 78 | num_features, DIMENSIONS, num_classes, device=device, **params[classifier] 79 | ) 80 | 81 | model.fit(train_ld) 82 | accuracy = model.accuracy(test_ld) 83 | print(f"Testing accuracy of {(accuracy * 100):.3f}%") 84 | -------------------------------------------------------------------------------- /examples/emg_hand_gestures.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.nn.functional as F 4 | import torch.utils.data as data 5 | 6 | # Note: this example requires the torchmetrics library: https://torchmetrics.readthedocs.io 7 | import torchmetrics 8 | from tqdm import tqdm 9 | 10 | import torchhd 11 | from torchhd import embeddings 12 | from torchhd.models import Centroid 13 | from torchhd.datasets import EMGHandGestures 14 | 15 | device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 16 | print("Using {} device".format(device)) 17 | 18 | DIMENSIONS = 10000 # number of hypervector dimensions 19 | NUM_LEVELS = 21 20 | BATCH_SIZE = 1 # for GPUs with enough memory we can process multiple images at ones 21 | WINDOW = 256 22 | N_GRAM_SIZE = 4 23 | DOWNSAMPLE = 5 24 | SUBSAMPLES = torch.arange(0, WINDOW, int(WINDOW / DOWNSAMPLE)) 25 | 26 | 27 | def transform(x): 28 | return x[SUBSAMPLES] 29 | 30 | 31 | class Encoder(nn.Module): 32 | def __init__(self, out_features, timestamps, channels): 33 | super(Encoder, self).__init__() 34 | 35 | self.channels = embeddings.Random(channels, out_features) 36 | self.signals = embeddings.Level(NUM_LEVELS, out_features, high=20) 37 | 38 | def forward(self, input: torch.Tensor) -> torch.Tensor: 39 | signal = self.signals(input) 40 | samples = torchhd.bind(signal, self.channels.weight.unsqueeze(0)) 41 | 42 | samples = torchhd.multiset(samples) 43 | sample_hv = torchhd.ngrams(samples, n=N_GRAM_SIZE) 44 | return torchhd.hard_quantize(sample_hv) 45 | 46 | 47 | def experiment(subjects=[0]): 48 | print("List of subjects " + str(subjects)) 49 | ds = EMGHandGestures( 50 | "../data", download=True, subjects=subjects, transform=transform 51 | ) 52 | 53 | train_size = int(len(ds) * 0.7) 54 | test_size = len(ds) - train_size 55 | train_ds, test_ds = data.random_split(ds, [train_size, test_size]) 56 | 57 | train_ld = data.DataLoader(train_ds, batch_size=BATCH_SIZE, shuffle=True) 58 | test_ld = data.DataLoader(test_ds, batch_size=BATCH_SIZE, shuffle=False) 59 | 60 | encode = Encoder(DIMENSIONS, ds[0][0].size(-2), ds[0][0].size(-1)) 61 | encode = encode.to(device) 62 | 63 | num_classes = len(ds.classes) 64 | model = Centroid(DIMENSIONS, num_classes) 65 | model = model.to(device) 66 | 67 | with torch.no_grad(): 68 | for samples, targets in tqdm(train_ld, desc="Training"): 69 | samples = samples.to(device) 70 | targets = targets.to(device) 71 | 72 | sample_hv = encode(samples) 73 | model.add(sample_hv, targets) 74 | 75 | accuracy = torchmetrics.Accuracy("multiclass", num_classes=num_classes) 76 | 77 | with torch.no_grad(): 78 | model.normalize() 79 | 80 | for samples, targets in tqdm(test_ld, desc="Testing"): 81 | samples = samples.to(device) 82 | 83 | sample_hv = encode(samples) 84 | output = model(sample_hv, dot=True) 85 | accuracy.update(output.cpu(), targets) 86 | 87 | print(f"Testing accuracy of {(accuracy.compute().item() * 100):.3f}%") 88 | 89 | 90 | # Make a model for each subject 91 | for i in range(5): 92 | experiment([i]) 93 | -------------------------------------------------------------------------------- /examples/language_recognition.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.nn.functional as F 4 | import torch.utils.data as data 5 | 6 | # Note: this example requires the torchmetrics library: https://torchmetrics.readthedocs.io 7 | import torchmetrics 8 | from tqdm import tqdm 9 | 10 | import torchhd 11 | from torchhd import embeddings 12 | from torchhd.models import Centroid 13 | from torchhd.datasets import EuropeanLanguages as Languages 14 | 15 | device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 16 | print("Using {} device".format(device)) 17 | 18 | DIMENSIONS = 10000 19 | BATCH_SIZE = 1 # for GPUs with enough memory we can process multiple images at ones 20 | # cap maximum sample size to 128 characters (including spaces) 21 | MAX_INPUT_SIZE = 128 22 | PADDING_IDX = 0 23 | 24 | ASCII_A = ord("a") 25 | ASCII_Z = ord("z") 26 | ASCII_SPACE = ord(" ") 27 | NUM_TOKENS = ASCII_Z - ASCII_A + 3 # a through z plus space and padding 28 | 29 | 30 | def char2int(char: str) -> int: 31 | """Map a character to its integer identifier""" 32 | ascii_index = ord(char) 33 | 34 | if ascii_index == ASCII_SPACE: 35 | # Remap the space character to come after "z" 36 | return ASCII_Z - ASCII_A + 1 37 | 38 | return ascii_index - ASCII_A 39 | 40 | 41 | def transform(x: str) -> torch.Tensor: 42 | char_ids = x[:MAX_INPUT_SIZE] 43 | char_ids = [char2int(char) + 1 for char in char_ids.lower()] 44 | 45 | if len(char_ids) < MAX_INPUT_SIZE: 46 | char_ids += [PADDING_IDX] * (MAX_INPUT_SIZE - len(char_ids)) 47 | 48 | return torch.tensor(char_ids, dtype=torch.long) 49 | 50 | 51 | train_ds = Languages("../data", train=True, transform=transform, download=True) 52 | train_ld = data.DataLoader(train_ds, batch_size=BATCH_SIZE, shuffle=True) 53 | 54 | test_ds = Languages("../data", train=False, transform=transform, download=True) 55 | test_ld = data.DataLoader(test_ds, batch_size=BATCH_SIZE, shuffle=False) 56 | 57 | 58 | class Encoder(nn.Module): 59 | def __init__(self, out_features, size): 60 | super(Encoder, self).__init__() 61 | self.symbol = embeddings.Random(size, out_features, padding_idx=PADDING_IDX) 62 | 63 | def forward(self, x): 64 | symbols = self.symbol(x) 65 | sample_hv = torchhd.ngrams(symbols, n=3) 66 | return torchhd.hard_quantize(sample_hv) 67 | 68 | 69 | encode = Encoder(DIMENSIONS, NUM_TOKENS) 70 | encode = encode.to(device) 71 | 72 | num_classes = len(train_ds.classes) 73 | model = Centroid(DIMENSIONS, num_classes) 74 | model = model.to(device) 75 | 76 | with torch.no_grad(): 77 | for samples, labels in tqdm(train_ld, desc="Training"): 78 | samples = samples.to(device) 79 | labels = labels.to(device) 80 | 81 | samples_hv = encode(samples) 82 | model.add(samples_hv, labels) 83 | 84 | accuracy = torchmetrics.Accuracy("multiclass", num_classes=num_classes) 85 | 86 | with torch.no_grad(): 87 | model.normalize() 88 | 89 | for samples, labels in tqdm(test_ld, desc="Testing"): 90 | samples = samples.to(device) 91 | labels = labels.to(device) 92 | 93 | samples_hv = encode(samples) 94 | outputs = model(samples_hv, dot=True) 95 | accuracy.update(outputs.cpu(), labels) 96 | 97 | print(f"Testing accuracy of {(accuracy.compute().item() * 100):.3f}%") 98 | -------------------------------------------------------------------------------- /examples/mnist.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.nn.functional as F 4 | import torchvision 5 | from torchvision.datasets import MNIST 6 | 7 | # Note: this example requires the torchmetrics library: https://torchmetrics.readthedocs.io 8 | import torchmetrics 9 | from tqdm import tqdm 10 | 11 | import torchhd 12 | from torchhd.models import Centroid 13 | from torchhd import embeddings 14 | 15 | 16 | device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 17 | print("Using {} device".format(device)) 18 | 19 | DIMENSIONS = 10000 20 | IMG_SIZE = 28 21 | NUM_LEVELS = 1000 22 | BATCH_SIZE = 1 # for GPUs with enough memory we can process multiple images at ones 23 | 24 | transform = torchvision.transforms.ToTensor() 25 | 26 | train_ds = MNIST("../data", train=True, transform=transform, download=True) 27 | train_ld = torch.utils.data.DataLoader(train_ds, batch_size=BATCH_SIZE, shuffle=True) 28 | 29 | test_ds = MNIST("../data", train=False, transform=transform, download=True) 30 | test_ld = torch.utils.data.DataLoader(test_ds, batch_size=BATCH_SIZE, shuffle=False) 31 | 32 | 33 | class Encoder(nn.Module): 34 | def __init__(self, out_features, size, levels): 35 | super(Encoder, self).__init__() 36 | self.flatten = torch.nn.Flatten() 37 | self.position = embeddings.Random(size * size, out_features) 38 | self.value = embeddings.Level(levels, out_features) 39 | 40 | def forward(self, x): 41 | x = self.flatten(x) 42 | sample_hv = torchhd.bind(self.position.weight, self.value(x)) 43 | sample_hv = torchhd.multiset(sample_hv) 44 | return torchhd.hard_quantize(sample_hv) 45 | 46 | 47 | encode = Encoder(DIMENSIONS, IMG_SIZE, NUM_LEVELS) 48 | encode = encode.to(device) 49 | 50 | num_classes = len(train_ds.classes) 51 | model = Centroid(DIMENSIONS, num_classes) 52 | model = model.to(device) 53 | 54 | with torch.no_grad(): 55 | for samples, labels in tqdm(train_ld, desc="Training"): 56 | samples = samples.to(device) 57 | labels = labels.to(device) 58 | 59 | samples_hv = encode(samples) 60 | model.add(samples_hv, labels) 61 | 62 | accuracy = torchmetrics.Accuracy("multiclass", num_classes=num_classes) 63 | 64 | with torch.no_grad(): 65 | model.normalize() 66 | 67 | for samples, labels in tqdm(test_ld, desc="Testing"): 68 | samples = samples.to(device) 69 | 70 | samples_hv = encode(samples) 71 | outputs = model(samples_hv, dot=True) 72 | accuracy.update(outputs.cpu(), labels) 73 | 74 | print(f"Testing accuracy of {(accuracy.compute().item() * 100):.3f}%") 75 | -------------------------------------------------------------------------------- /examples/mnist_hugging_face.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.nn.functional as F 4 | import torchvision 5 | from torchvision.datasets import MNIST 6 | 7 | # Note: this example requires the torchmetrics library: https://torchmetrics.readthedocs.io 8 | import torchmetrics 9 | 10 | # Note: this example requires the accelerate library: https://github.com/huggingface/accelerate 11 | from accelerate import Accelerator 12 | from tqdm import tqdm 13 | 14 | import torchhd 15 | from torchhd.models import Centroid 16 | from torchhd import embeddings 17 | 18 | accelerator = Accelerator() 19 | device = accelerator.device 20 | print("Using {} device".format(device)) 21 | 22 | DIMENSIONS = 10000 23 | IMG_SIZE = 28 24 | NUM_LEVELS = 1000 25 | BATCH_SIZE = 1 # for GPUs with enough memory we can process multiple images at ones 26 | 27 | transform = torchvision.transforms.ToTensor() 28 | 29 | train_ds = MNIST("../data", train=True, transform=transform, download=True) 30 | train_ld = torch.utils.data.DataLoader(train_ds, batch_size=BATCH_SIZE, shuffle=True) 31 | 32 | test_ds = MNIST("../data", train=False, transform=transform, download=True) 33 | test_ld = torch.utils.data.DataLoader(test_ds, batch_size=BATCH_SIZE, shuffle=False) 34 | 35 | 36 | class Encoder(nn.Module): 37 | def __init__(self, out_features, size, levels): 38 | super(Encoder, self).__init__() 39 | self.flatten = torch.nn.Flatten() 40 | self.position = embeddings.Random(size * size, out_features) 41 | self.value = embeddings.Level(levels, out_features) 42 | 43 | def forward(self, x): 44 | x = self.flatten(x) 45 | sample_hv = torchhd.bind(self.position.weight, self.value(x)) 46 | sample_hv = torchhd.multiset(sample_hv) 47 | return torchhd.hard_quantize(sample_hv) 48 | 49 | 50 | class Model(nn.Module): 51 | def __init__(self, dimensions, num_classes, size, levels): 52 | super(Model, self).__init__() 53 | self.encode = Encoder(dimensions, size, levels) 54 | self.classify = Centroid(dimensions, num_classes) 55 | 56 | def forward(self, x, dot=False): 57 | y = self.encode(x) 58 | return self.classify(y, dot=dot) 59 | 60 | 61 | num_classes = len(train_ds.classes) 62 | model = Model(DIMENSIONS, num_classes, IMG_SIZE, NUM_LEVELS) 63 | model.to(device) 64 | 65 | model, train_ld, test_ld = accelerator.prepare(model, train_ld, test_ld) 66 | 67 | with torch.no_grad(): 68 | for samples, labels in tqdm(train_ld, desc="Training"): 69 | samples = samples.to(device) 70 | labels = labels.to(device) 71 | 72 | samples_hv = model.encode(samples) 73 | model.classify.add(samples_hv, labels) 74 | 75 | accuracy = torchmetrics.Accuracy("multiclass", num_classes=num_classes) 76 | 77 | with torch.no_grad(): 78 | model.classify.normalize() 79 | 80 | for samples, labels in tqdm(test_ld, desc="Testing"): 81 | samples = samples.to(device) 82 | 83 | outputs = model(samples, dot=True) 84 | accuracy.update(outputs.cpu(), labels) 85 | 86 | print(f"Testing accuracy of {(accuracy.compute().item() * 100):.3f}%") 87 | -------------------------------------------------------------------------------- /examples/mnist_nonlinear.py: -------------------------------------------------------------------------------- 1 | # This is an example of using nonlinear encoding on the MNIST dataset 2 | import torch 3 | import torch.nn as nn 4 | import torch.nn.functional as F 5 | import torchvision 6 | from torchvision.datasets import MNIST 7 | 8 | # Note: this example requires the torchmetrics library: https://torchmetrics.readthedocs.io 9 | import torchmetrics 10 | from tqdm import tqdm 11 | 12 | import torchhd 13 | from torchhd.models import Centroid 14 | from torchhd import embeddings 15 | 16 | 17 | device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 18 | print("Using {} device".format(device)) 19 | 20 | DIMENSIONS = 10000 21 | IMG_SIZE = 28 22 | BATCH_SIZE = 1 # for GPUs with enough memory we can process multiple images at ones 23 | 24 | transform = torchvision.transforms.ToTensor() 25 | 26 | train_ds = MNIST("../data", train=True, transform=transform, download=True) 27 | train_ld = torch.utils.data.DataLoader(train_ds, batch_size=BATCH_SIZE, shuffle=True) 28 | 29 | test_ds = MNIST("../data", train=False, transform=transform, download=True) 30 | test_ld = torch.utils.data.DataLoader(test_ds, batch_size=BATCH_SIZE, shuffle=False) 31 | 32 | 33 | class Encoder(nn.Module): 34 | def __init__(self, out_features, size): 35 | super(Encoder, self).__init__() 36 | self.flatten = torch.nn.Flatten() 37 | self.nonlinear_projection = embeddings.Sinusoid(size * size, out_features) 38 | 39 | def forward(self, x): 40 | x = self.flatten(x) 41 | sample_hv = self.nonlinear_projection(x) 42 | return torchhd.hard_quantize(sample_hv) 43 | 44 | 45 | encode = Encoder(DIMENSIONS, IMG_SIZE) 46 | encode = encode.to(device) 47 | 48 | num_classes = len(train_ds.classes) 49 | model = Centroid(DIMENSIONS, len(train_ds.classes)) 50 | model = model.to(device) 51 | 52 | with torch.no_grad(): 53 | for samples, labels in tqdm(train_ld, desc="Training"): 54 | samples = samples.to(device) 55 | labels = labels.to(device) 56 | 57 | samples_hv = encode(samples) 58 | model.add(samples_hv, labels) 59 | 60 | accuracy = torchmetrics.Accuracy("multiclass", num_classes=num_classes) 61 | 62 | with torch.no_grad(): 63 | model.normalize() 64 | 65 | for samples, labels in tqdm(test_ld, desc="Testing"): 66 | samples = samples.to(device) 67 | 68 | samples_hv = encode(samples) 69 | outputs = model(samples_hv, dot=True) 70 | accuracy.update(outputs.cpu(), labels) 71 | 72 | print(f"Testing accuracy of {(accuracy.compute().item() * 100):.3f}%") 73 | -------------------------------------------------------------------------------- /examples/reghd.py: -------------------------------------------------------------------------------- 1 | import math 2 | import torch 3 | import torch.nn as nn 4 | import torch.nn.functional as F 5 | import torch.utils.data as data 6 | 7 | # Note: this example requires the torchmetrics library: https://torchmetrics.readthedocs.io 8 | import torchmetrics 9 | from tqdm import tqdm 10 | 11 | import torchhd 12 | from torchhd import embeddings 13 | from torchhd.datasets import AirfoilSelfNoise 14 | 15 | device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 16 | print("Using {} device".format(device)) 17 | 18 | DIMENSIONS = 10000 # number of hypervector dimensions 19 | NUM_FEATURES = 5 # number of features in dataset 20 | 21 | ds = AirfoilSelfNoise("../data", download=True) 22 | 23 | # Get necessary statistics for data and target transform 24 | STD_DEVS = ds.data.std(0) 25 | MEANS = ds.data.mean(0) 26 | TARGET_STD = ds.targets.std(0) 27 | TARGET_MEAN = ds.targets.mean(0) 28 | 29 | 30 | def transform(x): 31 | x = x - MEANS 32 | x = x / STD_DEVS 33 | return x 34 | 35 | 36 | def target_transform(x): 37 | x = x - TARGET_MEAN 38 | x = x / TARGET_STD 39 | return x 40 | 41 | 42 | ds.transform = transform 43 | ds.target_transform = target_transform 44 | 45 | # Split the dataset into 70% training and 30% testing 46 | train_size = int(len(ds) * 0.7) 47 | test_size = len(ds) - train_size 48 | train_ds, test_ds = data.random_split(ds, [train_size, test_size]) 49 | 50 | train_dl = data.DataLoader(train_ds, batch_size=1, shuffle=True) 51 | test_dl = data.DataLoader(test_ds, batch_size=1) 52 | 53 | 54 | # Model based on RegHD application for Single model regression 55 | class SingleModel(nn.Module): 56 | def __init__(self, num_classes, size): 57 | super(SingleModel, self).__init__() 58 | 59 | self.lr = 0.00001 60 | self.M = torch.zeros(1, DIMENSIONS) 61 | self.project = embeddings.Sinusoid(size, DIMENSIONS) 62 | 63 | def encode(self, x): 64 | sample_hv = self.project(x) 65 | return torchhd.hard_quantize(sample_hv) 66 | 67 | def model_update(self, x, y): 68 | update = self.M + self.lr * (y - (F.linear(x, self.M))) * x 69 | update = update.mean(0) 70 | self.M = update 71 | 72 | def forward(self, x): 73 | enc = self.encode(x) 74 | res = F.linear(enc, self.M) 75 | return res 76 | 77 | 78 | model = SingleModel(1, NUM_FEATURES) 79 | model = model.to(device) 80 | 81 | # Model training 82 | with torch.no_grad(): 83 | for _ in range(10): 84 | for samples, labels in tqdm(train_dl, desc="Iteration {}".format(_ + 1)): 85 | samples = samples.to(device) 86 | labels = labels.to(device) 87 | 88 | samples_hv = model.encode(samples) 89 | model.model_update(samples_hv, labels) 90 | 91 | # Model accuracy 92 | mse = torchmetrics.MeanSquaredError() 93 | 94 | with torch.no_grad(): 95 | for samples, labels in tqdm(test_dl, desc="Testing"): 96 | samples = samples.to(device) 97 | 98 | predictions = model(samples) 99 | predictions = predictions * TARGET_STD + TARGET_MEAN 100 | labels = labels * TARGET_STD + TARGET_MEAN 101 | mse.update(predictions.cpu(), labels) 102 | 103 | print(f"Testing mean squared error of {(mse.compute().item()):.3f}") 104 | -------------------------------------------------------------------------------- /examples/voicehd.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.nn.functional as F 4 | 5 | # Note: this example requires the torchmetrics library: https://torchmetrics.readthedocs.io 6 | import torchmetrics 7 | from tqdm import tqdm 8 | 9 | import torchhd 10 | from torchhd import embeddings 11 | from torchhd.models import Centroid 12 | from torchhd.datasets.isolet import ISOLET 13 | 14 | device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 15 | print("Using {} device".format(device)) 16 | 17 | DIMENSIONS = 10000 # number of hypervector dimensions 18 | NUM_LEVELS = 100 19 | BATCH_SIZE = 1 # for GPUs with enough memory we can process multiple images at ones 20 | 21 | 22 | class Encoder(nn.Module): 23 | def __init__(self, num_classes, size): 24 | super(Encoder, self).__init__() 25 | self.id = embeddings.Random(size, DIMENSIONS) 26 | self.value = embeddings.Level(NUM_LEVELS, DIMENSIONS) 27 | 28 | def forward(self, x): 29 | sample_hv = torchhd.bind(self.id.weight, self.value(x)) 30 | sample_hv = torchhd.multiset(sample_hv) 31 | return torchhd.hard_quantize(sample_hv) 32 | 33 | 34 | train_ds = ISOLET("../data", train=True, download=True) 35 | train_ld = torch.utils.data.DataLoader(train_ds, batch_size=BATCH_SIZE, shuffle=True) 36 | 37 | test_ds = ISOLET("../data", train=False, download=True) 38 | test_ld = torch.utils.data.DataLoader(test_ds, batch_size=BATCH_SIZE, shuffle=False) 39 | 40 | encode = Encoder(DIMENSIONS, train_ds[0][0].size(-1)) 41 | encode = encode.to(device) 42 | 43 | num_classes = len(train_ds.classes) 44 | model = Centroid(DIMENSIONS, num_classes) 45 | model = model.to(device) 46 | 47 | with torch.no_grad(): 48 | for samples, labels in tqdm(train_ld, desc="Training"): 49 | samples = samples.to(device) 50 | labels = labels.to(device) 51 | 52 | samples_hv = encode(samples) 53 | model.add(samples_hv, labels) 54 | 55 | accuracy = torchmetrics.Accuracy("multiclass", num_classes=num_classes) 56 | 57 | with torch.no_grad(): 58 | model.normalize() 59 | 60 | for samples, labels in tqdm(test_ld, desc="Testing"): 61 | samples = samples.to(device) 62 | 63 | samples_hv = encode(samples) 64 | outputs = model(samples_hv, dot=True) 65 | accuracy.update(outputs.cpu(), labels) 66 | 67 | print(f"Testing accuracy of {(accuracy.compute().item() * 100):.3f}%") 68 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 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 | """ 6 | 7 | from setuptools import setup, find_packages 8 | 9 | # Read the version without importing any dependencies 10 | version = {} 11 | with open("torchhd/version.py") as f: 12 | exec(f.read(), version) 13 | 14 | setup( 15 | name="torch-hd", # use torch-hd on PyPi to install torchhd, torchhd is too similar according to PyPi 16 | version=version["__version__"], 17 | description="Torchhd is a Python library for Hyperdimensional Computing and Vector Symbolic Architectures", 18 | long_description=open("README.md").read(), 19 | long_description_content_type="text/markdown", 20 | url="https://github.com/hyperdimensional-computing/torchhd", 21 | license="MIT", 22 | install_requires=[ 23 | "torch>=1.9.0", 24 | "scipy", 25 | "pandas", 26 | "numpy", 27 | "requests", 28 | "tqdm", 29 | "openpyxl", 30 | ], 31 | packages=find_packages(exclude=["docs", "torchhd.tests", "examples"]), 32 | python_requires=">=3.8, <4", 33 | project_urls={ 34 | "Source": "https://github.com/hyperdimensional-computing/torchhd", 35 | "Documentation": "https://torchhd.readthedocs.io", 36 | }, 37 | ) 38 | -------------------------------------------------------------------------------- /torchhd/datasets/abalone.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Abalone(DatasetFourFold): 29 | """`Abalone `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 4177 41 | - 8 42 | - Classification 43 | - Life 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 48 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 49 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 50 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 51 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 52 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 53 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 54 | while the second row corresponds to test indices (used if ``train = False``). 55 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 56 | and returns a transformed version. 57 | target_transform (callable, optional): A function/transform that takes in the 58 | target and transforms it. 59 | download (bool, optional): If True, downloads the dataset from the internet and 60 | puts it in root directory. If dataset is already downloaded, it is not 61 | downloaded again. 62 | 63 | """ 64 | 65 | name = "abalone" 66 | classes: List[str] = [ 67 | "0", 68 | "1", 69 | "2", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/adult.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class Adult(DatasetTrainTest): 29 | """`Adult `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 48842 41 | - 14 42 | - Classification 43 | - Social 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 48 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 49 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 50 | while the second row corresponds to test indices (used if ``train = False``). 51 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 52 | and returns a transformed version. 53 | target_transform (callable, optional): A function/transform that takes in the 54 | target and transforms it. 55 | download (bool, optional): If True, downloads the dataset from the internet and 56 | puts it in root directory. If dataset is already downloaded, it is not 57 | downloaded again. 58 | 59 | """ 60 | 61 | name = "adult" 62 | classes: List[str] = [ 63 | ">50K", 64 | "<=50K", 65 | ] 66 | -------------------------------------------------------------------------------- /torchhd/datasets/annealing.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class Annealing(DatasetTrainTest): 29 | """`Annealing `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 798 41 | - 38 42 | - Classification 43 | - Physical 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 48 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 49 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 50 | while the second row corresponds to test indices (used if ``train = False``). 51 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 52 | and returns a transformed version. 53 | target_transform (callable, optional): A function/transform that takes in the 54 | target and transforms it. 55 | download (bool, optional): If True, downloads the dataset from the internet and 56 | puts it in root directory. If dataset is already downloaded, it is not 57 | downloaded again. 58 | 59 | """ 60 | 61 | name = "annealing" 62 | classes: List[str] = [ 63 | "1", 64 | "2", 65 | "3", 66 | "4", 67 | "5", 68 | ] 69 | -------------------------------------------------------------------------------- /torchhd/datasets/balloons.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Balloons(DatasetFourFold): 29 | """`Balloons `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 16 41 | - 4 42 | - Classification 43 | - Social 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 48 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 49 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 50 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 51 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 52 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 53 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 54 | while the second row corresponds to test indices (used if ``train = False``). 55 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 56 | and returns a transformed version. 57 | target_transform (callable, optional): A function/transform that takes in the 58 | target and transforms it. 59 | download (bool, optional): If True, downloads the dataset from the internet and 60 | puts it in root directory. If dataset is already downloaded, it is not 61 | downloaded again. 62 | 63 | """ 64 | 65 | name = "balloons" 66 | classes: List[str] = [ 67 | "inflated - F", 68 | "inflated - T", 69 | ] 70 | -------------------------------------------------------------------------------- /torchhd/datasets/bank.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Bank(DatasetFourFold): 29 | """`Bank Marketing `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 45211 41 | - 17 42 | - Classification 43 | - Business 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 49 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 50 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 51 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 52 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 53 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 54 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 55 | while the second row corresponds to test indices (used if ``train = False``). 56 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 57 | and returns a transformed version. 58 | target_transform (callable, optional): A function/transform that takes in the 59 | target and transforms it. 60 | download (bool, optional): If True, downloads the dataset from the internet and 61 | puts it in root directory. If dataset is already downloaded, it is not 62 | downloaded again. 63 | 64 | """ 65 | 66 | name = "bank" 67 | classes: List[str] = [ 68 | "no", 69 | "yes", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/conn_bench_vowel_deterding.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class ConnBenchVowelDeterding(DatasetTrainTest): 29 | """`Connectionist Bench (Vowel Recognition - Deterding Data) `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 528 41 | - 10 42 | - Classification 43 | - N/A 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 49 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 50 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 51 | while the second row corresponds to test indices (used if ``train = False``). 52 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 53 | and returns a transformed version. 54 | target_transform (callable, optional): A function/transform that takes in the 55 | target and transforms it. 56 | download (bool, optional): If True, downloads the dataset from the internet and 57 | puts it in root directory. If dataset is already downloaded, it is not 58 | downloaded again. 59 | 60 | 61 | """ 62 | 63 | name = "conn-bench-vowel-deterding" 64 | classes: List[str] = [ 65 | "0", 66 | "1", 67 | "2", 68 | "3", 69 | "4", 70 | "5", 71 | "6", 72 | "7", 73 | "8", 74 | "9", 75 | "10", 76 | ] 77 | -------------------------------------------------------------------------------- /torchhd/datasets/connect_4.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Connect4(DatasetFourFold): 29 | """`Connect-4 `_ dataset. 30 | 31 | 32 | .. list-table:: 33 | :widths: 10 10 10 10 34 | :align: center 35 | :header-rows: 1 36 | 37 | * - Instances 38 | - Attributes 39 | - Task 40 | - Area 41 | * - 67557 42 | - 42 43 | - Classification 44 | - Game 45 | 46 | 47 | Args: 48 | root (string): Root directory containing the files of the dataset. 49 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 50 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 51 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 52 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 53 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 54 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 55 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 56 | while the second row corresponds to test indices (used if ``train = False``). 57 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 58 | and returns a transformed version. 59 | target_transform (callable, optional): A function/transform that takes in the 60 | target and transforms it. 61 | download (bool, optional): If True, downloads the dataset from the internet and 62 | puts it in root directory. If dataset is already downloaded, it is not 63 | downloaded again. 64 | 65 | """ 66 | 67 | name = "connect-4" 68 | classes: List[str] = [ 69 | "draw", 70 | "loss", 71 | "win", 72 | ] 73 | -------------------------------------------------------------------------------- /torchhd/datasets/credit_approval.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class CreditApproval(DatasetFourFold): 29 | """`Credit Approval `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 690 41 | - 15 42 | - Classification 43 | - Financial 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 49 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 50 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 51 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 52 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 53 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 54 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 55 | while the second row corresponds to test indices (used if ``train = False``). 56 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 57 | and returns a transformed version. 58 | target_transform (callable, optional): A function/transform that takes in the 59 | target and transforms it. 60 | download (bool, optional): If True, downloads the dataset from the internet and 61 | puts it in root directory. If dataset is already downloaded, it is not 62 | downloaded again. 63 | 64 | """ 65 | 66 | name = "credit-approval" 67 | classes: List[str] = [ 68 | "+", 69 | "-", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/echocardiogram.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Echocardiogram(DatasetFourFold): 29 | """`Echocardiogram `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 132 41 | - 12 42 | - Classification 43 | - Life 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 49 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 50 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 51 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 52 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 53 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 54 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 55 | while the second row corresponds to test indices (used if ``train = False``). 56 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 57 | and returns a transformed version. 58 | target_transform (callable, optional): A function/transform that takes in the 59 | target and transforms it. 60 | download (bool, optional): If True, downloads the dataset from the internet and 61 | puts it in root directory. If dataset is already downloaded, it is not 62 | downloaded again. 63 | 64 | """ 65 | 66 | name = "echocardiogram" 67 | classes: List[str] = [ 68 | "dead", 69 | "alive", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/fertility.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Fertility(DatasetFourFold): 29 | """`Fertility `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 100 41 | - 10 42 | - Classification 43 | - Life 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 49 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 50 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 51 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 52 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 53 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 54 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 55 | while the second row corresponds to test indices (used if ``train = False``). 56 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 57 | and returns a transformed version. 58 | target_transform (callable, optional): A function/transform that takes in the 59 | target and transforms it. 60 | download (bool, optional): If True, downloads the dataset from the internet and 61 | puts it in root directory. If dataset is already downloaded, it is not 62 | downloaded again. 63 | 64 | 65 | """ 66 | 67 | name = "fertility" 68 | classes: List[str] = [ 69 | "normal", 70 | "altered", 71 | ] 72 | -------------------------------------------------------------------------------- /torchhd/datasets/hayes_roth.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class HayesRoth(DatasetTrainTest): 29 | """`Hayes-Roth `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 160 41 | - 5 42 | - Classification 43 | - Social 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 48 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 49 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 50 | while the second row corresponds to test indices (used if ``train = False``). 51 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 52 | and returns a transformed version. 53 | target_transform (callable, optional): A function/transform that takes in the 54 | target and transforms it. 55 | download (bool, optional): If True, downloads the dataset from the internet and 56 | puts it in root directory. If dataset is already downloaded, it is not 57 | downloaded again. 58 | 59 | """ 60 | 61 | name = "hayes-roth" 62 | classes: List[str] = [ 63 | "1", 64 | "2", 65 | "3", 66 | ] 67 | -------------------------------------------------------------------------------- /torchhd/datasets/hepatitis.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Hepatitis(DatasetFourFold): 29 | """`Hepatitis `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 155 41 | - 19 42 | - Classification 43 | - Life 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 49 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 50 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 51 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 52 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 53 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 54 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 55 | while the second row corresponds to test indices (used if ``train = False``). 56 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 57 | and returns a transformed version. 58 | target_transform (callable, optional): A function/transform that takes in the 59 | target and transforms it. 60 | download (bool, optional): If True, downloads the dataset from the internet and 61 | puts it in root directory. If dataset is already downloaded, it is not 62 | downloaded again. 63 | 64 | 65 | """ 66 | 67 | name = "hepatitis" 68 | classes: List[str] = [ 69 | "die", 70 | "live", 71 | ] 72 | -------------------------------------------------------------------------------- /torchhd/datasets/hill_valley.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class HillValley(DatasetTrainTest): 29 | """`Hill-Valley `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 606 41 | - 101 42 | - Classification 43 | - N/A 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 49 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 50 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 51 | while the second row corresponds to test indices (used if ``train = False``). 52 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 53 | and returns a transformed version. 54 | target_transform (callable, optional): A function/transform that takes in the 55 | target and transforms it. 56 | download (bool, optional): If True, downloads the dataset from the internet and 57 | puts it in root directory. If dataset is already downloaded, it is not 58 | downloaded again. 59 | 60 | 61 | """ 62 | 63 | name = "hill-valley" 64 | classes: List[str] = [ 65 | "valley", 66 | "hill", 67 | ] 68 | -------------------------------------------------------------------------------- /torchhd/datasets/horse_colic.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class HorseColic(DatasetTrainTest): 29 | """`Horse Colic `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 368 41 | - 27 42 | - Classification 43 | - Life 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 49 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 50 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 51 | while the second row corresponds to test indices (used if ``train = False``). 52 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 53 | and returns a transformed version. 54 | target_transform (callable, optional): A function/transform that takes in the 55 | target and transforms it. 56 | download (bool, optional): If True, downloads the dataset from the internet and 57 | puts it in root directory. If dataset is already downloaded, it is not 58 | downloaded again. 59 | 60 | 61 | """ 62 | 63 | name = "horse-colic" 64 | classes: List[str] = [ 65 | "Yes, it had surgery", 66 | "It was treated without surgery", 67 | ] 68 | -------------------------------------------------------------------------------- /torchhd/datasets/image_segmentation.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class ImageSegmentation(DatasetTrainTest): 29 | """`Image Segmentation `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 583 41 | - 10 42 | - Classification 43 | - Life 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 48 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 49 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 50 | while the second row corresponds to test indices (used if ``train = False``). 51 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 52 | and returns a transformed version. 53 | target_transform (callable, optional): A function/transform that takes in the 54 | target and transforms it. 55 | download (bool, optional): If True, downloads the dataset from the internet and 56 | puts it in root directory. If dataset is already downloaded, it is not 57 | downloaded again. 58 | 59 | """ 60 | 61 | name = "image-segmentation" 62 | classes: List[str] = [ 63 | "brickface", 64 | "sky", 65 | "foliage", 66 | "cement", 67 | "window", 68 | "path", 69 | "grass", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/ionosphere.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Ionosphere(DatasetFourFold): 29 | """`Ionosphere `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 351 41 | - 34 42 | - Classification 43 | - Physical 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 48 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 49 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 50 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 51 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 52 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 53 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 54 | while the second row corresponds to test indices (used if ``train = False``). 55 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 56 | and returns a transformed version. 57 | target_transform (callable, optional): A function/transform that takes in the 58 | target and transforms it. 59 | download (bool, optional): If True, downloads the dataset from the internet and 60 | puts it in root directory. If dataset is already downloaded, it is not 61 | downloaded again. 62 | 63 | 64 | """ 65 | 66 | name = "ionosphere" 67 | classes: List[str] = [ 68 | "good", 69 | "bad", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/iris.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Iris(DatasetFourFold): 29 | """`Iris `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 150 41 | - 4 42 | - Classification 43 | - Life 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 48 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 49 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 50 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 51 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 52 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 53 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 54 | while the second row corresponds to test indices (used if ``train = False``). 55 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 56 | and returns a transformed version. 57 | target_transform (callable, optional): A function/transform that takes in the 58 | target and transforms it. 59 | download (bool, optional): If True, downloads the dataset from the internet and 60 | puts it in root directory. If dataset is already downloaded, it is not 61 | downloaded again. 62 | 63 | 64 | """ 65 | 66 | name = "iris" 67 | classes: List[str] = [ 68 | "Iris Setosa", 69 | "Iris Versicolour", 70 | "Iris Virginica", 71 | ] 72 | -------------------------------------------------------------------------------- /torchhd/datasets/lung_cancer.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class LungCancer(DatasetFourFold): 29 | """`Lung Cancer `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 32 41 | - 56 42 | - Classification 43 | - Life 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 48 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 49 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 50 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 51 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 52 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 53 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 54 | while the second row corresponds to test indices (used if ``train = False``). 55 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 56 | and returns a transformed version. 57 | target_transform (callable, optional): A function/transform that takes in the 58 | target and transforms it. 59 | download (bool, optional): If True, downloads the dataset from the internet and 60 | puts it in root directory. If dataset is already downloaded, it is not 61 | downloaded again. 62 | 63 | 64 | """ 65 | 66 | name = "lung-cancer" 67 | classes: List[str] = [ 68 | "1", 69 | "2", 70 | "3", 71 | ] 72 | -------------------------------------------------------------------------------- /torchhd/datasets/monks_1.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class Monks1(DatasetTrainTest): 29 | """`MONK's Problems `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 432 41 | - 7 42 | - Classification 43 | - N/A 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 49 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 50 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 51 | while the second row corresponds to test indices (used if ``train = False``). 52 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 53 | and returns a transformed version. 54 | target_transform (callable, optional): A function/transform that takes in the 55 | target and transforms it. 56 | download (bool, optional): If True, downloads the dataset from the internet and 57 | puts it in root directory. If dataset is already downloaded, it is not 58 | downloaded again. 59 | 60 | 61 | """ 62 | 63 | name = "monks-1" 64 | classes: List[str] = [ 65 | "0", 66 | "1", 67 | ] 68 | -------------------------------------------------------------------------------- /torchhd/datasets/monks_2.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class Monks2(DatasetTrainTest): 29 | """`MONK's Problems `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 432 41 | - 7 42 | - Classification 43 | - N/A 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 49 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 50 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 51 | while the second row corresponds to test indices (used if ``train = False``). 52 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 53 | and returns a transformed version. 54 | target_transform (callable, optional): A function/transform that takes in the 55 | target and transforms it. 56 | download (bool, optional): If True, downloads the dataset from the internet and 57 | puts it in root directory. If dataset is already downloaded, it is not 58 | downloaded again. 59 | 60 | 61 | """ 62 | 63 | name = "monks-2" 64 | classes: List[str] = [ 65 | "0", 66 | "1", 67 | ] 68 | -------------------------------------------------------------------------------- /torchhd/datasets/monks_3.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class Monks3(DatasetTrainTest): 29 | """`MONK's Problems `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 432 41 | - 7 42 | - Classification 43 | - N/A 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 49 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 50 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 51 | while the second row corresponds to test indices (used if ``train = False``). 52 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 53 | and returns a transformed version. 54 | target_transform (callable, optional): A function/transform that takes in the 55 | target and transforms it. 56 | download (bool, optional): If True, downloads the dataset from the internet and 57 | puts it in root directory. If dataset is already downloaded, it is not 58 | downloaded again. 59 | 60 | 61 | """ 62 | 63 | name = "monks-3" 64 | classes: List[str] = [ 65 | "0", 66 | "1", 67 | ] 68 | -------------------------------------------------------------------------------- /torchhd/datasets/mushroom.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Mushroom(DatasetFourFold): 29 | """`Mushroom `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 8124 41 | - 22 42 | - Classification 43 | - Life 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 48 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 49 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 50 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 51 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 52 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 53 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 54 | while the second row corresponds to test indices (used if ``train = False``). 55 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 56 | and returns a transformed version. 57 | target_transform (callable, optional): A function/transform that takes in the 58 | target and transforms it. 59 | download (bool, optional): If True, downloads the dataset from the internet and 60 | puts it in root directory. If dataset is already downloaded, it is not 61 | downloaded again. 62 | 63 | 64 | """ 65 | 66 | name = "mushroom" 67 | classes: List[str] = [ 68 | "edible", 69 | "poisonous", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/musk_1.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Musk1(DatasetFourFold): 29 | """`Musk (Version 1) `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 476 41 | - 168 42 | - Classification 43 | - Physical 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 49 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 50 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 51 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 52 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 53 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 54 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 55 | while the second row corresponds to test indices (used if ``train = False``). 56 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 57 | and returns a transformed version. 58 | target_transform (callable, optional): A function/transform that takes in the 59 | target and transforms it. 60 | download (bool, optional): If True, downloads the dataset from the internet and 61 | puts it in root directory. If dataset is already downloaded, it is not 62 | downloaded again. 63 | 64 | 65 | """ 66 | 67 | name = "musk-1" 68 | classes: List[str] = [ 69 | "non-musk", 70 | "musk", 71 | ] 72 | -------------------------------------------------------------------------------- /torchhd/datasets/musk_2.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Musk2(DatasetFourFold): 29 | """`Musk (Version 2) `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 6598 41 | - 168 42 | - Classification 43 | - Physical 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 48 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 49 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 50 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 51 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 52 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 53 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 54 | while the second row corresponds to test indices (used if ``train = False``). 55 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 56 | and returns a transformed version. 57 | target_transform (callable, optional): A function/transform that takes in the 58 | target and transforms it. 59 | download (bool, optional): If True, downloads the dataset from the internet and 60 | puts it in root directory. If dataset is already downloaded, it is not 61 | downloaded again. 62 | 63 | 64 | """ 65 | 66 | name = "musk-2" 67 | classes: List[str] = [ 68 | "non-musk", 69 | "musk", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/oocytes_merluccius_nucleus_4d.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class OocytesMerlucciusNucleus4d(DatasetFourFold): 29 | """Description of the dataset is not available. 30 | 31 | Args: 32 | root (string): Root directory containing the files of the dataset. 33 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 34 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 35 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 36 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 37 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 38 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 39 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 40 | while the second row corresponds to test indices (used if ``train = False``). 41 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 42 | and returns a transformed version. 43 | target_transform (callable, optional): A function/transform that takes in the 44 | target and transforms it. 45 | download (bool, optional): If True, downloads the dataset from the internet and 46 | puts it in root directory. If dataset is already downloaded, it is not 47 | downloaded again. 48 | """ 49 | 50 | name = "oocytes_merluccius_nucleus_4d" 51 | classes: List[str] = [ 52 | "cn", 53 | "sn", 54 | ] 55 | -------------------------------------------------------------------------------- /torchhd/datasets/oocytes_merluccius_states_2f.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class OocytesMerlucciusStates2f(DatasetFourFold): 29 | """Description of the dataset is not available. 30 | 31 | Args: 32 | root (string): Root directory containing the files of the dataset. 33 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 34 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 35 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 36 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 37 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 38 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 39 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 40 | while the second row corresponds to test indices (used if ``train = False``). 41 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 42 | and returns a transformed version. 43 | target_transform (callable, optional): A function/transform that takes in the 44 | target and transforms it. 45 | download (bool, optional): If True, downloads the dataset from the internet and 46 | puts it in root directory. If dataset is already downloaded, it is not 47 | downloaded again. 48 | """ 49 | 50 | name = "oocytes_merluccius_states_2f" 51 | classes: List[str] = [ 52 | "ac", 53 | "hid", 54 | "v/at", 55 | ] 56 | -------------------------------------------------------------------------------- /torchhd/datasets/oocytes_trisopterus_nucleus_2f.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class OocytesTrisopterusNucleus2f(DatasetFourFold): 29 | """Description of the dataset is not available. 30 | 31 | Args: 32 | root (string): Root directory containing the files of the dataset. 33 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 34 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 35 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 36 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 37 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 38 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 39 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 40 | while the second row corresponds to test indices (used if ``train = False``). 41 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 42 | and returns a transformed version. 43 | target_transform (callable, optional): A function/transform that takes in the 44 | target and transforms it. 45 | download (bool, optional): If True, downloads the dataset from the internet and 46 | puts it in root directory. If dataset is already downloaded, it is not 47 | downloaded again. 48 | """ 49 | 50 | name = "oocytes_trisopterus_nucleus_2f" 51 | classes: List[str] = [ 52 | "cn", 53 | "sn", 54 | ] 55 | -------------------------------------------------------------------------------- /torchhd/datasets/oocytes_trisopterus_states_5b.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class OocytesTrisopterusStates5b(DatasetFourFold): 29 | """Description of the dataset is not available. 30 | 31 | Args: 32 | root (string): Root directory containing the files of the dataset. 33 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 34 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 35 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 36 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 37 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 38 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 39 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 40 | while the second row corresponds to test indices (used if ``train = False``). 41 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 42 | and returns a transformed version. 43 | target_transform (callable, optional): A function/transform that takes in the 44 | target and transforms it. 45 | download (bool, optional): If True, downloads the dataset from the internet and 46 | puts it in root directory. If dataset is already downloaded, it is not 47 | downloaded again. 48 | """ 49 | 50 | name = "oocytes_trisopterus_states_5b" 51 | classes: List[str] = [ 52 | "ac", 53 | "hid", 54 | "v/at", 55 | ] 56 | -------------------------------------------------------------------------------- /torchhd/datasets/optical.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class Optical(DatasetTrainTest): 29 | """`Optical Recognition of Handwritten Digits `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 5620 41 | - 64 42 | - Classification 43 | - Computer 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 48 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 49 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 50 | while the second row corresponds to test indices (used if ``train = False``). 51 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 52 | and returns a transformed version. 53 | target_transform (callable, optional): A function/transform that takes in the 54 | target and transforms it. 55 | download (bool, optional): If True, downloads the dataset from the internet and 56 | puts it in root directory. If dataset is already downloaded, it is not 57 | downloaded again. 58 | 59 | 60 | """ 61 | 62 | name = "optical" 63 | classes: List[str] = [ 64 | "0", 65 | "1", 66 | "2", 67 | "3", 68 | "4", 69 | "5", 70 | "6", 71 | "7", 72 | "8", 73 | "9", 74 | ] 75 | -------------------------------------------------------------------------------- /torchhd/datasets/parkinsons.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Parkinsons(DatasetFourFold): 29 | """`Parkinsons `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 197 41 | - 23 42 | - Classification 43 | - Life 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 48 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 49 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 50 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 51 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 52 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 53 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 54 | while the second row corresponds to test indices (used if ``train = False``). 55 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 56 | and returns a transformed version. 57 | target_transform (callable, optional): A function/transform that takes in the 58 | target and transforms it. 59 | download (bool, optional): If True, downloads the dataset from the internet and 60 | puts it in root directory. If dataset is already downloaded, it is not 61 | downloaded again. 62 | 63 | 64 | """ 65 | 66 | name = "parkinsons" 67 | classes: List[str] = [ 68 | "healthy", 69 | "Parkinson's disease", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/pendigits.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class Pendigits(DatasetTrainTest): 29 | """`Pen-Based Recognition of Handwritten Digits `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 10992 41 | - 16 42 | - Classification 43 | - Computer 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 48 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 49 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 50 | while the second row corresponds to test indices (used if ``train = False``). 51 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 52 | and returns a transformed version. 53 | target_transform (callable, optional): A function/transform that takes in the 54 | target and transforms it. 55 | download (bool, optional): If True, downloads the dataset from the internet and 56 | puts it in root directory. If dataset is already downloaded, it is not 57 | downloaded again. 58 | 59 | 60 | """ 61 | 62 | name = "pendigits" 63 | classes: List[str] = [ 64 | "0", 65 | "1", 66 | "2", 67 | "3", 68 | "4", 69 | "5", 70 | "6", 71 | "7", 72 | "8", 73 | "9", 74 | ] 75 | -------------------------------------------------------------------------------- /torchhd/datasets/pima.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Pima(DatasetFourFold): 29 | """`Pima Indians Diabetes `_ dataset. 30 | 31 | Args: 32 | root (string): Root directory containing the files of the dataset. 33 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 34 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 35 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 36 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 37 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 38 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 39 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 40 | while the second row corresponds to test indices (used if ``train = False``). 41 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 42 | and returns a transformed version. 43 | target_transform (callable, optional): A function/transform that takes in the 44 | target and transforms it. 45 | download (bool, optional): If True, downloads the dataset from the internet and 46 | puts it in root directory. If dataset is already downloaded, it is not 47 | downloaded again. 48 | """ 49 | 50 | name = "pima" 51 | classes: List[str] = [ 52 | "tested negative for diabetes", 53 | "tested positive for diabetes", 54 | ] 55 | -------------------------------------------------------------------------------- /torchhd/datasets/planning.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Planning(DatasetFourFold): 29 | """`Planning Relax `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 182 41 | - 13 42 | - Classification 43 | - Computer 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 48 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 49 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 50 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 51 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 52 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 53 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 54 | while the second row corresponds to test indices (used if ``train = False``). 55 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 56 | and returns a transformed version. 57 | target_transform (callable, optional): A function/transform that takes in the 58 | target and transforms it. 59 | download (bool, optional): If True, downloads the dataset from the internet and 60 | puts it in root directory. If dataset is already downloaded, it is not 61 | downloaded again. 62 | 63 | 64 | """ 65 | 66 | name = "planning" 67 | classes: List[str] = [ 68 | "1", 69 | "2", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/ringnorm.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Ringnorm(DatasetFourFold): 29 | """`Ringnorm `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 7400 41 | - 21 42 | - Classification 43 | - N/A 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 48 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 49 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 50 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 51 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 52 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 53 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 54 | while the second row corresponds to test indices (used if ``train = False``). 55 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 56 | and returns a transformed version. 57 | target_transform (callable, optional): A function/transform that takes in the 58 | target and transforms it. 59 | download (bool, optional): If True, downloads the dataset from the internet and 60 | puts it in root directory. If dataset is already downloaded, it is not 61 | downloaded again. 62 | 63 | 64 | """ 65 | 66 | name = "ringnorm" 67 | classes: List[str] = [ 68 | "1", 69 | "2", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/seeds.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Seeds(DatasetFourFold): 29 | """`Seeds `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 210 41 | - 7 42 | - Classification 43 | - Life 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 48 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 49 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 50 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 51 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 52 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 53 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 54 | while the second row corresponds to test indices (used if ``train = False``). 55 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 56 | and returns a transformed version. 57 | target_transform (callable, optional): A function/transform that takes in the 58 | target and transforms it. 59 | download (bool, optional): If True, downloads the dataset from the internet and 60 | puts it in root directory. If dataset is already downloaded, it is not 61 | downloaded again. 62 | 63 | 64 | """ 65 | 66 | name = "seeds" 67 | classes: List[str] = [ 68 | "Kama", 69 | "Rosa", 70 | "Canadian", 71 | ] 72 | -------------------------------------------------------------------------------- /torchhd/datasets/soybean.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class Soybean(DatasetTrainTest): 29 | """`Soybean (Large) `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 307 41 | - 35 42 | - Classification 43 | - Life 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 48 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 49 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 50 | while the second row corresponds to test indices (used if ``train = False``). 51 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 52 | and returns a transformed version. 53 | target_transform (callable, optional): A function/transform that takes in the 54 | target and transforms it. 55 | download (bool, optional): If True, downloads the dataset from the internet and 56 | puts it in root directory. If dataset is already downloaded, it is not 57 | downloaded again. 58 | 59 | 60 | """ 61 | 62 | name = "soybean" 63 | classes: List[str] = [ 64 | "diaporthe-stem-canker", 65 | "charcoal-rot", 66 | "rhizoctonia-root-rot", 67 | "phytophthora-rot", 68 | "brown-stem-rot", 69 | "powdery-mildew", 70 | "downy-mildew", 71 | "brown-spot", 72 | "bacterial-blight", 73 | "bacterial-pustule", 74 | "purple-seed-stain", 75 | "anthracnose", 76 | "phyllosticta-leaf-spot", 77 | "alternarialeaf-spot", 78 | "frog-eye-leaf-spot", 79 | "diaporthe-pod-&-stem-blight", 80 | "cyst-nematode", 81 | "herbicide-injury", 82 | ] 83 | -------------------------------------------------------------------------------- /torchhd/datasets/spambase.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Spambase(DatasetFourFold): 29 | """`Spambase `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 4601 41 | - 57 42 | - Classification 43 | - Computer 44 | 45 | Args: 46 | root (string): Root directory containing the files of the dataset. 47 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 48 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 49 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 50 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 51 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 52 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 53 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 54 | while the second row corresponds to test indices (used if ``train = False``). 55 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 56 | and returns a transformed version. 57 | target_transform (callable, optional): A function/transform that takes in the 58 | target and transforms it. 59 | download (bool, optional): If True, downloads the dataset from the internet and 60 | puts it in root directory. If dataset is already downloaded, it is not 61 | downloaded again. 62 | 63 | 64 | """ 65 | 66 | name = "spambase" 67 | classes: List[str] = [ 68 | "non-spam", 69 | "spam", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/spect.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class Spect(DatasetTrainTest): 29 | """`SPECT Heart Data `_ dataset. 30 | 31 | 32 | .. list-table:: 33 | :widths: 10 10 10 10 34 | :align: center 35 | :header-rows: 1 36 | 37 | * - Instances 38 | - Attributes 39 | - Task 40 | - Area 41 | * - 267 42 | - 22 43 | - Classification 44 | - Life 45 | 46 | 47 | Args: 48 | root (string): Root directory containing the files of the dataset. 49 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 50 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 51 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 52 | while the second row corresponds to test indices (used if ``train = False``). 53 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 54 | and returns a transformed version. 55 | target_transform (callable, optional): A function/transform that takes in the 56 | target and transforms it. 57 | download (bool, optional): If True, downloads the dataset from the internet and 58 | puts it in root directory. If dataset is already downloaded, it is not 59 | downloaded again. 60 | 61 | """ 62 | 63 | name = "spect" 64 | classes: List[str] = [ 65 | "normal", 66 | "abnormal", 67 | ] 68 | -------------------------------------------------------------------------------- /torchhd/datasets/spectf.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class Spectf(DatasetTrainTest): 29 | """`SPECTF Heart Data `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 267 41 | - 44 42 | - Classification 43 | - Life 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 49 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 50 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 51 | while the second row corresponds to test indices (used if ``train = False``). 52 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 53 | and returns a transformed version. 54 | target_transform (callable, optional): A function/transform that takes in the 55 | target and transforms it. 56 | download (bool, optional): If True, downloads the dataset from the internet and 57 | puts it in root directory. If dataset is already downloaded, it is not 58 | downloaded again. 59 | 60 | 61 | """ 62 | 63 | name = "spectf" 64 | classes: List[str] = [ 65 | "normal", 66 | "abnormal", 67 | ] 68 | -------------------------------------------------------------------------------- /torchhd/datasets/statlog_landsat.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class StatlogLandsat(DatasetTrainTest): 29 | """`Statlog (Landsat Satellite) `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 6435 41 | - 36 42 | - Classification 43 | - Physical 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 49 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 50 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 51 | while the second row corresponds to test indices (used if ``train = False``). 52 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 53 | and returns a transformed version. 54 | target_transform (callable, optional): A function/transform that takes in the 55 | target and transforms it. 56 | download (bool, optional): If True, downloads the dataset from the internet and 57 | puts it in root directory. If dataset is already downloaded, it is not 58 | downloaded again. 59 | 60 | """ 61 | 62 | name = "statlog-landsat" 63 | classes: List[str] = [ 64 | "red soil", 65 | "cotton crop", 66 | "grey soil", 67 | "damp grey soil", 68 | "soil with vegetation stubble", 69 | "mixture class (all types present)", 70 | ] 71 | -------------------------------------------------------------------------------- /torchhd/datasets/statlog_shuttle.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class StatlogShuttle(DatasetTrainTest): 29 | """`Statlog (Shuttle) `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 58000 41 | - 9 42 | - Classification 43 | - Physical 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 49 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 50 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 51 | while the second row corresponds to test indices (used if ``train = False``). 52 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 53 | and returns a transformed version. 54 | target_transform (callable, optional): A function/transform that takes in the 55 | target and transforms it. 56 | download (bool, optional): If True, downloads the dataset from the internet and 57 | puts it in root directory. If dataset is already downloaded, it is not 58 | downloaded again. 59 | 60 | 61 | """ 62 | 63 | name = "statlog-shuttle" 64 | classes: List[str] = [ 65 | "Rad Flow", 66 | "Fpv Close", 67 | "Fpv Open", 68 | "High", 69 | "Bypass", 70 | "Bpv Close", 71 | "Bpv Open", 72 | ] 73 | -------------------------------------------------------------------------------- /torchhd/datasets/thyroid.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetTrainTest 26 | 27 | 28 | class Thyroid(DatasetTrainTest): 29 | """`Thyroid Disease `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 7200 41 | - 21 42 | - Classification 43 | - Life 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by hyper_search variable. 49 | Otherwise returns a subset of train dataset if hyperparameter search is performed (``hyper_search = True``) if not (``hyper_search = False``) returns test set. 50 | hyper_search (bool, optional): If True, creates dataset using indices in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 51 | while the second row corresponds to test indices (used if ``train = False``). 52 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 53 | and returns a transformed version. 54 | target_transform (callable, optional): A function/transform that takes in the 55 | target and transforms it. 56 | download (bool, optional): If True, downloads the dataset from the internet and 57 | puts it in root directory. If dataset is already downloaded, it is not 58 | downloaded again. 59 | 60 | 61 | """ 62 | 63 | name = "thyroid" 64 | classes: List[str] = [ 65 | "normal", 66 | "hyperfunction", 67 | "subnormal functioning", 68 | ] 69 | -------------------------------------------------------------------------------- /torchhd/datasets/titanic.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Titanic(DatasetFourFold): 29 | """`Titanic `_ dataset. 30 | 31 | Args: 32 | root (string): Root directory containing the files of the dataset. 33 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 34 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 35 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 36 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 37 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 38 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 39 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 40 | while the second row corresponds to test indices (used if ``train = False``). 41 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 42 | and returns a transformed version. 43 | target_transform (callable, optional): A function/transform that takes in the 44 | target and transforms it. 45 | download (bool, optional): If True, downloads the dataset from the internet and 46 | puts it in root directory. If dataset is already downloaded, it is not 47 | downloaded again. 48 | """ 49 | 50 | name = "titanic" 51 | classes: List[str] = [ 52 | "no", 53 | "yes", 54 | ] 55 | -------------------------------------------------------------------------------- /torchhd/datasets/trains.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Trains(DatasetFourFold): 29 | """`Trains `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 10 41 | - 32 42 | - Classification 43 | - N/A 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 49 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 50 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 51 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 52 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 53 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 54 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 55 | while the second row corresponds to test indices (used if ``train = False``). 56 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 57 | and returns a transformed version. 58 | target_transform (callable, optional): A function/transform that takes in the 59 | target and transforms it. 60 | download (bool, optional): If True, downloads the dataset from the internet and 61 | puts it in root directory. If dataset is already downloaded, it is not 62 | downloaded again. 63 | 64 | 65 | """ 66 | 67 | name = "trains" 68 | classes: List[str] = [ 69 | "east", 70 | "west", 71 | ] 72 | -------------------------------------------------------------------------------- /torchhd/datasets/twonorm.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Twonorm(DatasetFourFold): 29 | """Leo Breiman's twonorm example - Classification of 2 overlapping normal distributions. 30 | 31 | Args: 32 | root (string): Root directory containing the files of the dataset. 33 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 34 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 35 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 36 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 37 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 38 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 39 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 40 | while the second row corresponds to test indices (used if ``train = False``). 41 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 42 | and returns a transformed version. 43 | target_transform (callable, optional): A function/transform that takes in the 44 | target and transforms it. 45 | download (bool, optional): If True, downloads the dataset from the internet and 46 | puts it in root directory. If dataset is already downloaded, it is not 47 | downloaded again. 48 | """ 49 | 50 | name = "twonorm" 51 | classes: List[str] = [ 52 | "0", 53 | "1", 54 | ] 55 | -------------------------------------------------------------------------------- /torchhd/datasets/utils.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | import zipfile 25 | import requests 26 | import tqdm 27 | 28 | 29 | def download_file(url, destination): 30 | response = requests.get(url, allow_redirects=True, stream=True) 31 | write_response_to_disk(response, destination) 32 | 33 | 34 | def download_file_from_google_drive(file_id, destination): 35 | try: 36 | import gdown 37 | except ImportError: 38 | raise ImportError( 39 | "Downloading files from Google drive requires gdown to be installed, see: https://github.com/wkentaro/gdown" 40 | ) 41 | 42 | url = f"https://drive.google.com/uc?id={file_id}" 43 | gdown.download(url, destination) 44 | 45 | 46 | def get_download_progress_bar(response): 47 | total = response.headers.get("Content-Length") 48 | if total is not None: 49 | total = int(total) 50 | 51 | if total is not None: 52 | pbar = tqdm.tqdm(total=total, unit="B", unit_scale=True) 53 | 54 | def update(progress): 55 | if total is not None: 56 | pbar.update(progress) 57 | 58 | return update 59 | 60 | 61 | def write_response_to_disk(response, destination): 62 | CHUNK_SIZE = 32768 63 | 64 | update_progress_bar = get_download_progress_bar(response) 65 | 66 | with open(destination, "wb") as file: 67 | for chunk in response.iter_content(CHUNK_SIZE): 68 | if chunk: # filter out keep-alive new chunks 69 | file.write(chunk) 70 | update_progress_bar(len(chunk)) 71 | 72 | 73 | def unzip_file(file, destination): 74 | with zipfile.ZipFile(file, "r") as zip_file: 75 | zip_file.extractall(destination) 76 | -------------------------------------------------------------------------------- /torchhd/datasets/wine.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import List 25 | from torchhd.datasets import DatasetFourFold 26 | 27 | 28 | class Wine(DatasetFourFold): 29 | """`Wine `_ dataset. 30 | 31 | .. list-table:: 32 | :widths: 10 10 10 10 33 | :align: center 34 | :header-rows: 1 35 | 36 | * - Instances 37 | - Attributes 38 | - Task 39 | - Area 40 | * - 178 41 | - 13 42 | - Classification 43 | - Physical 44 | 45 | 46 | Args: 47 | root (string): Root directory containing the files of the dataset. 48 | train (bool, optional): If True, returns training (sub)set from the file storing training data as further determined by fold and hyper_search variables. 49 | Otherwise returns a subset of train dataset if hypersearch is performed (``hyper_search = True``) if not (``hyper_search = False``) returns a subset of training dataset 50 | as specified in ``conxuntos_kfold.dat`` if fold number is correct. Otherwise issues an error. 51 | fold (int, optional): Specifies which fold number to use. The default value of -1 returns all the training data from the corresponding file. 52 | Values between 0 and 3 specify, which fold in ``conxuntos_kfold.dat`` to use. Relevant only if hyper_search is set to False and ``0 <= fold <= 3``. 53 | Indices in even rows (zero indexing) of ``conxuntos_kfold.dat`` correspond to train subsets while indices in odd rows correspond to test subsets. 54 | hyper_search (bool, optional): If True, creates dataset using indeces in ``conxuntos.dat``. This split is used for hyperparameter search. The first row corresponds to train indices (used if ``train = True``) 55 | while the second row corresponds to test indices (used if ``train = False``). 56 | transform (callable, optional): A function/transform that takes in an torch.FloatTensor 57 | and returns a transformed version. 58 | target_transform (callable, optional): A function/transform that takes in the 59 | target and transforms it. 60 | download (bool, optional): If True, downloads the dataset from the internet and 61 | puts it in root directory. If dataset is already downloaded, it is not 62 | downloaded again. 63 | 64 | 65 | """ 66 | 67 | name = "wine" 68 | classes: List[str] = [ 69 | "1", 70 | "2", 71 | "3", 72 | ] 73 | -------------------------------------------------------------------------------- /torchhd/tensors/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | -------------------------------------------------------------------------------- /torchhd/tests/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | -------------------------------------------------------------------------------- /torchhd/tests/basis_hv/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | -------------------------------------------------------------------------------- /torchhd/tests/structures/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | -------------------------------------------------------------------------------- /torchhd/tests/utils.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import Union, Type 25 | import torch 26 | import torchhd 27 | from torchhd.types import VSAOptions 28 | 29 | number = Union[float, int] 30 | 31 | 32 | def between(value: number, low: number, high: number) -> bool: 33 | return low < value < high 34 | 35 | 36 | def within(value: number, target: number, delta: number) -> bool: 37 | return between(value, target - delta, target + delta) 38 | 39 | 40 | torch_float_dtypes = { 41 | torch.float16, 42 | torch.bfloat16, 43 | torch.float32, 44 | torch.float64, 45 | } 46 | 47 | torch_complex_dtypes = { 48 | torch.complex64, 49 | torch.complex128, 50 | } 51 | 52 | torch_int_dtypes = { 53 | torch.uint8, 54 | torch.int8, 55 | torch.int16, 56 | torch.int32, 57 | torch.int64, 58 | } 59 | 60 | torch_dtypes = { 61 | torch.float16, 62 | torch.bfloat16, 63 | torch.float32, 64 | torch.float64, 65 | torch.complex64, 66 | torch.complex128, 67 | torch.uint8, 68 | torch.int8, 69 | torch.int16, 70 | torch.int32, 71 | torch.int64, 72 | torch.bool, 73 | } 74 | 75 | 76 | def supported_dtype( 77 | dtype: torch.dtype, vsa: Union[Type[torchhd.VSATensor], VSAOptions] 78 | ) -> bool: 79 | if isinstance(vsa, str): 80 | vsa_tensor = torchhd.functional.get_vsa_tensor_class(vsa) 81 | else: 82 | vsa_tensor = vsa 83 | 84 | if not issubclass(vsa_tensor, torchhd.VSATensor): 85 | raise ValueError("Must provide a VSATensor class") 86 | 87 | return dtype in vsa_tensor.supported_dtypes 88 | 89 | 90 | vsa_tensors = [ 91 | "BSC", 92 | "MAP", 93 | "HRR", 94 | "FHRR", 95 | "BSBC", 96 | "VTB", 97 | "MCR", 98 | "CGR" 99 | ] 100 | -------------------------------------------------------------------------------- /torchhd/types.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | from typing import Literal 25 | 26 | VSAOptions = Literal["BSC", "MAP", "HRR", "FHRR", "BSBC", "VTB", "MCR", "CGR"] 27 | -------------------------------------------------------------------------------- /torchhd/version.py: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2023 Mike Heddes, Igor Nunes, Pere Vergés, Denis Kleyko, and Danny Abraham 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | __version__ = "5.8.4" 25 | --------------------------------------------------------------------------------