Skip to content

遗传编码器

代码来自 https://github.com/EpistasisLab/autoqtl 该文件包含所有遗传编码器的类定义。 所有遗传编码器类都继承自Scikit learn的BaseEstimator和TransformerMixin类,以遵循Scikit-learn的范式。

DominantEncoder

基类:BaseEstimator, TransformerMixin

该类包含用于将输入特征编码为显性遗传模型的函数定义。 使用的编码是 AA(0)->1, Aa(1)->1, aa(2)->0。

Source code in tpot2/builtin_modules/genetic_encoders.py
class DominantEncoder(BaseEstimator, TransformerMixin):
    """This class contains the function definition for encoding the input features as a Dominant genetic model.
    The encoding used is AA(0)->1, Aa(1)->1, aa(2)->0. """

    def fit(self, X, y=None):
        """Do nothing and return the estimator unchanged.
        Dummy function to fit in with the sklearn API and hence work in pipelines.

        Parameters
        ----------
        X : array-like
        """
        return self

    def transform(self, X, y=None):
        """Transform the data by applying the Dominant encoding.

        Parameters
        ----------
        X : numpy ndarray, {n_samples, n_components}
            New data, where n_samples is the number of samples (number of individuals)
            and n_components is the number of components (number of features).
        y : None
            Unused

        Returns
        -------
        X_transformed: numpy ndarray, {n_samples, n_components}
            The encoded feature set
        """
        X = check_array(X)
        map = {0: 1, 1: 1, 2: 0}
        mapping_function = np.vectorize(lambda i: map[i] if i in map else i)

        X_transformed = mapping_function(X)

        return X_transformed

fit(X, y=None)

什么都不做并返回未更改的估计器。 这是一个虚拟函数,用于适应sklearn API,从而在管道中工作。

参数:

名称 类型 描述 默认值
X array - like
必填
Source code in tpot2/builtin_modules/genetic_encoders.py
def fit(self, X, y=None):
    """什么都不做并返回未更改的估计器。
    这是一个虚拟函数,用于适应sklearn API,从而在管道中工作。

    参数
    ----------
    X : 类数组
    """
    return self

transform(X, y=None)

通过应用Dominant编码来转换数据。

参数:

名称 类型 描述 默认值
X numpy ndarray, {n_samples, n_components}

新数据,其中 n_samples 是样本数量(个体数量),n_components 是组件数量(特征数量)。

required
y None

未使用

None

返回:

名称 类型 描述
X_transformed numpy ndarray, {n_samples, n_components}

编码后的特征集

Source code in tpot2/builtin_modules/genetic_encoders.py
def transform(self, X, y=None):
    """Transform the data by applying the Dominant encoding.

    Parameters
    ----------
    X : numpy ndarray, {n_samples, n_components}
        New data, where n_samples is the number of samples (number of individuals)
        and n_components is the number of components (number of features).
    y : None
        Unused

    Returns
    -------
    X_transformed: numpy ndarray, {n_samples, n_components}
        The encoded feature set
    """
    X = check_array(X)
    map = {0: 1, 1: 1, 2: 0}
    mapping_function = np.vectorize(lambda i: map[i] if i in map else i)

    X_transformed = mapping_function(X)

    return X_transformed

HeterosisEncoder

基类:BaseEstimator, TransformerMixin

该类包含将输入特征编码为杂合子优势遗传模型的函数定义。 使用的编码是AA(0)->0, Aa(1)->1, aa(2)->0。

Source code in tpot2/builtin_modules/genetic_encoders.py
class HeterosisEncoder(BaseEstimator, TransformerMixin):
    """This class contains the function definition for encoding the input features as a Heterozygote Advantage genetic model.
    The encoding used is AA(0)->0, Aa(1)->1, aa(2)->0. """

    def fit(self, X, y=None):
        """Do nothing and return the estimator unchanged.
        Dummy function to fit in with the sklearn API and hence work in pipelines.

        Parameters
        ----------
        X : array-like
        """
        return self

    def transform(self, X, y=None):
        """Transform the data by applying the Heterosis encoding.

        Parameters
        ----------
        X : numpy ndarray, {n_samples, n_components}
            New data, where n_samples is the number of samples (number of individuals)
            and n_components is the number of components (number of features).
        y : None
            Unused

        Returns
        -------
        X_transformed: numpy ndarray, {n_samples, n_components}
            The encoded feature set
        """
        X = check_array(X)
        map = {0: 0, 1: 1, 2: 0}
        mapping_function = np.vectorize(lambda i: map[i] if i in map else i)

        X_transformed = mapping_function(X)

        return X_transformed

fit(X, y=None)

什么都不做并返回未更改的估计器。 这是一个虚拟函数,用于适应sklearn API,从而在管道中工作。

参数:

名称 类型 描述 默认值
X array - like
必填
Source code in tpot2/builtin_modules/genetic_encoders.py
def fit(self, X, y=None):
    """什么都不做并返回未更改的估计器。
    这是一个虚拟函数,用于适应sklearn API,从而在管道中工作。

    参数
    ----------
    X : 类数组
    """
    return self

transform(X, y=None)

通过应用杂种优势编码来转换数据。

参数:

名称 类型 描述 默认值
X numpy ndarray, {n_samples, n_components}

新数据,其中 n_samples 是样本数量(个体数量),n_components 是组件数量(特征数量)。

required
y None

未使用

None

返回:

名称 类型 描述
X_transformed numpy ndarray, {n_samples, n_components}

编码后的特征集

Source code in tpot2/builtin_modules/genetic_encoders.py
def transform(self, X, y=None):
    """Transform the data by applying the Heterosis encoding.

    Parameters
    ----------
    X : numpy ndarray, {n_samples, n_components}
        New data, where n_samples is the number of samples (number of individuals)
        and n_components is the number of components (number of features).
    y : None
        Unused

    Returns
    -------
    X_transformed: numpy ndarray, {n_samples, n_components}
        The encoded feature set
    """
    X = check_array(X)
    map = {0: 0, 1: 1, 2: 0}
    mapping_function = np.vectorize(lambda i: map[i] if i in map else i)

    X_transformed = mapping_function(X)

    return X_transformed

OverDominanceEncoder

基类:BaseEstimator, TransformerMixin

该类包含用于将输入特征编码为超显性遗传模型的函数定义。 使用的编码是 AA(0)->1, Aa(1)->2, aa(2)->0。

Source code in tpot2/builtin_modules/genetic_encoders.py
class OverDominanceEncoder(BaseEstimator, TransformerMixin):
    """This class contains the function definition for encoding the input features as a Over Dominance genetic model.
    The encoding used is AA(0)->1, Aa(1)->2, aa(2)->0. """

    def fit(self, X, y=None):
        """Do nothing and return the estimator unchanged.
        Dummy function to fit in with the sklearn API and hence work in pipelines.

        Parameters
        ----------
        X : array-like
        """
        return self

    def transform(self, X, y=None):
        """Transform the data by applying the Heterosis encoding.

        Parameters
        ----------
        X : numpy ndarray, {n_samples, n_components}
            New data, where n_samples is the number of samples (number of individuals)
            and n_components is the number of components (number of features).
        y : None
            Unused

        Returns
        -------
        X_transformed: numpy ndarray, {n_samples, n_components}
            The encoded feature set
        """
        X = check_array(X)
        map = {0: 1, 1: 2, 2: 0}
        mapping_function = np.vectorize(lambda i: map[i] if i in map else i)

        X_transformed = mapping_function(X)

        return X_transformed

fit(X, y=None)

什么都不做并返回未更改的估计器。 这是一个虚拟函数,用于适应sklearn API,从而在管道中工作。

参数:

名称 类型 描述 默认值
X array - like
必填
Source code in tpot2/builtin_modules/genetic_encoders.py
def fit(self, X, y=None):
    """什么都不做并返回未更改的估计器。
    这是一个虚拟函数,用于适应sklearn API,从而在管道中工作。

    参数
    ----------
    X : 类数组
    """
    return self

transform(X, y=None)

通过应用杂种优势编码来转换数据。

参数:

名称 类型 描述 默认值
X numpy ndarray, {n_samples, n_components}

新数据,其中 n_samples 是样本数量(个体数量),n_components 是组件数量(特征数量)。

required
y None

未使用

None

返回:

名称 类型 描述
X_transformed numpy ndarray, {n_samples, n_components}

编码后的特征集

Source code in tpot2/builtin_modules/genetic_encoders.py
def transform(self, X, y=None):
    """Transform the data by applying the Heterosis encoding.

    Parameters
    ----------
    X : numpy ndarray, {n_samples, n_components}
        New data, where n_samples is the number of samples (number of individuals)
        and n_components is the number of components (number of features).
    y : None
        Unused

    Returns
    -------
    X_transformed: numpy ndarray, {n_samples, n_components}
        The encoded feature set
    """
    X = check_array(X)
    map = {0: 1, 1: 2, 2: 0}
    mapping_function = np.vectorize(lambda i: map[i] if i in map else i)

    X_transformed = mapping_function(X)

    return X_transformed

RecessiveEncoder

基类:BaseEstimator, TransformerMixin

该类包含将输入特征编码为隐性遗传模型的函数定义。 使用的编码是 AA(0)->0, Aa(1)->1, aa(2)->1。

Source code in tpot2/builtin_modules/genetic_encoders.py
class RecessiveEncoder(BaseEstimator, TransformerMixin):
    """This class contains the function definition for encoding the input features as a Recessive genetic model.
    The encoding used is AA(0)->0, Aa(1)->1, aa(2)->1. """

    def fit(self, X, y=None):
        """Do nothing and return the estimator unchanged.
        Dummy function to fit in with the sklearn API and hence work in pipelines.

        Parameters
        ----------
        X : array-like
        """
        return self

    def transform(self, X, y=None):
        """Transform the data by applying the Recessive encoding.

        Parameters
        ----------
        X : numpy ndarray, {n_samples, n_components}
            New data, where n_samples is the number of samples (number of individuals)
            and n_components is the number of components (number of features).
        y : None
            Unused

        Returns
        -------
        X_transformed: numpy ndarray, {n_samples, n_components}
            The encoded feature set
        """
        X = check_array(X)
        map = {0: 0, 1: 1, 2: 1}
        mapping_function = np.vectorize(lambda i: map[i] if i in map else i)

        X_transformed = mapping_function(X)

        return X_transformed

fit(X, y=None)

什么都不做并返回未更改的估计器。 这是一个虚拟函数,用于适应sklearn API,从而在管道中工作。

参数:

名称 类型 描述 默认值
X array - like
必填
Source code in tpot2/builtin_modules/genetic_encoders.py
def fit(self, X, y=None):
    """什么都不做并返回未更改的估计器。
    这是一个虚拟函数,用于适应sklearn API,从而在管道中工作。

    参数
    ----------
    X : 类数组
    """
    return self

transform(X, y=None)

通过应用隐性编码来转换数据。

参数:

名称 类型 描述 默认值
X numpy ndarray, {n_samples, n_components}

新数据,其中 n_samples 是样本数量(个体数量),n_components 是组件数量(特征数量)。

required
y None

未使用

None

返回:

名称 类型 描述
X_transformed numpy ndarray, {n_samples, n_components}

编码后的特征集

Source code in tpot2/builtin_modules/genetic_encoders.py
def transform(self, X, y=None):
    """Transform the data by applying the Recessive encoding.

    Parameters
    ----------
    X : numpy ndarray, {n_samples, n_components}
        New data, where n_samples is the number of samples (number of individuals)
        and n_components is the number of components (number of features).
    y : None
        Unused

    Returns
    -------
    X_transformed: numpy ndarray, {n_samples, n_components}
        The encoded feature set
    """
    X = check_array(X)
    map = {0: 0, 1: 1, 2: 1}
    mapping_function = np.vectorize(lambda i: map[i] if i in map else i)

    X_transformed = mapping_function(X)

    return X_transformed

UnderDominanceEncoder

基类:BaseEstimator, TransformerMixin

该类包含用于将输入特征编码为Under Dominance遗传模型的函数定义。 使用的编码是AA(0)->2, Aa(1)->0, aa(2)->1。

Source code in tpot2/builtin_modules/genetic_encoders.py
class UnderDominanceEncoder(BaseEstimator, TransformerMixin):
    """This class contains the function definition for encoding the input features as a Under Dominance genetic model.
    The encoding used is AA(0)->2, Aa(1)->0, aa(2)->1. """

    def fit(self, X, y=None):
        """Do nothing and return the estimator unchanged.
        Dummy function to fit in with the sklearn API and hence work in pipelines.

        Parameters
        ----------
        X : array-like
        """
        return self

    def transform(self, X, y=None):
        """Transform the data by applying the Heterosis encoding.

        Parameters
        ----------
        X : numpy ndarray, {n_samples, n_components}
            New data, where n_samples is the number of samples (number of individuals)
            and n_components is the number of components (number of features).
        y : None
            Unused

        Returns
        -------
        X_transformed: numpy ndarray, {n_samples, n_components}
            The encoded feature set
        """
        X = check_array(X)
        map = {0: 2, 1: 0, 2: 1}
        mapping_function = np.vectorize(lambda i: map[i] if i in map else i)

        X_transformed = mapping_function(X)

        return X_transformed

fit(X, y=None)

什么都不做并返回未更改的估计器。 这是一个虚拟函数,用于适应sklearn API,从而在管道中工作。

参数:

名称 类型 描述 默认值
X array - like
必填
Source code in tpot2/builtin_modules/genetic_encoders.py
def fit(self, X, y=None):
    """什么都不做并返回未更改的估计器。
    这是一个虚拟函数,用于适应sklearn API,从而在管道中工作。

    参数
    ----------
    X : array-like
    """
    return self

transform(X, y=None)

通过应用杂种优势编码来转换数据。

参数:

名称 类型 描述 默认值
X numpy ndarray, {n_samples, n_components}

新数据,其中 n_samples 是样本数量(个体数量),n_components 是组件数量(特征数量)。

required
y None

未使用

None

返回:

名称 类型 描述
X_transformed numpy ndarray, {n_samples, n_components}

编码后的特征集

Source code in tpot2/builtin_modules/genetic_encoders.py
def transform(self, X, y=None):
    """Transform the data by applying the Heterosis encoding.

    Parameters
    ----------
    X : numpy ndarray, {n_samples, n_components}
        New data, where n_samples is the number of samples (number of individuals)
        and n_components is the number of components (number of features).
    y : None
        Unused

    Returns
    -------
    X_transformed: numpy ndarray, {n_samples, n_components}
        The encoded feature set
    """
    X = check_array(X)
    map = {0: 2, 1: 0, 2: 1}
    mapping_function = np.vectorize(lambda i: map[i] if i in map else i)

    X_transformed = mapping_function(X)

    return X_transformed