Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change plugin templates #116

Merged
merged 7 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/vai_lab/Core/vai_lab_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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")
14 changes: 6 additions & 8 deletions src/vai_lab/DataProcessing/DataProcessing_core.py
sevisal marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,25 @@ 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

: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"]))
Expand Down
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/binarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/kbinsdiscretizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/labelbinarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/labelencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/maxabsscaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/minmaxscaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/multilabelbinarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/onehotencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/ordinalencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/polynomialfeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/quantiletransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
15 changes: 13 additions & 2 deletions src/vai_lab/DataProcessing/plugins/standardscaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
Loading
Loading