python类isfinite()的实例源码

pyfrp_ROI.py 文件源码 项目:PyFRAP 作者: alexblaessle 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def getROIHeight(self):

        """Returns height of ROI.

        Returns:
            float: Height of ROI.

        """

        if np.isfinite(self.zmax):
            zMax=self.zmax
        else:
            dump,zMax=self.getMeshIdxZExtend()

        if np.isfinite(self.zmin):
            zMin=self.zmin
        else:
            zMin,dump=self.getMeshIdxZExtend()

        return abs(zMax-zMin)
test_optimizer.py 文件源码 项目:bolero 作者: rock-learning 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_contextual_optimizers_follow_standard_protocol():
    for name, ContextualOptimizer in ALL_CONTEXTUALOPTIMIZERS:
        opt = ContextualOptimizer()
        n_params = 1
        n_context_dims = 1
        opt.init(n_params, n_context_dims)
        context = opt.get_desired_context()
        if context is None:
            context = np.zeros(n_context_dims)
        opt.set_context(context)
        assert_false(opt.is_behavior_learning_done())
        params = np.empty(n_params)
        opt.get_next_parameters(params)
        assert_true(np.isfinite(params).all())
        opt.set_evaluation_feedback(np.array([0.0]))

        policy = opt.best_policy()
        assert_true(np.isfinite(policy(context)).all())

        assert_pickle(name, opt)
test_baseline.py 文件源码 项目:bolero 作者: rock-learning 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_random_behavior():
    beh = RandomBehavior(random_state=0)
    beh.init(4, 5)

    assert_equal(beh.get_n_params(), 0)
    assert_array_equal(beh.get_params(), np.array([]))

    outputs = np.empty(5)
    outputs[:] = np.nan
    beh.get_outputs(outputs)
    assert_true(np.isfinite(outputs).all())

    assert_raises_regexp(
        NotImplementedError, "does not accept any meta parameters",
        beh.set_meta_parameters, ["key"], [0.0])
    beh.reset()

    assert_raises_regexp(
        ValueError, "Length of parameter vector must be 0",
        beh.set_params, np.zeros(2))
    beh.set_params(np.array([]))
pyPhewasCore.py 文件源码 项目:pyPheWAS 作者: BennettLandman 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def get_bon_thresh(normalized,power): #same
    """
    Calculate the bonferroni correction threshold.

    Divide the power by the sum of all finite values (all non-nan values).

    :param normalized: an array of all normalized p-values. Normalized p-values are -log10(p) where p is the p-value.
    :param power: the threshold power being used (usually 0.05)
    :type normalized: numpy array
    :type power: float

    :returns: The bonferroni correction
    :rtype: float

    """
    return power/sum(np.isfinite(normalized))
pyPhewasCore.py 文件源码 项目:pyPheWAS 作者: BennettLandman 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_fdr_thresh(p_values, power):
    """
    Calculate the false discovery rate threshold.

    :param p_values: a list of p-values obtained by executing the regression
    :param power: the thershold power being used (usually 0.05)
    :type p_values: numpy array
    :type power: float

    :returns: the false discovery rate
    :rtype: float
    """
    sn = np.sort(p_values)
    sn = sn[np.isfinite(sn)]
    sn = sn[::-1]
    for i in range(len(sn)):
        thresh=0.05*i/len(sn)
        if sn[i]<=power:
            break
    return sn[i]
pyProWAS.py 文件源码 项目:pyPheWAS 作者: BennettLandman 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_bon_thresh(normalized, power):  # same
    """
    Calculate the bonferroni correction threshold.

    Divide the power by the sum of all finite values (all non-nan values).

    :param normalized: an array of all normalized p-values. Normalized p-values are -log10(p) where p is the p-value.
    :param power: the threshold power being used (usually 0.05)
    :type normalized: numpy array
    :type power: float

    :returns: The bonferroni correction
    :rtype: float

    """
    return power / sum(np.isfinite(normalized))
