{"id":20157254,"url":"https://github.com/robinka/tfga","last_synced_at":"2025-08-02T08:34:42.846Z","repository":{"id":44910676,"uuid":"266543428","full_name":"RobinKa/tfga","owner":"RobinKa","description":"Python package for Geometric / Clifford Algebra with TensorFlow","archived":false,"fork":false,"pushed_at":"2023-05-23T06:16:13.000Z","size":2423,"stargazers_count":52,"open_issues_count":11,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-07-30T20:38:23.201Z","etag":null,"topics":["automatic-differentiation","bivector","clifford-algebra","deep-learning","geometric-algebra","gpu-acceleration","keras","mathematics","multivector","neural-networks","paravector","physics","python","quantum-electrodynamics","real-dirac-theory","tensorflow","vector"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobinKa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-05-24T13:10:36.000Z","updated_at":"2025-06-12T14:42:50.000Z","dependencies_parsed_at":"2024-01-14T23:58:41.128Z","dependency_job_id":"47644f12-325b-4d0c-8fb4-13120e7ba623","html_url":"https://github.com/RobinKa/tfga","commit_stats":{"total_commits":108,"total_committers":5,"mean_commits":21.6,"dds":"0.13888888888888884","last_synced_commit":"31350b9159626083c6f9ddfa8ac67a6c36cf5089"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/RobinKa/tfga","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinKa%2Ftfga","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinKa%2Ftfga/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinKa%2Ftfga/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinKa%2Ftfga/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobinKa","download_url":"https://codeload.github.com/RobinKa/tfga/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinKa%2Ftfga/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268355765,"owners_count":24237367,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automatic-differentiation","bivector","clifford-algebra","deep-learning","geometric-algebra","gpu-acceleration","keras","mathematics","multivector","neural-networks","paravector","physics","python","quantum-electrodynamics","real-dirac-theory","tensorflow","vector"],"created_at":"2024-11-13T23:44:55.468Z","updated_at":"2025-08-02T08:34:42.819Z","avatar_url":"https://github.com/RobinKa.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TFGA - TensorFlow Geometric Algebra\n[![Build status](https://github.com/RobinKa/tfga/workflows/Build%20Test%20Publish/badge.svg)](https://github.com/RobinKa/tfga/actions) [![PyPI](https://badge.fury.io/py/tfga.svg)](https://badge.fury.io/py/tfga) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3902404.svg)](https://doi.org/10.5281/zenodo.3902404)\n\n[GitHub](https://github.com/RobinKa/tfga) | [Docs](https://tfga.warlock.ai) | [Benchmarks](https://github.com/RobinKa/tfga/tree/master/benchmarks) | [Slides](https://tfgap.warlock.ai)\n\nPython package for Geometric / Clifford Algebra with TensorFlow 2.\n\n**This project is a work in progress. Its API may change and the examples aren't polished yet.**\n\nPull requests and suggestions either by opening an issue or by [sending me an email](mailto:tora@warlock.ai) are welcome.\n\n## Installation\nInstall using pip: `pip install tfga`\n\nRequirements:\n- Python 3\n- tensorflow 2\n- numpy\n\n## Basic usage\nThere are two ways to use this library. In both ways we first create a [`GeometricAlgebra`](https://tfga.warlock.ai/tfga.html#tfga.tfga.GeometricAlgebra) instance given a metric.\nThen we can either work on [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) instances directly where the last axis is assumed to correspond to\nthe algebra's blades.\n```python\nimport tensorflow as tf\nfrom tfga import GeometricAlgebra\n\n# Create an algebra with 3 basis vectors given their metric.\n# Contains geometric algebra operations.\nga = GeometricAlgebra(metric=[1, 1, 1])\n\n# Create geometric algebra tf.Tensor for vector blades (ie. e_0 + e_1 + e_2).\n# Represented as tf.Tensor with shape [8] (one value for each blade of the algebra).\n# tf.Tensor: [0, 1, 1, 1, 0, 0, 0, 0]\nordinary_vector = ga.from_tensor_with_kind(tf.ones(3), kind=\"vector\")\n\n# 5 + 5 e_01 + 5 e_02 + 5 e_12\nquaternion = ga.from_tensor_with_kind(tf.fill(dims=4, value=5), kind=\"even\")\n\n# 5 + 1 e_0 + 1 e_1 + 1 e_2 + 5 e_01 + 5 e_02 + 5 e_12\nmultivector = ordinary_vector + quaternion\n\n# Inner product e_0 | (e_0 + e_1 + e_2) = 1\n# ga.print is like print, but has extra formatting for geometric algebra tf.Tensor instances.\nga.print(ga.inner_prod(ga.e0, ordinary_vector))\n\n# Exterior product e_0 ^ e_1 = e_01.\nga.print(ga.ext_prod(ga.e0, ga.e1))\n\n# Grade reversal ~(5 + 5 e_01 + 5 e_02 + 5 e_12)\n# = 5 + 5 e_10 + 5 e_20 + 5 e_21\n# = 5 - 5 e_01 - 5 e_02 - 5 e_12\nga.print(ga.reversion(quaternion))\n\n# tf.Tensor 5\nga.print(quaternion[0])\n\n# tf.Tensor of shape [1]: -5 (ie. reversed sign of e_01 component)\nga.print(ga.select_blades_with_name(quaternion, \"10\"))\n\n# tf.Tensor of shape [8] with only e_01 component equal to 5\nga.print(ga.keep_blades_with_name(quaternion, \"10\"))\n```\n\nAlternatively we can convert the geometric algebra [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) instance to [`MultiVector`](https://tfga.warlock.ai/tfga.html#tfga.mv.MultiVector)\ninstances which wrap the operations and provide operator overrides for convenience.\nThis can be done by using the `__call__` operator of the [`GeometricAlgebra`](https://tfga.warlock.ai/tfga.html#tfga.tfga.GeometricAlgebra) instance.\n```python\n# Create geometric algebra tf.Tensor instances\na = ga.e123\nb = ga.e1\n\n# Wrap them as `MultiVector` instances\nmv_a = ga(a)\nmv_b = ga(b)\n\n# Reversion ((~mv_a).tensor equivalent to ga.reversion(a))\nprint(~mv_a)\n\n# Geometric / inner / exterior product\nprint(mv_a * mv_b)\nprint(mv_a | mv_b)\nprint(mv_a ^ mv_b)\n```\n\n## Keras layers\nTFGA also provides [Keras](https://www.tensorflow.org/guide/keras/sequential_model) layers which provide\nlayers similar to the existing ones but using multivectors instead. For example the [`GeometricProductDense`](https://tfga.warlock.ai/tfga.html#tfga.layers.GeometricProductDense)\nlayer is exactly the same as the [`Dense`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense) layer but uses\nmultivector-valued weights and biases instead of scalar ones. The exact kind of multivector-type can be\npassed too. Example:\n\n```python\nimport tensorflow as tf\nfrom tfga import GeometricAlgebra\nfrom tfga.layers import TensorToGeometric, GeometricToTensor, GeometricProductDense\n\n# 4 basis vectors (e0^2=+1, e1^2=-1, e2^2=-1, e3^2=-1)\nsta = GeometricAlgebra([1, -1, -1, -1])\n\n# We want our dense layer to perform a matrix multiply\n# with a matrix that has vector-valued entries.\nvector_blade_indices = sta.get_kind_blade_indices(BladeKind.VECTOR),\n\n# Create our input of shape [Batch, Units, BladeValues]\ntensor = tf.ones([20, 6, 4])\n\n# The matrix-multiply will perform vector * vector\n# so our result will be scalar + bivector.\n# Use the resulting blade type for the bias too which is\n# added to the result.\nresult_indices = tf.concat([\n    sta.get_kind_blade_indices(BladeKind.SCALAR), # 1 index\n    sta.get_kind_blade_indices(BladeKind.BIVECTOR) # 6 indices\n], axis=0)\n\nsequence = tf.keras.Sequential([\n    # Converts the last axis to a dense multivector\n    # (so, 4 -\u003e 16 (total number of blades in the algebra))\n    TensorToGeometric(sta, blade_indices=vector_blade_indices),\n    # Perform matrix multiply with vector-valued matrix\n    GeometricProductDense(\n        algebra=sta, units=8, # units is analagous to Keras' Dense layer\n        blade_indices_kernel=vector_blade_indices,\n        blade_indices_bias=result_indices\n    ),\n    # Extract our wanted blade indices (last axis 16 -\u003e 7 (1+6))\n    GeometricToTensor(sta, blade_indices=result_indices)\n])\n\n# Result will have shape [20, 8, 7]\nresult = sequence(tensor)\n```\n\n### Available layers\n| Class | Description |\n|--|--|\n| [`GeometricProductDense`](https://tfga.warlock.ai/tfga.html#tfga.layers.GeometricProductDense) | Analagous to Keras' [`Dense`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense) with multivector-valued weights and biases. Each term in the matrix multiplication does the geometric product `x * w`. |\n| [`GeometricSandwichProductDense`](https://tfga.warlock.ai/tfga.html#tfga.layers.GeometricSandwichProductDense) | Analagous to Keras' [`Dense`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense) with multivector-valued weights and biases. Each term in the matrix multiplication does the geometric product `w *x * ~w`. |\n| [`GeometricProductElementwise`](https://tfga.warlock.ai/tfga.html#tfga.layers.GeometricProductElementwise) | Performs multivector-valued elementwise geometric product of the input units with a different weight for each unit. |\n| [`GeometricSandwichProductElementwise`](https://tfga.warlock.ai/tfga.html#tfga.layers.GeometricSandwichProductElementwise) | Performs multivector-valued elementwise geometric sandwich product of the input units with a different weight for each unit. |\n| [`GeometricProductConv1D`](https://tfga.warlock.ai/tfga.html#tfga.layers.GeometricProductConv1D) | Analagous to Keras' [`Conv1D`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv1D) with multivector-valued kernels and biases. Each term in the kernel multiplication does the geometric product `x * k`. |\n| [`TensorToGeometric`](https://tfga.warlock.ai/tfga.html#tfga.layers.TensorToGeometric) | Converts from a [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) to the geometric algebra [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) with as many blades on the last axis as basis blades in the algebra where blade indices determine which basis blades the input's values belong to. |\n| [`GeometricToTensor`](https://tfga.warlock.ai/tfga.html#tfga.layers.GeometricToTensor) | Converts from a geometric algebra [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) with as many blades on the last axis as basis blades in the algebra to a [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) where blade indices determine which basis blades we extract for the output. |\n| [`TensorWithKindToGeometric`](https://tfga.warlock.ai/tfga.html#tfga.layers.TensorWithKindToGeometric) | Same as [`TensorToGeometric`](https://tfga.warlock.ai/tfga.html#tfga.layers.TensorToGeometric) but using [`BladeKind`](https://tfga.warlock.ai/tfga.html#tfga.blades.BladeKind) (eg. `\"bivector\"`, `\"even\"`) instead of blade indices. |\n| [`GeometricToTensorWithKind`](https://tfga.warlock.ai/tfga.html#tfga.layers.GeometricToTensorWithKind) | Same as [`GeometricToTensor`](https://tfga.warlock.ai/tfga.html#tfga.layers.GeometricToTensor) but using [`BladeKind`](https://tfga.warlock.ai/tfga.html#tfga.blades.BladeKind) (eg. `\"bivector\"`, `\"even\"`) instead of blade indices. |\n| [`GeometricAlgebraExp`](https://tfga.warlock.ai/tfga.html#tfga.layers.GeometricAlgebraExp) | Calculates the exponential function of the input. Input must square to a scalar. |\n\n## Notebooks\n[Generic examples](https://github.com/RobinKa/tfga/tree/master/notebooks/tfga.ipynb)\n\n[Using Keras layers to estimate triangle area](https://github.com/RobinKa/tfga/tree/master/notebooks/keras-triangles.ipynb)\n\n[Classical Electromagnetism using Geometric Algebra](https://github.com/RobinKa/tfga/tree/master/notebooks/em.ipynb)\n\n[Quantum Electrodynamics using Geometric Algebra](https://github.com/RobinKa/tfga/tree/master/notebooks/qed.ipynb)\n\n[Projective Geometric Algebra](https://github.com/RobinKa/tfga/tree/master/notebooks/pga.ipynb)\n\n[1D Multivector-valued Convolution Example](https://github.com/RobinKa/tfga/tree/master/notebooks/conv.ipynb)\n\n## Tests\nTests using Python's built-in [`unittest`](https://docs.python.org/3/library/unittest.html) module are available in the `tests` directory. All tests can be run by\nexecuting `python -m unittest discover tests` from the root directory of the repository.\n\n## Citing\nSee our [Zenodo](https://doi.org/10.5281/zenodo.3902404) page. For citing all versions the following BibTeX can be used\n\n```\n@software{python_tfga,\n  author       = {Kahlow, Robin},\n  title        = {TensorFlow Geometric Algebra},\n  publisher    = {Zenodo},\n  doi          = {10.5281/zenodo.3902404},\n  url          = {https://doi.org/10.5281/zenodo.3902404}\n}\n```\n\n## Disclaimer\nTensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinka%2Ftfga","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobinka%2Ftfga","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinka%2Ftfga/lists"}