hypercube-lcn 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,76 @@
1
+ cmake_minimum_required(VERSION 3.20)
2
+ project(HypercubeLCNPython 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 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 sources compiled directly into the module (PIC required) ──
31
+ set(CORE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
32
+ set(CORE_SOURCES
33
+ ${CORE_DIR}/Core.cpp
34
+ ${CORE_DIR}/Training.cpp
35
+ )
36
+
37
+ # ── Package version (single source: hypercube_lcn/_version.py) ──
38
+ set(_HLCN_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/hypercube_lcn/_version.py")
39
+ set(HYPERCUBE_LCN_VERSION "")
40
+ file(STRINGS "${_HLCN_VERSION_FILE}" _HLCN_VERSION_LINES)
41
+ foreach(_line IN LISTS _HLCN_VERSION_LINES)
42
+ # Strip CR (Windows) and match: __version__ = "x.y.z"
43
+ string(REPLACE "\r" "" _line "${_line}")
44
+ if(_line MATCHES "^__version__[ \t]*=[ \t]*\"([^\"]+)\"")
45
+ set(HYPERCUBE_LCN_VERSION "${CMAKE_MATCH_1}")
46
+ break()
47
+ endif()
48
+ endforeach()
49
+ if(HYPERCUBE_LCN_VERSION STREQUAL "")
50
+ message(FATAL_ERROR
51
+ "Could not parse __version__ from hypercube_lcn/_version.py")
52
+ endif()
53
+ message(STATUS "hypercube_lcn version: ${HYPERCUBE_LCN_VERSION}")
54
+
55
+ # ── Build the Python extension module ──
56
+ pybind11_add_module(_core bindings.cpp ${CORE_SOURCES})
57
+ target_include_directories(_core PRIVATE ${CORE_DIR})
58
+ target_compile_definitions(_core PRIVATE
59
+ "HYPERCUBE_LCN_VERSION=\"${HYPERCUBE_LCN_VERSION}\"")
60
+
61
+ # ── Linking ──
62
+ if(MINGW)
63
+ # Static libgcc/libstdc++ keep the .pyd free of those DLLs. Do NOT static-link
64
+ # winpthread: mingw-w64 15.2.0's libwinpthread.a references __intrinsic_setjmpex
65
+ # and fails at link (same constraint as the sibling python builds).
66
+ # Posix-model MinGW still needs libwinpthread-1.dll at runtime — ship the DLL
67
+ # from THIS toolchain (stale copies miss symbols like nanosleep64).
68
+ target_link_options(_core PRIVATE -static-libgcc -static-libstdc++)
69
+ find_file(WINPTHREAD_DLL libwinpthread-1.dll PATHS ENV PATH NO_DEFAULT_PATH)
70
+ if(WINPTHREAD_DLL)
71
+ install(FILES ${WINPTHREAD_DLL} DESTINATION hypercube_lcn)
72
+ endif()
73
+ endif()
74
+
75
+ # ── Install into the hypercube_lcn package directory ──
76
+ install(TARGETS _core DESTINATION hypercube_lcn)
@@ -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,329 @@
1
+ Metadata-Version: 2.4
2
+ Name: hypercube-lcn
3
+ Version: 1.0.0
4
+ Summary: Python bindings for HypercubeLCN: a locally connected network on a Boolean hypercube, every weight trained
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/HypercubeLCN
20
+ Project-URL: Documentation, https://github.com/dliptak001/HypercubeLCN/blob/main/docs/Python_SDK.md
21
+ Project-URL: Repository, https://github.com/dliptak001/HypercubeLCN
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 LCN
29
+
30
+ This package is the **Python** surface for HypercubeLCN
31
+ (`import hypercube_lcn`).
32
+ Full API reference: **[docs/Python_SDK.md](https://github.com/dliptak001/HypercubeLCN/blob/main/docs/Python_SDK.md)**.
33
+ C++ integration guide: **[docs/CPP_SDK.md](https://github.com/dliptak001/HypercubeLCN/blob/main/docs/CPP_SDK.md)**.
34
+ Project home: **[github.com/dliptak001/HypercubeLCN](https://github.com/dliptak001/HypercubeLCN)**.
35
+
36
+ HypercubeLCN is a **Locally Connected Network** on a Boolean
37
+ hypercube: a deep feedforward network whose connectivity is the
38
+ cube's own edges and whose weights are trained. It is built from two
39
+ core classes.
40
+
41
+ The **Core** class is the network. It owns the weights and runs the
42
+ forward pass: one field in, one field out, with a stack of
43
+ intermediate fields written on the same cube in between.
44
+
45
+ The **Training** class walks that same pass in reverse. It
46
+ accumulates gradients through every depth and steps the weights with
47
+ Adam.
48
+
49
+ That is the whole architecture. There is no preprocessor, no
50
+ reservoir, no separate readout — the cube is the model. In Python the
51
+ two are wrapped by a single class, **`hypercube_lcn.LCN`**.
52
+
53
+ This is the opposite bet from the sibling projects. HypercubeEtalon,
54
+ HypercubeWTF, and HypercubeCascade all put a *frozen random*
55
+ hypercube stage in front of a small trained readout, and the point of
56
+ those experiments is how far fixed dynamics can carry a thin
57
+ classifier. This project asks instead: how much better does the
58
+ hypercube do when every weight in it is trained?
59
+
60
+ ---
61
+
62
+ <p align="center">
63
+ <strong>HypercubeAI ecosystem</strong><br/>
64
+ </p>
65
+
66
+ <p align="center">
67
+ <a href="https://github.com/dliptak001/HypercubeESN"><strong>HypercubeESN</strong></a>
68
+ &nbsp;·&nbsp;
69
+ <a href="https://github.com/dliptak001/HypercubeCNN"><strong>HypercubeCNN</strong></a>
70
+ &nbsp;·&nbsp;
71
+ <a href="https://github.com/dliptak001/HypercubeHopfield"><strong>HypercubeHopfield</strong></a>
72
+ &nbsp;·&nbsp;
73
+ <a href="https://github.com/dliptak001/HypercubeWTF"><strong>HypercubeWTF</strong></a>
74
+ &nbsp;·&nbsp;
75
+ <a href="https://github.com/dliptak001/HypercubeEtalon"><strong>HypercubeEtalon</strong></a>
76
+ &nbsp;·&nbsp;
77
+ <a href="https://github.com/dliptak001/HypercubeCascade"><strong>HypercubeCascade</strong></a>
78
+ &nbsp;·&nbsp;
79
+ <a href="https://github.com/dliptak001/HypercubeLCN"><strong>HypercubeLCN</strong></a>
80
+ </p>
81
+
82
+ HypercubeLCN is an experiment in the **HypercubeAI** project — our
83
+ quest to systematically re-implement classical neural architectures
84
+ on a Boolean hypercube topology instead of Euclidean grids or random
85
+ graphs. The central thesis is "topology-native intelligence": the
86
+ hypercube's algebraic structure (vertex-transitive symmetry, Hamming
87
+ geometry, bitwise addressing) can serve as a first-class
88
+ computational substrate.
89
+
90
+ - **A topology you don’t store** — the graph is specified: connectivity is
91
+ implicit in the vertex indices; with a seed and a few config scalars the
92
+ whole reservoir reconstructs mathematically.
93
+ - **Perfect homogeneity** — every vertex has the same degree and the same local
94
+ world, so local dynamics mean the same thing everywhere — no structural
95
+ favorites baked in by a random graph.
96
+ - **Cheap navigation** — each neighbor is a few bit operations on the vertex
97
+ index, not a pointer chase through a stored edge list, so walks stay
98
+ arithmetic and cache-friendly.
99
+ - **Nothing leaves the cube** — input, every intermediate field, and output
100
+ all live on the same vertices. Depth is the only direction anything travels.
101
+
102
+ Each product in the family is a different architecture on that same
103
+ foundation.
104
+
105
+ ---
106
+
107
+ ## The LCN
108
+
109
+ A **locally connected network** is wired like a convolutional layer
110
+ — each unit reads only a small neighborhood — but where a CNN slides
111
+ one shared kernel across every position, an LCN lets every position
112
+ train its own private weights.
113
+
114
+ Here the hypercube supplies the neighborhoods. A vertex's neighbors
115
+ are the indices one bit-flip away, and at every depth each vertex
116
+ gathers from all of them at once. Each vertex owns a private weight
117
+ table at every depth — one weight for each neighbor and each field
118
+ that neighbor shows it — and shares nothing with any other vertex.
119
+ The one wrinkle is a lookback window: when a vertex reads from a
120
+ neighbor, it sees not just that neighbor's newest field but the last
121
+ few written (a configurable width, two to six). This acts as a short
122
+ skip connection and keeps the input visible to the early depths.
123
+
124
+ Training runs the forward pass's loops in reverse, and no depth is
125
+ spared: the gradient reaches every weight at every depth. For the full story,
126
+ [docs/forward.md](https://github.com/dliptak001/HypercubeLCN/blob/main/docs/forward.md) and
127
+ [docs/training.md](https://github.com/dliptak001/HypercubeLCN/blob/main/docs/training.md)
128
+ walk through the code loop by loop, with dim-4 examples small enough
129
+ to check by hand.
130
+
131
+ ---
132
+
133
+ ## Raman baseline extraction (a vibrational spectroscopy application)
134
+
135
+ The benchmark is the one the sibling projects established: recover
136
+ the slow fluorescence background under sharp molecular peaks without
137
+ lifting the baseline into the bands or cutting trenches beneath them.
138
+ The dataset is 10,000 synthetic LiCoO₂ (lithium cobalt oxide)
139
+ training spectra and 2,000 held-out validation spectra, scored as
140
+ RMSE in raw counts.
141
+
142
+ On this task the frozen-stage siblings — Etalon, WTF, and Cascade,
143
+ each feeding the same one-layer, one-channel readout — all landed on
144
+ one floor: 4.76 to 4.82 validation. The LCN, with a dim-11 cube
145
+ matched to the 2048-bin spectrum and every weight trained, scores
146
+ **1.98 training / 2.03 validation**.
147
+
148
+ ![Held-out validation extract, spectra 351 through 354](https://raw.githubusercontent.com/dliptak001/HypercubeLCN/main/examples/RamanBaseline/extracted_baselines.png)
149
+
150
+ Grey is the raw spectrum, red the true baseline, blue the extract. At
151
+ two counts of RMSE the residual is at the scale of the label's own
152
+ noise, and the red trace all but disappears under the blue. A second
153
+ experiment widens the cube to dim 12 so half the vertices serve as
154
+ free hidden units, and scores **1.64 / 1.69**. The write-ups are
155
+ [examples/RamanBaseline/](https://github.com/dliptak001/HypercubeLCN/blob/main/examples/RamanBaseline/README.md) and
156
+ [examples/RamanBaselineNarrowIO/](https://github.com/dliptak001/HypercubeLCN/blob/main/examples/RamanBaselineNarrowIO/README.md).
157
+
158
+ ---
159
+
160
+ ## Installation
161
+
162
+ **Preferred:** install a pre-built wheel from PyPI (no compiler).
163
+
164
+ ```bash
165
+ pip install hypercube-lcn
166
+ ```
167
+
168
+ ```python
169
+ import hypercube_lcn as hl
170
+ print(hl.__version__)
171
+ ```
172
+
173
+ Package name on PyPI: **`hypercube-lcn`**. Import name:
174
+ **`hypercube_lcn`**. Main type: **`hl.LCN`**.
175
+
176
+ Wheels target Python 3.10–3.14 on common Windows, Linux, and macOS machines.
177
+ Runtime dependency: NumPy only.
178
+
179
+ ### From source (full repository)
180
+
181
+ To compile the extension yourself, clone this **entire** repository (not a
182
+ minimal source-only download of the `python/` folder alone — the C++ core
183
+ lives next to `python/`). You need Python 3.10+, a C++23 compiler, and
184
+ CMake ≥ 3.20.
185
+
186
+ ```bash
187
+ git clone https://github.com/dliptak001/HypercubeLCN.git
188
+ cd HypercubeLCN/python
189
+ pip install .
190
+ ```
191
+
192
+ On Windows with CLion's MinGW, put that compiler's `bin` folder (and Ninja) on
193
+ your `PATH`, then:
194
+
195
+ ```bash
196
+ pip install . --no-build-isolation --force-reinstall --no-deps
197
+ ```
198
+
199
+ (Exact CLion paths change with the version.)
200
+
201
+ ---
202
+
203
+ ## Quick start
204
+
205
+ You bring each sample as a length-**N** float array (N = 2<sup>dim</sup>). How
206
+ you get there — pad an image, reshape a spectrum, invent a layout — is up to
207
+ you. This package does not pack 784 pixels or 2048 bins for you.
208
+
209
+ Shapes that matter:
210
+
211
+ | Array | Shape | Notes |
212
+ |-------|-------|-------|
213
+ | `fields` | `(count, N)` | one length-N field per row |
214
+ | `targets` | `(count, width)` | width ≤ N; width < N masks the loss to vertices 0..width-1 |
215
+
216
+ ```python
217
+ import numpy as np
218
+ import hypercube_lcn as hl
219
+
220
+ dim = 6
221
+ N = 2**dim
222
+ rng = np.random.default_rng(0)
223
+ fields = rng.standard_normal((256, N)).astype(np.float32)
224
+ targets = 0.5 * (fields + fields[:, np.arange(N) ^ 1]) # a local map
225
+
226
+ net = hl.LCN(dim=dim, gather_span=3, tanh_last=False,
227
+ lr=1e-2, lr_min_frac=0.05, restore_best=True)
228
+ net.fit(fields, targets, epochs=40, batch_size=16, verbose=True)
229
+
230
+ prediction = net.forward(fields[0]) # (N,) float32
231
+ print(net)
232
+
233
+ net.save("model.pkl")
234
+ loaded = hl.LCN.load("model.pkl")
235
+ ```
236
+
237
+ ### Step by step (same loop, more control)
238
+
239
+ `fit` is nothing but this loop — drive it yourself to interleave your own
240
+ metrics, schedules, or early stopping:
241
+
242
+ ```python
243
+ for epoch in range(epochs):
244
+ net.set_epoch(epoch, epochs) # cosine learning rate
245
+ for start in range(0, count, batch_size):
246
+ net.zero_grad()
247
+ for i in range(start, start + batch_size):
248
+ net.forward(fields[i])
249
+ net.loss(targets[i]) # seeds the gradient
250
+ net.backward() # accumulates (sums) it
251
+ net.adam() # one step per batch
252
+ net.observe(epoch_metric, epoch) # restore_best bookkeeping
253
+ net.restore_best()
254
+ ```
255
+
256
+ The gradient is a **sum** over the batch, so the effective step scales with
257
+ batch size — the same convention as the C++ examples.
258
+
259
+ ---
260
+
261
+ ## Features
262
+
263
+ - **One class** — `hypercube_lcn.LCN` is the whole product surface
264
+ - **`fit`** — shuffle, batch, cosine schedule, restore-best, in one call
265
+ - **Custom loops** — `zero_grad` / `forward` / `loss` / `backward` / `adam` /
266
+ `set_epoch` exposed one-to-one with the C++ API
267
+ - **dim 4–24** — field length N = 2<sup>dim</sup>; depth `z_max`
268
+ (default: dim); lookback window `gather_span` 2–6
269
+ - **Masked loss** — targets narrower than N leave the rest of the cube as
270
+ free hidden units
271
+ - **`tanh_last`** — off by default (raw accumulator out); on confines the
272
+ output to (-1, 1)
273
+ - **Weights and gradient as NumPy** — `net.weights` (settable) and
274
+ `net.grad`, z-major layout: depth, vertex, axis, tap
275
+ - **Save / load** — `save` / `load` (pickle: config + weights; optimizer
276
+ state is not stored)
277
+ - **NumPy float32** — arrays converted for you; prefer contiguous float32
278
+
279
+ ---
280
+
281
+ ## Examples
282
+
283
+ For a first try, paste the [Quick start](#quick-start) after
284
+ `pip install hypercube-lcn`. That is self-contained.
285
+
286
+ The demo scripts on GitHub under
287
+ [`python/examples/`](https://github.com/dliptak001/HypercubeLCN/tree/main/python/examples)
288
+ are there to open or download — they are not added to your machine by pip.
289
+
290
+ | Script | What it is for |
291
+ |--------|----------------|
292
+ | [synthetic_regression.py](https://github.com/dliptak001/HypercubeLCN/blob/main/python/examples/synthetic_regression.py) | Toy field map: `fit` with verbose loss, then held-out MSE |
293
+
294
+ ```bash
295
+ # from a clone of HypercubeLCN, after: pip install hypercube-lcn
296
+ python python/examples/synthetic_regression.py
297
+ ```
298
+
299
+ These use easy made-up fields so the API is obvious — not scores to publish.
300
+
301
+ ---
302
+
303
+ ## Documentation
304
+
305
+ | Doc | Role |
306
+ |-----|------|
307
+ | **[docs/Python_SDK.md](https://github.com/dliptak001/HypercubeLCN/blob/main/docs/Python_SDK.md)** | Canonical Python API — every method, layout, pickle, limits |
308
+ | [docs/CPP_SDK.md](https://github.com/dliptak001/HypercubeLCN/blob/main/docs/CPP_SDK.md) | Native library guide (same product, C++) |
309
+ | [Project README](https://github.com/dliptak001/HypercubeLCN#readme) | Product story and C++ demos from the repo root |
310
+ | [docs/forward.md](https://github.com/dliptak001/HypercubeLCN/blob/main/docs/forward.md) | The forward pass, loop by loop, with hand-checkable examples |
311
+ | [docs/training.md](https://github.com/dliptak001/HypercubeLCN/blob/main/docs/training.md) | Backprop and Adam through the same loops |
312
+ | [examples/README.md](https://github.com/dliptak001/HypercubeLCN/blob/main/examples/README.md) | The C++ example programs and datasets |
313
+
314
+ ---
315
+
316
+ ## Ecosystem
317
+
318
+ - **[HypercubeEtalon](https://github.com/dliptak001/HypercubeEtalon)** — frozen etalon transit + thin readout.
319
+ - **[HypercubeWTF](https://github.com/dliptak001/HypercubeWTF)** — frozen reservoir orbit + thin readout.
320
+ - **[HypercubeCascade](https://github.com/dliptak001/HypercubeCascade)** — both frozen stages in series + thin readout.
321
+ - **[HypercubeCNN](https://github.com/dliptak001/HypercubeCNN)** — cube-native conv stack with shared kernels.
322
+ - **[HypercubeESN](https://github.com/dliptak001/HypercubeESN)** — echo-state / reservoir computing on streams.
323
+ - **[HypercubeHopfield](https://github.com/dliptak001/HypercubeHopfield)** — Hopfield-style dynamics on the cube.
324
+
325
+ ---
326
+
327
+ ## License
328
+
329
+ Apache 2.0.