MorphingAwareRatioEstimator constructor without compulsory h5 filename
@@ -821,14 +821,32 @@ class ParameterizedRatioEstimator(ConditionalEstimator):
class MorphingAwareRatioEstimator(ParameterizedRatioEstimator):
- def __init__(self, morphing_setup_filename, optimize_morphing_basis=False, features=None, n_hidden=(100,), activation="tanh", dropout_prob=0.0):
+ def __init__(
+ self,
+ morphing_setup_filename=None,
+ optimize_morphing_basis=False,
+ features=None,
+ n_hidden=(100,),
+ activation="tanh",
+ dropout_prob=0.0,
+ ):
super(ParameterizedRatioEstimator, self).__init__(features, n_hidden, activation, dropout_prob)
- self.components, self.morphing_matrix = self._load_morphing_setup(morphing_setup_filename, optimize_morphing_basis)
-
+ if morphing_setup_filename is not None:
+ self.components, self.morphing_matrix = self._load_morphing_setup(
+ morphing_setup_filename, optimize_morphing_basis
+ )
logger.info("Setting up morphing-aware ratio estimator with %s morphing components", len(self.components))
+ else:
+ self.components, self.morphing_matrix = None, None
def train(self, *args, **kwargs):
+ if self.morphing_matrix is None:
+ raise RuntimeError(
+ "Please provide morphing setup during instantiation or load a previously trained morphing-aware "
+ "estimator!"
+ )
+
super(MorphingAwareRatioEstimator, self).train(*args, scale_parameters=False, **kwargs)
def _load_morphing_setup(self, filename, optimize_morphing_basis=False):