pyProWAS.py 文件源码 项目:pyPheWAS 作者: BennettLandman 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_fdr_thresh(p_values, power):
    """
    Calculate the false discovery rate threshold.

    :param p_values: a list of p-values obtained by executing the regression
    :param power: the thershold power being used (usually 0.05)
    :type p_values: numpy array
    :type power: float

    :returns: the false discovery rate
    :rtype: float
    """
    sn = np.sort(p_values)
    sn = sn[np.isfinite(sn)]
    sn = sn[::-1]
    for i in range(len(sn)):
        thresh = 0.05 * i / len(sn)
        if sn[i] <= power:
            break
    return sn[i]
rt_censor_diagnosis.py 文件源码 项目:pyPheWAS 作者: BennettLandman 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def censor_diagnosis(genotype_file,phenotype_file,final_pfile, field ='na',start_time=float('nan'),end_time=float('nan')):
        import pandas as pd
        import numpy as np
        genotypes = pd.read_csv(genotype_file)
        phenotypes = pd.read_csv(phenotype_file)
        mg=pd.merge(phenotypes,genotypes,on='id')
        if np.isnan(start_time) and np.isnan(end_time):
                print("Choose appropriate time period")
        if field=='na':
                if np.isfinite(start_time) and np.isnan(end_time):
                        final = mg[mg['AgeAtICD']>start_time]
                elif np.isnan(start_time) and np.isfinite(end_time):
                        final = mg[mg['AgeAtICD']<end_time]
                else:
                        final = mg[(mg['AgeAtICD']>start_time)&(mg['AgeAtICD']<end_time)]

        else:
                mg['diff']=mg[field]-mg['AgeAtICD']
                if np.isfinite(start_time) and np.isnan(end_time):
                        final = mg[(mg['diff']>start_time)|(np.isnan(mg['diff']))]
                elif np.isnan(start_time) and np.isfinite(end_time):
                        final = mg[(mg['diff']<end_time)|(np.isnan(mg['diff']))]
                else:
                        final = mg[(mg['diff']>start_time)&(mg['diff']<end_time)|(np.isnan(mg['diff']))]
        final[['id','icd9','AgeAtICD']].to_csv(final_pfile)
pyPhewasv2.py 文件源码 项目:pyPheWAS 作者: BennettLandman 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_fdr_thresh(p_values, power):
    """
    Calculate the false discovery rate threshold.

    :param p_values: a list of p-values obtained by executing the regression
    :param power: the thershold power being used (usually 0.05)
    :type p_values: numpy array
    :type power: float

    :returns: the false discovery rate
    :rtype: float
    """
    sn = np.sort(p_values)
    sn = sn[np.isfinite(sn)]
    sn = sn[::-1]
    for i in range(len(sn)):
        thresh = power * i / len(sn)
        if sn[i] <= thresh:
            break
    return sn[i]
pyPhewasv2.py 文件源码 项目:pyPheWAS 作者: BennettLandman 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_bhy_thresh(p_values, power):
    """
    Calculate the false discovery rate threshold.

    :param p_values: a list of p-values obtained by executing the regression
    :param power: the thershold power being used (usually 0.05)
    :type p_values: numpy array
    :type power: float

    :returns: the false discovery rate
    :rtype: float
    """
    sn = np.sort(p_values)
    sn = sn[np.isfinite(sn)]
    sn = sn[::-1]
    for i in range(len(sn)):
        thresh = power * i / (8.1*len(sn))
        if sn[i] <= thresh:
            break
    return sn[i]
pyPhewasv3.py 文件源码 项目:pyPheWAS 作者: BennettLandman 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_bon_thresh(normalized, power):  # same
    """
    Calculate the bonferroni correction threshold.

    Divide the power by the sum of all finite values (all non-nan values).

    :param normalized: an array of all normalized p-values. Normalized p-values are -log10(p) where p is the p-value.
    :param power: the threshold power being used (usually 0.05)
    :type normalized: numpy array
    :type power: float

    :returns: The bonferroni correction
    :rtype: float

    """
    return power / sum(np.isfinite(normalized))
