Reconstruction Encoder
neureptrace.decoding.reconstruction_encoder provides label-free reconstruction baselines for
cross-subject decoding. An encoder/decoder is fit with a reconstruction objective, and the downstream
classifier is trained only on source labels in the learned latent space.
Two protocol scopes are exposed:
source_only: fit the encoder on source rows only. This is Protocol 1 / strict source-only.source_plus_target: fit the encoder on source rows plus unlabeled target rows. This is Protocol 2 / unlabeled target-adaptive. If no separatetarget_encoder_featuresblock is provided, the test feature matrix is used as a transductive unlabeled target batch and this is recorded in metadata.
Two encoder families are available:
encoder_kind="linear"uses the deterministic closed-form linear autoencoder/PCA baseline.encoder_kind="masked_autoencoder"uses an optional PyTorch nonlinear masked autoencoder. During training, random feature entries are masked and optional Gaussian noise is added; the network reconstructs the original clean feature vector and exposes the encoder bottleneck as the latent representation. Aliases include"deep","nonlinear","deep_masked_autoencoder","torch_masked_autoencoder", and"mae".
Target labels are not accepted by either the latent-space helper or the classifier helper. Passing
target_labels raises a ValueError.
from neureptrace.decoding.reconstruction_encoder import (
fit_reconstruction_latent_classifier,
reconstruction_encoder_config,
)
config = reconstruction_encoder_config(
encoder_kind="masked_autoencoder",
fit_scope="source_plus_target",
n_components=32,
hidden_units=(128, 64),
mask_fraction=0.25,
max_epochs=100,
batch_size=128,
standardize=True,
device="auto",
)
result = fit_reconstruction_latent_classifier(
train_features=X_source,
train_labels=y_source,
test_features=X_target_test,
target_encoder_features=X_target_unlabeled_calibration,
config=config,
)
print(result.metadata["representation_protocol"])
print(result.metadata["representation_method"])
print(result.predictions)
Relevant metadata fields include representation_protocol, representation_method,
representation_encoder_kind, representation_is_nonlinear, representation_uses_unlabeled_target_data,
representation_target_labels_used, representation_target_feature_source, and reconstruction MSE
summaries for the fit, source-train, and target-test matrices. Masked-autoencoder runs also report
representation_mask_fraction, representation_hidden_units, representation_epochs_run,
representation_validation_reconstruction_mse, and representation_masked_training_reconstruction_mse.
neureptrace.decoding.reconstruction_encoder
Reconstruction-loss latent representations for cross-subject decoding.
This module implements the protocol where an encoder/decoder is fit from an unlabeled reconstruction objective and a supervised classifier is then trained only on source labels in the latent space. Fitting the encoder on source rows only is Protocol 1. Fitting it on source rows plus unlabeled target rows is Protocol 2. Target labels are rejected by design.
LinearReconstructionEncoder
Closed-form linear autoencoder/PCA fitted by reconstruction loss.
Source code in src/neureptrace/decoding/reconstruction_encoder.py
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 | |
ReconstructionEncoderConfig
dataclass
Configuration for reconstruction-loss latent encoders.
Source code in src/neureptrace/decoding/reconstruction_encoder.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
ReconstructionLatentClassificationResult
dataclass
Classifier outputs from reconstruction-latent features.
Source code in src/neureptrace/decoding/reconstruction_encoder.py
70 71 72 73 74 75 76 77 78 79 80 81 | |
ReconstructionLatentResult
dataclass
Latent train/test features and protocol metadata.
Source code in src/neureptrace/decoding/reconstruction_encoder.py
60 61 62 63 64 65 66 67 | |
TorchMaskedReconstructionEncoder
Nonlinear masked autoencoder fitted from unlabeled reconstruction loss.
The model receives randomly masked/noised feature vectors and is optimized to
reconstruct the original clean vector. transform then returns the latent
code for clean feature vectors. The implementation intentionally has no label
arguments, so target labels cannot affect the encoder fit.
Source code in src/neureptrace/decoding/reconstruction_encoder.py
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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
fit_reconstruction_latent_classifier(*, train_features, train_labels, test_features, config=None, target_encoder_features=None, target_labels=None, classifier=None, sample_weight=None)
Train a source-label classifier in the reconstruction latent space.
Source code in src/neureptrace/decoding/reconstruction_encoder.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | |
fit_reconstruction_latent_space(*, train_features, test_features, config=None, target_encoder_features=None, target_labels=None)
Fit the reconstruction encoder and return latent train/test features.
Source code in src/neureptrace/decoding/reconstruction_encoder.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | |
normalize_reconstruction_encoder_kind(encoder_kind)
Normalize aliases for linear and deep masked reconstruction encoders.
Source code in src/neureptrace/decoding/reconstruction_encoder.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
normalize_reconstruction_fit_scope(fit_scope)
Normalize aliases for source-only and source-plus-target encoder fits.
Source code in src/neureptrace/decoding/reconstruction_encoder.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | |
reconstruction_encoder_config(*, n_components=DEFAULT_RECONSTRUCTION_COMPONENTS, fit_scope=RECONSTRUCTION_SOURCE_PLUS_TARGET, standardize=False, encoder_kind=RECONSTRUCTION_LINEAR_ENCODER, hidden_units=DEFAULT_MASKED_AUTOENCODER_HIDDEN_UNITS, mask_fraction=0.25, noise_std=0.0, max_epochs=100, batch_size=128, learning_rate=0.001, weight_decay=0.0001, validation_fraction=0.1, patience=10, dropout=0.1, classifier_max_iter=1000, classifier_C=1.0, classifier_class_weight=None, random_state=13, device='auto')
Normalize user-facing reconstruction-encoder options.
Source code in src/neureptrace/decoding/reconstruction_encoder.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 | |