hypercube-cascade 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.
- hypercube_cascade-1.0.0/CMakeLists.txt +88 -0
- hypercube_cascade-1.0.0/PKG-INFO +366 -0
- hypercube_cascade-1.0.0/README.md +339 -0
- hypercube_cascade-1.0.0/bindings.cpp +465 -0
- hypercube_cascade-1.0.0/examples/README.md +38 -0
- hypercube_cascade-1.0.0/examples/synthetic_classification.py +80 -0
- hypercube_cascade-1.0.0/hypercube_cascade/__init__.py +708 -0
- hypercube_cascade-1.0.0/hypercube_cascade/_version.py +5 -0
- hypercube_cascade-1.0.0/pyproject.toml +84 -0
- hypercube_cascade-1.0.0/tests/__init__.py +0 -0
- hypercube_cascade-1.0.0/tests/test_basic.py +388 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.20)
|
|
2
|
+
project(HypercubeCascadePython 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}/Exciter.cpp
|
|
34
|
+
${CORE_DIR}/Reservoir.cpp
|
|
35
|
+
${CORE_DIR}/Readout.cpp
|
|
36
|
+
${CORE_DIR}/Cascade.cpp
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# ── HypercubeCNN dependency ──
|
|
40
|
+
# Vendored read-only snapshot at ../third_party/HypercubeCNN (see VENDORED.md).
|
|
41
|
+
# No sibling checkout, no pre-built .a, no network fetch — offline & version-pinned.
|
|
42
|
+
# third_party/ lies outside this source tree, so a binary dir arg is required.
|
|
43
|
+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third_party/HypercubeCNN
|
|
44
|
+
${CMAKE_BINARY_DIR}/HypercubeCNN-build)
|
|
45
|
+
set(HCNN_LIBS HypercubeCNNCore)
|
|
46
|
+
|
|
47
|
+
# ── Package version (single source: hypercube_cascade/_version.py) ──
|
|
48
|
+
set(_HCAS_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/hypercube_cascade/_version.py")
|
|
49
|
+
set(HYPERCUBE_CASCADE_VERSION "")
|
|
50
|
+
file(STRINGS "${_HCAS_VERSION_FILE}" _HCAS_VERSION_LINES)
|
|
51
|
+
foreach(_line IN LISTS _HCAS_VERSION_LINES)
|
|
52
|
+
# Strip CR (Windows) and match: __version__ = "x.y.z"
|
|
53
|
+
string(REPLACE "\r" "" _line "${_line}")
|
|
54
|
+
if(_line MATCHES "^__version__[ \t]*=[ \t]*\"([^\"]+)\"")
|
|
55
|
+
set(HYPERCUBE_CASCADE_VERSION "${CMAKE_MATCH_1}")
|
|
56
|
+
break()
|
|
57
|
+
endif()
|
|
58
|
+
endforeach()
|
|
59
|
+
if(HYPERCUBE_CASCADE_VERSION STREQUAL "")
|
|
60
|
+
message(FATAL_ERROR
|
|
61
|
+
"Could not parse __version__ from hypercube_cascade/_version.py")
|
|
62
|
+
endif()
|
|
63
|
+
message(STATUS "hypercube_cascade version: ${HYPERCUBE_CASCADE_VERSION}")
|
|
64
|
+
|
|
65
|
+
# ── Build the Python extension module ──
|
|
66
|
+
# HypercubeCNNCore's PUBLIC include dir propagates through the link below.
|
|
67
|
+
pybind11_add_module(_core bindings.cpp ${CORE_SOURCES})
|
|
68
|
+
target_include_directories(_core PRIVATE ${CORE_DIR})
|
|
69
|
+
target_link_libraries(_core PRIVATE ${HCNN_LIBS})
|
|
70
|
+
target_compile_definitions(_core PRIVATE
|
|
71
|
+
"HYPERCUBE_CASCADE_VERSION=\"${HYPERCUBE_CASCADE_VERSION}\"")
|
|
72
|
+
|
|
73
|
+
# ── Linking ──
|
|
74
|
+
if(MINGW)
|
|
75
|
+
# Static libgcc/libstdc++ keep the .pyd free of those DLLs. Do NOT static-link
|
|
76
|
+
# winpthread: mingw-w64 15.2.0's libwinpthread.a references __intrinsic_setjmpex
|
|
77
|
+
# and fails at link (same constraint as the top-level CMakeLists.txt exes).
|
|
78
|
+
# Posix-model MinGW still needs libwinpthread-1.dll at runtime — ship the DLL
|
|
79
|
+
# from THIS toolchain (stale copies miss symbols like nanosleep64).
|
|
80
|
+
target_link_options(_core PRIVATE -static-libgcc -static-libstdc++)
|
|
81
|
+
find_file(WINPTHREAD_DLL libwinpthread-1.dll PATHS ENV PATH NO_DEFAULT_PATH)
|
|
82
|
+
if(WINPTHREAD_DLL)
|
|
83
|
+
install(FILES ${WINPTHREAD_DLL} DESTINATION hypercube_cascade)
|
|
84
|
+
endif()
|
|
85
|
+
endif()
|
|
86
|
+
|
|
87
|
+
# ── Install into the hypercube_cascade package directory ──
|
|
88
|
+
install(TARGETS _core DESTINATION hypercube_cascade)
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hypercube-cascade
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python bindings for HypercubeCascade: frozen etalon transit + frozen reservoir orbit + HypercubeCNN on end state
|
|
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/HypercubeCascade
|
|
20
|
+
Project-URL: Repository, https://github.com/dliptak001/HypercubeCascade
|
|
21
|
+
Project-URL: Documentation, https://github.com/dliptak001/HypercubeCascade/blob/main/docs/Python_SDK.md
|
|
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
|
+
# HypercubeCascade
|
|
29
|
+
|
|
30
|
+
**HypercubeCascade** is for high-dimensional data that has no natural clock —
|
|
31
|
+
spectra, sensor frames, packed images, stills. Those are the same kinds of
|
|
32
|
+
static fields people usually feed a spatial CNN, an MLP, or a similar
|
|
33
|
+
feed-forward stack. HypercubeCascade puts **two frozen hypercube
|
|
34
|
+
preprocessors in series** in front of the CNN: first an **etalon transit**
|
|
35
|
+
(the [HypercubeEtalon](https://github.com/dliptak001/HypercubeEtalon)
|
|
36
|
+
mechanism — a deterministic wave swept across every vertex/antipode cavity of
|
|
37
|
+
the cube), then a short **reservoir orbit** (the
|
|
38
|
+
[HypercubeWTF](https://github.com/dliptak001/HypercubeWTF) mechanism — a
|
|
39
|
+
frozen recurrent core driven by re-addressing the same field for T synthetic
|
|
40
|
+
passes). A small
|
|
41
|
+
[HypercubeCNN](https://github.com/dliptak001/HypercubeCNN) head trains on the
|
|
42
|
+
**end state only**. The CNN never sees the original field — it sees what the
|
|
43
|
+
transit and the orbit leave behind.
|
|
44
|
+
|
|
45
|
+
That is the product idea: take a static field, pass it through two different
|
|
46
|
+
frozen nonlinearities, and train a spatial readout on what remains. The aim is
|
|
47
|
+
a preprocessor effective enough that the readout can be a single convolutional
|
|
48
|
+
layer with a single channel and no pooling.
|
|
49
|
+
|
|
50
|
+
This package is the **Python** surface for that product
|
|
51
|
+
(`import hypercube_cascade`).
|
|
52
|
+
Full API reference: **[docs/Python_SDK.md](https://github.com/dliptak001/HypercubeCascade/blob/main/docs/Python_SDK.md)**.
|
|
53
|
+
C++ integration guide: **[docs/CPP_SDK.md](https://github.com/dliptak001/HypercubeCascade/blob/main/docs/CPP_SDK.md)**.
|
|
54
|
+
Project home: **[github.com/dliptak001/HypercubeCascade](https://github.com/dliptak001/HypercubeCascade)**.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
<p align="center">
|
|
59
|
+
<strong>HypercubeAI ecosystem</strong><br/>
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
<p align="center">
|
|
63
|
+
<a href="https://github.com/dliptak001/HypercubeESN"><strong>HypercubeESN</strong></a>
|
|
64
|
+
·
|
|
65
|
+
<a href="https://github.com/dliptak001/HypercubeCNN"><strong>HypercubeCNN</strong></a>
|
|
66
|
+
·
|
|
67
|
+
<a href="https://github.com/dliptak001/HypercubeHopfield"><strong>HypercubeHopfield</strong></a>
|
|
68
|
+
·
|
|
69
|
+
<a href="https://github.com/dliptak001/HypercubeWTF"><strong>HypercubeWTF</strong></a>
|
|
70
|
+
·
|
|
71
|
+
<a href="https://github.com/dliptak001/HypercubeEtalon"><strong>HypercubeEtalon</strong></a>
|
|
72
|
+
·
|
|
73
|
+
<a href="https://github.com/dliptak001/HypercubeCascade"><strong>HypercubeCascade</strong></a>
|
|
74
|
+
</p>
|
|
75
|
+
|
|
76
|
+
HypercubeCascade is an experiment in the **HypercubeAI** project — our quest to
|
|
77
|
+
systematically re-implement classical neural architectures on a Boolean
|
|
78
|
+
hypercube topology instead of Euclidean grids or random graphs. The central
|
|
79
|
+
thesis is “topology-native intelligence”: the hypercube’s algebraic structure
|
|
80
|
+
(vertex-transitive symmetry, Hamming geometry, bitwise addressing) can serve
|
|
81
|
+
as a first-class computational substrate.
|
|
82
|
+
|
|
83
|
+
- **A topology you don’t store** — the graph is specified: connectivity is
|
|
84
|
+
implicit in the vertex indices; with a seed and a few config scalars the whole
|
|
85
|
+
preprocessor reconstructs mathematically.
|
|
86
|
+
- **Perfect homogeneity** — every vertex has the same degree and the same local
|
|
87
|
+
world, so local dynamics mean the same thing everywhere — no structural
|
|
88
|
+
favorites baked in by a random graph.
|
|
89
|
+
- **Cheap navigation** — each neighbor is a few bit operations on the vertex
|
|
90
|
+
index, not a pointer chase through a stored edge list, so walks stay
|
|
91
|
+
arithmetic and cache-friendly.
|
|
92
|
+
- **Topology-native pairing** — the readout consumes the preprocessor output
|
|
93
|
+
with zero geometric distortion, and the learned kernels exploit the same
|
|
94
|
+
locality that generated the dynamics. The data never leaves the hypercube it
|
|
95
|
+
was born on.
|
|
96
|
+
|
|
97
|
+
Each product in the family is a different architecture on that same foundation.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## What is HypercubeCascade?
|
|
102
|
+
|
|
103
|
+
[HypercubeEtalon](https://github.com/dliptak001/HypercubeEtalon) preprocesses a
|
|
104
|
+
static field with **one etalon transit**.
|
|
105
|
+
[HypercubeWTF](https://github.com/dliptak001/HypercubeWTF) preprocesses a
|
|
106
|
+
static field with **one reservoir orbit**. HypercubeCascade is **both of them,
|
|
107
|
+
in series, on one cube**: the transit output, times a gain, becomes the orbit
|
|
108
|
+
drive, and the orbit's end state, times a second gain, is what the CNN head
|
|
109
|
+
trains on.
|
|
110
|
+
|
|
111
|
+
In classical reservoir computing (and in both single-stage siblings):
|
|
112
|
+
|
|
113
|
+
- Preprocessor weights are **frozen**
|
|
114
|
+
- Only a **readout** is trained
|
|
115
|
+
- Nonlinear dynamics expand and mix the drive into a rich state
|
|
116
|
+
|
|
117
|
+
Whether the two-stage pipeline has **real product value** is still an open
|
|
118
|
+
question. Early studies suggest the second stage adds filtering on top of what
|
|
119
|
+
the first stage already adds (see
|
|
120
|
+
[Early observations](#early-observations-exploratory)).
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Pipeline
|
|
125
|
+
|
|
126
|
+
```text
|
|
127
|
+
x (your length-N field — already on the cube, no natural time)
|
|
128
|
+
│
|
|
129
|
+
▼
|
|
130
|
+
frozen etalon transit (one wave over every cavity)
|
|
131
|
+
│
|
|
132
|
+
▼
|
|
133
|
+
× interstage_scale → frozen reservoir orbit (T re-addressed passes)
|
|
134
|
+
│
|
|
135
|
+
▼
|
|
136
|
+
end-of-orbit state × readout_scale → HypercubeCNN → logits / values
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- Cube size from **dim** (N = 2<sup>dim</sup>; dim 5…12). One dim serves all
|
|
140
|
+
three stages.
|
|
141
|
+
- Only the readout trains.
|
|
142
|
+
- Everyday loop in this package:
|
|
143
|
+
`collect_batch` → `train` → `predict` / `predict_class`,
|
|
144
|
+
or one-shot `fit` (collect + train).
|
|
145
|
+
|
|
146
|
+
Unlike HypercubeESN’s Python API, there is no stream of small samples over real
|
|
147
|
+
time and no next-step `fit` on a 1D signal. Each sample is one full field; the
|
|
148
|
+
“time” is the short synthetic orbit; the CNN only ever sees the state at the end.
|
|
149
|
+
|
|
150
|
+
Full method list and knobs:
|
|
151
|
+
**[docs/Python_SDK.md](https://github.com/dliptak001/HypercubeCascade/blob/main/docs/Python_SDK.md)**.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Early observations (exploratory)
|
|
156
|
+
|
|
157
|
+
On the MNIST white-noise study (train clean, test with Gaussian field noise),
|
|
158
|
+
the cascade behaves as a near-unity passthrough on clean fields and pulls
|
|
159
|
+
ahead of both the etalon-only path and the pack-only bypass from σ = 0.3
|
|
160
|
+
upward. On a Raman baseline-extraction regression it matches the etalon-only
|
|
161
|
+
sibling to within ~1% RMSE while training with a visibly more stable epoch
|
|
162
|
+
profile. The write-ups have the details and how we ran them:
|
|
163
|
+
|
|
164
|
+
| Document | Question |
|
|
165
|
+
|----------|----------|
|
|
166
|
+
| [WhiteNoiseFilter.md](https://github.com/dliptak001/HypercubeCascade/blob/main/examples/mnist/WhiteNoiseFilter.md) | Noisy test fields: do two stages help vs one stage vs pack-only → CNN? |
|
|
167
|
+
| [RamanBaselineExtraction/README.md](https://github.com/dliptak001/HypercubeCascade/blob/main/examples/RamanBaselineExtraction/README.md) | Baseline regression: cascade vs etalon-only, overlays and training profiles |
|
|
168
|
+
|
|
169
|
+
The MNIST study uses small cubes because they are handy to pack and run, not
|
|
170
|
+
because we are chasing digit accuracy. A more rigorous study is still needed
|
|
171
|
+
before treating any of those results as settled. You can reproduce the same
|
|
172
|
+
ideas from Python with this package (pack fields yourself, then collect,
|
|
173
|
+
train, and predict). The original write-ups and C++ demos that produced the
|
|
174
|
+
numbers live under
|
|
175
|
+
[`examples/`](https://github.com/dliptak001/HypercubeCascade/tree/main/examples).
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Installation
|
|
180
|
+
|
|
181
|
+
**Preferred:** install a pre-built wheel from PyPI (no compiler).
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
pip install hypercube-cascade
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
import hypercube_cascade as hc
|
|
189
|
+
print(hc.__version__)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Package name on PyPI: **`hypercube-cascade`**. Import name:
|
|
193
|
+
**`hypercube_cascade`**. Main type: **`hc.Cascade`**.
|
|
194
|
+
|
|
195
|
+
Wheels target Python 3.10–3.14 on common Windows, Linux, and macOS machines.
|
|
196
|
+
Runtime dependency: NumPy only.
|
|
197
|
+
|
|
198
|
+
### From source (full repository)
|
|
199
|
+
|
|
200
|
+
To compile the extension yourself, clone this **entire** repository (not a
|
|
201
|
+
minimal source-only download of the `python/` folder alone — the C++ core and
|
|
202
|
+
vendored HypercubeCNN live next to `python/`). You need Python 3.10+, a C++23
|
|
203
|
+
compiler, and CMake ≥ 3.20.
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
git clone https://github.com/dliptak001/HypercubeCascade.git
|
|
207
|
+
cd HypercubeCascade/python
|
|
208
|
+
pip install .
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
On Windows with CLion’s MinGW, put that compiler’s `bin` folder (and Ninja) on
|
|
212
|
+
your `PATH`, then:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
pip install . --no-build-isolation --force-reinstall --no-deps
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
(Exact CLion paths change with the version.) Step-by-step toolchain notes:
|
|
219
|
+
[docs/Python_SDK.md](https://github.com/dliptak001/HypercubeCascade/blob/main/docs/Python_SDK.md).
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Quick start
|
|
224
|
+
|
|
225
|
+
You bring each sample as a length-**N** float array (N = 2<sup>dim</sup>). How
|
|
226
|
+
you get there — pad an image, reshape a spectrum, invent a layout — is up to
|
|
227
|
+
you. This package does not pack 784 pixels or 300 bins for you.
|
|
228
|
+
|
|
229
|
+
Shapes that matter:
|
|
230
|
+
|
|
231
|
+
| Array | Shape | Notes |
|
|
232
|
+
|-------|-------|-------|
|
|
233
|
+
| `fields` | `(count, N)` | one length-N field per row |
|
|
234
|
+
| `labels` (classification) | `(count,)` | integer class indices |
|
|
235
|
+
| `targets` (regression) | `(count, num_outputs)` | float targets |
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
import numpy as np
|
|
239
|
+
import hypercube_cascade as hc
|
|
240
|
+
|
|
241
|
+
dim = 7
|
|
242
|
+
N = 2**dim
|
|
243
|
+
rng = np.random.default_rng(0)
|
|
244
|
+
fields = rng.standard_normal((200, N), dtype=np.float32)
|
|
245
|
+
labels = rng.integers(0, 4, size=200)
|
|
246
|
+
|
|
247
|
+
cas = hc.Cascade(
|
|
248
|
+
dim=dim,
|
|
249
|
+
exciter_subcube_dim=5,
|
|
250
|
+
history_depth=4,
|
|
251
|
+
T=50,
|
|
252
|
+
ic_seed=2,
|
|
253
|
+
readout_num_outputs=4,
|
|
254
|
+
readout_task="classification",
|
|
255
|
+
readout_epochs=80,
|
|
256
|
+
)
|
|
257
|
+
cas.fit(fields, labels) # collect_batch + train
|
|
258
|
+
|
|
259
|
+
print(cas.N, cas.T, cas.num_collected)
|
|
260
|
+
print(f"train sanity check: {cas.accuracy_on_collected():.3f}")
|
|
261
|
+
print(cas.predict_class(fields[0]), cas.predict(fields[0]).shape)
|
|
262
|
+
|
|
263
|
+
cas.save("model.pkl")
|
|
264
|
+
loaded = hc.Cascade.load("model.pkl")
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Step by step (same loop, more control)
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
cas = hc.Cascade(
|
|
271
|
+
dim=7,
|
|
272
|
+
exciter_subcube_dim=5,
|
|
273
|
+
readout_num_outputs=4,
|
|
274
|
+
readout_task="classification",
|
|
275
|
+
)
|
|
276
|
+
cas.collect_batch(fields_train, labels_train)
|
|
277
|
+
cas.train()
|
|
278
|
+
logits = cas.predict(fields_test[0]) # (num_outputs,) float32
|
|
279
|
+
cls = cas.predict_class(fields_test[0]) # int
|
|
280
|
+
test_acc = cas.accuracy(fields_test, labels_test) # held-out, fresh maps
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
For regression, set `readout_task="regression"` and pass float targets instead
|
|
284
|
+
of class labels. Then use `r2_on_collected()` / `r2(fields, targets)` the same
|
|
285
|
+
way.
|
|
286
|
+
|
|
287
|
+
`accuracy_on_collected` and `r2_on_collected` only look at the samples you
|
|
288
|
+
already trained on — they are a quick sanity check, not a test score. For real
|
|
289
|
+
evaluation, hold fields out and call `accuracy` / `r2` (or `predict` /
|
|
290
|
+
`predict_class` yourself).
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Features
|
|
295
|
+
|
|
296
|
+
- **One class** — `hypercube_cascade.Cascade` is the whole product surface
|
|
297
|
+
- **Map loop** — `collect` / `collect_batch` → `train` →
|
|
298
|
+
`predict` / `predict_class`
|
|
299
|
+
- **`fit`** — clear, collect, and train when your arrays are ready
|
|
300
|
+
- **dim 5–12** — field length N = 2<sup>dim</sup>; one dim for all three
|
|
301
|
+
stages; orbit length `T`; etalon face `exciter_subcube_dim`
|
|
302
|
+
- **Two gains** — `interstage_scale` (transit → orbit) and `readout_scale`
|
|
303
|
+
(orbit → readout)
|
|
304
|
+
- **Classification or regression** — `readout_task` fixed at construction
|
|
305
|
+
- **Held-out scoring** — `accuracy(fields, labels)` / `r2(fields, targets)`
|
|
306
|
+
map fresh in bulk
|
|
307
|
+
- **Bulk calls can parallelize** — `collect_threads` (0 = auto)
|
|
308
|
+
- **Inspect a map** — `run(x)` then `last_features()`, plus per-stage probes
|
|
309
|
+
`last_exciter()` / `last_interstage()` / `last_reservoir()` for gain tuning
|
|
310
|
+
- **Save / load** — `save` / `load` (pickle: config + readout weights;
|
|
311
|
+
collected samples are not stored). Optional `save_readout_hcnn_model` /
|
|
312
|
+
`load_readout_hcnn_model` for portable HCNW + arch JSON
|
|
313
|
+
- **NumPy float32** — arrays converted for you; prefer contiguous float32
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Examples
|
|
318
|
+
|
|
319
|
+
For a first try, paste the [Quick start](#quick-start) after
|
|
320
|
+
`pip install hypercube-cascade`. That is self-contained.
|
|
321
|
+
|
|
322
|
+
If you want a longer walk-through, the demo scripts on GitHub under
|
|
323
|
+
[`python/examples/`](https://github.com/dliptak001/HypercubeCascade/tree/main/python/examples)
|
|
324
|
+
are there to open or download — they are not added to your machine by pip.
|
|
325
|
+
|
|
326
|
+
| Script | What it is for |
|
|
327
|
+
|--------|----------------|
|
|
328
|
+
| [synthetic_classification.py](https://github.com/dliptak001/HypercubeCascade/blob/main/python/examples/synthetic_classification.py) | Multi-class toy fields: `fit`, then train and test accuracy |
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
# from a clone of HypercubeCascade, after: pip install hypercube-cascade
|
|
332
|
+
python python/examples/synthetic_classification.py
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
These use easy made-up fields so the API is obvious — not scores to publish.
|
|
336
|
+
More notes:
|
|
337
|
+
[python/examples/README.md](https://github.com/dliptak001/HypercubeCascade/blob/main/python/examples/README.md).
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## Documentation
|
|
342
|
+
|
|
343
|
+
| Doc | Role |
|
|
344
|
+
|-----|------|
|
|
345
|
+
| **[docs/Python_SDK.md](https://github.com/dliptak001/HypercubeCascade/blob/main/docs/Python_SDK.md)** | Canonical Python API — every method, layout, pickle, limits |
|
|
346
|
+
| [python/examples/README.md](https://github.com/dliptak001/HypercubeCascade/blob/main/python/examples/README.md) | Demo scripts on GitHub |
|
|
347
|
+
| [Project README](https://github.com/dliptak001/HypercubeCascade#readme) | Product story and C++ demos from the repo root |
|
|
348
|
+
| [docs/CPP_SDK.md](https://github.com/dliptak001/HypercubeCascade/blob/main/docs/CPP_SDK.md) | Native library guide (same product, C++) |
|
|
349
|
+
| [docs/CascadeWhitePaper.md](https://github.com/dliptak001/HypercubeCascade/blob/main/docs/CascadeWhitePaper.md) | The two-stage concept, mechanism by mechanism |
|
|
350
|
+
| [WhiteNoiseFilter.md](https://github.com/dliptak001/HypercubeCascade/blob/main/examples/mnist/WhiteNoiseFilter.md) | Early white-noise study (MNIST as a test bed) |
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
## Ecosystem
|
|
355
|
+
|
|
356
|
+
- **[HypercubeEtalon](https://github.com/dliptak001/HypercubeEtalon)** — the etalon transit alone; Cascade’s first stage.
|
|
357
|
+
- **[HypercubeWTF](https://github.com/dliptak001/HypercubeWTF)** — the reservoir orbit alone; Cascade’s second stage.
|
|
358
|
+
- **[HypercubeCNN](https://github.com/dliptak001/HypercubeCNN)** — cube-native conv stack; Cascade’s trainable head.
|
|
359
|
+
- **[HypercubeESN](https://github.com/dliptak001/HypercubeESN)** — echo-state / reservoir computing on streams.
|
|
360
|
+
- **[HypercubeHopfield](https://github.com/dliptak001/HypercubeHopfield)** — Hopfield-style dynamics on the cube.
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## License
|
|
365
|
+
|
|
366
|
+
Apache 2.0. See [LICENSE](https://github.com/dliptak001/HypercubeCascade/blob/main/LICENSE).
|