QDpy
Loading...
Searching...
No Matches
qdpy.containers.feature_extraction.TorchFeatureExtractionContainerDecorator Class Reference
Inheritance diagram for qdpy.containers.feature_extraction.TorchFeatureExtractionContainerDecorator:
qdpy.containers.base.ContainerDecorator qdpy.containers.base.ContainerDecorator qdpy.base.CreatableFromConfig qdpy.base.Copyable qdpy.base.Summarisable qdpy.containers.base.ContainerLike qdpy.base.CreatableFromConfig qdpy.base.Copyable qdpy.base.Summarisable qdpy.containers.base.ContainerLike qdpy.containers.mc_aurora._EnsembleDescriptors

Public Member Functions

 __setstate__ (self, state)
 Reinstall the descriptor lookup after loading an archive.
Sequence[FeaturesLike] compute_latent (self, Sequence[IndividualLike] inds, *, bool fit_transform=False)
 Encode named scores and cache the descriptors used for admission.
None train (self, int nb_epochs)
None recompute_features_all_ind (self, update_params=None)
Optional[int] add (self, IndividualLike individual, bool raise_if_not_added_to_parents=False)
int update (self, Iterable iterable, bool ignore_exceptions=True, bool issue_warning=False)
Public Member Functions inherited from qdpy.base.Summarisable
Mapping[str, Any] __get_summary_state__ (self)
str summary (self, Optional[int] max_depth=None, Optional[int] max_entry_length=250)
Public Member Functions inherited from qdpy.base.CreatableFromConfig
Any from_config (cls, Mapping[str, Any] config, **Any kwargs)

Protected Member Functions

 _init_methods_hooks (self)
 Route descriptor lookups through the wrapping encoder.
tuple[str,...] _extracted_score_names (self)
 List the stable names of the wrapped archive's latent coordinates.
torch.Tensor _score_tensor (self, Sequence[IndividualLike] inds)
 _model_input (self, model, data)
 Move encoder inputs to the model's device and floating-point dtype.
 _encode (self, model, data)
 Encode a batch without autograd or training-time layers.
 _fit_quantile_transform (self, latent)
 Fit one empirical quantile mapping per latent coordinate.
 _transform_latent (self, latent, transformer)
 Apply a fitted transform, or use sigmoid before the first fit.
 _store_descriptors (self, inds, rows)
 Cache the descriptors returned to the underlying archive.
None _create_default_model (self, IndividualLike example_ind)
 Construct a dense autoencoder from an example record.
 _make_default_model (self, IndividualLike example_ind)
 Build a default model without installing it or changing the archive.
 _input_shape (self, example_ind)
 Infer the shape of a score vector or array-valued observation.
 _train_and_recompute_if_needed (self, update_params=None)
 Train while the current archive is still available.

Detailed Description

Use an autoencoder's latent values as archive descriptors.

Install PyTorch separately. Supply consistent numeric named scores
across candidates. Choose their order with ``base_scores``. By default,
use the non-extracted scores in the order of the first training
entry's keys. The default model uses the wrapped container's
descriptor dimension as its latent width. Set ``observation_score``
to encode one fixed-shape numeric observation per individual.
The default model flattens these records. Supplied models receive
the observation shape with a leading batch dimension.

Train periodically from explicit training archives, immediate parents,
or the retained entries. After training, recompute latent features
and rebuild the wrapped archive. Pair with an autoscaling grid when
the latent domain should adjust as the model changes. Alternatively,
set ``quantile_transform=True`` and use a fixed unit grid. The decoder
still trains in observation space. Before the first fit, a sigmoid
maps provisional descriptors into the unit domain.

:param quantile_transform: Fit a separate empirical cumulative
    distribution for each latent coordinate during a rebuild.
:param observation_score: Name of the array-valued record to encode.
    Supply this or ``base_scores`` to choose the input.

Definition at line 96 of file feature_extraction.py.

Member Function Documentation

◆ _encode()

qdpy.containers.feature_extraction.TorchFeatureExtractionContainerDecorator._encode ( self,
model,
data )
protected

Encode a batch without autograd or training-time layers.

Exceptions
ValueErrorIf the descriptor width or values are invalid.

Definition at line 230 of file feature_extraction.py.

◆ _score_tensor()

torch.Tensor qdpy.containers.feature_extraction.TorchFeatureExtractionContainerDecorator._score_tensor ( self,
Sequence[IndividualLike] inds )
protected
Build the encoder input in the configured score order.

Definition at line 192 of file feature_extraction.py.

◆ _train_and_recompute_if_needed()

qdpy.containers.feature_extraction.TorchFeatureExtractionContainerDecorator._train_and_recompute_if_needed ( self,
update_params = None )
protected

Train while the current archive is still available.

Parameters
update_paramsOptional arguments for archive readmission.

A model can train from the wrapped archive itself. Start training before clearing it and record the training count only after the rebuild.

Definition at line 375 of file feature_extraction.py.

◆ add()

Optional[int] qdpy.containers.feature_extraction.TorchFeatureExtractionContainerDecorator.add ( self,
IndividualLike individual,
bool raise_if_not_added_to_parents = False )
Check the retraining schedule, then offer one candidate to the wrapped archive.

Reimplemented from qdpy.containers.base.ContainerDecorator.

Definition at line 385 of file feature_extraction.py.

◆ compute_latent()

Sequence[FeaturesLike] qdpy.containers.feature_extraction.TorchFeatureExtractionContainerDecorator.compute_latent ( self,
Sequence[IndividualLike] inds,
* ,
bool fit_transform = False )

Encode named scores and cache the descriptors used for admission.

Parameters
indsNonempty sequence of evaluated candidates in input order.
fit_transformWhether to refit the optional quantile transform.
Returns
One descriptor vector per candidate.
Encode candidates and cache the returned latent descriptors.

Set ``fit_transform=True`` when encoding the training archive
before rebuilding it. Ordinary inference reuses the fitted
transform.

Definition at line 262 of file feature_extraction.py.

◆ recompute_features_all_ind()

None qdpy.containers.feature_extraction.TorchFeatureExtractionContainerDecorator.recompute_features_all_ind ( self,
update_params = None )
Recalculate latent descriptors and re-admit the training archive.

Compute the descriptors before clearing the wrapped archive so
records remain available if encoding fails.

Definition at line 357 of file feature_extraction.py.

◆ train()

None qdpy.containers.feature_extraction.TorchFeatureExtractionContainerDecorator.train ( self,
int nb_epochs )
Fit the model to score records for the requested number of epochs.

The training data comes from configured training containers first,
parent archives second, or the wrapped container last. Update
``current_loss`` with the most recent batch's reconstruction loss.
Call ``recompute_features_all_ind()`` after manual training to
realign the archive with the encoder.

:raises ValueError: If there are no training records or no epochs.

Definition at line 321 of file feature_extraction.py.

◆ update()

int qdpy.containers.feature_extraction.TorchFeatureExtractionContainerDecorator.update ( self,
Iterable iterable,
bool ignore_exceptions = True,
bool issue_warning = False )
Check the retraining schedule once, then pass the batch to the wrapped archive.

Reimplemented from qdpy.containers.base.ContainerDecorator.

Definition at line 391 of file feature_extraction.py.


The documentation for this class was generated from the following file: