當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.fmin方法代碼示例

本文整理匯總了Python中numpy.fmin方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.fmin方法的具體用法?Python numpy.fmin怎麽用?Python numpy.fmin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.fmin方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: compute_corr_significance

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def compute_corr_significance(r, N):
    """ Compute statistical significance for a pearson correlation between
        two xarray objects.

    Parameters
    ----------
    r : `xarray.DataArray` object
        correlation coefficient between two time series.

    N : int
        length of time series being correlated.

    Returns
    -------
    pval : float
        p value for pearson correlation.

    """
    df = N - 2
    t_squared = r ** 2 * (df / ((1.0 - r) * (1.0 + r)))
    # method used in scipy, where `np.fmin` constrains values to be
    # below 1 due to errors in floating point arithmetic.
    pval = special.betainc(0.5 * df, 0.5, np.fmin(df / (df + t_squared), 1.0))
    return xr.DataArray(pval, coords=t_squared.coords, dims=t_squared.dims) 
開發者ID:NCAR,項目名稱:esmlab,代碼行數:26,代碼來源:statistics.py

示例2: test_NotImplemented_not_returned

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def test_NotImplemented_not_returned(self):
        # See gh-5964 and gh-2091. Some of these functions are not operator
        # related and were fixed for other reasons in the past.
        binary_funcs = [
            np.power, np.add, np.subtract, np.multiply, np.divide,
            np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
            np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
            np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
            np.logical_and, np.logical_or, np.logical_xor, np.maximum,
            np.minimum, np.mod,
            np.greater, np.greater_equal, np.less, np.less_equal,
            np.equal, np.not_equal]

        a = np.array('1')
        b = 1
        c = np.array([1., 2.])
        for f in binary_funcs:
            assert_raises(TypeError, f, a, b)
            assert_raises(TypeError, f, c, a) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:test_ufunc.py

示例3: test_reduce

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def test_reduce(self):
        dflt = np.typecodes['AllFloat']
        dint = np.typecodes['AllInteger']
        seq1 = np.arange(11)
        seq2 = seq1[::-1]
        func = np.fmin.reduce
        for dt in dint:
            tmp1 = seq1.astype(dt)
            tmp2 = seq2.astype(dt)
            assert_equal(func(tmp1), 0)
            assert_equal(func(tmp2), 0)
        for dt in dflt:
            tmp1 = seq1.astype(dt)
            tmp2 = seq2.astype(dt)
            assert_equal(func(tmp1), 0)
            assert_equal(func(tmp2), 0)
            tmp1[::2] = np.nan
            tmp2[::2] = np.nan
            assert_equal(func(tmp1), 1)
            assert_equal(func(tmp2), 1) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:22,代碼來源:test_umath.py

示例4: test_NotImplemented_not_returned

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def test_NotImplemented_not_returned(self):
        # See gh-5964 and gh-2091. Some of these functions are not operator
        # related and were fixed for other reasons in the past.
        binary_funcs = [
            np.power, np.add, np.subtract, np.multiply, np.divide,
            np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
            np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
            np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
            np.logical_and, np.logical_or, np.logical_xor, np.maximum,
            np.minimum, np.mod
            ]

        # These functions still return NotImplemented. Will be fixed in
        # future.
        # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal]

        a = np.array('1')
        b = 1
        for f in binary_funcs:
            assert_raises(TypeError, f, a, b) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:22,代碼來源:test_ufunc.py

示例5: optimize_transformation

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def optimize_transformation(self):
        """
        returns optimal transformation
        """
        x0 = [1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0]
        self._add_params_trafo_stack_(x0)
        print("starts optimizing...")
        np.fmin(self._calc_min_func_, x0, full_output=1, maxiter=2000)
        # self.alpha1=self.multiplier_x*self.alpha1
        # self.beta1=self.multiplier_x*self.beta1
        # self.gamma1=self.multiplier_x*self.gamma1
        # self.alpha2=self.multiplier_y*self.alpha2
        # self.beta2=self.multiplier_y*self.beta2
        # self.gamma2=self.multiplier_y*self.gamma2
        self._set_transformation_to_all_axis_()
        # self._calc_bounding_box_()
        # self._trafo_to_paper_() 
開發者ID:lefakkomies,項目名稱:pynomo,代碼行數:19,代碼來源:nomo_axis_func.py

示例6: predict_movement

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def predict_movement(self, data, epsilon):
        rand_val = np.random.random(data.shape[0])
        # q_actions = self.model.predict(data)
        p_actions = self.model_policy.predict(data)
        opt_policy_orig = np.argmax(np.abs(p_actions), axis=-1)
        opt_policy = 1.0 * opt_policy_orig
        opt_policy[rand_val < epsilon] = np.random.randint(0, self.action_size, size=(np.sum(rand_val < epsilon)))

        # store the qvalue_evolution (lots of computation time maybe here)
        tmp = np.zeros((data.shape[0], self.action_size))
        tmp[np.arange(data.shape[0]), opt_policy_orig] = 1.0
        q_actions0 = self.model_Q.predict([data, tmp])
        q_actions2 = self.model_Q2.predict([data, tmp])
        q_actions = np.fmin(q_actions0, q_actions2).reshape(-1)
        self.qvalue_evolution = np.concatenate((self.qvalue_evolution, q_actions))
        # above is not mandatory for predicting a movement so, might need to be moved somewhere else...

        opt_policy = opt_policy.astype(np.int)
        return opt_policy, p_actions[:, opt_policy] 
開發者ID:rte-france,項目名稱:Grid2Op,代碼行數:21,代碼來源:ml_agent.py

