Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# ERI[:,jl]
eri_col = mol.intor('int2e_sph',
shls_slice=(0,mol.nbas,0,mol.nbas,sj,sj+1,sl,sl+1))
cj, cl = max(j-dims[sj],0), max(l-dims[sl],0)
chol_vecs[0] = numpy.copy(eri_col[:,:,cj,cl].reshape(nao*nao)) / delta_max**0.5
nchol = 0
while abs(delta_max) > max_error:
# Update cholesky vector
start = time.time()
# M'_ii = \sum_x L_i^x L_i^x
Mapprox += chol_vecs[nchol] * chol_vecs[nchol]
# D_ii = M_ii - M'_ii
delta = diag - Mapprox
nu = numpy.argmax(numpy.abs(delta))
delta_max = numpy.abs(delta[nu])
# Compute ERI chunk.
# shls_slice computes shells of integrals as determined by the angular
# momentum of the basis function and the number of contraction
# coefficients. Need to search for AO index within this shell indexing
# scheme.
# AO index.
j = nu // nao
l = nu % nao
# Associated shell index.
sj = numpy.searchsorted(dims, j)
sl = numpy.searchsorted(dims, l)
if dims[sj] != j and j != 0:
sj -= 1
if dims[sl] != l and l != 0:
sl -= 1
# Compute ERI chunk.
m = np.log(np.ones(prb.sigmaMap.nP)*CONDUCTIVITY)
mu = np.ones(prb.mesh.nC)*MU
if addrandoms is True:
m = m + np.random.randn(prb.sigmaMap.nP)*np.log(CONDUCTIVITY)*1e-1
mu = mu + np.random.randn(prb.mesh.nC)*MU*1e-1
survey = prb.survey
u = prb.fields(m)
v = np.random.rand(survey.nD)
w = np.random.rand(prb.mesh.nC)
vJw = v.dot(prb.Jvec(m, w, u))
wJtv = w.dot(prb.Jtvec(m, v, u))
tol = np.max([TOL*(10**int(np.log10(np.abs(vJw)))),FLR])
print(vJw, wJtv, vJw - wJtv, tol, np.abs(vJw - wJtv) < tol)
return np.abs(vJw - wJtv) < tol
pval : float
p-value
"""
x_vals = self._get_single_residuals(array, target_var=0)
y_vals = self._get_single_residuals(array, target_var=1)
array_resid = np.array([x_vals, y_vals])
xyz_resid = np.array([0, 1])
null_dist = self._get_shuffle_dist(array_resid, xyz_resid,
self.get_dependence_measure,
sig_samples=self.sig_samples,
sig_blocklength=self.sig_blocklength,
verbosity=self.verbosity)
pval = (null_dist >= np.abs(value)).mean()
# Adjust p-value for two-sided measures
if pval < 1.:
pval *= 2.
if return_null_dist:
return pval, null_dist
return pval
def GM11(x0): # 自定义灰色预测函数
import numpy as np
x1 = x0.cumsum() # 1-AGO序列
z1 = (x1[:len(x1) - 1] + x1[1:]) / 2.0 # 紧邻均值(MEAN)生成序列
z1 = z1.reshape((len(z1), 1))
B = np.append(-z1, np.ones_like(z1), axis=1)
Yn = x0[1:].reshape((len(x0) - 1, 1))
[[a], [b]] = np.dot(np.dot(np.linalg.inv(np.dot(B.T, B)), B.T), Yn) # 计算参数
f = lambda k: (x0[0] - b / a) * np.exp(-a * (k - 1)) - \
(x0[0] - b / a) * np.exp(-a * (k - 2)) # 还原值
delta = np.abs(x0 - np.array([f(i) for i in range(1, len(x0) + 1)]))
C = delta.std() / x0.std()
P = 1.0 * (np.abs(delta - delta.mean()) <
0.6745 * x0.std()).sum() / len(x0)
return f, a, b, x0[0], C, P # 返回灰色预测函数、a、b、首项、方差比、小残差概率
for i in range(n):
# Print progress
if i % 500 == 0:
print "Computing P-values for point ", i, " of ", n, "..."
# Compute the Gaussian kernel and entropy for the current precision
betamin = -math.inf
betamax = math.inf
d_i = d[i, math.concatenate((math.r_[0:i], math.r_[i + 1:n]))]
(h, this_p) = h_beta(d_i, beta[i])
# Evaluate whether the perplexity is within tolerance
h_diff = h - log_u
tries = 0
while math.abs(h_diff) > tol and tries < 50:
# If not, increase or decrease precision
if h_diff > 0:
betamin = beta[i].copy()
if betamax == math.inf or betamax == -math.inf:
beta[i] *= 2
else:
beta[i] = (beta[i] + betamax) / 2
else:
betamax = beta[i].copy()
if betamin == math.inf or betamin == -math.inf:
beta[i] /= 2
else:
beta[i] = (beta[i] + betamin) / 2
# Recompute the values
(h, this_p) = h_beta(d_i, beta[i])
def adjust_filter_sim(inst_dm, filter_sim, keep_top=20000):
import pandas as pd
import numpy as np
inst_df = pd.DataFrame(inst_dm)
val_vect = np.abs(inst_df.values.flatten())
val_vect = val_vect[val_vect > 0.01]
if len(val_vect) > keep_top:
inst_series = pd.Series(val_vect)
inst_series.sort(ascending=False)
sort_values = inst_series.values
filter_sim = sort_values[keep_top]
return filter_sim
if (fdf == 0) or (fd == 0):
gain_array = 0*f_array
else:
# Draw the D gain curve:
if self.qchk_bKpCrossing.isChecked() == False:
# fi relative to 0 dB crossing
gain_array = fdf/fd + 0*f_array
else:
# fi relative to kp dB crossing
gain_array = 10**(kp/20) * fdf/fd + 0*f_array
# print(20*np.log10(gain_array))
self.curve_fdf.setData(f_array, 20*np.log10(gain_array + self.MINIMUM_GAIN_DISPLAY))
f_array = np.logspace(np.log10(fmin), np.log10(fmax), 100)
actual_gain_array = np.abs(self.sl.pll[self.filter_number].get_current_transfer_function(f_array, self.sl.fs) * self.kc)
self.curve_actual.setData(f_array, 20*np.log10(actual_gain_array + self.MINIMUM_GAIN_DISPLAY))
# print('LoopFiltersUI: setting X range: %f, %f' % (fmin, fmax))
# print('LoopFiltersUI: setting Y range: %f, %f' % (gain_min, gain_max))
#self.qplot_tf.setXRange(np.log10(fmin), np.log10(fmax))
self.qplot_tf.setYRange(gain_min, gain_max)
def distanceMatrix(x, y):
xL2S = np.sum(x*x,axis=-1)
yL2S = np.sum(y*y,axis=-1)
xL2SM = np.tile(xL2S, (len(y), 1))
yL2SM = np.tile(yL2S, (len(x), 1))
squaredDistances = xL2SM + yL2SM.T - 2.0*y.dot(x.T)
# elementwise. abs is to supress negative values caused by rounding errors.
# TODO Should switch to squared distances everywhere, but be careful about fitAndVis fitAndVisNNBaseline.
distances = np.sqrt(np.abs(squaredDistances))
return distances
rigid_body_mode = eigenvector[-10:]
max_angle = 10 * np.pi/180
v = rigid_body_mode[0:3].real
omega = rigid_body_mode[3:6].real
dquat = rigid_body_mode[-4:]
euler = algebra.quat2euler(dquat)
max_euler = np.max(np.abs(euler))
if max_euler >= max_angle:
fact = max_euler / max_angle
else:
fact = 1
if np.abs(freq_d) < 1e-3:
fact = 1 / np.max(np.abs(v))
else:
max_omega = max_angle * freq_d
fact = np.max(np.abs(omega)) / max_omega
return fact
def _nipals_twoblocks_inner_loop(X, Y, mode="A", max_iter=500, tol=1e-06,
norm_y_weights=False):
"""Inner loop of the iterative NIPALS algorithm.
Provides an alternative to the svd(X'Y); returns the first left and right
singular vectors of X'Y. See PLS for the meaning of the parameters. It is
similar to the Power method for determining the eigenvectors and
eigenvalues of a X'Y.
"""
for col in Y.T:
if np.any(np.abs(col) > np.finfo(np.double).eps):
y_score = col.reshape(len(col), 1)
break
x_weights_old = 0
ite = 1
X_pinv = Y_pinv = None
eps = np.finfo(X.dtype).eps
if mode == "B":
# Uses condition from scipy<1.3 in pinv2 which was changed in
# https://github.com/scipy/scipy/pull/10067. In scipy 1.3, the
# condition was changed to depend on the largest singular value
X_t = X.dtype.char.lower()
Y_t = Y.dtype.char.lower()
factor = {'f': 1E3, 'd': 1E6}