supervised
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 |