示例7: _fof_local

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def _fof_local(layout, pos, boxsize, ll, comm):
    from kdcount import cluster

    N = len(pos)

    pos = layout.exchange(pos)
    if boxsize is not None:
        pos %= boxsize
    data = cluster.dataset(pos, boxsize=boxsize)
    fof = cluster.fof(data, linking_length=ll, np=0)
    labels = fof.labels
    del fof

    PID = numpy.arange(N, dtype='intp')
    PID += numpy.sum(comm.allgather(N)[:comm.rank], dtype='intp')

    PID = layout.exchange(PID)
    # initialize global labels
    minid = equiv_class(labels, PID, op=numpy.fmin)[labels]

    return minid 
開發者ID:bccp,項目名稱:nbodykit,代碼行數:23,代碼來源:fof.py

示例8: test_reduce_complex

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def test_reduce_complex(self):
        assert_equal(np.fmin.reduce([1, 2j]), 2j)
        assert_equal(np.fmin.reduce([1+3j, 2j]), 2j) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:5,代碼來源:test_umath.py

示例9: test_float_nans

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def test_float_nans(self):
        nan = np.nan
        arg1 = np.array([0,   nan, nan])
        arg2 = np.array([nan, 0,   nan])
        out = np.array([0,   0,   nan])
        assert_equal(np.fmin(arg1, arg2), out) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:8,代碼來源:test_umath.py

示例10: MTS_LS3v1

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def MTS_LS3v1(Xk, Xk_fit, Xb, Xb_fit, improve, SR, task, phi=3, BONUS1=10, BONUS2=1, rnd=rand, **ukwargs):
	r"""Multiple trajectory local search three version one.

	Args:
		Xk (numpy.ndarray): Current solution.
		Xk_fit (float): Current solutions fitness/function value.
		Xb (numpy.ndarray): Global best solution.
		Xb_fit (float): Global best solutions fitness/function value.
		improve (bool): Has the solution been improved.
		SR (numpy.ndarray): Search range.
		task (Task): Optimization task.
		phi (int): Number of new generated positions.
		BONUS1 (int): Bonus reward for improving global best solution.
		BONUS2 (int): Bonus reward for improving solution.
		rnd (mtrand.RandomState): Random number generator.
		**ukwargs (Dict[str, Any]): Additional arguments.

	Returns:
		Tuple[numpy.ndarray, float, numpy.ndarray, float, bool, numpy.ndarray]:
			1. New solution.
			2. New solutions fitness/function value.
			3. Global best if found else old global best.
			4. Global bests function/fitness value.
			5. If solution has improved.
			6. Search range.
	"""
	grade, Disp = 0.0, task.bRange / 10
	while True in (Disp > 1e-3):
		Xn = apply_along_axis(task.repair, 1, asarray([rnd.permutation(Xk) + Disp * rnd.uniform(-1, 1, len(Xk)) for _ in range(phi)]), rnd)
		Xn_f = apply_along_axis(task.eval, 1, Xn)
		iBetter, iBetterBest = argwhere(Xn_f < Xk_fit), argwhere(Xn_f < Xb_fit)
		grade += len(iBetterBest) * BONUS1 + (len(iBetter) - len(iBetterBest)) * BONUS2
		if len(Xn_f[iBetterBest]) > 0:
			ib, improve = argmin(Xn_f[iBetterBest]), True
			Xb, Xb_fit, Xk, Xk_fit = Xn[iBetterBest][ib][0].copy(), Xn_f[iBetterBest][ib][0], Xn[iBetterBest][ib][0].copy(), Xn_f[iBetterBest][ib][0]
		elif len(Xn_f[iBetter]) > 0:
			ib, improve = argmin(Xn_f[iBetter]), True
			Xk, Xk_fit = Xn[iBetter][ib][0].copy(), Xn_f[iBetter][ib][0]
		Su, Sl = fmin(task.Upper, Xk + 2 * Disp), fmax(task.Lower, Xk - 2 * Disp)
		Disp = (Su - Sl) / 10
	return Xk, Xk_fit, Xb, Xb_fit, improve, grade, SR 
開發者ID:NiaOrg,項目名稱:NiaPy,代碼行數:43,代碼來源:mts.py

示例11: MutationUros

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def MutationUros(pop, ic, mr, task, rnd=rand):
	r"""Mutation method made by Uros Mlakar.

	Args:
		pop (numpy.ndarray[Individual]): Current population.
		ic (int): Index of individual.
		mr (float): Mutation rate.
		task (Task): Optimization task.
		rnd (mtrand.RandomState): Random generator.

	Returns:
		numpy.ndarray: New genotype.
	"""
	return fmin(fmax(rnd.normal(pop[ic], mr * task.bRange), task.Lower), task.Upper) 
開發者ID:NiaOrg,項目名稱:NiaPy,代碼行數:16,代碼來源:ga.py

示例12: test_complex_nans

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def test_complex_nans(self):
        nan = np.nan
        for cnan in [complex(nan, 0), complex(0, nan), complex(nan, nan)]:
            arg1 = np.array([0, cnan, cnan], dtype=np.complex)
            arg2 = np.array([cnan, 0, cnan], dtype=np.complex)
            out = np.array([0,    0, nan], dtype=np.complex)
            assert_equal(np.fmin(arg1, arg2), out) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:9,代碼來源:test_umath.py

示例13: test_complex_nans

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import fmin [as 別名]
def test_complex_nans(self):
        nan = np.nan
        for cnan in [complex(nan, 0), complex(0, nan), complex(nan, nan)]:
            arg1 = np.array([0, cnan, cnan], dtype=complex)
            arg2 = np.array([cnan, 0, cnan], dtype=complex)
            out = np.array([0,    0, nan], dtype=complex)
            assert_equal(np.fmin(arg1, arg2), out) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:9,代碼來源:test_umath.py


注:本文中的numpy.fmin方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。