PrePostProcessing {SBCK} | R Documentation |
PrePostProcessing base class
Description
Base class to pre/post process data before/after a bias correction
Details
This base class can be considered as the identity pre-post processing, and
is used to be herited by others pre/post processing class. The key ideas are:
- A PrePostProcessing based class contains a bias correction method, initalized
by the 'bc_method' argument, always available for all herited class
- The 'pipe' keyword is a list of pre/post processing class, applied one after
the other.
Try with an example, start with a dataset similar to tas/pr:
>>> XY = SBCK::dataset_like_tas_pr(2000)
>>> X0 = XY$X0
>>> X1 = XY$X1
>>> Y0 = XY$Y0
The first column is Gaussian, but the second is an exponential law with a Dirac
mass at 0, represented the 0 of precipitations. For a quantile mapping
correction in the calibration period, we just apply
>>> qm = SBCK::QM$new()
>>> qm$fit(Y0,X0)
>>> Z0 = qm$predict(X0)
Now, if we want to pre-post process with the SSR method (0 are replaced by
random values between 0 (excluded) and the minimal non zero value), we write:
>>> ppp = SBCK::PPPSSR$new( bc_method = QM , cols = 2 )
>>> ppp$fit(Y0,X0)
>>> Z0 = ppp$predict(X0)
The SSR approach is applied only on the second column (the precipitation), and
the syntax is the same than for a simple bias correction method.
Imagine now that we want to apply the SSR, and to ensure the positivity of CDFt
for precipitation, we also want to use the LogLinLink pre-post processing
method. This can be done with the following syntax:
>>> ppp = PPPLogLinLink$new( bc_method = CDFt , cols = 2 ,
>>> pipe = list(PPPSSR) ,
>>> pipe_kwargs = list( list(cols = 2) ) )
>>> ppp$fit(Y0,X0,X1)
>>> Z = ppp$predict(X1,X0)
With this syntax, the pre processing operation is
PPPLogLinLink$transform(PPPSSR$transform(data)) and post processing operation
PPPSSR$itransform(PPPLogLinLink$itransform(bc_data)). So the formula can read
from right to left (as the mathematical composition). Note it is equivalent
to define:
>>> ppp = PrePostProcessing$new( bc_method = CDFt,
>>> pipe = list(PPPLogLinLink,PPPSSR),
>>> pipe_kwargs = list( list(cols=2) , list(cols=2) ) )
Methods
Public methods
Method new()
Create a new PrePostProcessing object.
Usage
PrePostProcessing$new( bc_method = NULL, bc_method_kwargs = list(), pipe = list(), pipe_kwargs = list() )
Arguments
bc_method
The bias correction method
bc_method_kwargs
Dict of keyword arguments passed to bc_method
pipe
list of others PrePostProcessing class to pipe
pipe_kwargs
list of list of keyword arguments passed to each elements of pipe
Returns
A new 'PrePostProcessing' object.
Method transform()
Transformation applied to data before the bias correction. Just the identity for this class
Usage
PrePostProcessing$transform(X)
Arguments
X
[matrix: n_samples * n_features]
Returns
Xt [matrix: n_samples * n_features]
Method itransform()
Transformation applied to data after the bias correction. Just the identity for this class
Usage
PrePostProcessing$itransform(Xt)
Arguments
Xt
[matrix: n_samples * n_features]
Returns
X [matrix: n_samples * n_features]
Method fit()
Apply the pre processing and fit the bias correction method. If X1 is NULL, the method is considered as stationary
Usage
PrePostProcessing$fit(Y0, X0, X1 = NULL)
Arguments
Y0
[matrix: n_samples * n_features] Observations in calibration
X0
[matrix: n_samples * n_features] Model in calibration
X1
[matrix: n_samples * n_features] Model in projection
Returns
NULL
Method predict()
Predict the correction, apply pre-processing before, and post-processing after
Usage
PrePostProcessing$predict(X1 = NULL, X0 = NULL)
Arguments
X1
[matrix: n_samples * n_features or NULL] Model in projection
X0
[matrix: n_samples * n_features or NULL] Model in calibration
Returns
[matrix or list] Return the matrix of correction of X1 if X0 is NULL (and vice-versa), else return a list containing Z1 and Z0, the corrections of X1 and X0
Method clone()
The objects of this class are cloneable with this method.
Usage
PrePostProcessing$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
## Start with data
XY = SBCK::dataset_like_tas_pr(2000)
X0 = XY$X0
X1 = XY$X1
Y0 = XY$Y0
## Define pre/post processing method
ppp = PrePostProcessing$new( bc_method = CDFt,
pipe = list(PPPLogLinLink,PPPSSR),
pipe_kwargs = list( list(cols=2) , list(cols=2) ) )
## Bias correction
ppp$fit(Y0,X0,X1)
Z = ppp$predict(X1,X0)