<commit_before>from abc import abstractmethod

from neupy.utils import preformat_value
from neupy.helpers.logs import Verbose
from .config import ConfigurableABC


__all__ = ('BaseSkeleton',)


class BaseSkeleton(ConfigurableABC, Verbose):
    """
    Base class for neural network algorithms.

    Methods
    -------
    fit(\*args, \*\*kwargs)
        Alias to the ``train`` method.

    predict(input_data)
        Predicts output for the specified input.
    """
    def get_params(self, deep=False):
        options = {}
        for property_name, option in self.options.items():
            value = getattr(self, property_name)
            property_ = option.value

            # Options that have choices contains values that would
            # be invalid after parameter initialization
            is_choices_option = hasattr(option.value, 'choices')
            if is_choices_option and value in property_.choices.values():
                choices = {v: k for k, v in property_.choices.items()}
                value = choices[value]

            # Default value is not always valid type. For this reason we
            # need to ignore all the values that have the same value as
            # in default attibute.
            if value != property_.default:
                options[property_name] = value

        return options

    def set_params(self, **params):
        self.__dict__.update(params)
        return self
<commit_msg>fixed `get_params` for parameters that can contain numpy arrays<commit_after>from abc import abstractmethod

import numpy as np

from neupy.utils import preformat_value
from neupy.helpers.logs import Verbose
from .config import ConfigurableABC


__all__ = ('BaseSkeleton',)


class BaseSkeleton(ConfigurableABC, Verbose):
    """
    Base class for neural network algorithms.

    Methods
    -------
    fit(\*args, \*\*kwargs)
        Alias to the ``train`` method.

    predict(input_data)
        Predicts output for the specified input.
    """
    def get_params(self, deep=False):
        options = {}
        for property_name, option in self.options.items():
            value = getattr(self, property_name)
            property_ = option.value
            is_numpy_array = isinstance(value, np.ndarray)

            # Options that have choices contains values that would
            # be invalid after parameter initialization
            if hasattr(option.value, 'choices'):
                choices = property_.choices

                if not is_numpy_array and value in choices.values():
                    choices = {v: k for k, v in choices.items()}
                    value = choices[value]

            # Default value is not always valid type. For this reason we
            # need to ignore all the values that have the same value as
            # in default attibute.
            if is_numpy_array or value != property_.default:
                options[property_name] = value

        return options

    def set_params(self, **params):
        self.__dict__.update(params)
        return self

{'fraction_non_alphanumeric': 0.07807905913100294, 'fraction_numerical': 0.0, 'mean_word_length': 2.202928870292887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6770349', 'n_tokens_mistral': 806, 'n_tokens_neox': 775, 'n_words': 274}