pyPhewasv3.py 文件源码 项目:pyPheWAS 作者: BennettLandman 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_fdr_thresh(p_values, power):
    """
    Calculate the false discovery rate threshold.

    :param p_values: a list of p-values obtained by executing the regression
    :param power: the thershold power being used (usually 0.05)
    :type p_values: numpy array
    :type power: float

    :returns: the false discovery rate
    :rtype: float
    """
    sn = np.sort(p_values)
    sn = sn[np.isfinite(sn)]
    sn = sn[::-1]
    for i in range(len(sn)):
        thresh = power * i / len(sn)
        if sn[i] <= thresh:
            break
    return sn[i]
pyPhewasCorev2.py 文件源码 项目:pyPheWAS 作者: BennettLandman 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_bon_thresh(normalized,power): #same
    """
    Calculate the bonferroni correction threshold.

    Divide the power by the sum of all finite values (all non-nan values).

    :param normalized: an array of all normalized p-values. Normalized p-values are -log10(p) where p is the p-value.
    :param power: the threshold power being used (usually 0.05)
    :type normalized: numpy array
    :type power: float

    :returns: The bonferroni correction
    :rtype: float

    """
    return power/sum(np.isfinite(normalized))
pyPhewasCorev2.py 文件源码 项目:pyPheWAS 作者: BennettLandman 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def get_fdr_thresh(p_values, power):
    """
    Calculate the false discovery rate threshold.

    :param p_values: a list of p-values obtained by executing the regression
    :param power: the thershold power being used (usually 0.05)
    :type p_values: numpy array
    :type power: float

    :returns: the false discovery rate
    :rtype: float
    """
    sn = np.sort(p_values)
    sn = sn[np.isfinite(sn)]
    sn = sn[::-1]
    for i in range(len(sn)):
        thresh = power * i / len(sn)
        if sn[i] <= thresh:
            break
    return sn[i]
minibatch2.py 文件源码 项目:Automatic_Group_Photography_Enhancement 作者: Yuliang-Zou 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _get_viewpoint_estimation_labels(viewpoint_data, clss, num_classes):
    """Bounding-box regression targets are stored in a compact form in the
    roidb.

    This function expands those targets into the 4-of-4*K representation used
    by the network (i.e. only one class has non-zero targets). The loss weights
    are similarly expanded.

    Returns:
        view_target_data (ndarray): N x 3K blob of regression targets
        view_loss_weights (ndarray): N x 3K blob of loss weights
    """
    view_targets = np.zeros((clss.size, 3 * num_classes), dtype=np.float32)
    view_loss_weights = np.zeros(view_targets.shape, dtype=np.float32)
    inds = np.where( (clss > 0) & np.isfinite(viewpoint_data[:,0]) & np.isfinite(viewpoint_data[:,1]) & np.isfinite(viewpoint_data[:,2]) )[0]
    for ind in inds:
        cls = clss[ind]
        start = 3 * cls
        end = start + 3
        view_targets[ind, start:end] = viewpoint_data[ind, :]
        view_loss_weights[ind, start:end] = [1., 1., 1.]

    assert not np.isinf(view_targets).any(), 'viewpoint undefined'
    return view_targets, view_loss_weights
utils.py 文件源码 项目:geepee 作者: thangbui 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __call__(self, params, params_args, obj, idxs, alpha, prop_mode):
        params_dict = unflatten_dict(params, params_args)
        f, grad_dict = obj.objective_function(
            params_dict, idxs, alpha=alpha, prop_mode=prop_mode)
        g, _ = flatten_dict(grad_dict)
        g_is_fin = np.isfinite(g)
        if np.all(g_is_fin):
            self.previous_x = params
            return f, g
        else:
            print("Warning: inf or nan in gradient: replacing with zeros")
            return f, np.where(g_is_fin, g, 0.)

