hypercube-hopfield1984 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,75 @@
1
+ cmake_minimum_required(VERSION 3.20)
2
+ project(HypercubeHopfield1984Python LANGUAGES CXX)
3
+
4
+ set(CMAKE_CXX_STANDARD 23)
5
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
6
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
7
+
8
+ # ── pybind11 ──
9
+ find_package(pybind11 CONFIG REQUIRED)
10
+
11
+ # ── Optimization flags (match the main project / sibling python builds) ──
12
+ # HYPERCUBE_ARCH controls -march. Defaults to "native" for local dev builds.
13
+ # cibuildwheel overrides to "x86-64-v2" (x86_64) or "none" (ARM, MSVC).
14
+ set(HYPERCUBE_ARCH "native" CACHE STRING "Target architecture for -march (native, x86-64-v2, none)")
15
+
16
+ if(MSVC)
17
+ add_compile_options(/O2 /fp:fast)
18
+ else()
19
+ add_compile_options(-O3 -ffast-math)
20
+ if(NOT HYPERCUBE_ARCH STREQUAL "none")
21
+ if(HYPERCUBE_ARCH STREQUAL "native")
22
+ add_compile_options(-march=native -mtune=native)
23
+ else()
24
+ add_compile_options(-march=${HYPERCUBE_ARCH} -mtune=generic)
25
+ endif()
26
+ endif()
27
+ add_compile_options(-Wall -Wextra -Wno-unknown-pragmas)
28
+ endif()
29
+
30
+ # ── Core source compiled directly into the module (PIC required) ──
31
+ set(CORE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
32
+ set(CORE_SOURCES
33
+ ${CORE_DIR}/Hopfield.cpp
34
+ )
35
+
36
+ # ── Package version (single source: hypercube_hopfield1984/_version.py) ──
37
+ set(_HH84_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/hypercube_hopfield1984/_version.py")
38
+ set(HYPERCUBE_HOPFIELD1984_VERSION "")
39
+ file(STRINGS "${_HH84_VERSION_FILE}" _HH84_VERSION_LINES)
40
+ foreach(_line IN LISTS _HH84_VERSION_LINES)
41
+ # Strip CR (Windows) and match: __version__ = "x.y.z"
42
+ string(REPLACE "\r" "" _line "${_line}")
43
+ if(_line MATCHES "^__version__[ \t]*=[ \t]*\"([^\"]+)\"")
44
+ set(HYPERCUBE_HOPFIELD1984_VERSION "${CMAKE_MATCH_1}")
45
+ break()
46
+ endif()
47
+ endforeach()
48
+ if(HYPERCUBE_HOPFIELD1984_VERSION STREQUAL "")
49
+ message(FATAL_ERROR
50
+ "Could not parse __version__ from hypercube_hopfield1984/_version.py")
51
+ endif()
52
+ message(STATUS "hypercube_hopfield1984 version: ${HYPERCUBE_HOPFIELD1984_VERSION}")
53
+
54
+ # ── Build the Python extension module ──
55
+ pybind11_add_module(_core bindings.cpp ${CORE_SOURCES})
56
+ target_include_directories(_core PRIVATE ${CORE_DIR})
57
+ target_compile_definitions(_core PRIVATE
58
+ "HYPERCUBE_HOPFIELD1984_VERSION=\"${HYPERCUBE_HOPFIELD1984_VERSION}\"")
59
+
60
+ # ── Linking ──
61
+ if(MINGW)
62
+ # Static libgcc/libstdc++ keep the .pyd free of those DLLs. Do NOT static-link
63
+ # winpthread: mingw-w64 15.2.0's libwinpthread.a references __intrinsic_setjmpex
64
+ # and fails at link (same constraint as the sibling python builds).
65
+ # Posix-model MinGW still needs libwinpthread-1.dll at runtime — ship the DLL
66
+ # from THIS toolchain (stale copies miss symbols like nanosleep64).
67
+ target_link_options(_core PRIVATE -static-libgcc -static-libstdc++)
68
+ find_file(WINPTHREAD_DLL libwinpthread-1.dll PATHS ENV PATH NO_DEFAULT_PATH)
69
+ if(WINPTHREAD_DLL)
70
+ install(FILES ${WINPTHREAD_DLL} DESTINATION hypercube_hopfield1984)
71
+ endif()
72
+ endif()
73
+
74
+ # ── Install into the hypercube_hopfield1984 package directory ──
75
+ install(TARGETS _core DESTINATION hypercube_hopfield1984)
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 David Charles Liptak
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,306 @@
1
+ Metadata-Version: 2.4
2
+ Name: hypercube-hopfield1984
3
+ Version: 1.0.0
4
+ Summary: Python bindings for HypercubeHopfield1984: Hopfield's 1984 graded associative memory on a Boolean hypercube
5
+ License-Expression: Apache-2.0
6
+ Classifier: Development Status :: 5 - Production/Stable
7
+ Classifier: Intended Audience :: Science/Research
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Programming Language :: C++
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Classifier: Operating System :: POSIX :: Linux
18
+ Classifier: Operating System :: MacOS
19
+ Project-URL: Homepage, https://github.com/dliptak001/HypercubeHopfield1984
20
+ Project-URL: Documentation, https://github.com/dliptak001/HypercubeHopfield1984/blob/master/docs/Python_SDK.md
21
+ Project-URL: Repository, https://github.com/dliptak001/HypercubeHopfield1984
22
+ Requires-Python: >=3.10
23
+ Requires-Dist: numpy>=1.21
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest>=7.0; extra == "test"
26
+ Description-Content-Type: text/markdown
27
+
28
+ # Hypercube Hopfield 1984
29
+
30
+ [![Build wheels](https://github.com/dliptak001/HypercubeHopfield1984/actions/workflows/wheels.yml/badge.svg)](https://github.com/dliptak001/HypercubeHopfield1984/actions/workflows/wheels.yml)
31
+ [![PyPI](https://img.shields.io/pypi/v/hypercube-hopfield1984)](https://pypi.org/project/hypercube-hopfield1984/)
32
+ [![Python](https://img.shields.io/pypi/pyversions/hypercube-hopfield1984)](https://pypi.org/project/hypercube-hopfield1984/)
33
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/dliptak001/HypercubeHopfield1984/blob/master/LICENSE)
34
+ [![C++23](https://img.shields.io/badge/C%2B%2B-23-blue.svg)](https://en.cppreference.com/w/cpp/23)
35
+
36
+ This package is the **Python** surface for HypercubeHopfield1984
37
+ (`import hypercube_hopfield1984`).
38
+ Full API reference: **[docs/Python_SDK.md](https://github.com/dliptak001/HypercubeHopfield1984/blob/master/docs/Python_SDK.md)**.
39
+ C++ integration guide: **[docs/CPP_SDK.md](https://github.com/dliptak001/HypercubeHopfield1984/blob/master/docs/CPP_SDK.md)**.
40
+ Project home: **[github.com/dliptak001/HypercubeHopfield1984](https://github.com/dliptak001/HypercubeHopfield1984)**.
41
+
42
+ HypercubeHopfield1984 is Hopfield's **graded associative memory**, the
43
+ model of J. J. Hopfield's 1984 paper, "Neurons with graded response have
44
+ collective computational properties like those of two-state neurons"
45
+ (Proc. Natl. Acad. Sci. USA 81, 3088–3092), built on a Boolean hypercube.
46
+ Every vertex holds a floating-point state and every edge a floating-point
47
+ weight, both in [−1, 1]. The caller shows the network a pattern. In
48
+ training mode the network adjusts its weights so the pattern becomes a
49
+ low point of its energy. In latch mode the pattern plays two roles at
50
+ once: it is the starting state of the cube, and it also stays applied to
51
+ every vertex for the whole settle as a steady push, Hopfield's input
52
+ current. The weights pull the cube toward what they have stored while the
53
+ pattern keeps pulling it back toward itself, and the network returns the
54
+ state where those two pulls balance.
55
+
56
+ That balance is the point of this network. Because the pattern never
57
+ stops pulling, the output is never a stored pattern looked up from a
58
+ fragment; it is the input, pulled part of the way toward what the memory
59
+ has seen. **It is a shaper, not a recall.** A stored pattern comes back
60
+ nearly as it went in. A damaged one comes back repaired toward its stored
61
+ form. An unknown one comes back moved toward the nearest thing the memory
62
+ knows, by an amount that says how familiar it is. If you want a clean
63
+ retrieval from a cue, use a modern Hopfield network; if you want a signal
64
+ bent by experience and passed on, use this one.
65
+
66
+ There is one class, `Hopfield`, and it stays a float network throughout:
67
+ nothing is ever rounded to ±1. It stands beside
68
+ [HypercubeHopfield](https://github.com/dliptak001/HypercubeHopfield), the
69
+ modern (dense, softmax-over-patterns) Hopfield network in the same family,
70
+ which does the retrieval this one does not.
71
+
72
+ ---
73
+
74
+ <p align="center">
75
+ <strong>HypercubeAI ecosystem</strong><br/>
76
+ </p>
77
+
78
+ <p align="center">
79
+ <a href="https://github.com/dliptak001/HypercubeCascade"><strong>HypercubeCascade</strong></a>
80
+ &nbsp;·&nbsp;
81
+ <a href="https://github.com/dliptak001/HypercubeCNN"><strong>HypercubeCNN</strong></a>
82
+ &nbsp;·&nbsp;
83
+ <a href="https://github.com/dliptak001/HypercubeESN"><strong>HypercubeESN</strong></a>
84
+ &nbsp;·&nbsp;
85
+ <a href="https://github.com/dliptak001/HypercubeEtalon"><strong>HypercubeEtalon</strong></a>
86
+ &nbsp;·&nbsp;
87
+ <a href="https://github.com/dliptak001/HypercubeHopfield"><strong>HypercubeHopfield</strong></a>
88
+ &nbsp;·&nbsp;
89
+ <a href="https://github.com/dliptak001/HypercubeHopfield1984"><strong>HypercubeHopfield1984</strong></a>
90
+ &nbsp;·&nbsp;
91
+ <a href="https://github.com/dliptak001/HypercubeLCN"><strong>HypercubeLCN</strong></a>
92
+ &nbsp;·&nbsp;
93
+ <a href="https://github.com/dliptak001/HypercubeWorldModel"><strong>HypercubeWorldModel</strong></a>
94
+ &nbsp;·&nbsp;
95
+ <a href="https://github.com/dliptak001/HypercubeWTF"><strong>HypercubeWTF</strong></a>
96
+ </p>
97
+
98
+ <p align="center">
99
+ 📄 Foundational paper:
100
+ <a href="https://github.com/dliptak001/HypercubeHopfield1984/blob/master/docs/Boolean_hypercubes_as_a_neural_substrate.pdf"><em>Boolean Hypercubes as a Neural Substrate</em></a>
101
+ (D.&nbsp;C.&nbsp;Liptak, 2026)
102
+ </p>
103
+
104
+ HypercubeHopfield1984 is an experiment in the **HypercubeAI** project,
105
+ our quest to systematically re-implement classical neural architectures
106
+ on a Boolean hypercube topology instead of Euclidean grids or random
107
+ graphs. The central thesis is "topology-native intelligence": the
108
+ hypercube's algebraic structure (vertex-transitive symmetry, Hamming
109
+ geometry, bitwise addressing) can serve as a first-class computational
110
+ substrate.
111
+
112
+ - **A topology you don't store**: connectivity is implicit in the vertex
113
+ indices, and the neighborhood is programmable. Two vertices are joined
114
+ when their indices differ in exactly `distance` bits, so stepping to a
115
+ neighbor is one XOR with a `distance`-bit mask. The dimension and that
116
+ one number fix the whole graph, from the hypercube at distance 1 to the
117
+ middle shell at dim/2.
118
+ - **Perfect homogeneity**: every vertex has the same degree and the same
119
+ local world, so the dynamics mean the same thing everywhere.
120
+ - **Cheap navigation**: each neighbor is a few bit operations on the
121
+ vertex index, not a pointer chase through a stored edge list.
122
+
123
+ Each product in the family is a different architecture on that same
124
+ foundation.
125
+
126
+ ---
127
+
128
+ ## The network
129
+
130
+ A vertex is an integer from 0 to 2ᵈⁱᵐ − 1. Its neighbors are the vertices
131
+ whose index differs from it in exactly `distance` bits, so at distance 1
132
+ the graph is the hypercube itself and at larger distances every vertex has
133
+ C(dim, distance) neighbors. Each edge carries one weight, read from both
134
+ ends.
135
+
136
+ A settle rewrites each vertex to tanh(gain · hᵥ), where the local field hᵥ
137
+ is the weighted sum of its neighbors' states plus the input current, the
138
+ input gain times the pattern's value at that vertex. The vertices are
139
+ rewritten one popcount class at a time, in place, so every rewrite is a
140
+ descent on Hopfield's energy and the settle stops at a stationary point of
141
+ it. Training adds η · eᵥ · eᵤ to every edge and clamps it to [−1, 1].
142
+ The full description, with the energy, the sweep, and the measured
143
+ operating points, is in
144
+ [docs/hopfield.md](https://github.com/dliptak001/HypercubeHopfield1984/blob/master/docs/hopfield.md).
145
+
146
+ ---
147
+
148
+ ## Installation
149
+
150
+ **Preferred:** install a pre-built wheel from PyPI (no compiler).
151
+
152
+ ```bash
153
+ pip install hypercube-hopfield1984
154
+ ```
155
+
156
+ ```python
157
+ import hypercube_hopfield1984 as hh
158
+ print(hh.__version__)
159
+ ```
160
+
161
+ Package name on PyPI: **`hypercube-hopfield1984`**. Import name:
162
+ **`hypercube_hopfield1984`**. Main type: **`hh.Hopfield`**.
163
+
164
+ Wheels target Python 3.10 through 3.14 on common Windows, Linux, and macOS
165
+ machines. Runtime dependency: NumPy only.
166
+
167
+ ### From source (full repository)
168
+
169
+ To compile the extension yourself, clone this **entire** repository (not a
170
+ minimal source-only download of the `python/` folder alone; the C++ core
171
+ lives next to `python/`). You need Python 3.10+, a C++23 compiler, and
172
+ CMake ≥ 3.20.
173
+
174
+ ```bash
175
+ git clone https://github.com/dliptak001/HypercubeHopfield1984.git
176
+ cd HypercubeHopfield1984/python
177
+ pip install .
178
+ ```
179
+
180
+ On Windows with CLion's MinGW, put that compiler's `bin` folder (and Ninja)
181
+ on your `PATH`, then:
182
+
183
+ ```bash
184
+ pip install . --no-build-isolation --force-reinstall --no-deps
185
+ ```
186
+
187
+ (Exact CLion paths change with the version.)
188
+
189
+ ---
190
+
191
+ ## Quick start
192
+
193
+ You bring each pattern as an array of 2ᵏ floats, k ≤ dim. How you get there
194
+ (pad an image, reshape a spectrum, invent a layout) is up to you. A shorter
195
+ pattern repeats onto every copy of the low-k cube.
196
+
197
+ ```python
198
+ import numpy as np
199
+ import hypercube_hopfield1984 as hh
200
+
201
+ net = hh.Hopfield(dim=10, gain=0.03, sweep_budget=64, rest_tolerance=0.01,
202
+ eta=0.003, input_gain=20.0, distance=5)
203
+ N = net.N # 1024
204
+
205
+ rng = np.random.default_rng(0)
206
+ patterns = rng.uniform(-1, 1, (50, N)).astype(np.float32)
207
+ for _ in range(50):
208
+ for p in patterns:
209
+ net.train(p) # deepen each pattern's well
210
+
211
+ latch = net.latch(patterns[0]) # (N,) float32: the settled cube
212
+ print(net.sweep_count, net.at_rest)
213
+ print(net)
214
+
215
+ net.save("memory.pkl")
216
+ loaded = hh.Hopfield.load("memory.pkl")
217
+ ```
218
+
219
+ The operating point above (dim 10, distance 5, gain 0.03, input gain 20,
220
+ η 0.003) is the measured one: a stored pattern comes back with cosine
221
+ 0.987 to itself and a pattern with a quarter of its sites randomized is
222
+ repaired from cosine 0.75 to 0.85. The rows for dim 11 and 12 are one
223
+ rule, gain = 7.56 / degree and input gain = degree / 12.6.
224
+
225
+ ---
226
+
227
+ ## Features
228
+
229
+ - **One class**: `hypercube_hopfield1984.Hopfield` is the whole product surface
230
+ - **`train` / `latch` / `energy`**: exposed one-to-one with the C++ API
231
+ - **dim 1 through 31**: N = 2ᵈⁱᵐ vertices; `distance` picks the degree, the capacity lever
232
+ - **Graded throughout**: states and weights are floats in [−1, 1]; nothing is rounded to ±1
233
+ - **Short exposures tile**: a 2ᵏ pattern repeats onto every copy of the low-k cube
234
+ - **Latch record**: `sweep_count` and `at_rest` say how the last settle ended
235
+ - **Weights as NumPy**: `net.weights` (settable), row-major N × degree
236
+ - **Save / load**: `save` / `load` (pickle: config + weights)
237
+ - **NumPy float32**: arrays converted for you; prefer contiguous float32
238
+ - **GIL released** during `latch`, `train`, `energy`, and a weights load
239
+
240
+ ---
241
+
242
+ ## Examples
243
+
244
+ For a first try, paste the [Quick start](#quick-start) after
245
+ `pip install hypercube-hopfield1984`. That is self-contained.
246
+
247
+ The demo script on GitHub under
248
+ [`python/examples/`](https://github.com/dliptak001/HypercubeHopfield1984/tree/master/python/examples)
249
+ is there to open or download; it is not added to your machine by pip.
250
+
251
+ | Script | What it is for |
252
+ |--------|----------------|
253
+ | [shaper.py](https://github.com/dliptak001/HypercubeHopfield1984/blob/master/python/examples/shaper.py) | Store the fifty bundled exemplars, then latch a stored, a damaged, and a novel pattern; the latch energy tells them apart |
254
+
255
+ ```bash
256
+ # from a clone of HypercubeHopfield1984, after: pip install hypercube-hopfield1984
257
+ python python/examples/shaper.py
258
+ ```
259
+
260
+ ---
261
+
262
+ ## Documentation
263
+
264
+ | Doc | Role |
265
+ |-----|------|
266
+ | **[docs/Python_SDK.md](https://github.com/dliptak001/HypercubeHopfield1984/blob/master/docs/Python_SDK.md)** | Canonical Python API: every method, layout, pickle, limits |
267
+ | [docs/CPP_SDK.md](https://github.com/dliptak001/HypercubeHopfield1984/blob/master/docs/CPP_SDK.md) | Native library guide (same product, C++) |
268
+ | [Project README](https://github.com/dliptak001/HypercubeHopfield1984#readme) | Product story and the C++ programs from the repo root |
269
+ | [docs/hopfield.md](https://github.com/dliptak001/HypercubeHopfield1984/blob/master/docs/hopfield.md) | The network, the energy, the sweep, and the measured operating points |
270
+
271
+ ---
272
+
273
+ ## Ecosystem
274
+
275
+ - **[HypercubeCascade](https://github.com/dliptak001/HypercubeCascade)**: both frozen stages in series + thin readout.
276
+ - **[HypercubeCNN](https://github.com/dliptak001/HypercubeCNN)**: cube-native conv stack with shared kernels.
277
+ - **[HypercubeESN](https://github.com/dliptak001/HypercubeESN)**: echo-state / reservoir computing on streams.
278
+ - **[HypercubeEtalon](https://github.com/dliptak001/HypercubeEtalon)**: frozen etalon transit + thin readout.
279
+ - **[HypercubeHopfield](https://github.com/dliptak001/HypercubeHopfield)**: the modern Hopfield network; clean retrieval from a cue.
280
+ - **[HypercubeHopfield1984](https://github.com/dliptak001/HypercubeHopfield1984)**: Hopfield's 1984 graded memory; a shaper, not a recall.
281
+ - **[HypercubeLCN](https://github.com/dliptak001/HypercubeLCN)**: the locally connected net, every weight trained.
282
+ - **[HypercubeWorldModel](https://github.com/dliptak001/HypercubeWorldModel)**: frozen WTF encoder + trained LCN predictor and decoder.
283
+ - **[HypercubeWTF](https://github.com/dliptak001/HypercubeWTF)**: frozen reservoir orbit + thin readout.
284
+
285
+ ---
286
+
287
+ ## License
288
+
289
+ Apache 2.0.
290
+
291
+ ## Definitions
292
+
293
+ | Symbol / term | Meaning |
294
+ |---------------|---------|
295
+ | Hopfield | The Python class: train, latch, energy, weights, persistence. |
296
+ | dim | Hypercube dimension, 1 through 31. |
297
+ | N | Vertex count, N = 2ᵈⁱᵐ. The length of a cube. |
298
+ | distance | Hamming distance between neighbors, 1 through max(1, dim // 2). |
299
+ | degree | Neighbors per vertex, C(dim, distance). |
300
+ | exposure | The caller's pattern: 2ᵏ finite floats, k ≤ dim. |
301
+ | latch | The settled cube `latch` returns: the exposure pulled toward what the memory has stored. |
302
+ | sweep | One in-place rewrite of every even-popcount vertex in index order, then every odd-popcount vertex. |
303
+ | settle | Sweeps repeated until one moves every vertex by at most rest_tolerance, or sweep_budget is spent. |
304
+ | rest_tolerance | The largest move at one vertex that still counts as rest. Finite, 0 or more; default 0, bit-for-bit equality. Reaching it ends the settle with `at_rest` True. |
305
+ | sweep_budget | The most sweeps one settle will run, 1 or more. A cube still moving when the budget is spent stops there, with `at_rest` False. |
306
+ | weights | N · degree float32: row v holds v's weights in mask order, each edge in both endpoints' rows. |