Skip to content

Commit

Permalink
Change plugin templates (#116)
Browse files Browse the repository at this point in the history
* Change plugin templates

* Remove test

* Fix issue with environment modules

* Add datatype and remove innecesary variables

* Add default type

* Fix warning

* Fixed minor warning issues
  • Loading branch information
sevisal authored Oct 24, 2023
1 parent 425a4e2 commit 7e582b5
Show file tree
Hide file tree
Showing 50 changed files with 634 additions and 190 deletions.
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")
22 changes: 11 additions & 11 deletions src/vai_lab/DataProcessing/DataProcessing_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from vai_lab._import_helper import import_plugin_absolute
from vai_lab._types import PluginSpecsInterface, DataInterface, DataProcessingPluginInterface

from pandas import DataFrame
from numpy import array
class DataProcessing(object):
def __init__(self) -> None:
self.output_data: DataInterface
Expand All @@ -11,34 +12,33 @@ 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: DataInterface) -> None:
avail_plugins = self._avail_plugins.find_from_readable_name(
plugin_name)
self._plugin_name = 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"]))
out = getattr(self._plugin, "{}".format(method))(self._plugin._parse_options_dict(self._module_config["plugin"]["methods"][method]["options"]))
else:
getattr(self._plugin, "{}".format(method))()
out = getattr(self._plugin, "{}".format(method))()

self.output_data = self._data_in.copy()
if len(out) > 0 and (isinstance(out[0], DataFrame) or isinstance(out[0], array)):
self.output_data.data[list(out[1])[0]] = out[0]

def get_result(self) -> DataInterface:
return self.output_data
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

0 comments on commit 7e582b5

Please sign in to comment.