23. Views API¶
This page documents the views API. For workflows, see Views how-to.
23.1 What it is for¶
The views brick creates multiple feature views for multi-view SSL methods like co-training. [1][2]
23.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. [2]
23.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.
23.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.
23.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 | |
23.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 | |
23.6
ViewsError
¶
Bases: Exception
Base exception for the modssc.views brick.
Source code in src/modssc/views/errors.py
4 5 | |
23.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 | |
23.8
ViewsResult
dataclass
¶
Result of generate_views.
23.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 | |
23.9
ViewsValidationError
¶
Bases: 23.6 ViewsError, ValueError
Raised when a ViewsPlan / ViewSpec is invalid.
Source code in src/modssc/views/errors.py
8 9 | |
23.10
generate_views(dataset, *, plan, seed=0, cache=True, fit_indices=None)
¶
Generate multiple feature views from a dataset.
23.10.0.1 Parameters¶
dataset:
Input dataset from :mod:modssc.data_loader (train/test splits).
plan:
ViewsPlan describing how to create each view.
seed:
Global seed controlling stochastic view operations (e.g. random feature split).
cache:
Passed through to :func:modssc.preprocess.preprocess when preprocessing is used.
fit_indices:
Indices (relative to the train split) to use when fitting preprocessing steps
(e.g. PCA). Defaults to np.arange(len(train)).
23.10.0.2 Returns¶
ViewsResult
Each view is returned as a LoadedDataset where .train.X and .test.X are view-specific
feature matrices, while labels / edges / masks are preserved.
Source code in src/modssc/views/api.py
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
23.11
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 | |