From 2176ac62c04853b77ce168031ad2fbfef7cd08ff Mon Sep 17 00:00:00 2001 From: Carlos Sevilla Salcedo <22427519+sevisal@users.noreply.github.com> Date: Tue, 14 Nov 2023 12:17:45 +0100 Subject: [PATCH] Css fix plugin loading (#117) * Fixing issues with decission making modules * Remove plugins from incomplete branch * Added ini bolean to identify cases * Adapt to new plugin setting * Improve minor aesthetic XML info --- .../DataProcessing/plugins/binarizer.py | 27 ++++--- .../plugins/kbinsdiscretizer.py | 26 ++++--- .../DataProcessing/plugins/labelbinarizer.py | 26 ++++--- .../DataProcessing/plugins/labelencoder.py | 26 ++++--- .../DataProcessing/plugins/maxabsscaler.py | 26 ++++--- .../DataProcessing/plugins/minmaxscaler.py | 26 ++++--- .../plugins/multilabelbinarizer.py | 26 ++++--- .../DataProcessing/plugins/normalizer.py | 26 ++++--- .../DataProcessing/plugins/onehotencoder.py | 26 ++++--- .../DataProcessing/plugins/ordinalencoder.py | 26 ++++--- .../plugins/polynomialfeatures.py | 26 ++++--- .../plugins/quantiletransformer.py | 26 ++++--- .../DataProcessing/plugins/standardscaler.py | 26 ++++--- .../DecisionMaking/DecisionMaking_core.py | 2 - .../plugins/BayesianOptimisation(GPy).py | 72 ------------------- .../BayesianOptimisation(bayes_opt).py | 60 ---------------- .../Modelling/plugins/affinitypropagation.py | 26 ++++--- .../Modelling/plugins/bayesianridge.py | 26 ++++--- src/vai_lab/Modelling/plugins/birch.py | 26 ++++--- .../plugins/decisiontreeclassifier.py | 26 ++++--- .../plugins/decisiontreeregressor.py | 26 ++++--- src/vai_lab/Modelling/plugins/elasticnet.py | 26 ++++--- src/vai_lab/Modelling/plugins/gpclassifier.py | 26 ++++--- src/vai_lab/Modelling/plugins/gpregressor.py | 26 ++++--- src/vai_lab/Modelling/plugins/kernelridge.py | 26 ++++--- src/vai_lab/Modelling/plugins/kmeans.py | 26 ++++--- .../Modelling/plugins/knnclassifier.py | 26 ++++--- src/vai_lab/Modelling/plugins/knnregressor.py | 26 ++++--- src/vai_lab/Modelling/plugins/lasso.py | 26 ++++--- .../Modelling/plugins/linearregression.py | 26 ++++--- .../Modelling/plugins/logisticregression.py | 26 ++++--- src/vai_lab/Modelling/plugins/meanshift.py | 26 ++++--- .../plugins/passiveaggressiveclassifier.py | 26 ++++--- src/vai_lab/Modelling/plugins/perceptron.py | 26 ++++--- .../plugins/randomforestclassifier.py | 26 ++++--- .../plugins/randomforestregressor.py | 26 ++++--- .../Modelling/plugins/ridgeregression.py | 26 ++++--- src/vai_lab/Modelling/plugins/svc.py | 26 ++++--- src/vai_lab/Modelling/plugins/svr.py | 26 ++++--- src/vai_lab/_plugin_templates.py | 29 +++++--- .../xml_files/k-mean_clustering_demo.xml | 16 ++--- src/vai_lab/run_pipeline.py | 2 - src/vai_lab/utils/plugins/pluginCanvas.py | 7 +- 43 files changed, 573 insertions(+), 552 deletions(-) delete mode 100644 src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(GPy).py delete mode 100644 src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(bayes_opt).py diff --git a/src/vai_lab/DataProcessing/plugins/binarizer.py b/src/vai_lab/DataProcessing/plugins/binarizer.py index 4dab8267..73ce1b88 100644 --- a/src/vai_lab/DataProcessing/plugins/binarizer.py +++ b/src/vai_lab/DataProcessing/plugins/binarizer.py @@ -15,20 +15,25 @@ class Binarizer(DataProcessingT): Binarize data (set feature values to 0 or 1) according to a threshold """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + + # Method mapping 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 99aa302f..ffcce6a0 100644 --- a/src/vai_lab/DataProcessing/plugins/kbinsdiscretizer.py +++ b/src/vai_lab/DataProcessing/plugins/kbinsdiscretizer.py @@ -15,20 +15,24 @@ class KBinsDiscretizer(DataProcessingT): Bin continuous data into interval """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 f5c76520..df88bac6 100644 --- a/src/vai_lab/DataProcessing/plugins/labelbinarizer.py +++ b/src/vai_lab/DataProcessing/plugins/labelbinarizer.py @@ -13,20 +13,24 @@ class LabelBinarizer(DataProcessingT): """ Binarize labels in a one-vs-all fashion """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 a1dd209f..88e22aa3 100644 --- a/src/vai_lab/DataProcessing/plugins/labelencoder.py +++ b/src/vai_lab/DataProcessing/plugins/labelencoder.py @@ -14,20 +14,24 @@ class LabelEncoder(DataProcessingT): Encode target labels with value between 0 and n_classes-1 """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 c7664835..545d40cc 100644 --- a/src/vai_lab/DataProcessing/plugins/maxabsscaler.py +++ b/src/vai_lab/DataProcessing/plugins/maxabsscaler.py @@ -14,20 +14,24 @@ class MaxAbsScaler(DataProcessingT): Scale each feature by its maximum absolute value """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 1cdb349d..516c265e 100644 --- a/src/vai_lab/DataProcessing/plugins/minmaxscaler.py +++ b/src/vai_lab/DataProcessing/plugins/minmaxscaler.py @@ -15,20 +15,24 @@ class MinMaxScaler(DataProcessingT): is in the given range on the training set, e.g. between zero and one """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 5bbeaa06..cb1c4b9d 100644 --- a/src/vai_lab/DataProcessing/plugins/multilabelbinarizer.py +++ b/src/vai_lab/DataProcessing/plugins/multilabelbinarizer.py @@ -14,20 +14,24 @@ class MultiLabelBinarizer(DataProcessingT): Transform between iterable of iterables and a multilabel format """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 05812b33..9b517397 100644 --- a/src/vai_lab/DataProcessing/plugins/normalizer.py +++ b/src/vai_lab/DataProcessing/plugins/normalizer.py @@ -18,20 +18,24 @@ class Normalizer(DataProcessingT): Normalize samples individually to unit norm """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 44edd661..70b274be 100644 --- a/src/vai_lab/DataProcessing/plugins/onehotencoder.py +++ b/src/vai_lab/DataProcessing/plugins/onehotencoder.py @@ -14,20 +14,24 @@ class OneHotEncoder(DataProcessingT): Encode categorical features as a one-hot numeric array """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 7e48d568..206fb2cc 100644 --- a/src/vai_lab/DataProcessing/plugins/ordinalencoder.py +++ b/src/vai_lab/DataProcessing/plugins/ordinalencoder.py @@ -15,20 +15,24 @@ class OrdinalEncoder(DataProcessingT): Encode categorical features as an integer array """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 b1bcd423..93a467a4 100644 --- a/src/vai_lab/DataProcessing/plugins/polynomialfeatures.py +++ b/src/vai_lab/DataProcessing/plugins/polynomialfeatures.py @@ -18,20 +18,24 @@ class PolynomialFeatures(DataProcessingT): Generate polynomial and interaction features """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 306d4724..43118dc5 100644 --- a/src/vai_lab/DataProcessing/plugins/quantiletransformer.py +++ b/src/vai_lab/DataProcessing/plugins/quantiletransformer.py @@ -16,20 +16,24 @@ class QuantileTransformer(DataProcessingT): Transform features using quantiles information """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 029f49c5..1c8708d7 100644 --- a/src/vai_lab/DataProcessing/plugins/standardscaler.py +++ b/src/vai_lab/DataProcessing/plugins/standardscaler.py @@ -16,20 +16,24 @@ class StandardScaler(DataProcessingT): Standardize features by removing the mean and scaling to unit variance """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 a38ad013..0792744b 100644 --- a/src/vai_lab/DecisionMaking/DecisionMaking_core.py +++ b/src/vai_lab/DecisionMaking/DecisionMaking_core.py @@ -13,7 +13,6 @@ def set_data_in(self,data_in: DataInterface): def _load_plugin(self, data_in: DataInterface): 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"],\ @@ -28,7 +27,6 @@ def set_options(self, module_config: dict): self._module_config = module_config def launch(self): - 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"])) diff --git a/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(GPy).py b/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(GPy).py deleted file mode 100644 index 28cde0ef..00000000 --- a/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(GPy).py +++ /dev/null @@ -1,72 +0,0 @@ -from vai_lab._plugin_templates import DecisionMakingPluginT -from GPyOpt.methods import BayesianOptimization as model -from typing import Dict - -_PLUGIN_READABLE_NAMES = {"GPyOpt": "default", - "BayesianOptimisation": "alias", - "BayesianOptimisation_GPy": "alias",} # type:ignore -_PLUGIN_MODULE_OPTIONS = {"Type": "decision making"} # type:ignore -_PLUGIN_REQUIRED_SETTINGS = {"f": "function"} # type:ignore -_PLUGIN_OPTIONAL_SETTINGS = {"domain": "list", - "constraints": "list", - "acquisition_type ": "str", - "files": "list", - "normalize_Y": "bool", - "evaluator_type": "str", - "batch_size": "int", - "acquisition_jitter": "float"} # type:ignore -_PLUGIN_REQUIRED_DATA = {} # type:ignore -_PLUGIN_OPTIONAL_DATA = {"X","Y"} # type:ignore - -class GPyOpt(DecisionMakingPluginT): - """ - Bayesian optimisation model using GPyOpt. Compatible with no objective function using tabular data. - """ - - def __init__(self, config = {}, data_in = [None]): - """Initialises parent class. - Passes `globals` dict of all current variables - """ - super().__init__(globals()) - 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) - if self.X is not None: - options_dict['X'] = self.X - if self.Y is not None: - options_dict['Y'] = self.Y.reshape(-1,1) - return options_dict - - def optimise(self): - """Sends parameters to optimizer, then runs Bayesian Optimization for a number 'max_iter' of iterations""" - try: - self.BO.run_optimization() - except Exception as exc: - print('The plugin encountered an error when running the optimization ' - +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+'.') - raise - - def suggest_locations(self): - """Run a single optimization step and return the next locations to evaluate the objective. - Number of suggested locations equals to batch_size. - :returns: array, shape (n_samples,) - Returns suggested values. - """ - try: - return self.BO.suggest_next_locations() - except Exception as exc: - print('The plugin encountered an error when suggesting points with ' - +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+'.') - raise \ No newline at end of file diff --git a/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(bayes_opt).py b/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(bayes_opt).py deleted file mode 100644 index 105c8e9d..00000000 --- a/src/vai_lab/DecisionMaking/plugins/BayesianOptimisation(bayes_opt).py +++ /dev/null @@ -1,60 +0,0 @@ -from vai_lab._plugin_templates import DecisionMakingPluginT -from bayes_opt import BayesianOptimization as model - -_PLUGIN_READABLE_NAMES = {"bayes_opt": "default", - "BayesOpt": "alias",} # type:ignore -_PLUGIN_MODULE_OPTIONS = {"Type": "decision making"} # type:ignore -_PLUGIN_REQUIRED_SETTINGS = {"f": "function", - "pbounds": "dict"} # type:ignore -_PLUGIN_OPTIONAL_SETTINGS = { - # "constraint": "ConstraintModel", - "random_state ": "int", - "verbose": "bool", - # "bounds_transformer": "DomainTransformer", - "allow_duplicate_points": "str"} # type:ignore -_PLUGIN_REQUIRED_DATA = {} # type:ignore -_PLUGIN_OPTIONAL_DATA = {"X","Y"} # type:ignore - -class bayes_opt(DecisionMakingPluginT): - """ - Bayesian optimisation model using bayes_opt. - """ - - def __init__(self, config = {}, data_in = [None]): - """Initialises parent class. - Passes `globals` dict of all current variables - """ - super().__init__(globals()) - 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.""" - try: - self.BO.maximize() - except Exception as exc: - print('The plugin encountered an error when running the optimization ' - +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+'.') - raise - - def suggest_locations(self, utility_function): - """Run a single optimization step and return the next locations to evaluate the objective. - :returns: array, shape (n_samples,) - Returns suggested values. - """ - try: - return self.BO.suggest(utility_function) - except Exception as exc: - print('The plugin encountered an error when suggesting points with ' - +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+'.') - raise \ No newline at end of file diff --git a/src/vai_lab/Modelling/plugins/affinitypropagation.py b/src/vai_lab/Modelling/plugins/affinitypropagation.py index d1c0d115..21a7e906 100644 --- a/src/vai_lab/Modelling/plugins/affinitypropagation.py +++ b/src/vai_lab/Modelling/plugins/affinitypropagation.py @@ -14,20 +14,24 @@ class AffinityPropagation(ModellingPluginT): Perform Affinity Propagation Clustering of data """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 7853e1c6..69a4c094 100644 --- a/src/vai_lab/Modelling/plugins/bayesianridge.py +++ b/src/vai_lab/Modelling/plugins/bayesianridge.py @@ -13,21 +13,25 @@ class BayesianRidge(ModellingPluginT): """ Bayesian ridge regression """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 dc0ac4f8..a2b0b0f7 100644 --- a/src/vai_lab/Modelling/plugins/birch.py +++ b/src/vai_lab/Modelling/plugins/birch.py @@ -15,20 +15,24 @@ class Birch(ModellingPluginT): Implements the BIRCH clustering algorithm """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 15c1f284..f47dde08 100644 --- a/src/vai_lab/Modelling/plugins/decisiontreeclassifier.py +++ b/src/vai_lab/Modelling/plugins/decisiontreeclassifier.py @@ -15,21 +15,25 @@ class DecisionTreeClassifier(ModellingPluginTClass): A decision tree classifier """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + self.fit_plugin = self.model.fit self.predict_plugin = self.model.predict self.predict_proba_plugin = self.model.predict_proba diff --git a/src/vai_lab/Modelling/plugins/decisiontreeregressor.py b/src/vai_lab/Modelling/plugins/decisiontreeregressor.py index f5f8b705..75ec0572 100644 --- a/src/vai_lab/Modelling/plugins/decisiontreeregressor.py +++ b/src/vai_lab/Modelling/plugins/decisiontreeregressor.py @@ -15,21 +15,25 @@ class DecisionTreeRegressor(ModellingPluginT): A decision tree regressor """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 c986b309..2b93e67b 100644 --- a/src/vai_lab/Modelling/plugins/elasticnet.py +++ b/src/vai_lab/Modelling/plugins/elasticnet.py @@ -14,21 +14,25 @@ class ElasticNet(ModellingPluginT): Linear regression with combined L1 and L2 priors as regularizer """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 a8b25126..7a66253b 100644 --- a/src/vai_lab/Modelling/plugins/gpclassifier.py +++ b/src/vai_lab/Modelling/plugins/gpclassifier.py @@ -17,21 +17,25 @@ class GPClassifier(ModellingPluginTClass): Gaussian process Classifier (GPC) based on Laplace approximation """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + self.fit_plugin = self.model.fit self.predict_plugin = self.model.predict self.predict_proba_plugin = self.model.predict_proba diff --git a/src/vai_lab/Modelling/plugins/gpregressor.py b/src/vai_lab/Modelling/plugins/gpregressor.py index ee83e8a5..900a1638 100644 --- a/src/vai_lab/Modelling/plugins/gpregressor.py +++ b/src/vai_lab/Modelling/plugins/gpregressor.py @@ -17,21 +17,25 @@ class GPRegressor(ModellingPluginT): Gaussian process regressor """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 864c6c39..428f37b7 100644 --- a/src/vai_lab/Modelling/plugins/kernelridge.py +++ b/src/vai_lab/Modelling/plugins/kernelridge.py @@ -17,21 +17,25 @@ class KernelRidge(ModellingPluginT): Kernel ridge regression. """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 0fa2a9f4..5040757c 100644 --- a/src/vai_lab/Modelling/plugins/kmeans.py +++ b/src/vai_lab/Modelling/plugins/kmeans.py @@ -14,21 +14,25 @@ class KMeans(ModellingPluginT): K-Means clustering """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 25fe692c..f91450c5 100644 --- a/src/vai_lab/Modelling/plugins/knnclassifier.py +++ b/src/vai_lab/Modelling/plugins/knnclassifier.py @@ -15,21 +15,25 @@ class KNNClassifier(ModellingPluginTClass): Classifier implementing the k-nearest neighbors vote """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + self.fit_plugin = self.model.fit self.predict_plugin = self.model.predict self.predict_proba_plugin = self.model.predict_proba diff --git a/src/vai_lab/Modelling/plugins/knnregressor.py b/src/vai_lab/Modelling/plugins/knnregressor.py index 7b9a5fc3..cbf8abdf 100644 --- a/src/vai_lab/Modelling/plugins/knnregressor.py +++ b/src/vai_lab/Modelling/plugins/knnregressor.py @@ -15,21 +15,25 @@ class KNNRegressor(ModellingPluginT): Regression based on k-nearest neighbors """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 081f6d88..e8938cf6 100644 --- a/src/vai_lab/Modelling/plugins/lasso.py +++ b/src/vai_lab/Modelling/plugins/lasso.py @@ -13,21 +13,25 @@ class Lasso(ModellingPluginT): Linear Model trained with L1 prior as regularizer """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 faee6278..7ddbebd3 100644 --- a/src/vai_lab/Modelling/plugins/linearregression.py +++ b/src/vai_lab/Modelling/plugins/linearregression.py @@ -15,21 +15,25 @@ class LinearRegression(ModellingPluginT): Ordinary least squares Linear Regression """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 6e4c0a17..c7c0028e 100644 --- a/src/vai_lab/Modelling/plugins/logisticregression.py +++ b/src/vai_lab/Modelling/plugins/logisticregression.py @@ -16,21 +16,25 @@ class LogisticRegression(ModellingPluginTClass): Logistic regression classification. """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + self.fit_plugin = self.model.fit self.predict_plugin = self.model.predict self.predict_proba_plugin = self.model.predict_proba diff --git a/src/vai_lab/Modelling/plugins/meanshift.py b/src/vai_lab/Modelling/plugins/meanshift.py index 38f0bd9a..e035d0f5 100644 --- a/src/vai_lab/Modelling/plugins/meanshift.py +++ b/src/vai_lab/Modelling/plugins/meanshift.py @@ -13,20 +13,24 @@ class MeanShift(ModellingPluginT): Mean shift clustering using a flat kernel. """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 64531891..4be668ac 100644 --- a/src/vai_lab/Modelling/plugins/passiveaggressiveclassifier.py +++ b/src/vai_lab/Modelling/plugins/passiveaggressiveclassifier.py @@ -15,21 +15,25 @@ class PassiveAggressiveClassifier(ModellingPluginTClass): Passive aggressive classifier """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + self.fit_plugin = self.model.fit self.predict_plugin = self.model.predict self.predict_proba_plugin = self.model.predict_proba diff --git a/src/vai_lab/Modelling/plugins/perceptron.py b/src/vai_lab/Modelling/plugins/perceptron.py index 69799653..62f12252 100644 --- a/src/vai_lab/Modelling/plugins/perceptron.py +++ b/src/vai_lab/Modelling/plugins/perceptron.py @@ -16,21 +16,25 @@ class Perceptron(ModellingPluginTClass): Linear perceptron classification """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + self.fit_plugin = self.model.fit self.predict_plugin = self.model.predict self.predict_proba_plugin = self.model.predict_proba diff --git a/src/vai_lab/Modelling/plugins/randomforestclassifier.py b/src/vai_lab/Modelling/plugins/randomforestclassifier.py index 4ac41571..5baa27cd 100644 --- a/src/vai_lab/Modelling/plugins/randomforestclassifier.py +++ b/src/vai_lab/Modelling/plugins/randomforestclassifier.py @@ -16,21 +16,25 @@ class RandomForestClassifier(ModellingPluginTClass): A random forest classifier """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + self.fit_plugin = self.model.fit self.predict_plugin = self.model.predict self.predict_proba_plugin = self.model.predict_proba diff --git a/src/vai_lab/Modelling/plugins/randomforestregressor.py b/src/vai_lab/Modelling/plugins/randomforestregressor.py index 116a80e5..6aefbede 100644 --- a/src/vai_lab/Modelling/plugins/randomforestregressor.py +++ b/src/vai_lab/Modelling/plugins/randomforestregressor.py @@ -16,21 +16,25 @@ class RandomForestRegressor(ModellingPluginT): A random forest regression """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 610d87ea..b4ba0f7f 100644 --- a/src/vai_lab/Modelling/plugins/ridgeregression.py +++ b/src/vai_lab/Modelling/plugins/ridgeregression.py @@ -15,21 +15,25 @@ class RidgeRegression(ModellingPluginT): Linear least squares with l2 regularization """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 1b8f19a9..60336b8a 100644 --- a/src/vai_lab/Modelling/plugins/svc.py +++ b/src/vai_lab/Modelling/plugins/svc.py @@ -18,21 +18,25 @@ class SVC(ModellingPluginTClass): C-Support Vector Classification """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + self.fit_plugin = self.model.fit self.predict_plugin = self.model.predict self.predict_proba_plugin = self.model.predict_proba diff --git a/src/vai_lab/Modelling/plugins/svr.py b/src/vai_lab/Modelling/plugins/svr.py index f01ef1c9..265c0d1e 100644 --- a/src/vai_lab/Modelling/plugins/svr.py +++ b/src/vai_lab/Modelling/plugins/svr.py @@ -18,21 +18,25 @@ class SVR(ModellingPluginT): Epsilon-Support Vector Regression """ - def __init__(self, config = {}, data_in = [None]): + def __init__(self, config = {}, data_in = [None], ini = False): """Initialises parent class. Passes `globals` dict of all current variables """ super().__init__(globals()) - 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 - + if not ini: + # Model configuration + self.set_data_in(data_in) + self.configure(config) + # Model initialisation + 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 + else: + self.model = model + 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 d30b87f9..460c0343 100644 --- a/src/vai_lab/_plugin_templates.py +++ b/src/vai_lab/_plugin_templates.py @@ -324,19 +324,30 @@ def __init__(self, plugin_globals: dict) -> None: def configure(self, config: dict): """Extended from PluginTemplate.configure""" super().configure(config) + if type(self.X) is None and type(self.Y) is None: + print('Invalid Data name. Indicate whether to use `X` or `Y`') + + def run_optimization(self): + """Sends parameters to optimizer, then runs Bayesian Optimization for a number 'max_iter' of iterations""" try: - if isinstance(self._clean_options(), list): - self.BO = self.model(*self._clean_options()) - if isinstance(self._clean_options(), list): - self.BO = self.model(**self._clean_options()) - else: - self.BO = self.model(self._clean_options()) + self.opt_plugin() except Exception as exc: - print('The plugin encountered an error on the parameters of ' + print('The plugin encountered an error when running the optimization ' + +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+'.') + raise + + def suggest_next_locations(self): + """Run a single optimization step and return the next locations to evaluate the objective. + Number of suggested locations equals to batch_size. + :returns: array, shape (n_samples,) + Returns suggested values. + """ + try: + return self.suggest_plugin() + except Exception as exc: + print('The plugin encountered an error when suggesting points with ' +str(list(self._PLUGIN_READABLE_NAMES.keys())[list(self._PLUGIN_READABLE_NAMES.values()).index('default')])+'.') raise - if type(self.X) is None and type(self.Y) is None: - print('Invalid Data name. Indicate whether to use `X` or `Y`') class UI(PluginTemplate, ABC): diff --git a/src/vai_lab/examples/xml_files/k-mean_clustering_demo.xml b/src/vai_lab/examples/xml_files/k-mean_clustering_demo.xml index 1c7ff0b8..adc42c95 100644 --- a/src/vai_lab/examples/xml_files/k-mean_clustering_demo.xml +++ b/src/vai_lab/examples/xml_files/k-mean_clustering_demo.xml @@ -25,20 +25,20 @@ - (0, 1) + (0, 1) - X + X - X + X @@ -58,23 +58,23 @@ - 4 + 4 - 500 + 500 - X + X - X + X @@ -96,7 +96,7 @@ Modelling - .\examples\results\output.pkl + .\examples\results\output.pkl diff --git a/src/vai_lab/run_pipeline.py b/src/vai_lab/run_pipeline.py index a2c0537e..88ec1319 100644 --- a/src/vai_lab/run_pipeline.py +++ b/src/vai_lab/run_pipeline.py @@ -8,7 +8,6 @@ import vai_lab as ai - def parse_args(): """ Parse command line arguments @@ -42,7 +41,6 @@ def _config_files_iter(core,files): core.load_config_file(abspath(f)) core.run() - def main(): # Parse command line arguments diff --git a/src/vai_lab/utils/plugins/pluginCanvas.py b/src/vai_lab/utils/plugins/pluginCanvas.py index 62dd8e54..c63e5950 100644 --- a/src/vai_lab/utils/plugins/pluginCanvas.py +++ b/src/vai_lab/utils/plugins/pluginCanvas.py @@ -505,7 +505,7 @@ def optionsWindow(self): self.opt_settings = {'__init__': ps.optional_settings[module][self.plugin[self.m].get()]} # Tries to upload the settings from the actual library try: - self.model = plugin().model + self.model = plugin(ini = True).model meth_req, meth_opt = self.getArgs(self.model.__init__) if meth_req is not None: self.req_settings['__init__'] = {**self.req_settings['__init__'], **meth_req} @@ -515,6 +515,7 @@ def optionsWindow(self): plugin_meth_list = [meth[0] for meth in getmembers(plugin, isfunction) if meth[0][0] != '_'] # Find available methods for the model model_meth_list = [meth[0] for meth in getmembers(self.model, ismethod) if meth[0][0] != '_'] + model_meth_list += [meth[0] for meth in getmembers(self.model, isfunction) if meth[0][0] != '_'] # List intersection # TODO: use only methods from the model set_2 = frozenset(model_meth_list) @@ -1096,7 +1097,7 @@ def upload(self): arrow = tk.LAST, arrowshape = (12,10,5), tags=('o'+str(parent_id), 'o'+str(1), modout['coordinates'][2][connect[p]])) - self.out_data.iloc[int(parent_id)][1] = 1 + self.out_data.iloc[int(parent_id)].iloc[1] = 1 self.connections[1][ int(parent_id)] = out[0]+str(parent_id) + '-' + ins[0]+str(1) self.m: int = self.id_mod[2] @@ -1206,7 +1207,7 @@ def draw_connection(self, modules): tags = ('o'+str(parent_id), # 'o'+str(self.id_mod[-1]), modules[key]['coordinates'][2][connect[p]])) - self.out_data.iloc[int(parent_id)][int(ins[1:])] = 1 + self.out_data.iloc[int(parent_id)].iloc[int(ins[1:])] = 1 self.connections[int(ins[1:])][ int(parent_id)] = out[0]+str(out[1:]) + '-' + ins[0]+str(ins[1:]) else: