diff --git a/src/vai_lab/Core/vai_lab_core.py b/src/vai_lab/Core/vai_lab_core.py index ebe9ca5d..6edb6114 100644 --- a/src/vai_lab/Core/vai_lab_core.py +++ b/src/vai_lab/Core/vai_lab_core.py @@ -67,8 +67,12 @@ def _execute_module(self, specs): mod._debug = self._debug mod.set_avail_plugins(self._avail_plugins) self._load_data(specs, specs["name"]) - mod.set_data_in(self.data[specs["name"]]) mod.set_options(specs) + if specs["name"] == 'User Interaction': + mod._load_plugin(specs["plugin"]["plugin_name"]) + mod.set_data_in(self.data[specs["name"]]) + else: + mod._load_plugin(self.data[specs["name"]]) print("\t"*self.loop_level + specs["module_type"] + " module: \"{}\" ".format(specs["name"]) @@ -189,4 +193,4 @@ def run(self): self._init_status(self._xml_handler.loaded_modules) self._execute(self._xml_handler.loaded_modules) - print("Pipeline Complete") + print("Pipeline Complete") \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/DataProcessing_core.py b/src/vai_lab/DataProcessing/DataProcessing_core.py index ba3716d6..baf32a97 100644 --- a/src/vai_lab/DataProcessing/DataProcessing_core.py +++ b/src/vai_lab/DataProcessing/DataProcessing_core.py @@ -11,14 +11,15 @@ def set_avail_plugins(self, avail_plugins: PluginSpecsInterface) -> None: def set_data_in(self, data_in: DataInterface) -> None: self._data_in = data_in - def _load_plugin(self, plugin_name: str) -> None: + def _load_plugin(self, data_in) -> None: avail_plugins = self._avail_plugins.find_from_readable_name( - plugin_name) - self._plugin_name = plugin_name + self._module_config["plugin"]["plugin_name"]) + self._plugin_name = self._module_config["plugin"]["plugin_name"] + self.set_data_in(data_in) self._plugin: DataProcessingPluginInterface = import_plugin_absolute(globals(), avail_plugins["_PLUGIN_PACKAGE"], avail_plugins["_PLUGIN_CLASS_NAME"])\ - .__call__() + .__call__(self._module_config["plugin"], data_in) def set_options(self, module_config: dict) -> None: """Send configuration arguments to plugin @@ -26,12 +27,9 @@ def set_options(self, module_config: dict) -> None: :param module_config: dict of settings to configure the plugin """ self._module_config = module_config - self._load_plugin(self._module_config["plugin"]["plugin_name"]) def launch(self) -> None: - self._plugin.set_data_in(self._data_in) - self._plugin.configure(self._module_config["plugin"]) - self._plugin.init() + for method in self._module_config["plugin"]["methods"]["_order"]: if "options" in self._module_config["plugin"]["methods"][method].keys(): getattr(self._plugin, "{}".format(method))(self._plugin._parse_options_dict(self._module_config["plugin"]["methods"][method]["options"])) diff --git a/src/vai_lab/DataProcessing/plugins/binarizer.py b/src/vai_lab/DataProcessing/plugins/binarizer.py index 71e334ed..4dab8267 100644 --- a/src/vai_lab/DataProcessing/plugins/binarizer.py +++ b/src/vai_lab/DataProcessing/plugins/binarizer.py @@ -15,9 +15,20 @@ class Binarizer(DataProcessingT): Binarize data (set feature values to 0 or 1) according to a threshold """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/kbinsdiscretizer.py b/src/vai_lab/DataProcessing/plugins/kbinsdiscretizer.py index 4fc7023e..99aa302f 100644 --- a/src/vai_lab/DataProcessing/plugins/kbinsdiscretizer.py +++ b/src/vai_lab/DataProcessing/plugins/kbinsdiscretizer.py @@ -15,9 +15,20 @@ class KBinsDiscretizer(DataProcessingT): Bin continuous data into interval """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/labelbinarizer.py b/src/vai_lab/DataProcessing/plugins/labelbinarizer.py index 811e1774..f5c76520 100644 --- a/src/vai_lab/DataProcessing/plugins/labelbinarizer.py +++ b/src/vai_lab/DataProcessing/plugins/labelbinarizer.py @@ -13,9 +13,20 @@ class LabelBinarizer(DataProcessingT): """ Binarize labels in a one-vs-all fashion """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/labelencoder.py b/src/vai_lab/DataProcessing/plugins/labelencoder.py index a7166062..a1dd209f 100644 --- a/src/vai_lab/DataProcessing/plugins/labelencoder.py +++ b/src/vai_lab/DataProcessing/plugins/labelencoder.py @@ -14,9 +14,20 @@ class LabelEncoder(DataProcessingT): Encode target labels with value between 0 and n_classes-1 """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/maxabsscaler.py b/src/vai_lab/DataProcessing/plugins/maxabsscaler.py index 58def4b4..c7664835 100644 --- a/src/vai_lab/DataProcessing/plugins/maxabsscaler.py +++ b/src/vai_lab/DataProcessing/plugins/maxabsscaler.py @@ -14,9 +14,20 @@ class MaxAbsScaler(DataProcessingT): Scale each feature by its maximum absolute value """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/minmaxscaler.py b/src/vai_lab/DataProcessing/plugins/minmaxscaler.py index c7e2d170..1cdb349d 100644 --- a/src/vai_lab/DataProcessing/plugins/minmaxscaler.py +++ b/src/vai_lab/DataProcessing/plugins/minmaxscaler.py @@ -15,9 +15,20 @@ class MinMaxScaler(DataProcessingT): is in the given range on the training set, e.g. between zero and one """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/multilabelbinarizer.py b/src/vai_lab/DataProcessing/plugins/multilabelbinarizer.py index 4be65da8..5bbeaa06 100644 --- a/src/vai_lab/DataProcessing/plugins/multilabelbinarizer.py +++ b/src/vai_lab/DataProcessing/plugins/multilabelbinarizer.py @@ -14,9 +14,20 @@ class MultiLabelBinarizer(DataProcessingT): Transform between iterable of iterables and a multilabel format """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/normalizer.py b/src/vai_lab/DataProcessing/plugins/normalizer.py index 6c0cbb8c..05812b33 100644 --- a/src/vai_lab/DataProcessing/plugins/normalizer.py +++ b/src/vai_lab/DataProcessing/plugins/normalizer.py @@ -18,9 +18,20 @@ class Normalizer(DataProcessingT): Normalize samples individually to unit norm """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/onehotencoder.py b/src/vai_lab/DataProcessing/plugins/onehotencoder.py index 73d8eb2c..44edd661 100644 --- a/src/vai_lab/DataProcessing/plugins/onehotencoder.py +++ b/src/vai_lab/DataProcessing/plugins/onehotencoder.py @@ -14,9 +14,20 @@ class OneHotEncoder(DataProcessingT): Encode categorical features as a one-hot numeric array """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/ordinalencoder.py b/src/vai_lab/DataProcessing/plugins/ordinalencoder.py index a9095ccf..7e48d568 100644 --- a/src/vai_lab/DataProcessing/plugins/ordinalencoder.py +++ b/src/vai_lab/DataProcessing/plugins/ordinalencoder.py @@ -15,9 +15,20 @@ class OrdinalEncoder(DataProcessingT): Encode categorical features as an integer array """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/polynomialfeatures.py b/src/vai_lab/DataProcessing/plugins/polynomialfeatures.py index c40c5ea7..b1bcd423 100644 --- a/src/vai_lab/DataProcessing/plugins/polynomialfeatures.py +++ b/src/vai_lab/DataProcessing/plugins/polynomialfeatures.py @@ -18,9 +18,20 @@ class PolynomialFeatures(DataProcessingT): Generate polynomial and interaction features """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/quantiletransformer.py b/src/vai_lab/DataProcessing/plugins/quantiletransformer.py index 91085593..306d4724 100644 --- a/src/vai_lab/DataProcessing/plugins/quantiletransformer.py +++ b/src/vai_lab/DataProcessing/plugins/quantiletransformer.py @@ -16,9 +16,20 @@ class QuantileTransformer(DataProcessingT): Transform features using quantiles information """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DataProcessing/plugins/standardscaler.py b/src/vai_lab/DataProcessing/plugins/standardscaler.py index cda34552..029f49c5 100644 --- a/src/vai_lab/DataProcessing/plugins/standardscaler.py +++ b/src/vai_lab/DataProcessing/plugins/standardscaler.py @@ -16,9 +16,20 @@ class StandardScaler(DataProcessingT): Standardize features by removing the mean and scaling to unit variance """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.transform_plugin = self.model.transform \ No newline at end of file diff --git a/src/vai_lab/DecisionMaking/DecisionMaking_core.py b/src/vai_lab/DecisionMaking/DecisionMaking_core.py index 88c8ea44..bc69adcb 100644 --- a/src/vai_lab/DecisionMaking/DecisionMaking_core.py +++ b/src/vai_lab/DecisionMaking/DecisionMaking_core.py @@ -10,13 +10,14 @@ def set_avail_plugins(self,avail_plugins): def set_data_in(self,data_in): self._data_in = data_in - def _load_plugin(self, plugin_name:str): - avail_plugins = self._avail_plugins.find_from_readable_name(plugin_name) - self._plugin_name = plugin_name + def _load_plugin(self, data_in): + avail_plugins = self._avail_plugins.find_from_readable_name(self._module_config["plugin"]["plugin_name"]) + self._plugin_name = self._module_config["plugin"]["plugin_name"] + self.set_data_in(data_in) self._plugin = import_plugin_absolute(globals(),\ avail_plugins["_PLUGIN_PACKAGE"],\ avail_plugins["_PLUGIN_CLASS_NAME"])\ - .__call__() + .__call__(self._module_config["plugin"], data_in) def set_options(self, module_config: dict): """Send configuration arguments to plugin @@ -24,12 +25,16 @@ def set_options(self, module_config: dict): :param module_config: dict of settings to configure the plugin """ self._module_config = module_config - self._load_plugin(self._module_config["plugin"]["plugin_name"]) def launch(self): - self._plugin.set_data_in(self._data_in) - self._plugin.configure(self._module_config["plugin"]) - # self._plugin.optimise() + + for method in self._module_config["plugin"]["methods"]["_order"]: + if "options" in self._module_config["plugin"]["methods"][method].keys(): + out = getattr(self._plugin, "{}".format(method))(self._plugin._parse_options_dict(self._module_config["plugin"]["methods"][method]["options"])) + else: + out = getattr(self._plugin, "{}".format(method))() + + self.output_data = self._data_in.copy() self.output_data = self._plugin.suggest_locations() def get_result(self): diff --git a/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(GPy).py b/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(GPy).py index bf9ff291..28cde0ef 100644 --- a/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(GPy).py +++ b/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(GPy).py @@ -23,12 +23,23 @@ class GPyOpt(DecisionMakingPluginT): Bayesian optimisation model using GPyOpt. Compatible with no objective function using tabular data. """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + # self.fit_plugin = self.model.fit + # self.transform_plugin = self.model.transform def _parse_options_dict(self, options_dict:Dict): super()._parse_options_dict(options_dict) diff --git a/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(bayes_opt).py b/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(bayes_opt).py index 544bcdc9..105c8e9d 100644 --- a/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(bayes_opt).py +++ b/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(bayes_opt).py @@ -20,12 +20,23 @@ class bayes_opt(DecisionMakingPluginT): Bayesian optimisation model using bayes_opt. """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + # self.fit_plugin = self.model.fit + # self.transform_plugin = self.model.transform def optimise(self): """Probes the target space to find the parameters that yield the maximum value for the given function.""" diff --git a/src/vai_lab/Environment/Environment_core.py b/src/vai_lab/Environment/Environment_core.py index 70bcf13c..9bb9a469 100644 --- a/src/vai_lab/Environment/Environment_core.py +++ b/src/vai_lab/Environment/Environment_core.py @@ -11,14 +11,15 @@ def set_avail_plugins(self, avail_plugins: PluginSpecsInterface) -> None: def set_data_in(self, data_in: DataInterface) -> None: self._data_in = data_in - def _load_plugin(self, plugin_name: str) -> None: + def _load_plugin(self, data_in) -> None: + self._plugin_name = self._module_config["plugin"]["plugin_name"] avail_plugins = self._avail_plugins.find_from_readable_name( - plugin_name) - self._plugin_name = plugin_name + self._plugin_name) + self.set_data_in(data_in) self._plugin: EnvironmentPluginInterface = import_plugin_absolute(globals(), avail_plugins["_PLUGIN_PACKAGE"], avail_plugins["_PLUGIN_CLASS_NAME"])\ - .__call__() + .__call__(self._module_config["plugin"], data_in) def set_options(self, module_config: dict) -> None: """Send configuration arguments to plugin @@ -29,8 +30,6 @@ def set_options(self, module_config: dict) -> None: self._load_plugin(self._module_config["plugin"]["plugin_name"]) def launch(self) -> None: - self._plugin.set_data_in(self._data_in) - self._plugin.configure(self._module_config["plugin"]) self._plugin.connect() self._plugin.load_model() self._plugin.run_simulation() @@ -38,4 +37,4 @@ def launch(self) -> None: def get_result(self) -> DataInterface: # return self.output_data - return self._data_in + return self._data_in \ No newline at end of file diff --git a/src/vai_lab/Environment/plugins/PyBulletEnv.py b/src/vai_lab/Environment/plugins/PyBulletEnv.py index 727f2d79..43b4f221 100644 --- a/src/vai_lab/Environment/plugins/PyBulletEnv.py +++ b/src/vai_lab/Environment/plugins/PyBulletEnv.py @@ -20,9 +20,11 @@ class PyBulletEnv(EnvironmentPluginT): Loads the pybullet library as wildcard and exposes all functions """ - def __init__(self) -> None: + def __init__(self, config = {}, data_in = [None]) -> None: super().__init__(globals()) self.model_ids: Dict = {} + self.set_data_in(data_in) + self.configure(config) def set_gui(self, use_gui: bool = True): if type(use_gui) == str: @@ -96,6 +98,4 @@ def __getattr__(self, attr: str) -> Any: if __name__ == "__main__": pb = PyBulletEnv() - print(pb.ACTIVATION_STATE_DISABLE_SLEEPING) - # pb.set_gui(True) - # pb.connect() + print(pb.ACTIVATION_STATE_DISABLE_SLEEPING) \ No newline at end of file diff --git a/src/vai_lab/Modelling/Modelling_core.py b/src/vai_lab/Modelling/Modelling_core.py index fa19e436..8cd89e97 100644 --- a/src/vai_lab/Modelling/Modelling_core.py +++ b/src/vai_lab/Modelling/Modelling_core.py @@ -10,13 +10,14 @@ def set_avail_plugins(self,avail_plugins): def set_data_in(self,data_in): self._data_in = data_in - def _load_plugin(self, plugin_name:str): - avail_plugins = self._avail_plugins.find_from_readable_name(plugin_name) - self._plugin_name = plugin_name + def _load_plugin(self, data_in): + self._plugin_name = self._module_config["plugin"]["plugin_name"] + avail_plugins = self._avail_plugins.find_from_readable_name(self._plugin_name) + self.set_data_in(data_in) self._plugin = import_plugin_absolute(globals(),\ avail_plugins["_PLUGIN_PACKAGE"],\ avail_plugins["_PLUGIN_CLASS_NAME"])\ - .__call__() + .__call__(self._module_config["plugin"], data_in) def set_options(self, module_config: dict): """Send configuration arguments to plugin @@ -24,12 +25,9 @@ def set_options(self, module_config: dict): :param module_config: dict of settings to configure the plugin """ self._module_config = module_config - self._load_plugin(self._module_config["plugin"]["plugin_name"]) def launch(self): - self._plugin.set_data_in(self._data_in) - self._plugin.configure(self._module_config["plugin"]) - self._plugin.init() + for method in self._module_config["plugin"]["methods"]["_order"]: if "options" in self._module_config["plugin"]["methods"][method].keys(): getattr(self._plugin, "{}".format(method))(self._plugin._parse_options_dict(self._module_config["plugin"]["methods"][method]["options"])) diff --git a/src/vai_lab/Modelling/plugins/affinitypropagation.py b/src/vai_lab/Modelling/plugins/affinitypropagation.py index 648a2091..d1c0d115 100644 --- a/src/vai_lab/Modelling/plugins/affinitypropagation.py +++ b/src/vai_lab/Modelling/plugins/affinitypropagation.py @@ -14,9 +14,20 @@ class AffinityPropagation(ModellingPluginT): Perform Affinity Propagation Clustering of data """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/bayesianridge.py b/src/vai_lab/Modelling/plugins/bayesianridge.py index c8c034f4..7853e1c6 100644 --- a/src/vai_lab/Modelling/plugins/bayesianridge.py +++ b/src/vai_lab/Modelling/plugins/bayesianridge.py @@ -13,10 +13,21 @@ class BayesianRidge(ModellingPluginT): """ Bayesian ridge regression """ - - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/birch.py b/src/vai_lab/Modelling/plugins/birch.py index 86325a30..dc0ac4f8 100644 --- a/src/vai_lab/Modelling/plugins/birch.py +++ b/src/vai_lab/Modelling/plugins/birch.py @@ -15,9 +15,20 @@ class Birch(ModellingPluginT): Implements the BIRCH clustering algorithm """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/decisiontreeclassifier.py b/src/vai_lab/Modelling/plugins/decisiontreeclassifier.py index 797de431..15c1f284 100644 --- a/src/vai_lab/Modelling/plugins/decisiontreeclassifier.py +++ b/src/vai_lab/Modelling/plugins/decisiontreeclassifier.py @@ -15,9 +15,22 @@ class DecisionTreeClassifier(ModellingPluginTClass): A decision tree classifier """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.predict_proba_plugin = self.model.predict_proba + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/decisiontreeregressor.py b/src/vai_lab/Modelling/plugins/decisiontreeregressor.py index 4665cd54..f5f8b705 100644 --- a/src/vai_lab/Modelling/plugins/decisiontreeregressor.py +++ b/src/vai_lab/Modelling/plugins/decisiontreeregressor.py @@ -15,9 +15,21 @@ class DecisionTreeRegressor(ModellingPluginT): A decision tree regressor """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/elasticnet.py b/src/vai_lab/Modelling/plugins/elasticnet.py index eabd33bf..c986b309 100644 --- a/src/vai_lab/Modelling/plugins/elasticnet.py +++ b/src/vai_lab/Modelling/plugins/elasticnet.py @@ -14,9 +14,21 @@ class ElasticNet(ModellingPluginT): Linear regression with combined L1 and L2 priors as regularizer """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/gpclassifier.py b/src/vai_lab/Modelling/plugins/gpclassifier.py index cefcf61a..a8b25126 100644 --- a/src/vai_lab/Modelling/plugins/gpclassifier.py +++ b/src/vai_lab/Modelling/plugins/gpclassifier.py @@ -17,9 +17,22 @@ class GPClassifier(ModellingPluginTClass): Gaussian process Classifier (GPC) based on Laplace approximation """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.predict_proba_plugin = self.model.predict_proba + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/gpregressor.py b/src/vai_lab/Modelling/plugins/gpregressor.py index add31a24..ee83e8a5 100644 --- a/src/vai_lab/Modelling/plugins/gpregressor.py +++ b/src/vai_lab/Modelling/plugins/gpregressor.py @@ -17,9 +17,21 @@ class GPRegressor(ModellingPluginT): Gaussian process regressor """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/kernelridge.py b/src/vai_lab/Modelling/plugins/kernelridge.py index fcac937a..864c6c39 100644 --- a/src/vai_lab/Modelling/plugins/kernelridge.py +++ b/src/vai_lab/Modelling/plugins/kernelridge.py @@ -17,9 +17,21 @@ class KernelRidge(ModellingPluginT): Kernel ridge regression. """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/kmeans.py b/src/vai_lab/Modelling/plugins/kmeans.py index 11e3e71e..0fa2a9f4 100644 --- a/src/vai_lab/Modelling/plugins/kmeans.py +++ b/src/vai_lab/Modelling/plugins/kmeans.py @@ -14,9 +14,21 @@ class KMeans(ModellingPluginT): K-Means clustering """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/knnclassifier.py b/src/vai_lab/Modelling/plugins/knnclassifier.py index 2c880e95..25fe692c 100644 --- a/src/vai_lab/Modelling/plugins/knnclassifier.py +++ b/src/vai_lab/Modelling/plugins/knnclassifier.py @@ -15,9 +15,22 @@ class KNNClassifier(ModellingPluginTClass): Classifier implementing the k-nearest neighbors vote """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.predict_proba_plugin = self.model.predict_proba + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/knnregressor.py b/src/vai_lab/Modelling/plugins/knnregressor.py index 64982701..7b9a5fc3 100644 --- a/src/vai_lab/Modelling/plugins/knnregressor.py +++ b/src/vai_lab/Modelling/plugins/knnregressor.py @@ -15,9 +15,21 @@ class KNNRegressor(ModellingPluginT): Regression based on k-nearest neighbors """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/lasso.py b/src/vai_lab/Modelling/plugins/lasso.py index bfb391b4..081f6d88 100644 --- a/src/vai_lab/Modelling/plugins/lasso.py +++ b/src/vai_lab/Modelling/plugins/lasso.py @@ -13,9 +13,21 @@ class Lasso(ModellingPluginT): Linear Model trained with L1 prior as regularizer """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/linearregression.py b/src/vai_lab/Modelling/plugins/linearregression.py index 25facd00..faee6278 100644 --- a/src/vai_lab/Modelling/plugins/linearregression.py +++ b/src/vai_lab/Modelling/plugins/linearregression.py @@ -15,9 +15,21 @@ class LinearRegression(ModellingPluginT): Ordinary least squares Linear Regression """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/logisticregression.py b/src/vai_lab/Modelling/plugins/logisticregression.py index 25eed6c2..6e4c0a17 100644 --- a/src/vai_lab/Modelling/plugins/logisticregression.py +++ b/src/vai_lab/Modelling/plugins/logisticregression.py @@ -16,9 +16,22 @@ class LogisticRegression(ModellingPluginTClass): Logistic regression classification. """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.predict_proba_plugin = self.model.predict_proba + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/meanshift.py b/src/vai_lab/Modelling/plugins/meanshift.py index 28d1327b..38f0bd9a 100644 --- a/src/vai_lab/Modelling/plugins/meanshift.py +++ b/src/vai_lab/Modelling/plugins/meanshift.py @@ -13,9 +13,20 @@ class MeanShift(ModellingPluginT): Mean shift clustering using a flat kernel. """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/passiveaggressiveclassifier.py b/src/vai_lab/Modelling/plugins/passiveaggressiveclassifier.py index dc01447a..64531891 100644 --- a/src/vai_lab/Modelling/plugins/passiveaggressiveclassifier.py +++ b/src/vai_lab/Modelling/plugins/passiveaggressiveclassifier.py @@ -15,9 +15,22 @@ class PassiveAggressiveClassifier(ModellingPluginTClass): Passive aggressive classifier """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.predict_proba_plugin = self.model.predict_proba + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/perceptron.py b/src/vai_lab/Modelling/plugins/perceptron.py index 93f35f40..69799653 100644 --- a/src/vai_lab/Modelling/plugins/perceptron.py +++ b/src/vai_lab/Modelling/plugins/perceptron.py @@ -16,9 +16,22 @@ class Perceptron(ModellingPluginTClass): Linear perceptron classification """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.predict_proba_plugin = self.model.predict_proba + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/randomforestclassifier.py b/src/vai_lab/Modelling/plugins/randomforestclassifier.py index a8dc60cd..4ac41571 100644 --- a/src/vai_lab/Modelling/plugins/randomforestclassifier.py +++ b/src/vai_lab/Modelling/plugins/randomforestclassifier.py @@ -16,9 +16,22 @@ class RandomForestClassifier(ModellingPluginTClass): A random forest classifier """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.predict_proba_plugin = self.model.predict_proba + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/randomforestregressor.py b/src/vai_lab/Modelling/plugins/randomforestregressor.py index 85cf9c10..116a80e5 100644 --- a/src/vai_lab/Modelling/plugins/randomforestregressor.py +++ b/src/vai_lab/Modelling/plugins/randomforestregressor.py @@ -16,9 +16,21 @@ class RandomForestRegressor(ModellingPluginT): A random forest regression """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/ridgeregression.py b/src/vai_lab/Modelling/plugins/ridgeregression.py index 0ee2f965..610d87ea 100644 --- a/src/vai_lab/Modelling/plugins/ridgeregression.py +++ b/src/vai_lab/Modelling/plugins/ridgeregression.py @@ -15,9 +15,21 @@ class RidgeRegression(ModellingPluginT): Linear least squares with l2 regularization """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/svc.py b/src/vai_lab/Modelling/plugins/svc.py index 7fd4d700..1b8f19a9 100644 --- a/src/vai_lab/Modelling/plugins/svc.py +++ b/src/vai_lab/Modelling/plugins/svc.py @@ -18,9 +18,22 @@ class SVC(ModellingPluginTClass): C-Support Vector Classification """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.predict_proba_plugin = self.model.predict_proba + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/svr.py b/src/vai_lab/Modelling/plugins/svr.py index 282fb622..f01ef1c9 100644 --- a/src/vai_lab/Modelling/plugins/svr.py +++ b/src/vai_lab/Modelling/plugins/svr.py @@ -18,9 +18,21 @@ class SVR(ModellingPluginT): Epsilon-Support Vector Regression """ - def __init__(self): + def __init__(self, config = {}, data_in = [None]): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - self.model = model() \ No newline at end of file + self.set_data_in(data_in) + self.configure(config) + + try: + self.model = model(**self._config["options"]) + except Exception as exc: + print('The plugin encountered an error on the parameters of ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') + raise + + self.fit_plugin = self.model.fit + self.predict_plugin = self.model.predict + self.score_plugin = self.model.score \ No newline at end of file diff --git a/src/vai_lab/_plugin_templates.py b/src/vai_lab/_plugin_templates.py index 437ff74c..f21e8184 100644 --- a/src/vai_lab/_plugin_templates.py +++ b/src/vai_lab/_plugin_templates.py @@ -209,30 +209,12 @@ def _clean_solver_options(self): _cleaned[key] = self.Y return _cleaned - def init(self): - """Sends params to model""" - try: - self.model.set_params(**self._config["options"]) - except Exception as exc: - print('The plugin encountered an error on the parameters of ' - +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') - raise - def fit(self, options={}): - try: - if type(self._clean_solver_options()) == list: - self.model.set_params(*self._clean_solver_options()) - else: - self.model.set_params(**self._clean_solver_options()) - except Exception as exc: - print('The plugin encountered an error on the parameters of ' - +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') - raise try: if type(options) == list: - return self.model.fit(*options) + return self.fit_plugin(*options) else: - return self.model.fit(**options) + return self.fit_plugin(**options) except Exception as exc: print('The plugin encountered an error when fitting ' +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') @@ -241,9 +223,9 @@ def fit(self, options={}): def transform(self, options={}) -> DataInterface: try: if type(options) == list: - return pd.DataFrame(self.model.transform(*options)) + return pd.DataFrame(self.transform_plugin(*options)) else: - return pd.DataFrame(self.model.transform(**options)) + return pd.DataFrame(self.transform_plugin(**options)) except Exception as exc: print('The plugin encountered an error when transforming the data with ' +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') @@ -254,23 +236,14 @@ def transform(self, options={}) -> DataInterface: class ModellingPluginT(PluginTemplate, ABC): def __init__(self, plugin_globals: dict) -> None: super().__init__(plugin_globals) - - def init(self): - """Sends params to model""" - try: - self.model.set_params(**self._config["options"]) - except Exception as exc: - print('The plugin encountered an error on the parameters of ' - +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') - raise def fit(self, options={}): """Sends params to fit, then runs fit""" try: if type(options) == list: - return self.model.fit(*options) + return self.fit_plugin(*options) else: - return self.model.fit(**options) + return self.fit_plugin(**options) except Exception as exc: print('The plugin encountered an error when fitting ' +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') @@ -286,9 +259,9 @@ def predict(self, options={}): """ try: if type(options) == list: - return self.model.predict(*options) + return self.predict_plugin(*options) else: - return self.model.predict(**options) + return self.predict_plugin(**options) except Exception as exc: print('The plugin encountered an error when predicting with ' +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+': '+str(exc)+'.') @@ -303,9 +276,9 @@ def score(self, options={}): """ try: if type(options) == list: - return self.model.score(*options) + return self.score_plugin(*options) else: - return self.model.score(**options) + return self.score_plugin(**options) except Exception as exc: print('The plugin encountered an error when calculating the score with ' +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+'.') @@ -325,9 +298,9 @@ def predict_proba(self, options={}): """ try: if type(options) == list: - return self.model.predict_proba(*options) + return self.predict_proba_plugin(*options) else: - return self.model.predict_proba(**options) + return self.predict_proba_plugin(**options) except Exception as exc: print('The plugin encountered an error when predicting the probability with ' +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+'.') diff --git a/src/vai_lab/examples/results/output.pkl b/src/vai_lab/examples/results/output.pkl index 37f85b48..bcb9c729 100644 Binary files a/src/vai_lab/examples/results/output.pkl and b/src/vai_lab/examples/results/output.pkl differ diff --git a/src/vai_lab/run_pipeline.py b/src/vai_lab/run_pipeline.py index a2c0537e..713995ad 100644 --- a/src/vai_lab/run_pipeline.py +++ b/src/vai_lab/run_pipeline.py @@ -56,6 +56,8 @@ def main(): for i in range(0,len(args.file)): args.file[i] = abspath(args.file[i]) core.load_config_file(args.file) + # core.load_config_file("./examples/xml_files/loop_demo.xml") + core.load_config_file("./examples/xml_files/random_forest_class_demo.xml") # Run pipeline core.run()