Download relational_geometry.py from PureOne/qaenthrix-eve: direct link, hf CLI and curl.
- Browser
- Download file 4.6 kB
-
https://huggingface.co/datasets/PureOne/qaenthrix-eve/resolve/main/relational_geometry.py
- Command line
-
hf download hf://datasets/PureOne/qaenthrix-eve/relational_geometry.py
-
curl -L -o relational_geometry.py https://huggingface.co/datasets/PureOne/qaenthrix-eve/resolve/main/relational_geometry.py
4.6 kB
| """Rank-one reference and relative-phase geometry for QÆNTHRIX. | |
| The model uses rank-one orthogonal projectors in complex coordinates. | |
| These routines are finite numerical constructions, not topological proofs. | |
| """ | |
| import numpy as np | |
| from eve_reserve import Event | |
| def ray(vector): | |
| """Return the rank-one projector of a nonzero vector; phase is discarded.""" | |
| u = np.asarray(vector, dtype=complex).reshape(-1) | |
| norm = np.linalg.norm(u) | |
| if norm == 0: | |
| raise ValueError("a ray requires a nonzero vector") | |
| u = u / norm | |
| return np.outer(u, u.conj()) | |
| def _unit(vector, n): | |
| w = np.asarray(vector, dtype=complex).reshape(n) | |
| if not np.isclose(np.vdot(w, w).real, 1., atol=1e-12, rtol=1e-12): | |
| raise ValueError("reference must have unit norm") | |
| return w | |
| def global_factor(p, weight, background=0.): | |
| """Continuous n-row factor of lambda P + mu (I-P), lambda >= mu >= 0.""" | |
| if not 0 <= background <= weight: | |
| raise ValueError("weights must satisfy lambda >= mu >= 0") | |
| p = np.asarray(p, dtype=complex) | |
| return np.sqrt(weight)*p + np.sqrt(background)*(np.eye(len(p))-p) | |
| def anchor_section(p, reference, blind_tolerance=1e-12): | |
| """Canonical unit vector P w / ||P w|| on the recognized domain. | |
| The numerical blind_tolerance is explicit; the analytic domain is ||P w||>0. | |
| """ | |
| p = np.asarray(p, dtype=complex) | |
| w = _unit(reference, len(p)) | |
| v = p @ w | |
| margin = np.linalg.norm(v) | |
| if margin <= blind_tolerance: | |
| raise ValueError("reference is blind at the declared numerical tolerance") | |
| return v / margin | |
| def anchor_factor(p, reference, weight, blind_tolerance=1e-12): | |
| if weight < 0: | |
| raise ValueError("weight must be nonnegative") | |
| return np.sqrt(weight)*anchor_section(p, reference, blind_tolerance).conj()[None, :] | |
| def recognition_margin(p, reference): | |
| """Exact-model distance in operator norm to the reference's blind locus.""" | |
| p = np.asarray(p, dtype=complex) | |
| return float(np.linalg.norm(p @ _unit(reference, len(p)))) | |
| def select_reference(p, references, blind_tolerance=1e-12): | |
| """Choose a largest-margin column of an n-by-q unit-reference matrix. | |
| Index changes are chart switches, not one continuous global scalar factor. | |
| """ | |
| p = np.asarray(p, dtype=complex) | |
| refs = np.asarray(references, dtype=complex) | |
| if refs.ndim != 2 or refs.shape[0] != len(p) or refs.shape[1] == 0: | |
| raise ValueError("references must be a nonempty n-by-q matrix") | |
| for j in range(refs.shape[1]): | |
| _unit(refs[:, j], len(p)) | |
| margins = np.linalg.norm(p @ refs, axis=0) | |
| index = int(np.argmax(margins)) | |
| section = anchor_section(p, refs[:, index], blind_tolerance) | |
| return index, section, float(margins[index]) | |
| def pair_transport(p, q, blind_tolerance=1e-12): | |
| """Canonical partial isometry from ray Q to ray P when they overlap.""" | |
| product = np.asarray(p, dtype=complex) @ np.asarray(q, dtype=complex) | |
| margin = np.linalg.norm(product, 'fro') | |
| if margin <= blind_tolerance: | |
| raise ValueError("orthogonal rays have no canonical phase comparison") | |
| return product / margin | |
| def cycle_holonomy(projectors, blind_tolerance=1e-12): | |
| """Phase of T(P0<-P1) ... T(P_last<-P0), with this orientation.""" | |
| if len(projectors) < 2: | |
| raise ValueError("a cycle requires at least two vertices") | |
| ps = [np.asarray(p, dtype=complex) for p in projectors] | |
| product = np.eye(len(ps[0]), dtype=complex) | |
| for i, p in enumerate(ps): | |
| product = product @ pair_transport(p, ps[(i+1) % len(ps)], blind_tolerance) | |
| return complex(np.trace(ps[0] @ product)) | |
| def relational_direction(p): | |
| """Column-major vec(P); a global unit vector in a different, n^2-state space.""" | |
| return np.asarray(p, dtype=complex).reshape(-1, order='F') | |
| def relational_factor(p, weight): | |
| """One-row factor of weight |vec(P)><vec(P)| on matrix-valued inputs.""" | |
| if weight < 0: | |
| raise ValueError("weight must be nonnegative") | |
| return np.sqrt(weight)*relational_direction(p).conj()[None, :] | |
| def relational_event(p, cosine, colour, transport=None): | |
| """Lift a matrix state through X -> U A(X) U*, using column-major vec. | |
| The direction is vec(P), and U conjugation acts as conjugate(U) tensor U. | |
| This is not an encoder of the original single-vector amplitude. | |
| """ | |
| p = np.asarray(p, dtype=complex) | |
| n = len(p) | |
| u = np.eye(n, dtype=complex) if transport is None else np.asarray(transport, dtype=complex) | |
| return Event(relational_direction(p), cosine, colour, np.kron(u.conj(), u)) | |