我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用numpy.vander()。
def ln_likelihood(p, joker_params, data): P, phi0, ecc, omega, s, K, *v_terms = p # a little repeated code here... # phi0 now is implicitly relative to data.t_offset, not mjd=0 t = data._t_bmjd zdot = rv_from_elements(times=t, P=P, K=1., e=ecc, omega=omega, phi0=phi0, anomaly_tol=joker_params.anomaly_tol) # TODO: right now, we only support a single, global velocity trend! A1 = np.vander(t, N=joker_params._n_trend, increasing=True) A = np.hstack((zdot[:,None], A1)) p = np.array([K] + v_terms) ivar = get_ivar(data, s) dy = A.dot(p) - data.rv.value return 0.5 * (-dy**2 * ivar - log_2pi + np.log(ivar))
def vander(x, n=None): """ Masked values in the input array result in rows of zeros. """ _vander = np.vander(x, n) m = getmask(x) if m is not nomask: _vander[m] = 0 return _vander
def partial_dynamics(self, level, node=None): """ Return the time evolution of the specific `level` and of the specific `node`; if `node` is not specified, the method returns the time evolution of the given `level` (all the nodes). :param int level: the index of the level from where the time evolution is extracted. :param int node: the index of the node from where the time evolution is extracted; if None, the time evolution is extracted from all the nodes of the given level. Default is None. """ def dynamic(eigs, amplitudes, step, nsamples): omega = old_div( np.log(np.power(eigs, old_div(1., step))), self.original_time['dt'] ) partial_timestep = np.arange(nsamples) * self.dmd_time['dt'] vander = np.exp(np.multiply(*np.meshgrid(omega, partial_timestep))) return (vander * amplitudes).T if node: indeces = [self._index_list(level, node)] else: indeces = [self._index_list(level, i) for i in range(2**level)] level_dynamics = [ dynamic( self._eigs[idx], self._b[idx], self._steps[idx], self._nsamples[idx] ) for idx in indeces ] return scipy.linalg.block_diag(*level_dynamics)
def design_matrix(nonlinear_p, data, joker_params): """ Parameters ---------- nonlinear_p : array_like Array of non-linear parameter values. For the default case, these are P (period, day), phi0 (phase at pericenter, rad), ecc (eccentricity), omega (argument of perihelion, rad). May also contain log(jitter^2) as the last index. data : `~thejoker.data.RVData` The observations. joker_params : `~thejoker.sampler.params.JokerParams` The specification of parameters to infer with The Joker. Returns ------- A : `numpy.ndarray` The design matrix with shape ``(n_times, n_params)``. """ P, phi0, ecc, omega = nonlinear_p[:4] # we don't need the jitter here # phi0 now is implicitly relative to data.t_offset, not mjd=0 t = data._t_bmjd zdot = rv_from_elements(times=t, P=P, K=1., e=ecc, omega=omega, phi0=phi0, anomaly_tol=joker_params.anomaly_tol) # TODO: right now, we only support a single, global velocity trend! A1 = np.vander(t, N=joker_params._n_trend, increasing=True) A = np.hstack((zdot[:,None], A1)) return A
def detrend(y, order): if order == -1: return y return OLS(y, np.vander(np.linspace(-1, 1, len(y)), order + 1)).fit().resid
def test_graph_laplacian(): for mat in (np.arange(10) * np.arange(10)[:, np.newaxis], np.ones((7, 7)), np.eye(19), np.vander(np.arange(4)) + np.vander(np.arange(4)).T,): sp_mat = sparse.csr_matrix(mat) for normed in (True, False): laplacian = graph_laplacian(mat, normed=normed) n_nodes = mat.shape[0] if not normed: np.testing.assert_array_almost_equal(laplacian.sum(axis=0), np.zeros(n_nodes)) np.testing.assert_array_almost_equal(laplacian.T, laplacian) np.testing.assert_array_almost_equal( laplacian, graph_laplacian(sp_mat, normed=normed).toarray())