コード例 #1
0
def fit_skew_t_pdf(
    _1d_array,
    skew_t_model=None,
    fit_fixed_location=None,
    fit_fixed_scale=None,
    fit_initial_location=None,
    fit_initial_scale=None,
):

    if skew_t_model is None:

        skew_t_model = ACSkewT_gen()

    kwargs = {}

    if fit_fixed_location is not None:

        kwargs['floc'] = fit_fixed_location

    if fit_fixed_scale is not None:

        kwargs['fscale'] = fit_fixed_scale

    if fit_initial_location is not None:

        kwargs['loc'] = fit_initial_location

    else:

        kwargs['loc'] = _1d_array.mean()

    if fit_initial_scale is not None:

        kwargs['scale'] = fit_initial_scale

    else:

        kwargs['scale'] = _1d_array.std()

    degree_of_freedom, shape, location, scale = skew_t_model.fit(
        _1d_array,
        **kwargs,
    )

    if 32 < abs(shape):

        warn('Refitting with the median to be the fixed location ...')

        degree_of_freedom, shape, location, scale = skew_t_model.fit(
            _1d_array,
            floc=median(_1d_array),
        )

    return _1d_array.size, location, scale, degree_of_freedom, shape
コード例 #2
0
def fit_skew_t_pdf(_1d_array,
                   fit_initial_location=None,
                   fit_initial_scale=None):

    _1d_array = _1d_array[
        ~check_nd_array_for_bad(_1d_array, raise_for_bad=False)]

    keyword_arguments = {}

    mean = _1d_array.mean()

    if abs(mean) <= ALMOST_ZERO:

        mean = 0

    keyword_arguments["loc"] = mean

    keyword_arguments["scale"] = _1d_array.std() / 2

    skew_t_model = ACSkewT_gen()

    degree_of_freedom, shape, location, scale = skew_t_model.fit(
        _1d_array, **keyword_arguments)

    if 24 < abs(shape):

        warn("Refitting with fixed scale ...")

        keyword_arguments["fscale"] = keyword_arguments["scale"]

        degree_of_freedom, shape, location, scale = skew_t_model.fit(
            _1d_array, **keyword_arguments)

        if 24 < abs(shape):

            warn("Refitting with fixed location ...")

            keyword_arguments["floc"] = keyword_arguments["loc"]

            degree_of_freedom, shape, location, scale = skew_t_model.fit(
                _1d_array, **keyword_arguments)

    return _1d_array.size, location, scale, degree_of_freedom, shape
コード例 #3
0
def _fit_essentiality(f_x_s):
    f_x_f = DataFrame(index=f_x_s.index,
                      columns=['N', 'DF', 'Shape', 'Location', 'Scale'])

    for i, (f_i, f_v) in enumerate(f_x_s.iterrows()):
        print('Fitting {} (@{}/{}) ...'.format(f_i, i, f_x_s.shape[0]))

        # Fit skew-t PDF and save
        skew_t = ACSkewT_gen()
        f_v.dropna(inplace=True)
        df, shape, location, scale = skew_t.fit(f_v)
        f_x_f.ix[f_i, :] = f_v.size, df, shape, location, scale

    return f_x_f
コード例 #4
0
def _fit_essentiality(args):
    feature_x_sample, plot, directory_path, bar_df, n_xgrids, overwrite, show_plot = args
    feature_x_fit = DataFrame(
        index=feature_x_sample.index,
        columns=['N', 'DF', 'Shape', 'Location', 'Scale'])

    # TODO: paralellize
    for i, (f_i, f_v) in enumerate(feature_x_sample.iterrows()):
        print_log('Fitting {} (@{}) ...'.format(f_i, i))

        # Fit skew-t PDF on this gene
        f_v.dropna(inplace=True)
        skew_t = ACSkewT_gen()
        n = f_v.size
        df, shape, location, scale = skew_t.fit(f_v)
        feature_x_fit.ix[f_i, :] = n, df, shape, location, scale

        # Plot
        if plot:

            # Make an output filepath
            if directory_path:
                filepath = join(directory_path, 'essentiality_plots',
                                '{}.png'.format(f_i))
            else:
                filepath = None

            _plot_essentiality(feature_x_sample.ix[f_i, :],
                               get_amp_mut_del(bar_df, f_i),
                               n=n,
                               df=df,
                               shape=shape,
                               location=location,
                               scale=scale,
                               n_x_grids=n_xgrids,
                               filepath=filepath,
                               overwrite=overwrite,
                               show_plot=show_plot)
    return feature_x_fit
コード例 #5
0
def fit_skew_t_pdf(
    _1d_array,
    fit_fixed_location=None,
    fit_fixed_scale=None,
    fit_initial_location=None,
    fit_initial_scale=None,
):

    _1d_array = _1d_array[
        ~check_nd_array_for_bad(_1d_array, raise_for_bad=False)]

    keyword_arguments = {}

    guessed_location = _1d_array.mean()

    guessed_scale = _1d_array.std() / 2

    if fit_fixed_location is not None:

        keyword_arguments["floc"] = fit_fixed_location

    if fit_fixed_scale is not None:

        keyword_arguments["fscale"] = fit_fixed_scale

    if fit_initial_location is not None:

        keyword_arguments["loc"] = fit_initial_location

    else:

        keyword_arguments["loc"] = guessed_location

    if fit_initial_scale is not None:

        keyword_arguments["scale"] = fit_initial_scale

    else:

        keyword_arguments["scale"] = guessed_scale

    skew_t_model = ACSkewT_gen()

    degree_of_freedom, shape, location, scale = skew_t_model.fit(
        _1d_array, **keyword_arguments)

    if 24 < abs(shape):

        warn("Refitting with scale = (standard deviation / 2) ...")

        keyword_arguments["fscale"] = guessed_scale

        degree_of_freedom, shape, location, scale = skew_t_model.fit(
            _1d_array, **keyword_arguments)

        if 24 < abs(shape):

            warn("Refitting with location = mean ...")

            keyword_arguments["floc"] = guessed_location

            degree_of_freedom, shape, location, scale = skew_t_model.fit(
                _1d_array, **keyword_arguments)

    return _1d_array.size, location, scale, degree_of_freedom, shape