From aa08765c64d6d9c9d93d2a3d1eb572ddf60682e4 Mon Sep 17 00:00:00 2001 From: <> Date: Fri, 26 Jan 2024 16:08:59 +0000 Subject: [PATCH] Deployed 5094a82 with MkDocs version: 1.5.3 --- .nojekyll | 0 404.html | 1725 +++++ api/SUMMARY/index.html | 1802 +++++ api/rul_adapt/approach/abstract/index.html | 2099 ++++++ api/rul_adapt/approach/adarul/index.html | 2595 +++++++ api/rul_adapt/approach/cnn_dann/index.html | 1931 +++++ api/rul_adapt/approach/conditional/index.html | 3178 ++++++++ api/rul_adapt/approach/consistency/index.html | 2763 +++++++ api/rul_adapt/approach/dann/index.html | 2597 +++++++ api/rul_adapt/approach/evaluation/index.html | 1847 +++++ api/rul_adapt/approach/index.html | 1802 +++++ .../approach/latent_align/index.html | 3459 +++++++++ api/rul_adapt/approach/mmd/index.html | 2464 ++++++ .../approach/pseudo_labels/index.html | 2158 ++++++ api/rul_adapt/approach/supervised/index.html | 2338 ++++++ api/rul_adapt/approach/tbigru/index.html | 2597 +++++++ .../construct/adarul/functional/index.html | 2156 ++++++ api/rul_adapt/construct/adarul/index.html | 1804 +++++ .../construct/cnn_dann/functional/index.html | 2132 ++++++ api/rul_adapt/construct/cnn_dann/index.html | 1804 +++++ .../consistency/functional/index.html | 2184 ++++++ .../construct/consistency/index.html | 1804 +++++ api/rul_adapt/construct/index.html | 1802 +++++ .../latent_align/functional/index.html | 2188 ++++++ .../construct/latent_align/index.html | 1804 +++++ .../construct/lstm_dann/functional/index.html | 2127 ++++++ api/rul_adapt/construct/lstm_dann/index.html | 1804 +++++ .../construct/tbigru/functional/index.html | 2127 ++++++ api/rul_adapt/construct/tbigru/index.html | 1804 +++++ api/rul_adapt/loss/adaption/index.html | 2703 +++++++ api/rul_adapt/loss/alignment/index.html | 2074 +++++ api/rul_adapt/loss/conditional/index.html | 2195 ++++++ api/rul_adapt/loss/index.html | 1802 +++++ api/rul_adapt/loss/rul/index.html | 1847 +++++ api/rul_adapt/loss/utils/index.html | 1847 +++++ api/rul_adapt/model/cnn/index.html | 2193 ++++++ api/rul_adapt/model/head/index.html | 2084 +++++ api/rul_adapt/model/index.html | 1826 +++++ api/rul_adapt/model/rnn/index.html | 2302 ++++++ api/rul_adapt/model/two_stage/index.html | 2061 +++++ api/rul_adapt/model/wrapper/index.html | 1847 +++++ api/rul_adapt/utils/index.html | 2235 ++++++ assets/_mkdocstrings.css | 109 + assets/images/favicon.png | Bin 0 -> 1870 bytes assets/javascripts/bundle.d7c377c4.min.js | 29 + assets/javascripts/bundle.d7c377c4.min.js.map | 7 + assets/javascripts/lunr/min/lunr.ar.min.js | 1 + assets/javascripts/lunr/min/lunr.da.min.js | 18 + assets/javascripts/lunr/min/lunr.de.min.js | 18 + assets/javascripts/lunr/min/lunr.du.min.js | 18 + assets/javascripts/lunr/min/lunr.el.min.js | 1 + assets/javascripts/lunr/min/lunr.es.min.js | 18 + assets/javascripts/lunr/min/lunr.fi.min.js | 18 + assets/javascripts/lunr/min/lunr.fr.min.js | 18 + assets/javascripts/lunr/min/lunr.he.min.js | 1 + assets/javascripts/lunr/min/lunr.hi.min.js | 1 + assets/javascripts/lunr/min/lunr.hu.min.js | 18 + assets/javascripts/lunr/min/lunr.hy.min.js | 1 + assets/javascripts/lunr/min/lunr.it.min.js | 18 + assets/javascripts/lunr/min/lunr.ja.min.js | 1 + assets/javascripts/lunr/min/lunr.jp.min.js | 1 + assets/javascripts/lunr/min/lunr.kn.min.js | 1 + assets/javascripts/lunr/min/lunr.ko.min.js | 1 + assets/javascripts/lunr/min/lunr.multi.min.js | 1 + assets/javascripts/lunr/min/lunr.nl.min.js | 18 + assets/javascripts/lunr/min/lunr.no.min.js | 18 + assets/javascripts/lunr/min/lunr.pt.min.js | 18 + assets/javascripts/lunr/min/lunr.ro.min.js | 18 + assets/javascripts/lunr/min/lunr.ru.min.js | 18 + assets/javascripts/lunr/min/lunr.sa.min.js | 1 + .../lunr/min/lunr.stemmer.support.min.js | 1 + assets/javascripts/lunr/min/lunr.sv.min.js | 18 + assets/javascripts/lunr/min/lunr.ta.min.js | 1 + assets/javascripts/lunr/min/lunr.te.min.js | 1 + assets/javascripts/lunr/min/lunr.th.min.js | 1 + assets/javascripts/lunr/min/lunr.tr.min.js | 18 + assets/javascripts/lunr/min/lunr.vi.min.js | 1 + assets/javascripts/lunr/min/lunr.zh.min.js | 1 + assets/javascripts/lunr/tinyseg.js | 206 + assets/javascripts/lunr/wordcut.js | 6708 +++++++++++++++++ .../workers/search.f886a092.min.js | 42 + .../workers/search.f886a092.min.js.map | 7 + assets/stylesheets/main.50c56a3b.min.css | 1 + assets/stylesheets/main.50c56a3b.min.css.map | 1 + assets/stylesheets/palette.06af60db.min.css | 1 + .../stylesheets/palette.06af60db.min.css.map | 1 + examples/adarul/index.html | 2943 ++++++++ examples/cnn_dann/index.html | 2859 +++++++ examples/conditional/index.html | 2695 +++++++ examples/consistency_dann/index.html | 2926 +++++++ examples/index.html | 1762 +++++ examples/latent_align/index.html | 3197 ++++++++ examples/lstm_dann/index.html | 2856 +++++++ examples/pseudo_labels/index.html | 2869 +++++++ examples/tbigru/index.html | 3383 +++++++++ gen_ref_pages/index.html | 2357 ++++++ index.html | 1869 +++++ objects.inv | Bin 0 -> 2203 bytes search/search_index.json | 1 + sitemap.xml | 253 + sitemap.xml.gz | Bin 0 -> 515 bytes 101 files changed, 125280 insertions(+) create mode 100644 .nojekyll create mode 100644 404.html create mode 100644 api/SUMMARY/index.html create mode 100644 api/rul_adapt/approach/abstract/index.html create mode 100644 api/rul_adapt/approach/adarul/index.html create mode 100644 api/rul_adapt/approach/cnn_dann/index.html create mode 100644 api/rul_adapt/approach/conditional/index.html create mode 100644 api/rul_adapt/approach/consistency/index.html create mode 100644 api/rul_adapt/approach/dann/index.html create mode 100644 api/rul_adapt/approach/evaluation/index.html create mode 100644 api/rul_adapt/approach/index.html create mode 100644 api/rul_adapt/approach/latent_align/index.html create mode 100644 api/rul_adapt/approach/mmd/index.html create mode 100644 api/rul_adapt/approach/pseudo_labels/index.html create mode 100644 api/rul_adapt/approach/supervised/index.html create mode 100644 api/rul_adapt/approach/tbigru/index.html create mode 100644 api/rul_adapt/construct/adarul/functional/index.html create mode 100644 api/rul_adapt/construct/adarul/index.html create mode 100644 api/rul_adapt/construct/cnn_dann/functional/index.html create mode 100644 api/rul_adapt/construct/cnn_dann/index.html create mode 100644 api/rul_adapt/construct/consistency/functional/index.html create mode 100644 api/rul_adapt/construct/consistency/index.html create mode 100644 api/rul_adapt/construct/index.html create mode 100644 api/rul_adapt/construct/latent_align/functional/index.html create mode 100644 api/rul_adapt/construct/latent_align/index.html create mode 100644 api/rul_adapt/construct/lstm_dann/functional/index.html create mode 100644 api/rul_adapt/construct/lstm_dann/index.html create mode 100644 api/rul_adapt/construct/tbigru/functional/index.html create mode 100644 api/rul_adapt/construct/tbigru/index.html create mode 100644 api/rul_adapt/loss/adaption/index.html create mode 100644 api/rul_adapt/loss/alignment/index.html create mode 100644 api/rul_adapt/loss/conditional/index.html create mode 100644 api/rul_adapt/loss/index.html create mode 100644 api/rul_adapt/loss/rul/index.html create mode 100644 api/rul_adapt/loss/utils/index.html create mode 100644 api/rul_adapt/model/cnn/index.html create mode 100644 api/rul_adapt/model/head/index.html create mode 100644 api/rul_adapt/model/index.html create mode 100644 api/rul_adapt/model/rnn/index.html create mode 100644 api/rul_adapt/model/two_stage/index.html create mode 100644 api/rul_adapt/model/wrapper/index.html create mode 100644 api/rul_adapt/utils/index.html create mode 100644 assets/_mkdocstrings.css create mode 100644 assets/images/favicon.png create mode 100644 assets/javascripts/bundle.d7c377c4.min.js create mode 100644 assets/javascripts/bundle.d7c377c4.min.js.map create mode 100644 assets/javascripts/lunr/min/lunr.ar.min.js create mode 100644 assets/javascripts/lunr/min/lunr.da.min.js create mode 100644 assets/javascripts/lunr/min/lunr.de.min.js create mode 100644 assets/javascripts/lunr/min/lunr.du.min.js create mode 100644 assets/javascripts/lunr/min/lunr.el.min.js create mode 100644 assets/javascripts/lunr/min/lunr.es.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.he.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hu.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hy.min.js create mode 100644 assets/javascripts/lunr/min/lunr.it.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ja.min.js create mode 100644 assets/javascripts/lunr/min/lunr.jp.min.js create mode 100644 assets/javascripts/lunr/min/lunr.kn.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ko.min.js create mode 100644 assets/javascripts/lunr/min/lunr.multi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.nl.min.js create mode 100644 assets/javascripts/lunr/min/lunr.no.min.js create mode 100644 assets/javascripts/lunr/min/lunr.pt.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ro.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ru.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sa.min.js create mode 100644 assets/javascripts/lunr/min/lunr.stemmer.support.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sv.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ta.min.js create mode 100644 assets/javascripts/lunr/min/lunr.te.min.js create mode 100644 assets/javascripts/lunr/min/lunr.th.min.js create mode 100644 assets/javascripts/lunr/min/lunr.tr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.vi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.zh.min.js create mode 100644 assets/javascripts/lunr/tinyseg.js create mode 100644 assets/javascripts/lunr/wordcut.js create mode 100644 assets/javascripts/workers/search.f886a092.min.js create mode 100644 assets/javascripts/workers/search.f886a092.min.js.map create mode 100644 assets/stylesheets/main.50c56a3b.min.css create mode 100644 assets/stylesheets/main.50c56a3b.min.css.map create mode 100644 assets/stylesheets/palette.06af60db.min.css create mode 100644 assets/stylesheets/palette.06af60db.min.css.map create mode 100644 examples/adarul/index.html create mode 100644 examples/cnn_dann/index.html create mode 100644 examples/conditional/index.html create mode 100644 examples/consistency_dann/index.html create mode 100644 examples/index.html create mode 100644 examples/latent_align/index.html create mode 100644 examples/lstm_dann/index.html create mode 100644 examples/pseudo_labels/index.html create mode 100644 examples/tbigru/index.html create mode 100644 gen_ref_pages/index.html create mode 100644 index.html create mode 100644 objects.inv create mode 100644 search/search_index.json create mode 100644 sitemap.xml create mode 100644 sitemap.xml.gz diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/404.html b/404.html new file mode 100644 index 00000000..8fc39df1 --- /dev/null +++ b/404.html @@ -0,0 +1,1725 @@ + + + +
+ + + + + + + + + + + + + + +A module for the abstract base class of all approaches.
+ + + +AdaptionApproach
+
+
+
+ Bases: LightningModule
This abstract class is the base of all adaption approaches.
+It defines that there needs to be a feature_extractor
, a regressor
. These
+members can be accessed via read-only properties. The feature_extractor
and
+regressor
are trainable neural networks.
All child classes are supposed to implement their own constructors. The
+feature_extractor
and regressor
should explicitly not be arguments of the
+constructor and should be set by calling set_model. This way, the approach can
+be initialized with all hyperparameters first and afterward supplied with the
+networks. This is useful for initializing the networks with pre-trained weights.
Because models are constructed outside the approach, the default checkpointing
+mechanism of PyTorch Lightning fails to load checkpoints of AdaptionApproaches.
+We extended the checkpointing mechanism by implementing the on_save_checkpoint
+and on_load_checkpoint
callbacks to make it work. If a subclass uses an
+additional model, besides feature extractor and regressor, that is not
+initialized in the constructor, the subclass needs to implement the
+CHECKPOINT_MODELS
class variable. This variable is a list of model names to be
+included in the checkpoint. For example, if your approach has an additional model
+self._domain_disc
, the CHECKPOINT_MODELS
variable should be set to
+['_domain_disc']
. Otherwise, loading a checkpoint of this approach will fail.
feature_extractor: nn.Module
+
+
+ property
+
+
+The feature extraction network.
+regressor: nn.Module
+
+
+ property
+
+
+The RUL regression network.
+set_model(feature_extractor, regressor, *args, **kwargs)
+
+Set the feature extractor and regressor for this approach.
+Child classes can override this function to add additional models to an
+approach. The args
and kwargs
making this possible are ignored in this
+function.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feature_extractor |
+
+ Module
+ |
+
+
+
+ The feature extraction network. + |
+ + required + | +
regressor |
+
+ Module
+ |
+
+
+
+ The RUL regression network. + |
+ + required + | +
The Adversarial Domain Adaption for Remaining Useful Life (ADARUL) approach +pre-trains a feature extractor and regressor on the source domain in a supervised +fashion. Afterwards the feature extractor is adapted by feeding it the target +features and training it adversarial against a domain discriminator. The +discriminator is trained to distinguish the source features fed to a frozen version +of the pre-trained feature extractor and the target features fed to the adapted +feature extractor.
+The approach was first introduced by Ragab et al. and evaluated on the CMAPSS dataset.
+ + + +AdaRulApproach
+
+
+
+ Bases: AdaptionApproach
The ADARUL approach uses a GAN setup to adapt a feature extractor. This +approach should only be used with a pre-trained feature extractor.
+The regressor and domain discriminator need the same number of input units as the +feature extractor has output units. The discriminator is not allowed to have an +activation function on its last layer for it to work with its loss.
+ + + +Examples:
+>>> from rul_adapt import model
+>>> from rul_adapt import approach
+>>> feat_ex = model.CnnExtractor(1, [16, 16, 1], 10, fc_units=16)
+>>> reg = model.FullyConnectedHead(16, [1])
+>>> disc = model.FullyConnectedHead(16, [8, 1], act_func_on_last_layer=False)
+>>> pre = approach.SupervisedApproach("mse", 125, lr=0.001)
+>>> pre.set_model(feat_ex, reg)
+>>> main = approach.AdaRulApproach(5, 1, 125, lr=0.001)
+>>> main.set_model(pre.feature_extractor, pre.regressor, disc)
+
domain_disc
+
+
+ property
+
+
+The domain discriminator network.
+__init__(num_disc_updates, num_gen_updates, max_rul=None, rul_score_mode='phm08', evaluate_degraded_only=False, **optim_kwargs)
+
+Create a new ADARUL approach.
+The discriminator is first trained for num_disc_updates
batches.
+Afterward, the feature extractor (generator) is trained for
+num_gen_updates
. This cycle repeats until the epoch ends.
The regressor is supposed to output a value between [0, 1] which is then
+scaled by max_rul
.
For more information about the possible optimizer keyword arguments, +see here.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
max_rul |
+
+ Optional[int]
+ |
+
+
+
+ Maximum RUL value of the training data. + |
+
+ None
+ |
+
num_disc_updates |
+
+ int
+ |
+
+
+
+ Number of batches to update discriminator with. + |
+ + required + | +
num_gen_updates |
+
+ int
+ |
+
+
+
+ Number of batches to update generator with. + |
+ + required + | +
rul_score_mode |
+
+ Literal['phm08', 'phm12']
+ |
+
+
+
+ The mode for the val and test RUL score, either 'phm08' + or 'phm12'. + |
+
+ 'phm08'
+ |
+
evaluate_degraded_only |
+
+ bool
+ |
+
+
+
+ Whether to only evaluate the RUL score on degraded + samples. + |
+
+ False
+ |
+
**optim_kwargs |
+
+ Any
+ |
+
+
+
+ Keyword arguments for the optimizer, e.g. learning rate. + |
+
+ {}
+ |
+
configure_optimizers()
+
+Configure an optimizer for the generator and discriminator respectively.
+ +forward(inputs)
+
+Predict the RUL values for a batch of input features.
+ +set_model(feature_extractor, regressor, domain_disc=None, *args, **kwargs)
+
+Set the feature extractor, regressor and domain discriminator for this approach. +The discriminator is not allowed to have an activation function on its last +layer and needs to use only a single output neuron.
+A frozen copy of the feature extractor is produced to be used for the real +samples fed to the discriminator. The feature extractor should, therefore, +be pre-trained.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feature_extractor |
+
+ Module
+ |
+
+
+
+ The feature extraction network. + |
+ + required + | +
regressor |
+
+ Module
+ |
+
+
+
+ The RUL regression network. + |
+ + required + | +
domain_disc |
+
+ Optional[Module]
+ |
+
+
+
+ The domain discriminator network. + |
+
+ None
+ |
+
test_step(batch, batch_idx, dataloader_idx)
+
+Execute one test step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader_idx
zero
+are assumed to be from the source domain and for dataloader_idx
one from the
+target domain. The metrics are written to the configured logger under the
+prefix test
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+ + required + | +
training_step(batch, batch_idx)
+
+Execute one training step.
+The batch
argument is a list of three tensors representing the source
+features, source labels and target features. Each iteration either only the
+discriminator or only the generator is trained. The respective loss is logged.
The real samples are source features passed though the frozen version of +the feature extractor. The fake samples are the target features passed +through the adapted feature extractor. The discriminator predicts if a sample +came from the source or target domain.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list of a source feature, source label and target feature tensors. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
Returns: + Either the discriminator or generator loss.
+ +validation_step(batch, batch_idx, dataloader_idx)
+
+Execute one validation step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader_idx
zero
+are assumed to be from the source domain and for dataloader_idx
one from the
+target domain. The metrics are written to the configured logger under the
+prefix val
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+ + required + | +
init_weights(feature_extractor, regressor)
+
+Initialize the weights of the feature extractor and regressor in-place.
+For the weight matrices the Xavier uniform initialization is used. The biases are +initialized to zero. This function works only for the networks returned by a call to +rul_adapt.construct.get_cnn_dann.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feature_extractor |
+
+ CnnExtractor
+ |
+
+
+
+ The feature extractor network to be initialized. + |
+ + required + | +
regressor |
+
+ DropoutPrefix
+ |
+
+
+
+ The regressor network to be initialized. + |
+ + required + | +
The Conditional Adaption approaches are derived from the [MMD] [ +rul_adapt.approach.mmd] and DANN approaches. They apply +their respective adaption loss not only to the whole data but also separately to +subsets of the data with a ConditionalAdaptionLoss. Fuzzy sets with rectangular +membership functions define these subsets.
+Both variants were introduced by +Cheng et al. in 2021.
+ + + +ConditionalDannApproach
+
+
+
+ Bases: AdaptionApproach
The conditional DANN approach uses a marginal and several conditional domain +discriminators. The features are produced by a shared feature extractor. The loss +in the domain discriminators is binary cross-entropy.
+The regressor and domain discriminators need the same number of input units as the +feature extractor has output units. The discriminators are not allowed to have an +activation function on their last layer and need to use only a single output +neuron because BCEWithLogitsLoss is used.
+ + + +Examples:
+>>> from rul_adapt import model
+>>> from rul_adapt import approach
+>>> feat_ex = model.CnnExtractor(1, [16, 16, 1], 10, fc_units=16)
+>>> reg = model.FullyConnectedHead(16, [1])
+>>> disc = model.FullyConnectedHead(16, [8, 1], act_func_on_last_layer=False)
+>>> cond_dann = approach.ConditionalDannApproach(1.0, 0.5, [(0, 1)])
+>>> cond_dann.set_model(feat_ex, reg, disc)
+
__init__(dann_factor, dynamic_adaptive_factor, fuzzy_sets, loss_type='mae', rul_score_mode='phm08', evaluate_degraded_only=False, **optim_kwargs)
+
+Create a new conditional DANN approach.
+The strength of the domain discriminator's influence on the feature extractor
+is controlled by the dann_factor
. The higher it is, the stronger the
+influence. The dynamic_adaptive_factor
controls the balance between the
+marginal and conditional DANN loss.
The domain discriminator is set by the set_model
function together with the
+feature extractor and regressor. For more information, see the approach module page.
For more information about the possible optimizer keyword arguments, +see here.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
dann_factor |
+
+ float
+ |
+
+
+
+ Strength of the domain DANN loss. + |
+ + required + | +
dynamic_adaptive_factor |
+
+ float
+ |
+
+
+
+ Balance between the marginal and conditional DANN + loss. + |
+ + required + | +
fuzzy_sets |
+
+ List[Tuple[float, float]]
+ |
+
+
+
+ Fuzzy sets for the conditional DANN loss. + |
+ + required + | +
loss_type |
+
+ Literal['mse', 'rmse', 'mae']
+ |
+
+
+
+ The type of regression loss, either 'mse', 'rmse' or 'mae'. + |
+
+ 'mae'
+ |
+
rul_score_mode |
+
+ Literal['phm08', 'phm12']
+ |
+
+
+
+ The mode for the val and test RUL score, either 'phm08' + or 'phm12'. + |
+
+ 'phm08'
+ |
+
**optim_kwargs |
+
+ Any
+ |
+
+
+
+ Keyword arguments for the optimizer, e.g. learning rate. + |
+
+ {}
+ |
+
configure_optimizers()
+
+Configure an Adam optimizer.
+ +forward(inputs)
+
+Predict the RUL values for a batch of input features.
+ +set_model(feature_extractor, regressor, domain_disc=None, *args, **kwargs)
+
+Set the feature extractor, regressor, and domain discriminator for this +approach.
+The discriminator is not allowed to have an activation function on its last +layer and needs to use only a single output neuron. +It is wrapped by a +DomainAdversarialLoss.
+A copy of the discriminator is used for each conditional loss governing a +fuzzy set.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feature_extractor |
+
+ Module
+ |
+
+
+
+ The feature extraction network. + |
+ + required + | +
regressor |
+
+ Module
+ |
+
+
+
+ The RUL regression network. + |
+ + required + | +
domain_disc |
+
+ Optional[Module]
+ |
+
+
+
+ The domain discriminator network. + Copied for each fuzzy set. + |
+
+ None
+ |
+
test_step(batch, batch_idx, dataloader_idx)
+
+Execute one test step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix test
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+ + required + | +
training_step(batch, batch_idx)
+
+Execute one training step.
+The batch
argument is a list of three tensors representing the source
+features, source labels and target features. Both types of features are fed
+to the feature extractor. Then the regression loss for the source domain,
+the MMD loss and the conditional MMD loss are computed. The
+regression, MMD, conditional MMD and combined loss are logged.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list of a source feature, source label and target feature tensors. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
Returns: + The combined loss.
+ +validation_step(batch, batch_idx, dataloader_idx)
+
+Execute one validation step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix val
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+ + required + | +
ConditionalMmdApproach
+
+
+
+ Bases: AdaptionApproach
The conditional MMD uses a combination of a marginal and conditional MML loss +to adapt a feature extractor to be used with the source regressor.
+The regressor needs the same number of input units as the feature extractor has +output units.
+ + + +Examples:
+>>> from rul_adapt import model
+>>> from rul_adapt import approach
+>>> feat_ex = model.CnnExtractor(1, [16, 16, 1], 10, fc_units=16)
+>>> reg = model.FullyConnectedHead(16, [1])
+>>> cond_mmd = approach.ConditionalMmdApproach(0.01, 5, 0.5, [(0, 1)])
+>>> cond_mmd.set_model(feat_ex, reg)
+
__init__(mmd_factor, num_mmd_kernels, dynamic_adaptive_factor, fuzzy_sets, loss_type='mae', rul_score_mode='phm08', evaluate_degraded_only=False, **optim_kwargs)
+
+Create a new conditional MMD approach.
+The strength of the influence of the MMD loss on the feature extractor is
+controlled by the mmd_factor
. The higher it is, the stronger the influence.
+The dynamic adaptive factor controls the balance between the marginal MMD and
+conditional MMD losses.
For more information about the possible optimizer keyword arguments, +see here.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
mmd_factor |
+
+ float
+ |
+
+
+
+ The strength of the MMD loss' influence. + |
+ + required + | +
num_mmd_kernels |
+
+ int
+ |
+
+
+
+ The number of kernels for the MMD loss. + |
+ + required + | +
dynamic_adaptive_factor |
+
+ float
+ |
+
+
+
+ The balance between marginal and conditional MMD. + |
+ + required + | +
fuzzy_sets |
+
+ List[Tuple[float, float]]
+ |
+
+
+
+ The fuzzy sets for the conditional MMD loss. + |
+ + required + | +
loss_type |
+
+ Literal['mse', 'rmse', 'mae']
+ |
+
+
+
+ The type of regression loss, either 'mse', 'rmse' or 'mae'. + |
+
+ 'mae'
+ |
+
rul_score_mode |
+
+ Literal['phm08', 'phm12']
+ |
+
+
+
+ The mode for the val and test RUL score, either 'phm08' + or 'phm12'. + |
+
+ 'phm08'
+ |
+
evaluate_degraded_only |
+
+ bool
+ |
+
+
+
+ Whether to only evaluate the RUL score on degraded + samples. + |
+
+ False
+ |
+
**optim_kwargs |
+
+ Any
+ |
+
+
+
+ Keyword arguments for the optimizer, e.g. learning rate. + |
+
+ {}
+ |
+
configure_optimizers()
+
+Configure an Adam optimizer.
+ +forward(inputs)
+
+Predict the RUL values for a batch of input features.
+ +test_step(batch, batch_idx, dataloader_idx)
+
+Execute one test step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix test
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+ + required + | +
training_step(batch, batch_idx)
+
+Execute one training step.
+The batch
argument is a list of three tensors representing the source
+features, source labels and target features. Both types of features are fed
+to the feature extractor. Then the regression loss for the source domain,
+the MMD loss and the conditional MMD loss are computed. The
+regression, MMD, conditional MMD and combined loss are logged.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list of a source feature, source label and target feature tensors. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
Returns: + The combined loss.
+ +validation_step(batch, batch_idx, dataloader_idx)
+
+Execute one validation step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix val
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+ + required + | +
The Consistency DANN approach uses a consistency loss in tandem with a DANN +loss. First, the network is pre-trained in a supervised +fashion on the source domain. The pre-trained weights are then used to initialize the +main training stage. The consistency loss penalizes the weights of the feature +extractor moving away from the pre-trained version. This way the feature extractor +weights stay close to the pre-trained weights.
+# pre-training stage
+
+Source --> PreFeatEx --> Source Feats --> Regressor --> RUL Prediction
+
+# main training stage
+
+ ------- PreTrainFeatEx --> PreTrain Source Feats --> Consistency Loss
+ |
+ |
+Source --> FeatEx --> Source Feats -----------> Regressor --> RUL Prediction
+ ^ | |
+ | | v
+Target -- --> Target Feats --> GRL --> DomainDisc --> Domain Prediction
+
This version of DANN was introduced by +Siahpour et al..
+ + + +ConsistencyApproach
+
+
+
+ Bases: AdaptionApproach
The Consistency DANN approach introduces a consistency loss that keeps the +weights of the feature extractor close to the ones of a pre-trained version. This +approach should only be used with a pre-trained feature extractor. Otherwise, +the consistency loss would serve no purpose.
+The regressor and domain discriminator need the same number of input units as the +feature extractor has output units. The discriminator is not allowed to have an +activation function on its last layer for it to work with the DANN loss.
+ + + +Examples:
+>>> from rul_adapt import model
+>>> from rul_adapt import approach
+>>> feat_ex = model.CnnExtractor(1, [16, 16, 1], 10, fc_units=16)
+>>> reg = model.FullyConnectedHead(16, [1])
+>>> disc = model.FullyConnectedHead(16, [8, 1], act_func_on_last_layer=False)
+>>> pre = approach.SupervisedApproach("rmse")
+>>> pre.set_model(feat_ex, reg, disc)
+>>> main = approach.ConsistencyApproach(1.0, 100)
+>>> main.set_model(pre.feature_extractor, pre.regressor, disc)
+
dann_factor
+
+
+ property
+
+
+Return the influency of the DANN loss based on the current epoch.
+It is calculated as: 2 / (1 + math.exp(-10 * current_epoch / max_epochs)) - 1
domain_disc
+
+
+ property
+
+
+The domain discriminator network.
+__init__(consistency_factor, max_epochs, loss_type='rmse', rul_score_mode='phm08', evaluate_degraded_only=False, **optim_kwargs)
+
+Create a new consistency DANN approach.
+The consistency factor is the strength of the consistency loss' influence.
+The influence of the DANN loss is increased during the training process. It
+starts at zero and reaches one at max_epochs
.
The domain discriminator is set by the set_model
function together with the
+feature extractor and regressor. For more information, see the approach module page.
For more information about the possible optimizer keyword arguments, +see here.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
consistency_factor |
+
+ float
+ |
+
+
+
+ The strength of the consistency loss' influence. + |
+ + required + | +
max_epochs |
+
+ int
+ |
+
+
+
+ The number of epochs after which the DANN loss' influence is + maximal. + |
+ + required + | +
loss_type |
+
+ Literal['mse', 'mae', 'rmse']
+ |
+
+
+
+ The type of regression loss, either 'mse', 'rmse' or 'mae'. + |
+
+ 'rmse'
+ |
+
rul_score_mode |
+
+ Literal['phm08', 'phm12']
+ |
+
+
+
+ The mode for the val and test RUL score, either 'phm08' + or 'phm12'. + |
+
+ 'phm08'
+ |
+
evaluate_degraded_only |
+
+ bool
+ |
+
+
+
+ Whether to only evaluate the RUL score on degraded + samples. + |
+
+ False
+ |
+
**optim_kwargs |
+
+ Any
+ |
+
+
+
+ Keyword arguments for the optimizer, e.g. learning rate. + |
+
+ {}
+ |
+
configure_optimizers()
+
+Configure an optimizer to train the feature extractor, regressor and +domain discriminator.
+ +forward(inputs)
+
+Predict the RUL values for a batch of input features.
+ +set_model(feature_extractor, regressor, domain_disc=None, *args, **kwargs)
+
+Set the feature extractor, regressor and domain discriminator for this approach. +The discriminator is not allowed to have an activation function on its last +layer and needs to use only a single output neuron. It is wrapped by a +DomainAdversarialLoss.
+A frozen copy of the feature extractor is produced to be used for the +consistency loss. The feature extractor should, therefore, be pre-trained.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feature_extractor |
+
+ Module
+ |
+
+
+
+ The pre-trained feature extraction network. + |
+ + required + | +
regressor |
+
+ Module
+ |
+
+
+
+ The optionally pre-trained RUL regression network. + |
+ + required + | +
domain_disc |
+
+ Optional[Module]
+ |
+
+
+
+ The domain discriminator network. + |
+
+ None
+ |
+
test_step(batch, batch_idx, dataloader_idx)
+
+Execute one test step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix test
.
+Args:
+ batch: A list containing a feature and a label tensor.
+ batch_idx: The index of the current batch.
+ dataloader_idx: The index of the current dataloader (0: source, 1: target).
training_step(batch, batch_idx)
+
+Execute one training step.
+The batch
argument is a list of three tensors representing the source
+features, source labels and target features. Both types of features are fed
+to the feature extractor. Then the regression loss for the source domain and
+the DANN loss between domains is computed. Afterwards the consistency loss is
+calculated. The regression, DANN, consistency and combined loss are logged.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list of a source feature, source label and target feature tensors. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
Returns: + The combined loss.
+ +validation_step(batch, batch_idx, dataloader_idx)
+
+Execute one validation step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix val
.
+Args:
+ batch: A list containing a feature and a label tensor.
+ batch_idx: The index of the current batch.
+ dataloader_idx: The index of the current dataloader (0: source, 1: target).
StdExtractor
+
+
+This extractor can be used to extract the per-feature standard deviation from +windows of data. It can be used to pre-process datasets like FEMTO and XJTU-SY +with the help of the RulDataModule.
+ + + +Examples:
+Extract the std of the horizontal acceleration and produce windows of size 30. +
>>> import rul_datasets
+>>> import rul_adapt
+>>> fd1 = rul_datasets.XjtuSyReader(fd=1)
+>>> extractor = rul_adapt.approach.consistency.StdExtractor([0])
+>>> dm = rul_datasets.RulDataModule(fd1, 32, extractor, window_size=30)
+
__call__(inputs, targets)
+
+Extract features from the input data.
+The input is expected to have a shape of [num_windows, window_size,
+num_features]
. The output will have a shape of [num_windows,
+len(self.channels)]
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
inputs |
+
+ ndarray
+ |
+
+
+
+ The input data. + |
+ + required + | +
Returns: + The features extracted from the input data.
+ +__init__(channels)
+
+Create a new feature extractor for standard deviations.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
channels |
+
+ List[int]
+ |
+
+
+
+ The list of channel indices to extract features from. + |
+ + required + | +
The Domain Adversarial Neural Network (DANN) approach uses a domain discriminator +trained on distinguishing the source and target features produced by a shared feature +extractor. A Gradient Reversal Layer +(GRL) is used to train the feature extractor on making its source and target outputs +indistinguishable.
+Source --> FeatEx --> Source Feats -----------> Regressor --> RUL Prediction
+ ^ | |
+ | | v
+Target -- --> Target Feats --> GRL --> DomainDisc --> Domain Prediction
+
It was originally introduced by Ganin et al. +for image classification.
+ +DannApproach
+
+
+
+ Bases: AdaptionApproach
The DANN approach introduces a domain discriminator that is trained on +distinguishing source and target features as a binary classification problem. The +features are produced by a shared feature extractor. The loss in the domain +discriminator is binary cross-entropy.
+The regressor and domain discriminator need the same number of input units as the +feature extractor has output units. The discriminator is not allowed to have an +activation function on its last layer and needs to use only a single output +neuron because BCEWithLogitsLoss is used.
+ + + +Examples:
+>>> from rul_adapt import model
+>>> from rul_adapt import approach
+>>> feat_ex = model.CnnExtractor(1, [16, 16, 1], 10, fc_units=16)
+>>> reg = model.FullyConnectedHead(16, [1])
+>>> disc = model.FullyConnectedHead(16, [8, 1], act_func_on_last_layer=False)
+>>> dann = approach.DannApproach(1.0)
+>>> dann.set_model(feat_ex, reg, disc)
+
domain_disc
+
+
+ property
+
+
+The domain discriminator network.
+__init__(dann_factor, loss_type='mae', rul_score_mode='phm08', evaluate_degraded_only=False, **optim_kwargs)
+
+Create a new DANN approach.
+The strength of the domain discriminator's influence on the feature
+extractor is controlled by the dann_factor
. The higher it is, the stronger
+the influence.
Possible options for the regression loss are mae
, mse
and rmse
.
The domain discriminator is set by the set_model
function together with the
+feature extractor and regressor. For more information, see the approach module page.
For more information about the possible optimizer keyword arguments, +see here.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
dann_factor |
+
+ float
+ |
+
+
+
+ Strength of the domain DANN loss. + |
+ + required + | +
loss_type |
+
+ Literal['mae', 'mse', 'rmse']
+ |
+
+
+
+ Type of regression loss. + |
+
+ 'mae'
+ |
+
rul_score_mode |
+
+ Literal['phm08', 'phm12']
+ |
+
+
+
+ The mode for the val and test RUL score, either 'phm08' + or 'phm12'. + |
+
+ 'phm08'
+ |
+
evaluate_degraded_only |
+
+ bool
+ |
+
+
+
+ Whether to only evaluate the RUL score on degraded + samples. + |
+
+ False
+ |
+
**optim_kwargs |
+
+ Any
+ |
+
+
+
+ Keyword arguments for the optimizer, e.g. learning rate. + |
+
+ {}
+ |
+
configure_optimizers()
+
+Configure an optimizer for the whole model.
+ +forward(inputs)
+
+Predict the RUL values for a batch of input features.
+ +set_model(feature_extractor, regressor, domain_disc=None, *args, **kwargs)
+
+Set the feature extractor, regressor, and domain discriminator for this +approach.
+The discriminator is not allowed to have an activation function on its last +layer and needs to use only a single output neuron. It is wrapped by a +DomainAdversarialLoss.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feature_extractor |
+
+ Module
+ |
+
+
+
+ The feature extraction network. + |
+ + required + | +
regressor |
+
+ Module
+ |
+
+
+
+ The RUL regression network. + |
+ + required + | +
domain_disc |
+
+ Optional[Module]
+ |
+
+
+
+ The domain discriminator network. + |
+
+ None
+ |
+
test_step(batch, batch_idx, dataloader_idx)
+
+Execute one test step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix test
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+ + required + | +
training_step(batch, batch_idx)
+
+Execute one training step.
+The batch
argument is a list of three tensors representing the source
+features, source labels and target features. Both types of features are fed
+to the feature extractor. Then the regression loss for the source domain and
+the DANN loss between domains is computed. The regression, DANN and combined
+loss are logged.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list of a source feature, source label and target feature tensors. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
Returns: + The combined loss.
+ +validation_step(batch, batch_idx, dataloader_idx)
+
+Execute one validation step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix val
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+ + required + | +
The latent space alignment approach uses several auxiliary losses to align the +latent space of the source and target domain produced by a shared feature extractor:
+Which features are considered in the healthy state and which in degradation is either +determined by taking the first few steps of each time series or by using a +first-time-to-predict estimation. The first variant is used for CMAPSS, the second +for XJTU-SY.
+The approach was introduced by Zhang et al. in 2021. For applying the approach on raw +vibration data, i.e. XJTU-SY, it uses a windowing scheme and +first-point-to-predict estimation introduced by Li et al. in 2020.
+ + + +LatentAlignApproach
+
+
+
+ Bases: AdaptionApproach
The latent alignment approach introduces four latent space alignment losses to +align the latent space of a shared feature extractor to both source and target +domain.
+ + + +Examples:
+>>> from rul_adapt import model, approach
+>>> feat_ex = model.CnnExtractor(1, [16, 16, 1], 10, fc_units=16)
+>>> reg = model.FullyConnectedHead(16, [1])
+>>> latent_align = approach.LatentAlignApproach(0.1, 0.1, 0.1, 0.1, lr=0.001)
+>>> latent_align.set_model(feat_ex, reg)
+
__init__(alpha_healthy, alpha_direction, alpha_level, alpha_fusion, loss_type='mse', rul_score_mode='phm08', evaluate_degraded_only=False, labels_as_percentage=False, **optim_kwargs)
+
+Create a new latent alignment approach.
+Each of the alphas controls the influence of the respective loss on the +training. Commonly they are all set to the same value.
+For more information about the possible optimizer keyword arguments, +see here.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
alpha_healthy |
+
+ float
+ |
+
+
+
+ The influence of the healthy state alignment loss. + |
+ + required + | +
alpha_direction |
+
+ float
+ |
+
+
+
+ The influence of the degradation direction alignment loss. + |
+ + required + | +
alpha_level |
+
+ float
+ |
+
+
+
+ The influence of the degradation level regularization loss. + |
+ + required + | +
alpha_fusion |
+
+ float
+ |
+
+
+
+ The influence of the degradation fusion (MMD) loss. + |
+ + required + | +
loss_type |
+
+ Literal['mse', 'mae', 'rmse']
+ |
+
+
+
+ The type of regression loss to use. + |
+
+ 'mse'
+ |
+
rul_score_mode |
+
+ Literal['phm08', 'phm12']
+ |
+
+
+
+ The mode for the val and test RUL score, either 'phm08' + or 'phm12'. + |
+
+ 'phm08'
+ |
+
evaluate_degraded_only |
+
+ bool
+ |
+
+
+
+ Whether to only evaluate the RUL score on degraded + samples. + |
+
+ False
+ |
+
labels_as_percentage |
+
+ bool
+ |
+
+
+
+ Whether to multiply labels by 100 to get percentages + |
+
+ False
+ |
+
**optim_kwargs |
+
+ Any
+ |
+
+
+
+ Keyword arguments for the optimizer, e.g. learning rate. + |
+
+ {}
+ |
+
configure_optimizers()
+
+Configure an optimizer.
+ +forward(features)
+
+Predict the RUL values for a batch of input features.
+ +test_step(batch, batch_idx, dataloader_idx)
+
+Execute one test step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix test
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+ + required + | +
training_step(batch, batch_idx)
+
+Execute one training step.
+The batch
contains the following tensors in order:
The easies way to produce such a batch is using the LatentAlignDataModule.
+The source, target and healthy features are passed through the feature +extractor. Afterward, these high-level features are used to compute the +alignment losses. The source domain RUL predictions are computed using the +regressor and used to calculate the MSE loss. The losses are then combined. +Each separate and the combined loss are logged.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ Tuple[Tensor, ...]
+ |
+
+
+
+ The batch of data. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the batch. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Tensor
+ |
+
+
+
+ The combined loss. + |
+
validation_step(batch, batch_idx, dataloader_idx)
+
+Execute one validation step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix val
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+ + required + | +
LatentAlignFttpApproach
+
+
+
+ Bases: AdaptionApproach
This first-point-to-predict estimation approach trains a GAN on healthy state +bearing data. The discriminator can be used afterward to compute a health +indicator for each bearing.
+The feature extractor and regressor models are used as the discriminator. The +regressor is not allowed to have an activation function on its last layer and +needs to use only a single output neuron because BCEWithLogitsLoss is used. The generator receives noise with the shape +[batch_size, 1, noise_dim]. The generator needs an output with enough elements so +that it can be reshaped to the same shape as the real input data. The reshaping +is done internally.
+Both generator and discriminator are trained at once by using a +Gradient Reversal Layer +between them.
+ + + +Examples:
+>>> from rul_adapt import model, approach
+>>> feat_ex = model.CnnExtractor(1, [16, 16, 1], 10, fc_units=16)
+>>> reg = model.FullyConnectedHead(16, [1])
+>>> gen = model.CnnExtractor(1, [1], 10, padding=True)
+>>> fttp_model = approach.LatentAlignFttpApproach(1e-4, 10)
+>>> fttp_model.set_model(feat_ex, reg, gen)
+>>> health_indicator = fttp_model(torch.randn(16, 1, 10)).std()
+
generator
+
+
+ property
+
+
+The generator network.
+__init__(noise_dim, **optim_kwargs)
+
+Create a new FTTP estimation approach.
+The generator is set by the set_model
function together with the feature
+extractor and regressor.
For more information about the possible optimizer keyword arguments, +see here.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
noise_dim |
+
+ int
+ |
+
+
+
+ The size of the last dimension of the noise tensor. + |
+ + required + | +
**optim_kwargs |
+
+ Any
+ |
+
+
+
+ Keyword arguments for the optimizer, e.g. learning rate. + |
+
+ {}
+ |
+
configure_optimizers()
+
+Configure an optimizer for the generator and discriminator.
+ +forward(inputs)
+
+Predict the health indicator for the given inputs.
+ +set_model(feature_extractor, regressor, generator=None, *args, **kwargs)
+
+Set the feature extractor, regressor (forming the discriminator) and +generator for this approach.
+The regressor is not allowed to have an activation function on its last layer +and needs to use only a single output neuron. The generator receives noise +with the shape [batch_size, 1, noise_dim]. The generator needs an output with +enough elements so that it can be reshaped to the same shape as the real +input data. The reshaping is done internally.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feature_extractor |
+
+ Module
+ |
+
+
+
+ The feature extraction network. + |
+ + required + | +
regressor |
+
+ Module
+ |
+
+
+
+ The regressor functioning as the head of the discriminator. + |
+ + required + | +
generator |
+
+ Optional[Module]
+ |
+
+
+
+ The generator network. + |
+
+ None
+ |
+
training_step(batch)
+
+Execute one training step.
+The batch is a tuple of the features and the labels. The labels are ignored. +A noise tensor is passed to the generator to generate fake features. The +discriminator classifies if the features are real or fake and the binary +cross entropy loss is calculated. Real features receive the label zero and +the fake features one.
+Both generator and discriminator are trained at once by using a +Gradient Reversal Layer +between them. At the end, the loss is logged.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ Tuple[Tensor, Tensor]
+ |
+
+
+
+ A tuple of feature and label tensors. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Tensor
+ |
+
+
+
+ The classification loss. + |
+
extract_chunk_windows(features, window_size, chunk_size)
+
+Extract chunk windows from the given features of shape [num_org_windows,
+org_window_size, num_features]
.
A chunk window is a window that consists of window_size
chunks. Each original
+window is split into chunks of size chunk_size
. A chunk window is then formed
+by concatenating chunks from the same position inside window_size
consecutive
+original windows. Therefore, each original window is represented by
+org_window_size // chunk_size
chunk windows. The original window size must
+therefor be divisible by the chunk size.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
features |
+
+ ndarray
+ |
+
+
+
+ The features to extract the chunk windows from. + |
+ + required + | +
window_size |
+
+ int
+ |
+
+
+
+ The number of consecutive original windows to form a chunk window + from. + |
+ + required + | +
chunk_size |
+
+ int
+ |
+
+
+
+ The size of the chunks to extract from the original windows. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ ndarray
+ |
+
+
+
+ Chunk windows of shape |
+
get_first_time_to_predict(fttp_model, features, window_size, chunk_size, healthy_index, threshold_coefficient)
+
+Get the first time step to predict for the given features.
+The features are pre-processed via the extract_chunk_windows function and fed in
+batches to the fttp_model
. Each batch consists of the chunk windows that end in
+the same original feature window. The health indicator for the original window is
+calculated as the standard deviation of the predictions of the fttp_model
.
The first-time-to-predict is the first time step where the health indicator is
+larger than threshold_coefficient
times the mean of the health indicator for
+the first healthy_index
time steps. If the threshold is never exceeded,
+a RuntimeError is raised.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
fttp_model |
+
+ LatentAlignFttpApproach
+ |
+
+
+
+ The model to use for the health indicator calculation. + |
+ + required + | +
features |
+
+ ndarray
+ |
+
+
+
+ The features to calculate the first-time-to-predict for. + |
+ + required + | +
window_size |
+
+ int
+ |
+
+
+
+ The size of the chunk windows to extract. + |
+ + required + | +
chunk_size |
+
+ int
+ |
+
+
+
+ The size of the chunks for each chunk window to extract. + |
+ + required + | +
healthy_index |
+
+ int
+ |
+
+
+
+ The index of the last healthy time step. + |
+ + required + | +
threshold_coefficient |
+
+ float
+ |
+
+
+
+ The threshold coefficient for the health indicator. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ int
+ |
+
+
+
+ The original window index of the first-time-to-predict. + |
+
get_health_indicator(fttp_model, features, window_size, chunk_size)
+
+Get the health indicator for the given features.
+The features are pre-processed via the extract_chunk_windows function and fed in
+batches to the fttp_model
. Each batch consists of the chunk windows that end in
+the same original feature window. The health indicator for the original window is
+calculated as the standard deviation of the predictions of the fttp_model
.
The length of the returned health indicator array is shorter than the features
+array by window_size - 1
, due to the chunk windowing. This means the first
+health indicator value belongs to the original window with the index
+window_size - 1
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
fttp_model |
+
+ Module
+ |
+
+
+
+ The model to use for the health indicator calculation. + |
+ + required + | +
features |
+
+ ndarray
+ |
+
+
+
+ The features to calculate the health indicator for. + |
+ + required + | +
window_size |
+
+ int
+ |
+
+
+
+ The size of the chunk windows to extract. + |
+ + required + | +
chunk_size |
+
+ int
+ |
+
+
+
+ The size of the chunks for each chunk window to extract. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ ndarray
+ |
+
+
+
+ The health indicator for the original windows. + |
+
The Maximum Mean Discrepancy (MMD) approach uses the distance measure of the same +name to adapt a feature extractor. This implementation uses a multi-kernel variant of +the MMD loss with bandwidths +set via the median heuristic.
+Source --> FeatEx --> Source Feats -----------> Regressor --> RUL Prediction
+ ^ | |
+ | | v
+Target -- --> Target Feats --> MMD Loss
+
It was first introduced by Long et al. as Deep Adaption Network (DAN) for +image classification.
+ +MmdApproach
+
+
+
+ Bases: AdaptionApproach
The MMD uses the Maximum Mean Discrepancy to adapt a feature extractor to +be used with the source regressor.
+The regressor needs the same number of input units as the feature extractor has +output units.
+ + + +Examples:
+>>> from rul_adapt import model
+>>> from rul_adapt import approach
+>>> feat_ex = model.CnnExtractor(1, [16, 16, 1], 10, fc_units=16)
+>>> reg = model.FullyConnectedHead(16, [1])
+>>> mmd = approach.MmdApproach(0.01)
+>>> mmd.set_model(feat_ex, reg)
+
__init__(mmd_factor, num_mmd_kernels=5, loss_type='mse', rul_score_mode='phm08', evaluate_degraded_only=False, **optim_kwargs)
+
+Create a new MMD approach.
+The strength of the influence of the MMD loss on the feature
+extractor is controlled by the mmd_factor
. The higher it is, the stronger
+the influence.
For more information about the possible optimizer keyword arguments, +see here.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
mmd_factor |
+
+ float
+ |
+
+
+
+ The strength of the MMD loss' influence. + |
+ + required + | +
num_mmd_kernels |
+
+ int
+ |
+
+
+
+ The number of kernels for the MMD loss. + |
+
+ 5
+ |
+
loss_type |
+
+ Literal['mse', 'rmse', 'mae']
+ |
+
+
+
+ The type of regression loss, either 'mse', 'rmse' or 'mae'. + |
+
+ 'mse'
+ |
+
rul_score_mode |
+
+ Literal['phm08', 'phm12']
+ |
+
+
+
+ The mode for the val and test RUL score, either 'phm08' + or 'phm12'. + |
+
+ 'phm08'
+ |
+
evaluate_degraded_only |
+
+ bool
+ |
+
+
+
+ Whether to only evaluate the RUL score on degraded + samples. + |
+
+ False
+ |
+
**optim_kwargs |
+
+ Any
+ |
+
+
+
+ Keyword arguments for the optimizer, e.g. learning rate. + |
+
+ {}
+ |
+
configure_optimizers()
+
+Configure an optimizer.
+ +forward(inputs)
+
+Predict the RUL values for a batch of input features.
+ +test_step(batch, batch_idx, dataloader_idx)
+
+Execute one test step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix test
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+ + required + | +
training_step(batch, batch_idx)
+
+Execute one training step.
+The batch
argument is a list of three tensors representing the source
+features, source labels and target features. Both types of features are fed
+to the feature extractor. Then the regression loss for the source domain and
+the MMD loss between domains is computed. The regression, MMD and combined
+loss are logged.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list of a source feature, source label and target feature tensors. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
Returns: + The combined loss.
+ +validation_step(batch, batch_idx, dataloader_idx)
+
+Execute one validation step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix val
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+ + required + | +
Pseudo labeling is a simple approach that takes a model trained on the source +domain to label the target domain. Afterward, the model training is continued on the +combined source and target data. This process is repeated until the validation loss +converges.
+ +Examples:
+import torch
+import rul_datasets
+import pytorch_lightning as pl
+
+from rul_adapt import model
+from rul_adapt import approach
+
+feat_ex = model.CnnExtractor(14, [16], 30, fc_units=16)
+reg = model.FullyConnectedHead(16, [1])
+
+supervised = approach.SupervisedApproach(0.001, "rmse", "adam")
+supervised.set_model(feat_ex, reg)
+
+fd1 = rul_datasets.RulDataModule(rul_datasets.CmapssReader(1), 32)
+fd1.setup()
+fd3 = rul_datasets.RulDataModule(rul_datasets.CmapssReader(3), 32)
+fd3.setup()
+
+trainer = pl.Trainer(max_epochs=10)
+trainer.fit(supervised, fd3)
+
+pseudo_labels = approach.generate_pseudo_labels(fd1, supervised)
+pseudo_labels = [max(0, min(125, pl)) for pl in pseudo_labels]
+approach.patch_pseudo_labels(fd3, pseudo_labels)
+
+combined_data = torch.utils.data.ConcatDataset(
+ [fd1.to_dataset("dev"), fd3.to_dataset("dev")]
+)
+combined_dl = torch.utils.data.DataLoader(combined_data, batch_size=32)
+
+trainer = pl.Trainer(max_epochs=10)
+trainer.fit(supervised, train_dataloader=combined_dl)
+
generate_pseudo_labels(dm, model, inductive=False)
+
+Generate pseudo labels for the dev set of a data module.
+The pseudo labels are generated for the last timestep of each run. They are
+returned raw and may therefore contain values bigger than max_rul
or negative
+values. It is recommended to clip them to zero and max_rul
respectively before
+using them to patch a reader.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
dm |
+
+ RulDataModule
+ |
+
+
+
+ The data module to generate pseudo labels for. + |
+ + required + | +
model |
+
+ Module
+ |
+
+
+
+ The model to use for generating the pseudo labels. + |
+ + required + | +
inductive |
+
+ bool
+ |
+
+
+
+ Whether to generate pseudo labels for inductive adaption, + i.e., use 'test' instead of 'dev' split. + |
+
+ False
+ |
+
Returns:
+Type | +Description | +
---|---|
+ List[float]
+ |
+
+
+
+ A list of pseudo labels for the dev set of the data module. + |
+
get_max_rul(reader)
+
+Resolve the maximum RUL of a reader to be comparable to floats.
+ +patch_pseudo_labels(dm, pseudo_labels, inductive=False)
+
+Patch a data module with pseudo labels in-place.
+The pseudo labels are used to replace the RUL targets of the dev set of the data +module. The validation and test sets are not affected.
+It is not possible to patch the same data module multiple times. Instead, +instantiate a fresh data module and patch that one.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
dm |
+
+ RulDataModule
+ |
+
+
+
+ The data module to patch. + |
+ + required + | +
pseudo_labels |
+
+ List[float]
+ |
+
+
+
+ The pseudo labels to use for patching the data module. + |
+ + required + | +
inductive |
+
+ bool
+ |
+
+
+
+ Whether to generate pseudo labels for inductive adaption, + i.e., use 'test' instead of 'dev' split. + |
+
+ False
+ |
+
The supervised approach trains solely on the labeled source domain. It can be used +for pre-training or as a baseline to compare adaption approaches against.
+ + + + +SupervisedApproach
+
+
+
+ Bases: AdaptionApproach
The supervised approach uses either MSE, MAE or RMSE loss to train a feature +extractor and regressor in a supervised fashion on the source domain. It can be +used either for pre-training or as a baseline to compare adaption approaches +against.
+The regressor needs the same number of input units as the feature extractor has +output units.
+ + + +Examples:
+>>> from rul_adapt import model
+>>> from rul_adapt import approach
+>>> feat_ex = model.CnnExtractor(1, [16, 16, 1], 10, fc_units=16)
+>>> reg = model.FullyConnectedHead(16, [1])
+>>> disc = model.FullyConnectedHead(16, [8, 1], act_func_on_last_layer=False)
+>>> main = approach.SupervisedApproach("mse")
+>>> main.set_model(feat_ex, reg, disc)
+
__init__(loss_type, rul_scale=1, rul_score_mode='phm08', evaluate_degraded_only=False, **optim_kwargs)
+
+Create a supervised approach.
+The regressor output can be scaled with rul_scale
to control its
+magnitude. By default, the RUL values are not scaled.
For more information about the possible optimizer keyword arguments, +see here.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
rul_score_mode |
+
+ Literal['phm08', 'phm12']
+ |
+
+
+
+
+ |
+
+ 'phm08'
+ |
+
loss_type |
+
+ Literal['mse', 'mae', 'rmse']
+ |
+
+
+
+ Training loss function to use. Either 'mse', 'mae' or 'rmse'. + |
+ + required + | +
rul_scale |
+
+ int
+ |
+
+
+
+ Scalar to multiply the RUL prediction with. + |
+
+ 1
+ |
+
evaluate_degraded_only |
+
+ bool
+ |
+
+
+
+ Whether to only evaluate the RUL score on degraded + samples. + |
+
+ False
+ |
+
**optim_kwargs |
+
+ Any
+ |
+
+
+
+ Keyword arguments for the optimizer, e.g. learning rate. + |
+
+ {}
+ |
+
test_step(batch, batch_idx, dataloader_idx=-1)
+
+Execute one test step.
+The batch
argument is a list of two tensors representing features and
+labels. A RUL prediction is made from the features and the validation RMSE
+and RUL score are calculated. The metrics recorded for dataloader idx zero
+are assumed to be from the source domain and for dataloader idx one from the
+target domain. The metrics are written to the configured logger under the
+prefix test
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list containing a feature and a label tensor. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
dataloader_idx |
+
+ int
+ |
+
+
+
+ The index of the current dataloader (0: source, 1: target). + |
+
+ -1
+ |
+
training_step(batch, batch_idx)
+
+Execute one training step.
+The batch
argument is a list of two tensors representing features and
+labels. The features are used to predict RUL values that are compared against
+the labels with the specified training loss. The loss is then logged.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list of feature and label tensors. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
Returns: + The training loss.
+ +validation_step(batch, batch_idx, dataloader_idx=-1)
+
+Execute one validation step.
+The batch
argument is a list of two tensors representing features and
+labels. The features are used to predict RUL values that are compared against
+the labels with an RMSE loss. The loss is then logged.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
batch |
+
+ List[Tensor]
+ |
+
+
+
+ A list of feature and label tensors. + |
+ + required + | +
batch_idx |
+
+ int
+ |
+
+
+
+ The index of the current batch. + |
+ + required + | +
The TBiGRU approach uses a feature selection mechanism to mine transferable +features and a bearing running state detection to determine the +first-time-to-predict. The training is done with an MMD approach.
+The feature selection uses a distance measure based on Dynamic Time Warping and the +Wasserstein distance. From a set of 30 common vibration features the ones with the +smallest distance between source and target domain are selected. These features serve +as inputs to the network.
+The first-time-to-predict (FTTP) is used to generate the RUL labels for training. +FTTP is the time step where the degradation can be detected for the first time. The +RUL labels before this time step should be constant. The TBiGRU approach uses the +moving average correlation (MAC) of the energy entropies of four levels of maximal +overlap discrete wavelet transform (MODWT) decompositions to determine four running +states of each bearing. The end of the steady running state marks the FTTP.
+TBiGRU was introduced by Cao et al. and evaluated on the FEMTO Bearing +dataset.
+ + + +VibrationFeatureExtractor
+
+
+This class extracts 30 different features from a raw acceleration signal.
+The features are: RMS, kurtosis, peak2peak, standard deviation, skewness, +margin factor, impulse factor, energy, median absolute, gini factor, maximum +absolute, mean absolute, energies of the 16 bands resulting from wavelet packet +decomposition, standard deviation of arccosh and arcsinh. If the input has n +features, n*30 features are extracted. Additionally, it features a scaler that +can be fit to scale all extracted features between [0, 1].
+ + + + +__call__(features, targets)
+
+Extract the features from the input and optionally scale them.
+The features should have the shape [num_windows, window_size,
+num_input_features]
and the targets [num_windows]
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
features |
+
+ ndarray
+ |
+
+
+
+ The input features. + |
+ + required + | +
targets |
+
+ ndarray
+ |
+
+
+
+ The input targets. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Tuple[ndarray, ndarray]
+ |
+
+
+
+ The extracted features and input targets. + |
+
__init__(num_input_features, feature_idx=None)
+
+Create a new vibration feature extractor with the selected features.
+The features are sorted as f1_1, .., f1_j, ..., fi_j, where i is the index of
+the computed feature (between 0 and 30) and j is the index of the raw
+feature (between 0 and num_input_features
).
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
num_input_features |
+
+ int
+ |
+
+
+
+ The number of input features. + |
+ + required + | +
feature_idx |
+
+ Optional[List[int]]
+ |
+
+
+
+ The indices of the features to compute. + |
+
+ None
+ |
+
fit(features)
+
+Fit the internal scaler on a list of raw feature time series.
+The time series are passed through the feature extractor and then used to fit
+the internal min-max scaler. Each time series in the list should have the
+shape [num_windows, window_size, num_input_features]
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
features |
+
+ List[ndarray]
+ |
+
+
+
+ The list of raw feature time series. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ VibrationFeatureExtractor
+ |
+
+
+
+ The feature extractor itself. + |
+
mac(inputs, window_size, wavelet='dmey')
+
+Calculate the moving average correlation (MAC) of the energy entropies of four +levels of maximal overlap discrete wavelet transform (MODWT) decompositions.
+The wavelet
is a wavelet description that can be passed to pywt
. The default
+wavelet was confirmed by the original authors. For more options call
+pywt.wavelist
. The input signal should have the shape [num_windows,
+window_size, num_features]
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
inputs |
+
+ ndarray
+ |
+
+
+
+ The input acceleration signal. + |
+ + required + | +
window_size |
+
+ int
+ |
+
+
+
+ The window size of the sliding window to calculate the average + over. + |
+ + required + | +
wavelet |
+
+ str
+ |
+
+
+
+ The description of the wavelet, e.g. 'sym4'. + |
+
+ 'dmey'
+ |
+
Returns:
+Type | +Description | +
---|---|
+ ndarray
+ |
+
+
+
+ The MAC of the input signal which is |
+
modwpt(inputs, wavelet, level)
+
+Apply Maximal Overlap Discrete Wavelet Packet Transformation (MODWT) of level
+to the input.
The wavelet
should be a string that can be passed to pywt
to construct a
+wavelet function. For more options call pywt.wavelist
. The implementation was
+inspired by this repository.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
inputs |
+
+ ndarray
+ |
+
+
+
+ An input signal of shape |
+ + required + | +
wavelet |
+
+ str
+ |
+
+
+
+ The description of the wavelet function, e.g. 'sym4'. + |
+ + required + | +
level |
+
+ int
+ |
+
+
+
+ The decomposition level. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ ndarray
+ |
+
+
+
+ The 2**level decompositions stacked in the last axis. + |
+
select_features(source, target, num_features)
+
+Select the most transferable features between source and target domain.
+30 features are considered: RMS, kurtosis, peak2peak, standard deviation, skewness, +margin factor, impulse factor, energy, median absolute, gini factor, maximum +absolute, mean absolute, energies of the 16 bands resulting from wavelet packet +decomposition, standard deviation of arccosh and arcsinh. If the input has n raw +features, n*30 features are extracted.
+The dev
splits of both domains are used to calculate a distance metric based on
+Dynamic Time Warping and the Wasserstein Distance. The indices of the
+num_feature
features with the lowest distances are returned.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source |
+
+ AbstractReader
+ |
+
+
+
+ The reader of the source domain. + |
+ + required + | +
target |
+
+ AbstractReader
+ |
+
+
+
+ The reader of the target domain. + |
+ + required + | +
num_features |
+
+ int
+ |
+
+
+
+ The number of transferable features to return. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ List[int]
+ |
+
+
+
+ The indices of features ordered by transferability. + |
+
adarul_from_config(config, pre_trainer_kwargs=None, trainer_kwargs=None)
+
+Construct an ADARUL approach from a configuration.
+The configuration can be created by calling get_adarul_config.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
config |
+
+ DictConfig
+ |
+
+
+
+ The ADARUL config. + |
+ + required + | +
pre_trainer_kwargs |
+
+ Optional[Dict[str, Any]]
+ |
+
+
+
+ Overrides for the pre-training trainer class. + |
+
+ None
+ |
+
trainer_kwargs |
+
+ Optional[Dict[str, Any]]
+ |
+
+
+
+ Overrides for the main trainer class. + |
+
+ None
+ |
+
Returns: + pre: The data module, approach and trainer for the pre-training stage + main: The data module, approach, domain discriminator and trainer for + the main stage
+ +get_adarul(source_fd, target_fd, pre_trainer_kwargs=None, trainer_kwargs=None)
+
+Construct an ADARUL approach with the original hyperparameters on CMAPSS.
+ + + +Examples:
+>>> import rul_adapt
+>>> pre, main = rul_adapt.construct.get_adarul(, 3, 1)
+>>> pre_dm, pre_approach, pre_trainer = pre
+>>> dm, approach, domain_disc, trainer = main
+
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source_fd |
+
+ int
+ |
+
+
+
+ The source FD of CMAPSS. + |
+ + required + | +
target_fd |
+
+ int
+ |
+
+
+
+ The target FD of CMAPSS. + |
+ + required + | +
pre_trainer_kwargs |
+
+ Optional[Dict[str, Any]]
+ |
+
+
+
+ Overrides for the pre-training trainer class. + |
+
+ None
+ |
+
trainer_kwargs |
+
+ Optional[Dict[str, Any]]
+ |
+
+
+
+ Overrides for the main trainer class. + |
+
+ None
+ |
+
Returns: + pre: The data module, approach and trainer for the pre-training stage + main: The data module, approach, domain discriminator and trainer for + the main stage
+ +get_adarul_config(source_fd, target_fd)
+
+Get a configuration for the ADARUL approach.
+The configuration can be modified and fed to adarul_from_config to create the +approach.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source_fd |
+
+ int
+ |
+
+
+
+ The source FD of CMAPSS. + |
+ + required + | +
target_fd |
+
+ int
+ |
+
+
+
+ The target FD of CMAPSS. + |
+ + required + | +
Returns: + The ADARUL configuration.
+ +cnn_dann_from_config(config, **trainer_kwargs)
+
+Construct a CNN-DANN approach from a configuration.
+The configuration can be created by calling get_cnn_dann_config.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
config |
+
+ DictConfig
+ |
+
+
+
+ The CNN-DANN configuration. + |
+ + required + | +
trainer_kwargs |
+
+ Any
+ |
+
+
+
+ Overrides for the trainer class. + |
+
+ {}
+ |
+
Returns: + dm: The data module for adaption of two CMAPSS sub-datasets. + dann: The DANN approach with feature extractor, regressor and domain disc. + trainer: The trainer object.
+ +get_cnn_dann(source_fd, target_fd, **trainer_kwargs)
+
+Construct an CNN-DANN approach for CMAPSS with the original hyperparameters.
+The adaption tasks 1-->4, 2-->3, 3-->2 and 4-->1 are missing because they were not +investigated in the paper.
+ + + +Examples:
+>>> import rul_adapt
+>>> dm, dann, trainer = rul_adapt.construct.get_cnn_dann(3, 1)
+>>> trainer.fit(dann, dm)
+>>> trainer.test(dann, dm)
+
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source_fd |
+
+ int
+ |
+
+
+
+ The source FD of CMAPSS. + |
+ + required + | +
target_fd |
+
+ int
+ |
+
+
+
+ The target FD of CMAPSS. + |
+ + required + | +
trainer_kwargs |
+
+ Any
+ |
+
+
+
+ Overrides for the trainer class. + |
+
+ {}
+ |
+
Returns: + dm: The data module for adaption of two CMAPSS sub-datasets. + dann: The DANN approach with feature extractor, regressor and domain disc. + trainer: The trainer object.
+ +get_cnn_dann_config(source_fd, target_fd)
+
+Get a configuration for the CNN-DANN approach.
+The adaption tasks 1-->4, 2-->3, 3-->2 and 4-->1 are missing because they were +not investigated in the paper. The configuration can be modified and fed to +cnn_dann_from_config to +create the approach.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source_fd |
+
+ int
+ |
+
+
+
+ The source FD of CMAPSS. + |
+ + required + | +
target_fd |
+
+ int
+ |
+
+
+
+ The target FD of CMAPSS. + |
+ + required + | +
Returns: + The CNN-DANN configuration.
+ +consistency_dann_from_config(config, pre_trainer_kwargs=None, trainer_kwargs=None)
+
+Construct a Consistency DANN approach from a configuration. +The configuration can be created by calling get_consistency_dann_config.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
config |
+
+ DictConfig
+ |
+
+
+
+ The Consistency DANN config. + |
+ + required + | +
pre_trainer_kwargs |
+
+ Optional[Dict[str, Any]]
+ |
+
+
+
+ Overrides for the pre-training trainer class. + |
+
+ None
+ |
+
trainer_kwargs |
+
+ Optional[Dict[str, Any]]
+ |
+
+
+
+ Overrides for the main trainer class. + |
+
+ None
+ |
+
Returns: + pre: The data module, approach and trainer for the pre-training stage + main: The data module, approach, domain discriminator and trainer for + the main stage
+ +get_consistency_dann(dataset, source_fd, target_fd, pre_trainer_kwargs=None, trainer_kwargs=None)
+
+Construct a Consistency DANN approach with the original hyperparameters.
+ + + +Examples:
+>>> import rul_adapt
+>>> pre, main = rul_adapt.construct.get_consistency_dann("cmapss", 3, 1)
+>>> pre_dm, pre_approach, pre_trainer = pre
+>>> dm, approach, domain_disc, trainer = main
+
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
dataset |
+
+ Literal['cmapss', 'xjtu-sy']
+ |
+
+
+
+ The name of the dataset, either |
+ + required + | +
source_fd |
+
+ int
+ |
+
+
+
+ The source FD of CMAPSS. + |
+ + required + | +
target_fd |
+
+ int
+ |
+
+
+
+ The target FD of CMAPSS. + |
+ + required + | +
pre_trainer_kwargs |
+
+ Optional[Dict[str, Any]]
+ |
+
+
+
+ Overrides for the pre-training trainer class. + |
+
+ None
+ |
+
trainer_kwargs |
+
+ Optional[Dict[str, Any]]
+ |
+
+
+
+ Overrides for the main trainer class. + |
+
+ None
+ |
+
Returns: + pre: The data module, approach and trainer for the pre-training stage + main: The data module, approach, domain discriminator and trainer for + the main stage
+ +get_consistency_dann_config(dataset, source_fd, target_fd)
+
+Get a configuration for the Consistency DANN approach.
+The configuration can be modified and fed to consistency_dann_from_config to create the +approach.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
dataset |
+
+ Literal['cmapss', 'xjtu-sy']
+ |
+
+
+
+ The name of the dataset, either |
+ + required + | +
source_fd |
+
+ int
+ |
+
+
+
+ The source FD of CMAPSS. + |
+ + required + | +
target_fd |
+
+ int
+ |
+
+
+
+ The target FD of CMAPSS. + |
+ + required + | +
Returns: + The Consistency DANN configuration.
+ +get_latent_align(dataset, source_fd, target_fd, xjtu_sy_subtask=None, **trainer_kwargs)
+
+Construct a Latent Alignment approach for the selected dataset with the original +hyperparameters.
+For the XJTU-SY task only FD001 and FD002 are available. The subtask controls if +the bearing with the id 1 or 2 is used as the target data.
+ + + +Examples:
+>>> import rul_adapt
+>>> dm, latent, trainer = rul_adapt.construct.get_latent_align("cmapss", 3, 1)
+>>> trainer.fit(latent, dm)
+>>> trainer.test(latent, dm)
+
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
dataset |
+
+ Literal['cmapss', 'xjtu-sy']
+ |
+
+
+
+ The dataset to use. + |
+ + required + | +
source_fd |
+
+ int
+ |
+
+
+
+ The source FD. + |
+ + required + | +
target_fd |
+
+ int
+ |
+
+
+
+ The target FD. + |
+ + required + | +
xjtu_sy_subtask |
+
+ Optional[int]
+ |
+
+
+
+ The subtask for the XJTU-SY (either 1 or 2). + |
+
+ None
+ |
+
trainer_kwargs |
+
+ Any
+ |
+
+
+
+ Overrides for the trainer class. + |
+
+ {}
+ |
+
Returns: + dm: The data module for adaption of the sub-datasets. + dann: The Latent Alignment approach with feature extractor and regressor. + trainer: The trainer object.
+ +get_latent_align_config(dataset, source_fd, target_fd, xjtu_sy_subtask=None)
+
+Get a configuration for the Latent Alignment approach.
+For the XJTU-SY task only FD001 and FD002 are available. The subtask controls if +the bearing with the id 1 or 2 is used as the target data. The configuration can +be modified and fed to latent_align_from_config to create the approach.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
dataset |
+
+ Literal['cmapss', 'xjtu-sy']
+ |
+
+
+
+ The dataset to use. + |
+ + required + | +
source_fd |
+
+ int
+ |
+
+
+
+ The source FD. + |
+ + required + | +
target_fd |
+
+ int
+ |
+
+
+
+ The target FD. + |
+ + required + | +
xjtu_sy_subtask |
+
+ Optional[int]
+ |
+
+
+
+ The subtask for the XJTU-SY (either 1 or 2). + |
+
+ None
+ |
+
Returns: + The Latent Alignment configuration.
+ +latent_align_from_config(config, **trainer_kwargs)
+
+Construct a Latent Alignment approach from a configuration.
+The configuration can be created by calling get_latent_align_config.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
config |
+
+ DictConfig
+ |
+
+
+
+ The Latent Alignment configuration. + |
+ + required + | +
trainer_kwargs |
+
+ Any
+ |
+
+
+
+ Overrides for the trainer class. + |
+
+ {}
+ |
+
Returns: + dm: The data module for adaption of the sub-datasets. + dann: The Latent Alignment approach with feature extractor, regressor. + trainer: The trainer object.
+ +get_lstm_dann(source_fd, target_fd, **trainer_kwargs)
+
+Construct an LSTM-DANN approach for CMAPSS with the original hyperparameters.
+ + + +Examples:
+>>> import rul_adapt
+>>> dm, dann, trainer = rul_adapt.construct.get_lstm_dann(3, 1)
+>>> trainer.fit(dann, dm)
+>>> trainer.test(dann, dm)
+
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source_fd |
+
+ int
+ |
+
+
+
+ The source FD of CMAPSS. + |
+ + required + | +
target_fd |
+
+ int
+ |
+
+
+
+ The target FD of CMAPSS. + |
+ + required + | +
trainer_kwargs |
+
+ Any
+ |
+
+
+
+ Overrides for the trainer class. + |
+
+ {}
+ |
+
Returns: + dm: The data module for adaption of two CMAPSS sub-datasets. + dann: The DANN approach with feature extractor, regressor and domain disc. + trainer: The trainer object.
+ +get_lstm_dann_config(source_fd, target_fd)
+
+Get a configuration for the LSTM-DANN approach.
+The configuration can be modified and fed to lstm_dann_from_config to create the approach.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source_fd |
+
+ int
+ |
+
+
+
+ The source FD of CMAPSS. + |
+ + required + | +
target_fd |
+
+ int
+ |
+
+
+
+ The target FD of CMAPSS. + |
+ + required + | +
Returns: + The LSTM-DANN configuration.
+ +lstm_dann_from_config(config, **trainer_kwargs)
+
+Construct a LSTM-DANN approach from a configuration.
+The configuration can be created by calling get_lstm_dann_config.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
config |
+
+ DictConfig
+ |
+
+
+
+ The LSTM-DANN configuration. + |
+ + required + | +
trainer_kwargs |
+
+ Any
+ |
+
+
+
+ Overrides for the trainer class. + |
+
+ {}
+ |
+
Returns: + dm: The data module for adaption of two CMAPSS sub-datasets. + dann: The DANN approach with feature extractor, regressor and domain disc. + trainer: The trainer object.
+ +get_tbigru(source_fd, target_fd, **trainer_kwargs)
+
+Construct a TBiGRU approach for FEMTO with the original hyperparameters.
+ + + +Examples:
+>>> import rul_adapt
+>>> dm, tbigru, trainer = rul_adapt.construct.get_tbigru(3, 1)
+>>> trainer.fit(tbigru, dm)
+>>> trainer.test(tbigru, dm)
+
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source_fd |
+
+ int
+ |
+
+
+
+ The source FD of FEMTO. + |
+ + required + | +
target_fd |
+
+ int
+ |
+
+
+
+ The target FD of FEMTO. + |
+ + required + | +
trainer_kwargs |
+
+ Any
+ |
+
+
+
+ Overrides for the trainer class. + |
+
+ {}
+ |
+
Returns: + dm: The data module for adaption of two FEMTO sub-datasets. + dann: The TBiGRU approach with feature extractor and regressor. + trainer: The trainer object.
+ +get_tbigru_config(source_fd, target_fd)
+
+Get a configuration for the TBiGRU approach.
+The configuration can be modified and fed to tbigru_from_config to create the approach.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source_fd |
+
+ int
+ |
+
+
+
+ The source FD of FEMTO. + |
+ + required + | +
target_fd |
+
+ int
+ |
+
+
+
+ The target FD of FEMTO. + |
+ + required + | +
Returns: + The TBiGRU configuration.
+ +tbigru_from_config(config, **trainer_kwargs)
+
+Construct a TBiGRU approach from a configuration. +The configuration can be created by calling get_tbigru_config.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
config |
+
+ DictConfig
+ |
+
+
+
+ The TBiGRU configuration. + |
+ + required + | +
trainer_kwargs |
+
+ Any
+ |
+
+
+
+ Overrides for the trainer class. + |
+
+ {}
+ |
+
Returns: + dm: The data module for adaption of two FEMTO sub-datasets. + dann: The TBiGRU approach with feature extractor and regressor. + trainer: The trainer object.
+ +A module for unsupervised domain adaption losses.
+ + + +DomainAdversarialLoss
+
+
+
+ Bases: Metric
The Domain Adversarial Neural Network Loss (DANN) uses a domain discriminator +to measure the distance between two feature distributions.
+The domain discriminator is a neural network that is jointly trained on +classifying its input as one of two domains. Its output should be a single +unscaled score (logit) which is fed to a binary cross entropy loss.
+The domain discriminator is preceded by a GradientReversalLayer. This way, the discriminator is +trained to separate the domains while the network generating the inputs is +trained to marginalize the domain difference.
+ + + + +__init__(domain_disc)
+
+Create a new DANN loss module.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
domain_disc |
+
+ Module
+ |
+
+
+
+ The neural network to act as the domain discriminator. + |
+ + required + | +
update(source, target)
+
+Calculate the DANN loss as the binary cross entropy of the discriminators +prediction for the source and target features.
+The source features receive a domain label of zero and the target features a +domain label of one.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source |
+
+ Tensor
+ |
+
+
+
+ The source features with domain label zero. + |
+ + required + | +
target |
+
+ Tensor
+ |
+
+
+
+ The target features with domain label one. + |
+ + required + | +
GradientReversalLayer
+
+
+
+ Bases: Module
The gradient reversal layer (GRL) acts as an identity function in the forward +pass and scales the gradient by a negative scalar in the backward pass.
+ + + + + +__init__(grad_weight=1.0)
+
+Create a new Gradient Reversal Layer.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
grad_weight |
+
+ float
+ |
+
+
+
+ The scalar that weights the negative gradient. + |
+
+ 1.0
+ |
+
JointMaximumMeanDiscrepancyLoss
+
+
+
+ Bases: Metric
The Joint Maximum Mean Discrepancy Loss (JMMD) is a distance measure between +multiple pairs of arbitrary distributions.
+It is related to the MMD insofar as the distance of each distribution pair in a +reproducing Hilbert kernel space (RHKS) is calculated and then multiplied before +the discrepancy is computed.
+ +For more information see +MaximumMeanDiscrepancyLoss.
+ + + + +__init__()
+
+Create a new JMMD loss module.
+It features a single Gaussian kernel with a bandwidth chosen by the median +heuristic.
+ +update(source_features, target_features)
+
+Compute the JMMD loss between multiple feature distributions.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source_features |
+
+ List[Tensor]
+ |
+
+
+
+ The list of source features of shape
+ |
+ + required + | +
target_features |
+
+ List[Tensor]
+ |
+
+
+
+ The list of target features of shape
+ |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ None
+ |
+
+
+
+ scalar JMMD loss + |
+
MaximumMeanDiscrepancyLoss
+
+
+
+ Bases: Metric
The Maximum Mean Discrepancy Loss (MMD) is a distance measure between two +arbitrary distributions.
+The distance is defined as the dot product in a reproducing Hilbert kernel space +(RHKS) and is zero if and only if the distributions are identical. The RHKS is +the space of the linear combination of multiple Gaussian kernels with bandwidths +derived by the median heuristic.
+The source and target feature batches are treated as samples from their +respective distribution. The linear pairwise distances between the two batches +are transformed into distances in the RHKS via the kernel trick:
+rhks(x, y) = dot(to_rhks(x), to_rhks(y)) = multi_kernel(dot(x, y))
+multi_kernel(distance) = mean([gaussian(distance, bw) for bw in bandwidths])
+gaussian(distance, bandwidth) = exp(-distance * bandwidth)
+
The n kernels will use bandwidths between median / (2**(n/ 2))
and median * (
+2**(n / 2))
, where median
is the median of the linear distances.
The MMD loss is then calculated as:
+ +This version of MMD is biased, which is acceptable for training purposes.
+ + + + +__init__(num_kernels)
+
+Create a new MMD loss module with n
kernels.
The bandwidths of the Gaussian kernels are derived by the median heuristic.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
num_kernels |
+
+ int
+ |
+
+
+
+ Number of Gaussian kernels to use. + |
+ + required + | +
update(source_features, target_features)
+
+Compute the MMD loss between source and target feature distributions.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source_features |
+
+ Tensor
+ |
+
+
+
+ Source features with shape |
+ + required + | +
target_features |
+
+ Tensor
+ |
+
+
+
+ Target features with shape |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ None
+ |
+
+
+
+ scalar MMD loss + |
+
These losses are used to create a latent space that is conductive to RUL +estimation. They are mainly used by the LatentAlignmentApproach.
+ + + +DegradationDirectionAlignmentLoss
+
+
+
+ Bases: Metric
This loss is used to align the direction of the degradation data in relation to +the healthy state data in the latent space.
+It computes the mean of the cosine of the pairwise-angle of the vectors from the +healthy state cluster to each degradation data point. The healthy state cluster +location is assumed to be the mean of the healthy state data in the latent space. +The loss is negated in order to maximize the cosine by minimizing the loss.
+The loss is implemented as a torchmetrics.Metric. See their documentation for more information.
+ + + +Examples:
+>>> from rul_adapt.loss.alignment import DegradationDirectionAlignmentLoss
+>>> degradation_align = DegradationDirectionAlignmentLoss()
+>>> degradation_align(torch.zeros(10, 5), torch.ones(10, 5))
+tensor(-1.0000)
+
DegradationLevelRegularizationLoss
+
+
+
+ Bases: Metric
This loss is used to regularize the degradation level of the data in the latent +space in relation to the healthy state data.
+It computes the mean of the difference between the normalized distance of the +degradation data points from the healthy state cluster and the normalized +degradation steps. The healthy state cluster location is assumed to be the mean +of the healthy state data in the latent space.
+The loss is implemented as a torchmetrics.Metric. See their documentation for more information.
+ + + +Examples:
+>>> from rul_adapt.loss.alignment import DegradationLevelRegularizationLoss
+>>> degradation_align = DegradationLevelRegularizationLoss()
+>>> degradation_align(torch.zeros(10, 5),
+... torch.ones(10, 5),
+... torch.ones(10),
+... torch.ones(10, 5),
+... torch.ones(10))
+tensor(0.)
+
HealthyStateAlignmentLoss
+
+
+
+ Bases: Metric
This loss is used to align the healthy state of the data in the latent space.
+It computes the mean of the variance of each latent feature which is supposed to +be minimized. This way a single compact cluster of healthy state data should be +formed.
+The loss is implemented as a torchmetrics.Metric. See their documentation for more information.
+ + + +Examples:
+>>> from rul_adapt.loss.alignment import HealthyStateAlignmentLoss
+>>> healthy_align = HealthyStateAlignmentLoss()
+>>> healthy_align(torch.zeros(10, 5))
+tensor(0.)
+
A module for conditional unsupervised domain adaption losses.
+ + + +ConditionalAdaptionLoss
+
+
+
+ Bases: Metric
The Conditional Adaptions loss is a combination of multiple losses, each of +which is only applied to a subset of the incoming data.
+The subsets are defined by fuzzy sets with a rectangular membership function. The +prediction for each sample is checked against the fuzzy sets, and the +corresponding loss is applied to the sample. The combined loss can be set as the +sum of all components or their mean.
+ + + + +__init__(adaption_losses, fuzzy_sets, mean_over_sets=True)
+
+Create a new Conditional Adaption loss over fuzzy sets.
+The fuzzy sets' boundaries are inclusive on the left and exclusive on the right. +The left boundary is supposed to be smaller than the right boundary.
+This loss should not be used as a way to accumulate its value over multiple +batches.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
adaption_losses |
+
+ Sequence[Metric]
+ |
+
+
+
+ The list of losses to be applied to the subsets. + |
+ + required + | +
fuzzy_sets |
+
+ List[Tuple[float, float]]
+ |
+
+
+
+ The fuzzy sets to be used for subset membership. + |
+ + required + | +
mean_over_sets |
+
+ bool
+ |
+
+
+
+ Whether to take the mean or the sum of the losses. + |
+
+ True
+ |
+
compute()
+
+Compute the loss as either the sum or mean of all subset losses.
+ + + +Returns:
+Type | +Description | +
---|---|
+ Tensor
+ |
+
+
+
+ The combined loss. + |
+
update(source, source_preds, target, target_preds)
+
+Update the loss with the given data.
+The predictions for the source and target data are checked against the fuzzy +sets to determine membership.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
source |
+
+ Tensor
+ |
+
+
+
+ The source features. + |
+ + required + | +
source_preds |
+
+ Tensor
+ |
+
+
+
+ The predictions for the source features. + |
+ + required + | +
target |
+
+ Tensor
+ |
+
+
+
+ The target features. + |
+ + required + | +
target_preds |
+
+ Tensor
+ |
+
+
+
+ The predictions for the target features. + |
+ + required + | +
A module of feature extractors based on convolutional neural networks.
+ + + +CnnExtractor
+
+
+
+ Bases: Module
A Convolutional Neural Network (CNN) based network that extracts a feature +vector from same-length time windows.
+This feature extractor consists of multiple CNN layers and an optional fully +connected (FC) layer. Each CNN layer can be configured with a number of filters +and a kernel size. Additionally, batch normalization, same-padding and dropout +can be applied. The fully connected layer can have a separate dropout +probability.
+Both CNN and FC layers use ReLU activation functions by default. Custom +activation functions can be set for each layer type.
+The data flow is as follows: Input --> CNN x n --> [FC] --> Output
The expected input shape is [batch_size, num_features, window_size]
. The output
+of this network is always flattened to [batch_size, num_extracted_features]
.
Examples:
+Without FC
+>>> import torch
+>>> from rul_adapt.model import CnnExtractor
+>>> cnn = CnnExtractor(14,units=[16, 1],seq_len=30)
+>>> cnn(torch.randn(10, 14, 30)).shape
+torch.Size([10, 26])
+
+With FC
+>>> import torch
+>>> from rul_adapt.model import CnnExtractor
+>>> cnn = CnnExtractor(14,units=[16, 1],seq_len=30,fc_units=16)
+>>> cnn(torch.randn(10, 14, 30)).shape
+torch.Size([10, 16])
+
__init__(input_channels, units, seq_len, kernel_size=3, dilation=1, stride=1, padding=False, fc_units=None, dropout=0.0, fc_dropout=0.0, batch_norm=False, act_func=nn.ReLU, fc_act_func=nn.ReLU)
+
+Create a new CNN-based feature extractor.
+The units
are the number of output filters for each CNN layer. The
+seq_len
is needed to calculate the input units for the FC layer. The kernel
+size of each CNN layer can be set by passing a list to kernel_size
. If an
+integer is passed, each layer has the same kernel size. If padding
is true,
+same-padding is applied before each CNN layer, which keeps the window_size
+the same. If batch_norm
is set, batch normalization is applied for each CNN
+layer. If fc_units
is set, a fully connected layer is appended.
Dropout can be applied to each CNN layer by setting conv_dropout
to a
+number greater than zero. The same is valid for the fully connected layer and
+fc_dropout
. Dropout will never be applied to the input layer.
The whole network uses ReLU activation functions. This can be customized by
+setting either conv_act_func
or fc_act_func
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
input_channels |
+
+ int
+ |
+
+
+
+ The number of input channels. + |
+ + required + | +
units |
+
+ List[int]
+ |
+
+
+
+ The list of output filters for the CNN layers. + |
+ + required + | +
seq_len |
+
+ int
+ |
+
+
+
+ The window_size of the input data. + |
+ + required + | +
kernel_size |
+
+ Union[int, List[int]]
+ |
+
+
+
+ The kernel size for the CNN layers. Passing an integer uses + the same kernel size for each layer. + |
+
+ 3
+ |
+
dilation |
+
+ int
+ |
+
+
+
+ The dilation for the CNN layers. + |
+
+ 1
+ |
+
stride |
+
+ int
+ |
+
+
+
+ The stride for the CNN layers. + |
+
+ 1
+ |
+
padding |
+
+ bool
+ |
+
+
+
+ Whether to apply same-padding before each CNN layer. + |
+
+ False
+ |
+
fc_units |
+
+ Optional[int]
+ |
+
+
+
+ Number of output units for the fully connected layer. + |
+
+ None
+ |
+
dropout |
+
+ float
+ |
+
+
+
+ The dropout probability for the CNN layers. + |
+
+ 0.0
+ |
+
fc_dropout |
+
+ float
+ |
+
+
+
+ The dropout probability for the fully connected layer. + |
+
+ 0.0
+ |
+
batch_norm |
+
+ bool
+ |
+
+
+
+ Whether to use batch normalization on the CNN layers. + |
+
+ False
+ |
+
act_func |
+
+ Type[Module]
+ |
+
+
+
+ The activation function for the CNN layers. + |
+
+ ReLU
+ |
+
fc_act_func |
+
+ Type[Module]
+ |
+
+
+
+ The activation function for the fully connected layer. + |
+
+ ReLU
+ |
+
A module for network working as a regression or classification head.
+ + + +FullyConnectedHead
+
+
+
+ Bases: Module
A fully connected (FC) network that can be used as a RUL regressor or a domain +discriminator.
+This network is a stack of fully connected layers with ReLU activation functions
+by default. The activation function can be customized through the act_func
+parameter. If the last layer of the network should not have an activation
+function, act_func_on_last_layer
can be set to False
.
The data flow is as follows: Inputs --> FC x n --> Outputs
The expected input shape is [batch_size, num_features]
.
Examples:
+Default
+>>> import torch
+>>> from rul_adapt.model import FullyConnectedHead
+>>> regressor = FullyConnectedHead(32, [16, 1])
+>>> outputs = regressor(torch.randn(10, 32))
+>>> outputs.shape
+torch.Size([10, 1])
+>>> type(outputs.grad_fn)
+<class 'ReluBackward0'>
+
Custom activation function
+>>> import torch
+>>> from rul_adapt.model import FullyConnectedHead
+>>> regressor = FullyConnectedHead(32, [16, 1], act_func=torch.nn.Sigmoid)
+>>> outputs = regressor(torch.randn(10, 32))
+>>> type(outputs.grad_fn)
+<class 'SigmoidBackward0'>
+
Without activation function on last layer
+>>> import torch
+>>> from rul_adapt.model import FullyConnectedHead
+>>> regressor = FullyConnectedHead(32, [16, 1], act_func_on_last_layer=False)
+>>> outputs = regressor(torch.randn(10, 32))
+>>> type(outputs.grad_fn)
+<class 'AddmmBackward0'>
+
__init__(input_channels, units, dropout=0.0, act_func=nn.ReLU, act_func_on_last_layer=True)
+
+Create a new fully connected head network.
+The units
are the number of output units for each FC layer. The number of
+output features is units[-1]
. If dropout is used, it is applied in each
+layer, including input.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
input_channels |
+
+ int
+ |
+
+
+
+ The number of input channels. + |
+ + required + | +
units |
+
+ List[int]
+ |
+
+
+
+ The number of output units for the FC layers. + |
+ + required + | +
dropout |
+
+ float
+ |
+
+
+
+ The dropout probability before each layer. Set to zero to + deactivate. + |
+
+ 0.0
+ |
+
act_func |
+
+ Type[Module]
+ |
+
+
+
+ The activation function for each layer. + |
+
+ ReLU
+ |
+
act_func_on_last_layer |
+
+ bool
+ |
+
+
+
+ Whether to add the activation function to the last + layer. + |
+
+ True
+ |
+
This module contains the necessary neural networks to build a RUL estimator.
+In general, a RUL estimator network consists of two parts: a feature extractor and a +regression head. The feature extractor is a network that transforms the input feature +windows into a latent feature vector. The regression head maps these latent features +to a scalar RUL value. The feature extractors can be found in the cnn and rnn modules. The regression head in +the head module.
+Some domain adaption approaches use a domain discriminator. The networks in the +head module can be used to construct them, too.
+ + + +Examples:
+>>> import torch
+>>> from rul_adapt import model
+>>> feature_extractor = model.CnnExtractor(14,[32, 16],30,fc_units=8)
+>>> regressor = model.FullyConnectedHead(8, [4, 1])
+>>> latent_features = feature_extractor(torch.randn(10, 14, 30))
+>>> latent_features.shape
+torch.Size([10, 8])
+>>> rul = regressor(latent_features)
+>>> rul.shape
+torch.Size([10, 1])
+
A module of feature extractors based on recurrent neural networks.
+ + + +GruExtractor
+
+
+
+ Bases: Module
A Gated Recurrent Unit (GRU) based network that extracts a feature vector +from same-length time windows.
+This feature extractor consists of multiple fully connected (FC) layers with +a ReLU activation functions and a multi-layer GRU. The GRU layers can be +configured as bidirectional. Dropout can be applied separately to the GRU +layers.
+The data flow is as follows: Input --> FC x n --> GRU x m --> Output
The expected input shape is [batch_size, num_features, window_size]
.
Examples:
+>>> import torch
+>>> from rul_adapt.model import GruExtractor
+>>> gru = GruExtractor(input_channels=14, fc_units=[16, 8], gru_units=[8])
+>>> gru(torch.randn(10, 14, 30)).shape
+torch.Size([10, 8])
+
__init__(input_channels, fc_units, gru_units, gru_dropout=0.0, bidirectional=False)
+
+Create a new GRU-based feature extractor.
+The fc_units
are the output units for each fully connected layer
+and gru_units
for each LSTM layer. If bidirectional
is set to True
,
+a BiGRU is used and the output units are doubled. The number of output
+features of this network is either gru_units[-1]
by default, or 2 *
+gru_units[ -1]
if bidirectional is set.
Dropout can be applied to each GRU layer by setting lstm_dropout
to a
+number greater than zero.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
input_channels |
+
+ int
+ |
+
+
+
+ The number of input channels. + |
+ + required + | +
fc_units |
+
+ List[int]
+ |
+
+
+
+ The list of output units for the fully connected layers. + |
+ + required + | +
gru_units |
+
+ List[int]
+ |
+
+
+
+ The list of output units for the GRU layers + |
+ + required + | +
gru_dropout |
+
+ float
+ |
+
+
+
+ The dropout probability for the GRU layers. + |
+
+ 0.0
+ |
+
bidirectional |
+
+ bool
+ |
+
+
+
+ Whether to use a BiGRU. + |
+
+ False
+ |
+
LstmExtractor
+
+
+
+ Bases: Module
A Long Short Term Memory (LSTM) based network that extracts a feature vector +from same-length time windows.
+This feature extractor consists of a multi-layer LSTM and an optional fully +connected (FC) layer with a ReLU activation function. The LSTM layers can be +configured as bidirectional. Dropout can be applied separately to LSTM and FC +layers.
+The data flow is as follows: Input --> LSTM x n --> [FC] --> Output
The expected input shape is [batch_size, num_features, window_size]
.
Examples:
+Without FC
+>>> import torch
+>>> from rul_adapt.model import LstmExtractor
+>>> lstm = LstmExtractor(input_channels=14,units=[16, 16])
+>>> lstm(torch.randn(10, 14, 30)).shape
+torch.Size([10, 16])
+
+With FC
+>>> from rul_adapt.model import LstmExtractor
+>>> lstm = LstmExtractor(input_channels=14,units=[16, 16],fc_units=8)
+>>> lstm(torch.randn(10, 14, 30)).shape
+torch.Size([10, 8])
+
__init__(input_channels, units, fc_units=None, dropout=0.0, fc_dropout=0.0, bidirectional=False)
+
+Create a new LSTM-based feature extractor.
+The units
are the output units for each LSTM layer. If bidirectional
+is set to True
, a BiLSTM is used and the output units are doubled. If
+fc_units
is set, a fully connected layer is appended. The number of output
+features of this network is either units[-1]
by default,
+2 * units[ -1]
if bidirectional is set, or fc_units
if it is set.
Dropout can be applied to each LSTM layer by setting lstm_dropout
to a
+number greater than zero. The same is valid for the fully connected layer and
+fc_dropout
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
input_channels |
+
+ int
+ |
+
+
+
+ The number of input channels. + |
+ + required + | +
units |
+
+ List[int]
+ |
+
+
+
+ The list of output units for the LSTM layers. + |
+ + required + | +
fc_units |
+
+ Optional[int]
+ |
+
+
+
+ The number of output units for the fully connected layer. + |
+
+ None
+ |
+
dropout |
+
+ float
+ |
+
+
+
+ The dropout probability for the LSTM layers. + |
+
+ 0.0
+ |
+
fc_dropout |
+
+ float
+ |
+
+
+
+ The dropout probability for the fully connected layer. + |
+
+ 0.0
+ |
+
bidirectional |
+
+ bool
+ |
+
+
+
+ Whether to use a BiLSTM. + |
+
+ False
+ |
+
TwoStageExtractor
+
+
+
+ Bases: Module
This module combines two feature extractors into a single network.
+The input data is expected to be of shape [batch_size, upper_seq_len,
+input_channels, lower_seq_len]
. An example would be vibration data recorded in
+spaced intervals, where lower_seq_len is the length of an interval and
+upper_seq_len is the window size of a sliding window over the intervals.
The lower_stage is applied to each interval individually to extract features. +The upper_stage is then applied to the extracted features of the window. +The resulting feature vector should represent the window without the need to +manually extract features from the raw data of the intervals.
+ + + + +__init__(lower_stage, upper_stage)
+
+Create a new two-stage extractor.
+The lower stage needs to take a tensor of shape [batch_size, input_channels,
+seq_len]
and return a tensor of shape [batch_size, lower_output_units]
. The
+upper stage needs to take a tensor of shape [batch_size, upper_seq_len,
+lower_output_units]
and return a tensor of shape [batch_size,
+upper_output_units]
. Args: lower_stage: upper_stage:
forward(inputs)
+
+Apply the two-stage extractor to the input tensor.
+The input tensor is expected to be of shape [batch_size, upper_seq_len,
+input_channels, lower_seq_len]
. The output tensor will be of shape
+[batch_size, upper_output_units]
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
inputs |
+
+ Tensor
+ |
+
+
+
+ the input tensor + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Tensor
+ |
+
+
+
+ an output tensor of shape |
+
OptimizerFactory
+
+
+Factory for creating optimizers and schedulers.
+After initialization, the factory can be called to create an optimizer with an +optional scheduler.
+ + + + +__call__(parameters)
+
+Create an optimizer with an optional scheduler for the given parameters.
+The object returned by this method is a lightning optimizer config and can be
+the return value of configure_optimizers
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
parameters |
+
+ Iterable[Parameter]
+ |
+
+
+
+ The model parameters to optimize. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ OptimizerLRSchedulerConfig
+ |
+
+
+
+ A lightning optimizer config. + |
+
__init__(optim_type='adam', lr=0.001, scheduler_type=None, **kwargs)
+
+Create a new factory to efficiently create optimizers and schedulers.
+The factory creates an optimizer of the specified optim_type
and adds an
+optional scheduler of the specified scheduler_type
. Additional keyword
+arguments for the optimizer can be passed by adding the 'optim_' prefix and
+for the scheduler by adding the 'scheduler_' prefix. The factory will ignore
+any other keyword arguments.
Available optimizers are 'adam', 'sgd' and 'rmsprop'. Available schedulers +are 'step', 'cosine', 'linear' and 'lambda'.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
optim_type |
+
+ str
+ |
+
+
+
+ The type of optimizer to create. + |
+
+ 'adam'
+ |
+
lr |
+
+ float
+ |
+
+
+
+ The learning rate to use. + |
+
+ 0.001
+ |
+
scheduler_type |
+
+ Optional[str]
+ |
+
+
+
+ The optional type of scheduler to create. + |
+
+ None
+ |
+
**kwargs |
+
+ Any
+ |
+
+
+
+ Additional keyword arguments for the optimizer and scheduler. + |
+
+ {}
+ |
+
get_loss(loss_type)
+
+Get a loss instance by specifying a string.
+ +pairwise(iterable)
+
+s -> (s0,s1), (s1,s2), (s2, s3), ...
+ +str2callable(cls, restriction='')
+
+Dynamically import a callable from a string.
+ +{"use strict";/*!
+ * escape-html
+ * Copyright(c) 2012-2013 TJ Holowaychuk
+ * Copyright(c) 2015 Andreas Lubbe
+ * Copyright(c) 2015 Tiancheng "Timothy" Gu
+ * MIT Licensed
+ */var Wa=/["'&<>]/;Vn.exports=Ua;function Ua(e){var t=""+e,r=Wa.exec(t);if(!r)return t;var o,n="",i=0,s=0;for(i=r.index;i