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

Wrapper for autoai_libs.nsfa transformer added #1329

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions lale/lib/autoai_libs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
* lale.lib.autoai_libs. `TGen`_
* lale.lib.autoai_libs. `FS1`_
* lale.lib.autoai_libs. `FS2`_
* lale.lib.autoai_libs. `NSFA`_

.. _`ColumnSelector`: lale.lib.autoai_libs.column_selector.html
.. _`NumpyColumnSelector`: lale.lib.autoai_libs.numpy_column_selector.html
Expand All @@ -88,6 +89,7 @@
.. _`TGen`: lale.lib.autoai_libs.tgen.html
.. _`FS1`: lale.lib.autoai_libs.fs1.html
.. _`FS2`: lale.lib.autoai_libs.fs2.html
.. _`NSFA`: lale.lib.autoai_libs.nsfa.html
"""

from lale import register_lale_wrapper_modules
Expand All @@ -102,6 +104,7 @@
from .float_str2_float import FloatStr2Float as FloatStr2Float
from .fs1 import FS1 as FS1
from .fs2 import FS2 as FS2
from .nsfa import NSFA as NSFA
from .num_imputer import NumImputer as NumImputer
from .numpy_column_selector import NumpyColumnSelector as NumpyColumnSelector
from .numpy_permute_array import NumpyPermuteArray as NumpyPermuteArray
Expand Down
127 changes: 127 additions & 0 deletions lale/lib/autoai_libs/nsfa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Copyright 2020 IBM Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import autoai_libs.cognito.transforms.transform_utils

import lale.docstrings
import lale.operators


class _NSFAImpl:
def __init__(self, **hyperparams):
self._wrapped_model = autoai_libs.cognito.transforms.transform_utils.NSFA(
**hyperparams
)

def fit(self, X, **fit_params):
self._wrapped_model.fit(X, **fit_params)
return self

def transform(self, X):
result = self._wrapped_model.transform(X)
return result
Comment on lines +21 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not look like this impl class is needed.
Instead, simply pass autoai_libs.cognito.transforms.transform_utils.NSF to the lale.operators.make_operator call on line 125



_hyperparams_schema = {
"allOf": [
{
"description": "This first object lists all constructor arguments with their types, but omits constraints for conditional hyperparameters.",
"type": "object",
"additionalProperties": False,
"required": [
"significance"
],
"relevantToOptimizer": [],
"properties": {
"significance": {
"description": "Array with a feature significance values for each column.",
"anyOf": [
{"type": "array", "items": {"type": "number", "minimum": 0.0}},
{"type": "array", "items": {"type": "integer", "minimum": 0}},
Comment on lines +50 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these are redundant. In JSON schema, integers are numbers. I would suggest removing the second line. If intent is to document that a common pattern is to provide specifically an array of integers, then it is reasonable to leave, although you may want a nested description string explaining.

{
"enum": [None],
"description": "Passing None will result in some failure to eliminate insignificant data.",
}
],
"default": None
},
"protected_cols": {
"description": "Array with indices of features that are protected by fairness definition.",
"anyOf": [
{"type": "array", "items": {"type": "integer", "minimum": 0}},
{"enum": [None]}
],
"default": None
},
"analyzer": {
"description": "A tool used to analyse insignificant columns.",
"laleType": "Any",
"default": None
}
},
}
]
}

_input_fit_schema = {
"type": "object",
"required": ["X"],
"additionalProperties": False,
"properties": {
"X": {
"type": "array",
"items": {"type": "array", "items": {"laleType": "Any"}}
}
}
}

_input_transform_schema = {
"type": "object",
"required": ["X"],
"additionalProperties": False,
"properties": {
"X": {
"type": "array",
"items": {"type": "array", "items": {"laleType": "Any"}}
}
}
}

_output_transform_schema = {
"description": "Features; the outer array is over samples.",
"type": "array",
"items": {"type": "array", "items": {"laleType": "Any"}}
}

_combined_schemas = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": """Operator from `autoai_libs`_. Feature transformation for dimension reduction by significance analysis.

.. _`autoai_libs`: https://pypi.org/project/autoai-libs""",
"documentation_url": "https://lale.readthedocs.io/en/latest/modules/lale.lib.autoai_libs.nsfa.html",
"import_from": "autoai_libs.cognito.transforms.transform_utils",
"type": "object",
"tags": {"pre": [], "op": ["transformer"], "post": []},
"properties": {
"hyperparams": _hyperparams_schema,
"input_fit": _input_fit_schema,
"input_transform": _input_transform_schema,
"output_transform": _output_transform_schema,
}
}


NSFA = lale.operators.make_operator(_NSFAImpl, _combined_schemas)

lale.docstrings.set_docstrings(NSFA)
Loading