Source feature masking
neureptrace.decoding.source_masking implements strict source-only feature masking augmentation for M/EEG feature matrices.
The protocol is Category 1 / strict source-only. It uses source features, source labels, and optional source-domain identifiers for provenance. It does not accept held-out target data.
Supported masking modes:
feature: randomly selected feature columnsblock: one contiguous feature block
Supported fill modes:
feature_mean: source-only column meansrow_mean: the sampled row meanzero: zeros
Typical usage:
from neureptrace.decoding.source_masking import augment_source_with_feature_masking
result = augment_source_with_feature_masking(
X_source,
y_source,
source_domains=subject_ids,
config={
"synthetic_per_class": 8,
"mask_fraction": 0.15,
"mask_mode": "feature",
"fill_mode": "feature_mean",
},
)
X_aug = result.features
y_aug = result.labels
neureptrace.decoding.source_masking
Strict source-only feature masking augmentation.
The utilities in this module create masked copies of labeled source feature rows. They are intended as a simple domain-generalization baseline for M/EEG feature matrices: rows keep their source labels while a random feature subset or a contiguous feature block is replaced by source-only fill statistics.
This is a Protocol-1 helper. The public API uses source features and source labels only, plus optional source-domain ids for provenance; held-out target data are not accepted.
SourceFeatureMaskingConfig
dataclass
Configuration for strict source-only feature masking.
Source code in src/neureptrace/decoding/source_masking.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
enabled
property
Whether synthetic rows should be generated.
SourceFeatureMaskingResult
dataclass
Augmented source rows and provenance.
Source code in src/neureptrace/decoding/source_masking.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
n_synthetic
property
Number of generated rows in the returned matrix.
augment_source_with_feature_masking(source_features, source_labels, *, source_domains=None, config=None)
Append masked source-row copies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_features
|
Sequence[Sequence[float]] | ndarray
|
Source feature matrix with rows as trials/windows and columns as features. |
required |
source_labels
|
Sequence[Any] | ndarray
|
One source label per row. Synthetic rows inherit the sampled row label. |
required |
source_domains
|
Sequence[Hashable] | ndarray | None
|
Optional source-domain ids recorded only for provenance. |
None
|
config
|
SourceFeatureMaskingConfig | Mapping[str, Any] | None
|
Masking options. Mappings are normalized through
:func: |
None
|
Returns:
| Type | Description |
|---|---|
SourceFeatureMaskingResult
|
Augmented feature rows, labels, synthetic-row mask, sampled content row ids, per-synthetic-row masked feature indices, and protocol metadata. |
Source code in src/neureptrace/decoding/source_masking.py
70 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 97 98 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 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 | |
feature_mask_indices(n_features, *, mask_fraction=DEFAULT_MASK_FRACTION, mask_mode='feature', block_size=None, rng=None)
Return sorted feature indices to replace for one synthetic row.
Source code in src/neureptrace/decoding/source_masking.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
source_feature_masking_config(*, synthetic_per_class=0, mask_fraction=DEFAULT_MASK_FRACTION, mask_mode='feature', block_size=None, fill_mode='feature_mean', noise_std=0.0, preserve_original=True, random_state=13)
Normalize public feature-masking options.
Source code in src/neureptrace/decoding/source_masking.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
normalize_mask_mode(value)
Normalize mask-mode aliases.
Source code in src/neureptrace/decoding/source_masking.py
228 229 230 231 232 233 234 235 | |
normalize_fill_mode(value)
Normalize fill-mode aliases.
Source code in src/neureptrace/decoding/source_masking.py
238 239 240 241 242 243 244 245 | |