File size: 1,647 Bytes
bd8f3ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Generates the shared parquet dataset used by tests/test_0_*.py.

Dataset is deterministic (fixed seed). Regenerate with:
    uv run python tests/data/make_datasets.py

Design (see CALIBRATION.md): 1000 items x 128 dims in 3 orthonormal clusters
of increasing sparsity. Dense clusters get low lambdas, sparse clusters high
lambdas — the spectral statistic tracks structural density.
"""
import os

import numpy as np
import pandas as pd

HERE = os.path.dirname(os.path.abspath(__file__))

D = 128
CLUSTER_SIZES = (400, 350, 250)      # dense, medium, sparse
CLUSTER_SIGMA = (0.02, 0.05, 0.12)
SEED = 11


def make_clustered(seed=SEED, d=D, sizes=CLUSTER_SIZES, sigmas=CLUSTER_SIGMA):
    rng = np.random.default_rng(seed)
    raw = rng.standard_normal((len(sizes), d))
    Q, _ = np.linalg.qr(raw.T)            # orthonormal 128-dim centroids
    centroids = Q.T

    rows, labels = [], []
    for c, (n, sig) in enumerate(zip(sizes, sigmas)):
        X = centroids[c][None, :] + sig * rng.standard_normal((n, d))
        X /= np.linalg.norm(X, axis=1, keepdims=True)
        rows.append(X)
        labels.append(np.full(n, c))
    return np.vstack(rows).astype(np.float64), np.concatenate(labels)


def save_parquet(items: np.ndarray, labels: np.ndarray, name: str):
    df = pd.DataFrame(items, columns=[f"f{i}" for i in range(items.shape[1])])
    df["cluster"] = labels.astype(np.int64)
    path = os.path.join(HERE, name)
    df.to_parquet(path, index=False)
    print(f"wrote {path}  shape={items.shape}")


if __name__ == "__main__":
    items, labels = make_clustered()
    save_parquet(items, labels, "eigenmaps_controlled.parquet")