HoloVec HoloVec HoloVec
  • Getting Started
  • Tutorials
  • User Guide
  • API
  • Examples
/
  1. HoloVec /
  2. HoloVec Examples /
  3. BSDC-SEG demo: segment-sparse codes, bundling, and segment-wise search

Note

Go to the end to download the full example code.

BSDC-SEG demo: segment-sparse codes, bundling, and segment-wise searchΒΆ

Run (optional):

python -m examples.bsdc_seg_demo

 9 from holovec.backends import get_backend
10 from holovec.models.bsdc_seg import BSDCSEGModel
11 from holovec.utils.search import segment_pattern, find_by_segment_pattern
12
13
14 def main():
15     backend = get_backend('numpy')
16     D, S = 80, 8
17     model = BSDCSEGModel(dimension=D, segments=S, backend=backend, seed=0)
18     space = model.space
19
20     # Build a small codebook
21     codebook = {
22         f"item{i}": space.random(seed=10 + i) for i in range(10)
23     }
24
25     # Bundle a couple of items
26     bundle = model.bundle([codebook['item1'], codebook['item2'], codebook['item3']])
27     print("Bundled vector pattern (first 3 segments):", segment_pattern(bundle, space)[:3])
28
29     # Query by segment pattern (wildcards allowed via None)
30     # e.g., find items where segments 0 and 1 match a target vector
31     target = codebook['item1']
32     pat = segment_pattern(target, space)
33     query_pattern = [pat[0], pat[1]] + [None] * (S - 2)
34
35     exact = find_by_segment_pattern(codebook, space, query_pattern, match_mode='exact')
36     print("Exact matches on first 2 segments:", [lbl for lbl, _ in exact])
37
38     frac = find_by_segment_pattern(codebook, space, query_pattern, match_mode='fraction', min_fraction=0.5)
39     print("Fraction >= 0.5 on specified segments:", frac)
40
41
42 if __name__ == "__main__":
43     main()

Download Jupyter notebook: 42_model_bsdc_seg.ipynb

Download Python source code: 42_model_bsdc_seg.py

Download zipped: 42_model_bsdc_seg.zip

Gallery generated by Sphinx-Gallery

Previous
GHRR usage example: diagonality/m sweeps and non-commutativity trends
Next
API Reference

2025, Twistient Corp.

Made with Sphinx and Shibuya theme.