32. Views API¶
This page documents the views API. For workflows, see Views how-to.
32.1 What it is for¶
The views brick creates multiple feature views for multi-view SSL methods like co-training. [1][2]
32.2 Examples¶
Generate two random feature views:
from modssc.data_loader import load_dataset
from modssc.views import generate_views, two_view_random_feature_split
ds = load_dataset("toy", download=True)
plan = two_view_random_feature_split(fraction=0.5)
views = generate_views(ds, plan=plan, seed=0)
print(list(views.views.keys()))
Create a custom plan with explicit indices:
from modssc.views import ColumnSelectSpec, ViewSpec, ViewsPlan
plan = ViewsPlan(
views=(
ViewSpec(name="view_a", columns=ColumnSelectSpec(mode="indices", indices=(0, 1, 2))),
ViewSpec(name="view_b", columns=ColumnSelectSpec(mode="complement", complement_of="view_a")),
)
)
The view plan schema is defined in src/modssc/views/plan.py. The public facade remains modssc.views, while internal orchestration is split into dedicated support modules. [2]
32.3 API reference¶
Multi-view feature generation.
This brick focuses on feature views (classic multi-view SSL methods such as Co-Training),
not on augmentation-based multi-view training (handled by :mod:modssc.data_augmentation).
The core entry-point is :func:modssc.views.generate_views.
32.4
ColumnSelectSpec
dataclass
¶
How to select columns from a 2D feature matrix.
This is used to generate feature views (e.g. classic Co-Training), where each view sees a different subset of the features.
32.4.0.1 Notes¶
mode="complement"assumes the referenced view has already been resolved.fractionis only used formode="random".
Source code in src/modssc/views/plan.py
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 | |
32.5
ViewSpec
dataclass
¶
A single view definition.
Source code in src/modssc/views/plan.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
32.6
ViewsError
¶
Bases: Exception
Base exception for the modssc.views brick.
Source code in src/modssc/views/errors.py
4 5 | |
32.7
ViewsPlan
dataclass
¶
A plan that generates multiple views from the same dataset.
Source code in src/modssc/views/plan.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
32.8
ViewsResult
dataclass
¶
Result of generate_views.
32.8.0.1 Attributes¶
views:
Mapping of view name -> dataset where each split's .X is the view-specific feature matrix.
columns:
Mapping of view name -> selected column indices (sorted, unique).
seed:
Global seed used for any stochastic view operations (e.g. random column selection).
plan:
The input plan (validated).
meta:
Arbitrary metadata.
Source code in src/modssc/views/types.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
32.9
ViewsValidationError
¶
Bases: 32.6 ViewsError, ValueError
Raised when a ViewsPlan / ViewSpec is invalid.
Source code in src/modssc/views/errors.py
8 9 | |
32.10
two_view_random_feature_split(*, preprocess=None, fraction=0.5, seed_offset=0, name_a='view_a', name_b='view_b')
¶
Convenience helper for classic 2-view feature split.
The first view picks a random subset of columns, the second view is its complement.
Source code in src/modssc/views/plan.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |