Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
[9,1,2,3]],
[[4,5,6,7],
[8,9,1,2],
[3,4,5,6]]]
a = scipy.asarray(a)
b = scipy.asarray(b)
c = scipy.asarray(c)
original_image_n = '/home/omaier/Experiments/Regionsegmentation/Evaluation_Viscous/00originalvolumes/o09.nii'
original_image = load(original_image_n)
original_image_d = scipy.squeeze(original_image.get_data())
original_image_d = original_image_d[0:50, 0:50, 0:50]
dir = scipy.zeros(original_image_d.shape).ravel()
oir = original_image_d.ravel()
for i in range(len(dir)):
dir[i] = oir[i]
dir = dir.reshape(original_image_d.shape)
coa, con, dir = tamura(dir, 5)
for i in range(5):
print "k=", i+1, " with ", len((coa == i).nonzero()[0])
def _applyWeights(self):
tmp = zeros(self.module.paramdim)
# scale it to the range [-range, range]
largest = 2**self.maxComplexity
for w in range(self.module.paramdim):
tmp[w] = self.weightRange - (2.*self.binaryWeights[w]*self.weightRange)/largest
self.module._setParameters(tmp)
def _mdlstm_handler(self, layer):
# See if there already is a proxy:
try:
proxy = self.map[layer]
except KeyError:
proxy = cppbridge.MdlstmLayer(layer.dimensions, layer.dim)
self[layer] = proxy
proxy.init_input(layer.inputbuffer)
proxy.init_output(layer.outputbuffer)
proxy.init_inerror(layer.inputerror)
proxy.init_outerror(layer.outputerror)
# FIXME: we have to make a buffer especially for this layer to give to
# arac. We attach this to the original pybrain layer object.
layer.inputx = scipy.zeros((layer.dimensions, layer.dim))
proxy.init_input_squashed(layer.inputx)
proxy.init_input_gate_squashed(layer.ingate);
proxy.init_input_gate_unsquashed(layer.ingatex);
proxy.init_output_gate_squashed(layer.outgate);
proxy.init_output_gate_unsquashed(layer.outgatex);
proxy.init_forget_gate_unsquashed(layer.forgetgatex);
proxy.init_forget_gate_squashed(layer.forgetgate);
return proxy
def Kgrad_x(self,theta,X,n=None,d=None):
"""
evaluates the gradient
"""
assert X.shape[1]==self.n_dimensions, 'dimensions do not match'
A = SP.exp(2*theta[0])
if n!=None:
# gradient with respect to X[n,d]
XX = SP.zeros((X.shape[0],X.shape[0]))
XX[:,n] = X[:,d]
XX[n,:] = X[:,d]
XX[n,n] *= 2
else:
# gradient with respect to X[:,d], but assuming K = XY^T (not symmetric!)
Xd = SP.reshape(X[:,d],(X.shape[0],1))
XX = SP.tile(Xd,X.shape[0])
return A*(XX)
def read(fname,winsize):
if fname =="-":
wf=wave.open(sys.stdin,'rb')
n=wf.getnframes()
str=wf.readframes(n)
params = ((wf.getnchannels(), wf.getsampwidth(),
wf.getframerate(), wf.getnframes(),
wf.getcomptype(), wf.getcompname()))
siglen=((int )(len(str)/2/winsize) + 1) * winsize
signal=sp.zeros(siglen, sp.int16)
signal[0:len(str)/2] = sp.fromstring(str,sp.int16)
return signal,params
else:
return read_signal(fname,winsize)
def __init__(self, seg_num):
self.segments = sp.zeros((seg_num,), dtype='float')
self.seg_pos = sp.zeros((seg_num,), dtype='float')
self.edges = sp.zeros((0, 2), dtype='float')
isingConvert = 0
isingSigns = {'hx': -1, 'hz': -1, 'hzz': -1}
# Scaling matrices for Ising coefficients (can be list, similar to multiT)
gbeg = 0.0
gend = 1.0
gstp = 0.5
hzscale = sp.arange(0.0, 10.0, 0.1)
hzzscale = None
hxscale = None
# This is gamma, the appropriate weighting on the input vector
# isingSigns['hz'] *= float(cmdargs['garg'])
alpha = sp.array(hparams['inputState'])
beta = sp.zeros((neurons,neurons))
delta = sp.array([])
# Construct the memory matrix according to a learning rule
if hparams['learningRule'] == 'hebb':
# Construct pattern matrix according to Hebb's rule
for i in range(neurons):
for j in range(neurons):
for p in range(len(memories)):
beta[i,j] += ( memories[p][i]*memories[p][j] -
len(memories)*(i == j) )
beta = sp.triu(beta)/float(neurons)
elif hparams['learningRule'] == 'stork':
# Construct the memory matrix according to the Storkey learning rule
memMat = sp.zeros((neurons,neurons))
for m, mem in enumerate(memories):
for i in range(neurons):
nearest point, in which case the background value is used
"""
import scipy
import scipy.interpolate
import scipy.spatial
import numpy as np
x = np.asarray(x).reshape(1, -1)[0,:]
y = np.asarray(y).reshape(1, -1)[0,:]
# Since ANUGA stores x,y internally in non-georeferenced coordinates,
# we adjust them here
xll = domain.geo_reference.xllcorner
yll = domain.geo_reference.yllcorner
z = scipy.zeros(shape=(len(x), 2))
z[:,0] = x+xll
z[:,1] = y+yll
# This will hold the quantity values
quantity_output = x*0. + background_value
# Compute the index of the nearest-neighbour in quantity_xyValue
neighbour_data = quantity_xy_interpolator.query(z,
k=k_nearest_neighbours)
# Next find indices with distance < threshold_distance
if(k_nearest_neighbours==1):
dist_lt_thresh = neighbour_data[0] < threshold_distance
else:
dist_lt_thresh = neighbour_data[0][:,0] < threshold_distance
dist_lt_thresh = dist_lt_thresh.nonzero()[0]
source_mode = 'nonlinear'
elif maxiter == 0:
source_mode = 'linear'
# Check value of tol
if tol is None:
tol = 1e-5
else:
try:
tol = float(tol)
except (ValueError, TypeError):
raise Exception('input for tol cannot be ' +
'converted to float!')
if ('pore.source_' + prop not in self.labels() or
mode == 'overwrite'):
self['pore.source_' + prop] = sp.zeros((self.Np,),
dtype=bool)
temp_arr = sp.ones((self.Np,), dtype=float) * sp.nan
self['pore.source_' + source_mode +
'_s1_' + prop] = temp_arr
self['pore.source_' + source_mode +
'_s2_' + prop] = temp_arr
# Setting the source term for all the modes except 'remove'
matching_physics = [phys for phys in self._phase._physics
if source_name in phys.models.keys()]
for phys in matching_physics:
x = phys.models[source_name]['x']
return_rate = phys.models[source_name]['return_rate']
regen_mode = phys.models[source_name]['regen_mode']
phys.models[source_name]['x'] = x0
phys.models[source_name]['return_rate'] = False
def V_EH_dipole(J_dip, r_dip, list_of_edges_numbers, RWGNumber_CFIE_OK, RWGNumber_signedTriangles, RWGNumber_edgeVertexes, RWGNumber_oppVertexes, vertexes_coord, w, eps_r, mu_r):
"""I don't know yet what's gonna go here.
Anyway, we use prefentially 2-D triangles arrays in the C++ code"""
# creation of the local V arrays
E = list_of_edges_numbers.shape[0]
V_EH = zeros((E, 4), 'D')
V_FULL_PRECISION = 1
# RWGNumber_vertexesCoord
RWGNumber_vertexesCoord = zeros((E, 6), 'd')
RWGNumber_vertexesCoord[:, 0:3] = take(vertexes_coord, RWGNumber_edgeVertexes[:,0], axis=0).astype('d')
RWGNumber_vertexesCoord[:, 3:6] = take(vertexes_coord, RWGNumber_edgeVertexes[:,1], axis=0).astype('d')
# RWGNumber_oppVertexesCoord
RWGNumber_oppVertexesCoord = zeros((E, 6), 'd')
RWGNumber_oppVertexesCoord[:, 0:3] = take(vertexes_coord, RWGNumber_oppVertexes[:,0], axis=0).astype('d')
RWGNumber_oppVertexesCoord[:, 3:6] = take(vertexes_coord, RWGNumber_oppVertexes[:,1], axis=0).astype('d')
wrapping_code = """
std::vector > V_tE_J, V_tH_J, V_nE_J, V_nH_J;
V_tE_J.resize(E);
V_tH_J.resize(E);
V_nE_J.resize(E);
V_nH_J.resize(E);
double rDip[3];