# def objective_wrapper(params, params_args, obj, idxs, alpha):
#     params_dict = unflatten_dict(params, params_args)
#     f, grad_dict = obj.objective_function(
#         params_dict, idxs, alpha=alpha)
#     g, _ = flatten_dict(grad_dict)
#     g_is_fin = np.isfinite(g)
#     if np.all(g_is_fin):
#         return f, g
#     else:
#         print("Warning: inf or nan in gradient: replacing with zeros")
#         return f, np.where(g_is_fin, g, 0.)
gym_pendula.py 文件源码 项目:bullet-gym 作者: benelot 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def calc_state(self):
        self.theta, theta_dot = self.j1.current_position()
        x, vx = self.slider.current_position()
        #assert( np.isfinite(x) )

        if not np.isfinite(x):
            print("x is inf")
            x = 0

        if not np.isfinite(vx):
            print("vx is inf")
            vx = 0

        if not np.isfinite(self.theta):
            print("theta is inf")
            self.theta = 0

        if not np.isfinite(theta_dot):
            print("theta_dot is inf")
            theta_dot = 0

        return np.array([
            x, vx,
            np.cos(self.theta), np.sin(self.theta), theta_dot
            ])
tdose_model_FoV.py 文件源码 项目:TDOSE 作者: kasperschmidt 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def residual_multigauss(param, dataimage, nonfinite = 0.0, ravelresidual=True, showimages=False, verbose=False):
    """
    Calculating the residual bestween the multigaussian model with the paramters 'param' and the data.

    --- INPUT ---
    param         Parameters of multi-gaussian model to generate. See modelimage_multigauss() header for details
    dataimage     Data image to take residual
    nonfinite     Value to replace non-finite entries in residual with
    ravelresidual To np.ravel() the residual image set this to True. Needed by scipy.optimize.leastsq()
                  optimizer function
    showimages    To show model and residiual images set to True
    verbose       Toggle verbosity

    --- EXAMPLE OF USE ---
    import tdose_model_FoV as tmf
    param      = [18,31,1*0.3,2.1*0.3,1.2*0.3,30*0.3,    110,90,200*0.5,20.1*0.5,15.2*0.5,0*0.5]
    dataimg    = pyfits.open('/Users/kschmidt/work/TDOSE/mock_cube_sourcecat161213_tdose_mock_cube.fits')[0].data[0,:,:]
    residual   = tmf.residual_multigauss(param, dataimg, showimages=True)

    """
    if verbose: ' - Estimating residual (= model - data) between model and data image'
    imgsize      = dataimage.shape
    xgrid, ygrid = tu.gen_gridcomponents(imgsize)
    modelimg     = tmf.modelimage_multigauss((xgrid, ygrid),param,imgsize,showmodelimg=showimages, verbose=verbose)

    residualimg  = modelimg - dataimage

    if showimages:
        plt.imshow(residualimg,interpolation='none', vmin=1e-5, vmax=np.max(residualimg), norm=mpl.colors.LogNorm())
        plt.title('Resdiaul (= model - data) image')
        plt.show()

    if nonfinite is not None:
        residualimg[~np.isfinite(residualimg)] = 0.0

    if ravelresidual:
        residualimg = np.ravel(residualimg)

    return residualimg
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
serving_test.py 文件源码 项目:treecat 作者: posterior 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_server_logprob_shape(model):
    table = TINY_TABLE
    server = TreeCatServer(model)
    logprobs = server.logprob(table.data)
    N = table.num_rows
    assert logprobs.dtype == np.float32
    assert logprobs.shape == (N, )
    assert np.isfinite(logprobs).all()
serving_test.py 文件源码 项目:treecat 作者: posterior 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_ensemble_logprob_shape(ensemble):
    table = TINY_TABLE
    server = EnsembleServer(ensemble)
    logprobs = server.logprob(table.data)
    N = table.num_rows
    assert logprobs.dtype == np.float32
    assert logprobs.shape == (N, )
    assert np.isfinite(logprobs).all()


问题


面经


文章

微信
公众号

扫码关注公众号