Skip to content

init_model_param

init_model_param

Classes

InitParam (BaseParam)

Initialize Parameters used in initializing a model.

Parameters:

Name Type Description Default
init_method {'random_uniform', 'random_normal', 'ones', 'zeros' or 'const'}

Initial method.

'random_uniform'
init_const int or float, default: 1

Required when init_method is 'const'. Specify the constant.

1
fit_intercept bool, default: True

Whether to initialize the intercept or not.

True
Source code in federatedml/param/init_model_param.py
class InitParam(BaseParam):
    """
    Initialize Parameters used in initializing a model.

    Parameters
    ----------
    init_method : {'random_uniform', 'random_normal', 'ones', 'zeros' or 'const'}
        Initial method.

    init_const : int or float, default: 1
        Required when init_method is 'const'. Specify the constant.

    fit_intercept : bool, default: True
        Whether to initialize the intercept or not.

    """

    def __init__(self, init_method='random_uniform', init_const=1, fit_intercept=True, random_seed=None):
        super().__init__()
        self.init_method = init_method
        self.init_const = init_const
        self.fit_intercept = fit_intercept
        self.random_seed = random_seed

    def check(self):
        if type(self.init_method).__name__ != "str":
            raise ValueError(
                "Init param's init_method {} not supported, should be str type".format(self.init_method))
        else:
            self.init_method = self.init_method.lower()
            if self.init_method not in ['random_uniform', 'random_normal', 'ones', 'zeros', 'const']:
                raise ValueError(
                    "Init param's init_method {} not supported, init_method should in 'random_uniform',"
                    " 'random_normal' 'ones', 'zeros' or 'const'".format(self.init_method))

        if type(self.init_const).__name__ not in ['int', 'float']:
            raise ValueError(
                "Init param's init_const {} not supported, should be int or float type".format(self.init_const))

        if type(self.fit_intercept).__name__ != 'bool':
            raise ValueError(
                "Init param's fit_intercept {} not supported, should be bool type".format(self.fit_intercept))

        if self.random_seed is not None:
            if type(self.random_seed).__name__ != 'int':
                raise ValueError(
                    "Init param's random_seed {} not supported, should be int or float type".format(self.random_seed))

        return True
__init__(self, init_method='random_uniform', init_const=1, fit_intercept=True, random_seed=None) special
Source code in federatedml/param/init_model_param.py
def __init__(self, init_method='random_uniform', init_const=1, fit_intercept=True, random_seed=None):
    super().__init__()
    self.init_method = init_method
    self.init_const = init_const
    self.fit_intercept = fit_intercept
    self.random_seed = random_seed
check(self)
Source code in federatedml/param/init_model_param.py
def check(self):
    if type(self.init_method).__name__ != "str":
        raise ValueError(
            "Init param's init_method {} not supported, should be str type".format(self.init_method))
    else:
        self.init_method = self.init_method.lower()
        if self.init_method not in ['random_uniform', 'random_normal', 'ones', 'zeros', 'const']:
            raise ValueError(
                "Init param's init_method {} not supported, init_method should in 'random_uniform',"
                " 'random_normal' 'ones', 'zeros' or 'const'".format(self.init_method))

    if type(self.init_const).__name__ not in ['int', 'float']:
        raise ValueError(
            "Init param's init_const {} not supported, should be int or float type".format(self.init_const))

    if type(self.fit_intercept).__name__ != 'bool':
        raise ValueError(
            "Init param's fit_intercept {} not supported, should be bool type".format(self.fit_intercept))

    if self.random_seed is not None:
        if type(self.random_seed).__name__ != 'int':
            raise ValueError(
                "Init param's random_seed {} not supported, should be int or float type".format(self.random_seed))

    return True

Last update: 2021-12-03
Back to top