Skip to content

Commit

Permalink
Add the checkf
Browse files Browse the repository at this point in the history
  • Loading branch information
yrobink committed Oct 19, 2022
1 parent aebbd23 commit 0f6fd2a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
29 changes: 26 additions & 3 deletions SBCK/ppp/__PrePostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
## Libraries ##
###############

from .__checkf import skipNotValid

###########
## Class ##
###########
Expand Down Expand Up @@ -77,7 +79,7 @@ class PrePostProcessing:##{{{
"""


def __init__( self , bc_method = None , bc_method_kwargs = {} , pipe = [] , pipe_kwargs = [] ):##{{{
def __init__( self , bc_method = None , bc_method_kwargs = {} , pipe = [] , pipe_kwargs = [] , checkf = skipNotValid ):##{{{
"""
Constructor
===========
Expand All @@ -93,7 +95,11 @@ def __init__( self , bc_method = None , bc_method_kwargs = {} , pipe = [] , pipe
correction.
pipe_kwargs: [list of dict]
List of keyword arguments to pass to each PreProcessing class
checkf: [function]
Boolean function controlling if the fit can occurs. Intercept
'bc_method' and 'pipe' before their applications. If check return
False on the dataset fitted, the fit doesn't occurs, and the predict
return the input.
"""
if not type(pipe) == list:
pipe = [pipe]
Expand All @@ -104,7 +110,9 @@ def __init__( self , bc_method = None , bc_method_kwargs = {} , pipe = [] , pipe
if bc_method is not None:
self._bc_method = bc_method( **bc_method_kwargs )

self._kind = None
self._kind = None
self._checkf = lambda x : True if x is None else checkf(x)
self._check = None

##}}}

Expand Down Expand Up @@ -156,10 +164,18 @@ def fit( self , Y0 , X0 , X1 = None ):##{{{
Fit the bias correction method after the pre-processing.
"""

## The check
self._check = all([self._checkf(K) for K in [Y0,X0,X1]])

if not self._check:
return

## The transform
Y0t = self._pipe_transform( Y0 , "Y0" )
X0t = self._pipe_transform( X0 , "X0" )
X1t = self._pipe_transform( X1 , "X1" )

## The fit
if X1 is None:
self._bc_method.fit( Y0t , X0t )
else:
Expand All @@ -172,6 +188,13 @@ def predict( self , X1 = None , X0 = None ):##{{{
the post-processing operation.
"""

if not self._check:
if X0 is None:
return X1
elif X1 is None:
return X0
return X1,X0

X0t = self._pipe_transform( X0 , "X0" )
X1t = self._pipe_transform( X1 , "X1" )
Z0t = None
Expand Down
4 changes: 2 additions & 2 deletions SBCK/ppp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
## along with SBCK. If not, see <https://www.gnu.org/licenses/>.


from .__checkf import skipNotValid

from .__PrePostProcessing import PrePostProcessing
from .__PPPSSR import PPPSSR
from .__PPPLinkFunction import PPPLinkFunction
Expand All @@ -29,5 +31,3 @@
from .__PPPNanValues import PPPRemoveNotFinite
from .__PPPNanValues import PPPNotFiniteAnalog

from .__BCISkipNotValid import BCISkipNotValid

0 comments on commit 0f6fd2a

Please sign in to comment.