Here are the examples of the python api numpy.power taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
170 Examples
3
Example 1
def CalculateModelPredictions(self, inCoeffs, inDataCacheDictionary):
x_in = inDataCacheDictionary['X'] # only need to perform this dictionary look-up once
a = inCoeffs[0]
b = inCoeffs[1]
c = inCoeffs[2]
try:
temp = x_in / numpy.power((a + b*x_in), (-1.0/c))
return self.extendedVersionHandler.GetAdditionalModelPredictions(temp, inCoeffs, inDataCacheDictionary, self)
except:
return numpy.ones(len(inDataCacheDictionary['DependentData'])) * 1.0E300
3
Example 2
def polynomial(p):
"""General polynomial kernel (1 + x'*y)^p"""
def p_kernel(x, y):
return np.power(1e0 + x * y.T, p)
return p_kernel
3
Example 3
def estimate_scale(self, Y=None):
"""
Return Pearson\'s X^2 estimate of scale.
"""
if Y is None:
Y = self.Y
resid = Y - self.results.mu
return (np.power(resid, 2) / self.family.variance(self.results.mu)).sum() \
/ self.df_resid #TODO check this
3
Example 4
def CalculateModelPredictions(self, inCoeffs, inDataCacheDictionary):
x_in = inDataCacheDictionary['X'] # only need to perform this dictionary look-up once
Youngs_Modulus = inCoeffs[0]
K = inCoeffs[1]
n = inCoeffs[2]
try:
temp = (x_in / Youngs_Modulus) + numpy.power(x_in / K, 1.0 / n)
return self.extendedVersionHandler.GetAdditionalModelPredictions(temp, inCoeffs, inDataCacheDictionary, self)
except:
return numpy.ones(len(inDataCacheDictionary['DependentData'])) * 1.0E300
3
Example 5
def testBasic(self):
for rank in VALID_FFT_RANKS:
for dims in xrange(rank, rank + 3):
self._Compare(
np.mod(
np.arange(np.power(4, dims)), 10).reshape((4,) * dims), rank)
3
Example 6
Project: sherpa Source File: test_stats.py
@staticmethod
def my_simulstat(data, model, staterror, *args, **kwargs):
data_size = kwargs['extra_args']['data_size']
data1 = data[:data_size[0]]
data2 = data[data_size[0]:]
model1 = model[:data_size[0]]
model2 = model[data_size[0]:]
staterror1 = staterror[:data_size[0]]
staterror2 = staterror[data_size[0]:]
mystat1 = Chi2DataVar()
mystat2 = Chi2DataVar()
stat1, fvec1 = mystat1.calc_stat(data1, model1, staterror1)
stat2, fvec2 = mystat2.calc_stat(data2, model2, staterror2)
fvec = numpy.power((data - model) / staterror, 2)
stat = numpy.sum(fvec)
# print stat1 + stat2 - stat
return (stat, fvec)
return (stat1 + stat2, numpy.append(fvec1, fvec2))
3
Example 7
Project: cvxpy Source File: quadratic.py
def _coeffs_power(self, expr):
if expr.p == 1:
return self.get_coeffs(expr.args[0])
elif expr.p == 2:
(_, A, b) = self._coeffs_affine(expr.args[0])
Ps = [(A[i, :].T*A[i, :]).tocsr() for i in range(A.shape[0])]
Q = 2*(sp.diags(b, 0)*A).tocsr()
R = np.power(b, 2)
return (Ps, Q, R)
else:
raise Exception("Error while processing power(x, %f)." % expr.p)
3
Example 8
Project: pyflux Source File: nllt.py
def state_likelihood(self, beta, alpha):
""" Returns likelihood of the states given the variance latent variables
Parameters
----------
beta : np.array
Contains untransformed starting values for latent variables
alpha : np.array
State matrix
Returns
----------
State likelihood
"""
_, _, _, Q = self._ss_matrices(beta)
residuals_1 = alpha[0][1:alpha[0].shape[0]]-alpha[0][0:alpha[0].shape[0]-1]
residuals_2 = alpha[1][1:alpha[1].shape[0]]-alpha[1][0:alpha[1].shape[0]-1]
return np.sum(ss.norm.logpdf(residuals_1,loc=0,scale=np.power(Q[0][0],0.5))) + np.sum(ss.norm.logpdf(residuals_2,loc=0,scale=np.power(Q[1][1],0.5)))
3
Example 9
def _compute_term_3(self, C, mag, R):
"""
(a12 + a13.*M + a14.*M.*M + a15.*M.*M.*M).*(d(r).^2)
"""
return (
(C['a12'] + C['a13'] * mag + C['a14'] * np.power(mag, 2) +
C['a15'] * np.power(mag, 3)) * np.power(R, 2)
)
3
Example 10
Project: scipy Source File: models.py
def _poly_fjacd(B, x, powers):
b = B[1:]
b.shape = (b.shape[0], 1)
b = b * powers
return np.sum(b * np.power(x, powers-1),axis=0)
3
Example 11
def CalculateModelPredictions(self, inCoeffs, inDataCacheDictionary):
x_in = inDataCacheDictionary['X'] # only need to perform this dictionary look-up once
a = inCoeffs[0]
b = inCoeffs[1]
c = inCoeffs[2]
try:
temp = numpy.power(a + b * x_in, c)
return self.extendedVersionHandler.GetAdditionalModelPredictions(temp, inCoeffs, inDataCacheDictionary, self)
except:
return numpy.ones(len(inDataCacheDictionary['DependentData'])) * 1.0E300
3
Example 12
Project: orange Source File: orngDimRed.py
def VarianceScaling(vector,param=None,inverse=0):
if param == None:
(v,m) = Centering(vector)
s = numpy.sqrt(numpy.average(numpy.power(v,2)))
if s > 1e-6:
s = 1.0/s
else:
(m,s) = param
if inverse == 0:
(v,m_) = Centering(vector,m)
else:
v = Centering(vector,m,1)
if inverse == 0:
return (s*v,(m,s))
else:
return s/v
3
Example 13
Project: SHARPpy Source File: thermo.py
def thalvl(theta, t):
'''
Returns the level (hPa) of a parcel.
Parameters
----------
theta : number, numpy array
Potential temperature of the parcel (C)
t : number, numpy array
Temperature of the parcel (C)
Returns
-------
Pressure Level (hPa [float]) of the parcel
'''
t = t + ZEROCNK
theta = theta + ZEROCNK
return 1000. / (np.power((theta / t),(1./ROCP)))
3
Example 14
def CalculateModelPredictions(self, inCoeffs, inDataCacheDictionary):
x_in = inDataCacheDictionary['X'] # only need to perform this dictionary look-up once
a = inCoeffs[0]
b = inCoeffs[1]
c = inCoeffs[2]
try:
temp = 1.0 / numpy.power((a + b*x_in), (-1.0/c))
return self.extendedVersionHandler.GetAdditionalModelPredictions(temp, inCoeffs, inDataCacheDictionary, self)
except:
return numpy.ones(len(inDataCacheDictionary['DependentData'])) * 1.0E300
3
Example 15
Project: pyflux Source File: scores.py
@staticmethod
def mu_score(y,loc,scale,shape,skewness):
try:
if (y-loc)>=0:
return (((shape+1.0)*power(y-loc,2))/float(power(skewness,2)*shape*exp(scale) + power(y-loc,2))) - 1.0
else:
return (((shape+1.0)*power(y-loc,2))/float(power(skewness,-2)*shape*exp(scale) + power(y-loc,2))) - 1.0
except:
return -1.0
3
Example 16
def cheap(X):
A=0.5
B=10
C=-5
D=0
print X
print ((X+D)*6-2)
return A*np.power( ((X+D)*6-2), 2 )*np.sin(((X+D)*6-2)*2)+((X+D)-0.5)*B+C
3
Example 17
Project: statsmodels Source File: links.py
def inverse_deriv(self, z):
"""
Derivative of the inverse of the power transform
Parameters
----------
z : array-like
`z` is usually the linear predictor for a GLM or GEE model.
Returns
-------
g^(-1)'(z) : array
The value of the derivative of the inverse of the power transform
function
"""
return np.power(z, (1 - self.power)/self.power) / self.power
3
Example 18
Project: pyunlocbox Source File: functions.py
def _eval(self, x):
if self.dim >= 2:
y = 0
grads = []
grads = op.grad(x, dim=self.dim, **self.kwargs)
for g in grads:
y += np.power(abs(g), 2)
y = np.sqrt(y)
return np.sum(y)
if self.dim == 1:
dx = op.grad(x, dim=self.dim, **self.kwargs)
y = np.sum(np.abs(dx), axis=0)
return np.sum(y)
3
Example 19
Project: chainer Source File: optimizer.py
def exponential_decay_noise(xp, shape, dtype, hook, opt):
"""Time-dependent annealed Gaussian noise function from the paper:
`Adding Gradient Noise Improves Learning for Very Deep Networks
<http://arxiv.org/pdf/1511.06807>`_.
"""
std = numpy.sqrt(hook.eta / numpy.power(1 + opt.t, 0.55))
return xp.random.normal(0, std, shape).astype(dtype)
3
Example 20
Project: oq-hazardlib Source File: edwards_fah_2013a.py
def _compute_term_2(self, C, mag, R):
"""
(a8 + a9.*M + a10.*M.*M + a11.*M.*M.*M).*d(r)
"""
return (
(C['a8'] + C['a9'] * mag + C['a10'] * np.power(mag, 2) +
C['a11'] * np.power(mag, 3)) * R
)
3
Example 21
def __pow__(self, other, z=None):
"""x.__pow__(y) <--> x**y"""
if not z is None:
raise NotImplementedError("only pow(self, y) implemented, not pow(self,y,z)")
x,dx = self.value, self.error
y,dy,yqid = self._astuple(other)
if self.isSame(other):
# not sure if error correct for a**a**a ...
f = numpy.power(x, y)
error = numpy.abs(dx*f*(1+numpy.log(x)))
qid = self.qid
else:
f = numpy.power(x,y)
error = self._dist(dx*f*y/x, dy*f*numpy.log(x))
qid = [self.qid, yqid]
return QuantityWithError(f, error, qid=qid)
3
Example 22
def __rpow__(self, other, z=None):
"""x.__rpow__(y) <--> y**x"""
if not z is None:
raise NotImplementedError("only rpow(self, y) implemented, not rpow(self,y,z)")
x,dx = self.value, self.error
y,dy,yqid = self._astuple(other)
if self.isSame(other):
# not sure if error correct for a**a**a ...
f = numpy.power(y, x)
error = numpy.abs(dy*f*(1+numpy.log(y)))
qid = self.qid
else:
f = numpy.power(y, x)
error = self._dist(dy*f*x/y, dx*f*numpy.log(y))
qid = [self.qid, yqid]
return QuantityWithError(f, error, qid=qid)
3
Example 23
Project: imageqa-public Source File: func.py
def meanSqErr(Y, T, weights=None):
diff = Y - T.reshape(Y.shape)
diff2 = np.sum(np.power(diff, 2), axis=-1)
if weights is not None:
diff2 *= weights
weights = weights.reshape(weights.shape[0], 1)
diff *= weights
E = 0.5 * np.sum(diff2) / float(Y.shape[0])
dEdY = diff / float(Y.shape[0])
return E, dEdY
3
Example 24
Project: orange Source File: orngDimRed.py
def __init__(self, data, components=1):
(u,d,v) = LinearAlgebra.svd(data)
self.loading = u # transformed data points
self.variance = d # principal components' variance
self.factors = v # the principal basis
d2 = numpy.power(d,2)
s = numpy.sum(d2)
if s > 1e-6:
s = d2/s
else:
s = 1.0
self.R_squared = s # percentage of total variance explained by individual components
3
Example 25
def _stats(self, p):
r = special.log1p(-p)
mu = p / (p - 1.0) / r
mu2p = -p / r / (p - 1.0)**2
var = mu2p - mu*mu
mu3p = -p / r * (1.0+p) / (1.0 - p)**3
mu3 = mu3p - 3*mu*mu2p + 2*mu**3
g1 = mu3 / np.power(var, 1.5)
mu4p = -p / r * (
1.0 / (p-1)**2 - 6*p / (p - 1)**3 + 6*p*p / (p-1)**4)
mu4 = mu4p - 4*mu3p*mu + 6*mu2p*mu*mu - 3*mu**4
g2 = mu4 / var**2 - 3.0
return mu, var, g1, g2
3
Example 26
def CalculateModelPredictions(self, inCoeffs, inDataCacheDictionary):
x_in = inDataCacheDictionary['X'] # only need to perform this dictionary look-up once
a = inCoeffs[0]
b = inCoeffs[1]
try:
temp = numpy.power(a + x_in, b)
return self.extendedVersionHandler.GetAdditionalModelPredictions(temp, inCoeffs, inDataCacheDictionary, self)
except:
return numpy.ones(len(inDataCacheDictionary['DependentData'])) * 1.0E300
3
Example 27
def CalculateModelPredictions(self, inCoeffs, inDataCacheDictionary):
x_in = inDataCacheDictionary['X'] # only need to perform this dictionary look-up once
a = inCoeffs[0]
b = inCoeffs[1]
c = inCoeffs[2]
try:
temp = a * numpy.power(b + x_in, -1.0 / c)
return self.extendedVersionHandler.GetAdditionalModelPredictions(temp, inCoeffs, inDataCacheDictionary, self)
except:
return numpy.ones(len(inDataCacheDictionary['DependentData'])) * 1.0E300
3
Example 28
def get_coefs(self, freq):
"""
Get frequency-dependent coefficients.
"""
eigs = self.eigs
f2 = freq*freq
aux = (f2 - self.gamma * eigs)
num = f2 * aux
denom = aux*aux + f2*(self.eta*self.eta)*nm.power(eigs, 2.0)
return num, denom
3
Example 29
def CalculateModelPredictions(self, inCoeffs, inDataCacheDictionary):
XSQPLUSYSQ = inDataCacheDictionary['XSQPLUSYSQ'] # only need to perform this dictionary look-up once
XSQPLUSYSQ_POW4_3D = inDataCacheDictionary['XSQPLUSYSQ_POW4_3D'] # only need to perform this dictionary look-up once
XSQPLUSYSQ_POW6_3D = inDataCacheDictionary['XSQPLUSYSQ_POW6_3D'] # only need to perform this dictionary look-up once
XSQPLUSYSQ_POW8_3D = inDataCacheDictionary['XSQPLUSYSQ_POW8_3D'] # only need to perform this dictionary look-up once
k = inCoeffs[0]
r = inCoeffs[1]
A4 = inCoeffs[2]
A6 = inCoeffs[3]
A8 = inCoeffs[4]
try:
s_sq = XSQPLUSYSQ
s_over_r = numpy.power(s_sq) / r
temp = (s_sq / r) / (1.0 + numpy.sqrt(1.0 - (k + 1.0) * s_over_r * s_over_r)) + A4 * XSQPLUSYSQ_POW4_3D + A6 * XSQPLUSYSQ_POW6_3D + A8 * XSQPLUSYSQ_POW8_3D
return self.extendedVersionHandler.GetAdditionalModelPredictions(temp, inCoeffs, inDataCacheDictionary, self)
except:
return numpy.ones(len(inDataCacheDictionary['DependentData'])) * 1.0E300
3
Example 30
@Operation.factory
def Pow(a, b):
"""
Power op.
"""
return np.power(a, b),
3
Example 31
def CalculateModelPredictions(self, inCoeffs, inDataCacheDictionary):
x_in = inDataCacheDictionary['X'] # only need to perform this dictionary look-up once
a = inCoeffs[0]
b = inCoeffs[1]
c = inCoeffs[2]
try:
temp = 1.0 - numpy.power(a, b * x_in + c)
return self.extendedVersionHandler.GetAdditionalModelPredictions(temp, inCoeffs, inDataCacheDictionary, self)
except:
return numpy.ones(len(inDataCacheDictionary['DependentData'])) * 1.0E300
3
Example 32
def theta(p, t, p2=1000.):
'''
Returns the potential temperature (C) of a parcel.
Parameters
----------
p : number, numpy array
The pressure of the parcel (hPa)
t : number, numpy array
Temperature of the parcel (C)
p2 : number, numpy array (default 1000.)
Reference pressure level (hPa)
Returns
-------
Potential temperature (C)
'''
return ((t + ZEROCNK) * np.power((p2 / p),ROCP)) - ZEROCNK
3
Example 33
def CalculateModelPredictions(self, inCoeffs, inDataCacheDictionary):
x_in = inDataCacheDictionary['X'] # only need to perform this dictionary look-up once
a = inCoeffs[0]
b = inCoeffs[1]
c = inCoeffs[2]
try:
temp = 1.0 / (a + b*numpy.power(x_in, c))
return self.extendedVersionHandler.GetAdditionalModelPredictions(temp, inCoeffs, inDataCacheDictionary, self)
except:
return numpy.ones(len(inDataCacheDictionary['DependentData'])) * 1.0E300
3
Example 34
Project: pele Source File: atom.py
def get_lj_sigma_epsilon(self):
"""
This calculates sigma and epsilon, based on the LJ A and B coefficients
described above and returns them as a tuple.
s = (A/B)**(1/6)
e = B**2/4A
"""
sigma = np.reciprocal(np.power(self.lj_a/self.lj_b, 6.0))
epsilon = self.lj_b * self.lj_b / (4.0 * self.lj_a)
return sigma, epsilon
3
Example 35
def CalculateModelPredictions(self, inCoeffs, inDataCacheDictionary):
x_in = inDataCacheDictionary['X'] # only need to perform this dictionary look-up once
a = inCoeffs[0]
b = inCoeffs[1]
c = inCoeffs[2]
try:
temp = x_in / (a + b*numpy.power(x_in, c))
return self.extendedVersionHandler.GetAdditionalModelPredictions(temp, inCoeffs, inDataCacheDictionary, self)
except:
return numpy.ones(len(inDataCacheDictionary['DependentData'])) * 1.0E300
3
Example 36
def deriv2(self, p):
"""
Second derivative of the power transform
Parameters
----------
p : array-like
Mean parameters
Returns
--------
g''(p) : array
Second derivative of the power transform of `p`
Notes
-----
g''(`p`) = `power` * (`power` - 1) * `p`**(`power` - 2)
"""
return self.power * (self.power - 1) * np.power(p, self.power - 2)
3
Example 37
@Elementwise.numpy_numeric
def numeric(self, values):
# Throw error if negative and power doesn't handle that.
if self.p < 0 and values[0].min() <= 0:
raise ValueError(
"power(x, %.1f) cannot be applied to negative or zero values." % float(self.p)
)
elif not is_power2(self.p) and self.p != 0 and values[0].min() < 0:
raise ValueError(
"power(x, %.1f) cannot be applied to negative values." % float(self.p)
)
else:
return np.power(values[0], float(self.p))
3
Example 38
Project: pyflux Source File: scores.py
@staticmethod
def mu_adj_score(y,loc,scale,shape,skewness):
try:
if (y-loc)>=0:
return (((shape+1.0)*power(y-loc,2))/float(power(skewness,2)*shape*exp(scale) + power(y-loc,2))) - 1.0
else:
return (((shape+1.0)*power(y-loc,2))/float(power(skewness,-2)*shape*exp(scale) + power(y-loc,2))) - 1.0
except:
return -1.0
3
Example 39
Project: tract_querier Source File: scalar_measures.py
def geodesic_anisotropy(evals):
""" Taken from dipy/reconst/dti.py
see for docuementation
:return:
"""
ev1, ev2, ev3 = evals
# this is the definition in [1]_
detD = numpy.power(ev1 * ev2 * ev3, 1 / 3.)
if detD > 1e-9:
log1 = numpy.log(ev1 / detD)
log2 = numpy.log(ev2 / detD)
log3 = numpy.log(ev3 / detD)
ga = numpy.sqrt(log1 ** 2 + log2 ** 2 + log3 ** 2)
else:
ga = 0.0
return ga
3
Example 40
Project: statsmodels Source File: copula.py
def copula_bv_clayton(u, v, theta):
'''Clayton or Cook, Johnson bivariate copula
'''
if not theta > 0:
raise ValueError('theta needs to be strictly positive')
return np.power(np.power(u, -theta) + np.power(v, -theta) - 1, -theta)
3
Example 41
Project: kepler_orrery Source File: diverging_map.py
def Lab2Msh(self, Lab):
"""
Conversion of CIELAB to Msh
"""
# unpack the Lab-array
L, a, b = Lab.tolist()
# calculation of M, s and h
M = np.sqrt(np.sum(np.power(Lab, 2)))
s = np.arccos(L/M)
h = np.arctan2(b,a)
return np.array([M,s,h])
3
Example 42
def setUp(self):
p=4
nspins = 10
interactions = np.ones(np.power(10,p))
coords = np.ones(nspins)
self.pot = MeanFieldPSpinSpherical(interactions, nspins, p)
self.x0 = coords
self.e0 = -210/np.power(nspins,(p-1)/2)
3
Example 43
Project: oq-hazardlib Source File: edwards_fah_2013a.py
def _compute_term_1(self, C, mag):
"""
Compute term 1
a1 + a2.*M + a3.*M.^2 + a4.*M.^3 + a5.*M.^4 + a6.*M.^5 + a7.*M.^6
"""
return (
C['a1'] + C['a2'] * mag + C['a3'] *
np.power(mag, 2) + C['a4'] * np.power(mag, 3)
+ C['a5'] * np.power(mag, 4) + C['a6'] *
np.power(mag, 5) + C['a7'] * np.power(mag, 6)
)
3
Example 44
def magnitude(a, b):
#calculate the magnitude
a = numpy.power(a, 2)
b = numpy.power(b, 2)
mag = numpy.add(a, b)
#We really don't need to take the square root here. It just adds overhead
#and we may get higher resolution on the threshold without doing it. Threshold
#just needs to be adjusted accordingly (make it larger by a square.)
#mag = numpy.sqrt(mag)
return mag
3
Example 45
Project: pyquante2 Source File: functionals.py
def xb88_array(rho,gam,tol=1e-6):
# Still doesn't work
rho = zero_low_density(rho)
rho13 = np.power(rho,1./3.)
x = np.zeros(rho.shape,dtype=float)
g = np.zeros(rho.shape,dtype=float)
dg = np.zeros(rho.shape,dtype=float)
x[rho>tol] = np.sqrt(gam)/rho13/rho
g[rho>tol] = b88_g(x[rho>tol])
dg[rho>tol] = b88_dg(x[rho>tol])
dfxdrho = (4./3.)*rho13*(g-x*dg)
dfxdgam = 0.5*dg/np.sqrt(gam)
fx = rho*rho13*g
return fx,dfxdrho,dfxdgam
3
Example 46
def setUp(self):
p=2
nspins = 10
interactions = np.ones(np.power(10,p))
coords = np.ones(nspins)
self.pot = MeanFieldPSpinSpherical(interactions, nspins, p)
self.x0 = coords
self.e0 = -45
3
Example 47
def setUp(self):
p=5
nspins = 10
interactions = np.ones(np.power(10,p))
coords = np.ones(nspins)
self.pot = MeanFieldPSpinSpherical(interactions, nspins, p)
self.x0 = coords
self.e0 = -252/np.power(nspins,(p-1)/2)
3
Example 48
def forward(self, X):
mu = self.W[0].reshape(1, self.W.shape[1])
pi = self.W[1].reshape(1, self.W.shape[1])
self.Xshape = X.shape
X = X.reshape(X.shape[0], 1)
self.X = X
Z = np.exp(mu * X + (pi - np.power(mu, 2) / 2))
Y = Z / np.sum(Z, axis=-1).reshape(X.shape[0], 1)
self.Z = Z
self.Y = Y
return Y
3
Example 49
Project: biggus Source File: test__Elementwise.py
def test_dual_argument_operation(self):
exponent = 2
expected = self.masked_array ** exponent
actual = Elementwise(self.masked_array, exponent, np.power, ma.power)
result = actual.masked_array()
assert_array_equal(result.mask, self.mask)
assert_array_equal(result, expected)
3
Example 50
def CalculateModelPredictions(self, inCoeffs, inDataCacheDictionary):
x_LogX = inDataCacheDictionary['LogX'] # only need to perform this dictionary look-up once
a = inCoeffs[0]
try:
temp = numpy.power(a, x_LogX)
return self.extendedVersionHandler.GetAdditionalModelPredictions(temp, inCoeffs, inDataCacheDictionary, self)
except:
return numpy.ones(len(inDataCacheDictionary['DependentData'])) * 1.0E300