data.preprocs.ProcPad¶
Class ยท Source
proc = mdnc.data.preprocs.ProcPad(
pad_width, inds=None, parent=None, **kwargs
)
This is a homogeneous processor. Use np.pad
to pad the data.
This processor supports all np.pad
options. Besides, this processor also support cropping. If any element in the argument pad_width
is negative, would perform cropping on that axis. For example:
p = ProcPad(pad_width=((5, -5),))
y = p(x) # x.shape=(20,), y.shape=(20,)
In this case, the data is padded by 5 samples at the beginning, but cropped 5 samples at the end.
This operator is not invertible when cropping is applied. The postprocess would try to revert the padding / cropping configurations to match the input data.
Warning
If cropping is used, this processor would be not invertible (unless we have the argument mode='wrap'
). The postprocess()
method would try to pad the cropped part with the processed data.
Arguments¶
Requries
Argument | Type | Description |
---|---|---|
pad_width | int or(int, int) ((int, int), ...) | The padding_width argument of the np.pad function. If any element is negative, it means this elment is a cropping size. This argument only supports 3 cases:
|
inds | int or(int, ) | Index or indicies of variables where the user implemented methods would be broadcasted. The variables not listed in this argument would be passed to the output without any processing. If set None , methods would be broadcasted to all variables. |
parent | ProcAbstract | Another instance derived from mdnc.data.preprocs.ProcAbstract . The output of parent.preprocess() would be used as the input of self.preprocess() . The input of self.postprocess() would be used as the input of parent.preprocess() . |
Methods¶
preprocess
¶
y_1, y_2, ... = proc.preprocess(x_1, x_2, ...)
The preprocess function. Perform the padding / cropping.
If parent
exists, the input of this function comes from the output of parent.preprocess()
. Otherwise, the input would comes from the input varibable directly.
Requries
Argument | Type | Description |
---|---|---|
(x, ) | np.ndarray | A sequence of variables. Each variable comes from the parent's outputs (if parent exists). The output of this method would be passed as the input of the next processor (if this processor is used as parent). |
Returns
Argument | Description |
---|---|
(y, ) | A sequence of np.ndarray , the final preprocessed data. |
postprocess
¶
x_1, x_2, ... = proc.postprocess(y_1, y_2, ...)
The postprocess function. The inverse operator is not invertible if cropping is used in preprocess()
. In this case, the cropped part would be padded by processed data (y, )
.
If parent
exists, the output of this function would be passed as the input of parent.postprocess()
. Otherwise, the output would be returned to users directly.
Requries
Argument | Type | Description |
---|---|---|
(y, ) | np.ndarray | A sequence of variables. Each variable comes from the next processors's outputs (if parent exists). The output of this method would be passed as the input of the parent's method. |
Returns
Argument | Description |
---|---|
(x, ) | A sequence of np.ndarray , the final postprocessed data. |
Properties¶
pad_width
¶
proc.pad_width
The padding width of the processor.
parent
¶
proc.parent
The parent processor of this instance. The processor is also a derived class of ProcAbstract
. If the parent does not exist, would return None
.
has_ind
¶
proc.has_ind
A bool flag, showing whether this processor and its all parent processors have inds
configured or initialized with _disable_inds
. In this case, the arguments of preprocess()
and postprocess()
would not share the same operation. We call such kind of processors "Inhomogeneous processors".
Examples¶
The processor need to be derived. We have two ways to implement the derivation, see the following examples.
Example 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Example 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|