Skip to content

adarul

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