|
| 1 | +# ------------------------------------------------------------- |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | +# |
| 20 | +# ------------------------------------------------------------- |
| 21 | + |
| 22 | +# Autogenerated By : src/main/python/generator/generator.py |
| 23 | +# Autogenerated From : scripts/builtin/adasyn.dml |
| 24 | + |
| 25 | +from typing import Dict, Iterable |
| 26 | + |
| 27 | +from systemds.operator import OperationNode, Matrix, Frame, List, MultiReturn, Scalar |
| 28 | +from systemds.utils.consts import VALID_INPUT_TYPES |
| 29 | + |
| 30 | + |
| 31 | +def adasyn(X: Matrix, |
| 32 | + Y: Matrix, |
| 33 | + **kwargs: Dict[str, VALID_INPUT_TYPES]): |
| 34 | + """ |
| 35 | + Builtin function for handing class imbalance using Adaptive Synthetic Sampling (ADASYN) |
| 36 | + by Haibo He et. al. In International Joint Conference on Neural Networks (2008). 1322-1328 |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + :param X: Feature matrix [shape: n-by-m] |
| 41 | + :param Y: Class labels [shape: n-by-1] |
| 42 | + :param k: Number of nearest neighbors |
| 43 | + :param beta: Desired balance level after generation of synthetic data [0, 1] |
| 44 | + :param dth: Distribution threshold |
| 45 | + :param seed: Seed for randomized data point selection |
| 46 | + :return: Feature matrix of n original rows followed by G = (ml-ms)*beta synthetic rows |
| 47 | + :return: Class labels aligned with output X |
| 48 | + """ |
| 49 | + |
| 50 | + params_dict = {'X': X, 'Y': Y} |
| 51 | + params_dict.update(kwargs) |
| 52 | + |
| 53 | + vX_0 = Matrix(X.sds_context, '') |
| 54 | + vX_1 = Matrix(X.sds_context, '') |
| 55 | + output_nodes = [vX_0, vX_1, ] |
| 56 | + |
| 57 | + op = MultiReturn(X.sds_context, 'adasyn', output_nodes, named_input_nodes=params_dict) |
| 58 | + |
| 59 | + vX_0._unnamed_input_nodes = [op] |
| 60 | + vX_1._unnamed_input_nodes = [op] |
| 61 | + |
| 62 | + return op |
0 commit comments