本文整理汇总了Python中numpy.array函数的典型用法代码示例。如果您正苦于以下问题:Python array函数的具体用法?Python array怎么用?Python array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_partial_dependence_helpers
def test_partial_dependence_helpers(est, method, target_feature):
# Check that what is returned by _partial_dependence_brute or
# _partial_dependence_recursion is equivalent to manually setting a target
# feature to a given value, and computing the average prediction over all
# samples.
# This also checks that the brute and recursion methods give the same
# output.
X, y = make_regression(random_state=0)
# The 'init' estimator for GBDT (here the average prediction) isn't taken
# into account with the recursion method, for technical reasons. We set
# the mean to 0 to that this 'bug' doesn't have any effect.
y = y - y.mean()
est.fit(X, y)
# target feature will be set to .5 and then to 123
features = np.array([target_feature], dtype=np.int32)
grid = np.array([[.5],
[123]])
if method == 'brute':
pdp = _partial_dependence_brute(est, grid, features, X,
response_method='auto')
else:
pdp = _partial_dependence_recursion(est, grid, features)
mean_predictions = []
for val in (.5, 123):
X_ = X.copy()
X_[:, target_feature] = val
mean_predictions.append(est.predict(X_).mean())
pdp = pdp[0] # (shape is (1, 2) so make it (2,))
assert_allclose(pdp, mean_predictions, atol=1e-3)
开发者ID:manhhomienbienthuy,项目名称:scikit-learn,代码行数:34,代码来源:test_partial_dependence.py
示例2: get_tracedata
def get_tracedata(self, format = 'AmpPha', single=False):
'''
Get the data of the current trace
Input:
format (string) : 'AmpPha': Amp in dB and Phase, 'RealImag',
Output:
'AmpPha':_ Amplitude and Phase
'''
#data = self._visainstrument.ask_for_values(':FORMAT REAL,32;*CLS;CALC1:DATA:NSW? SDAT,1;*OPC',format=1)
data = self._visainstrument.ask_for_values('FORM:DATA REAL; FORM:BORD SWAPPED; CALC%i:SEL:DATA:SDAT?'%(self._ci), format = visa.double)
data_size = numpy.size(data)
datareal = numpy.array(data[0:data_size:2])
dataimag = numpy.array(data[1:data_size:2])
if format.upper() == 'REALIMAG':
if self._zerospan:
return numpy.mean(datareal), numpy.mean(dataimag)
else:
return datareal, dataimag
elif format.upper() == 'AMPPHA':
if self._zerospan:
datareal = numpy.mean(datareal)
dataimag = numpy.mean(dataimag)
dataamp = numpy.sqrt(datareal*datareal+dataimag*dataimag)
datapha = numpy.arctan(dataimag/datareal)
return dataamp, datapha
else:
dataamp = numpy.sqrt(datareal*datareal+dataimag*dataimag)
datapha = numpy.arctan2(dataimag,datareal)
return dataamp, datapha
else:
raise ValueError('get_tracedata(): Format must be AmpPha or RealImag')
开发者ID:rotzinger,项目名称:qkit,代码行数:34,代码来源:Anritsu_VNA.py
示例3: test_RadiusNeighborsRegressor_multioutput_with_uniform_weight
def test_RadiusNeighborsRegressor_multioutput_with_uniform_weight():
"""Test radius neighbors in multi-output regression (uniform weight)"""
rng = check_random_state(0)
n_features = 5
n_samples = 40
n_output = 4
X = rng.rand(n_samples, n_features)
y = rng.rand(n_samples, n_output)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
for algorithm, weights in product(ALGORITHMS, [None, 'uniform']):
rnn = neighbors. RadiusNeighborsRegressor(weights=weights,
algorithm=algorithm)
rnn.fit(X_train, y_train)
neigh_idx = rnn.radius_neighbors(X_test, return_distance=False)
y_pred_idx = np.array([np.mean(y_train[idx], axis=0)
for idx in neigh_idx])
y_pred_idx = np.array(y_pred_idx)
y_pred = rnn.predict(X_test)
assert_equal(y_pred_idx.shape, y_test.shape)
assert_equal(y_pred.shape, y_test.shape)
assert_array_almost_equal(y_pred, y_pred_idx)
开发者ID:93sam,项目名称:scikit-learn,代码行数:28,代码来源:test_neighbors.py
示例4: test_continuum_seismicity
def test_continuum_seismicity(self):
'''
Tests the function hmtk.strain.shift.Shift.continuum_seismicity -
the python implementation of the Subroutine Continuum Seismicity from
the Fortran 90 code GSRM.f90
'''
self.strain_model = GeodeticStrain()
# Define a simple strain model
test_data = {'longitude': np.zeros(3, dtype=float),
'latitude': np.zeros(3, dtype=float),
'exx': np.array([1E-9, 1E-8, 1E-7]),
'eyy': np.array([5E-10, 5E-9, 5E-8]),
'exy': np.array([2E-9, 2E-8, 2E-7])}
self.strain_model.get_secondary_strain_data(test_data)
self.model = Shift([5.66, 6.66])
threshold_moment = moment_function(np.array([5.66, 6.66]))
expected_rate = np.array([[-14.43624419, -22.48168502],
[-13.43624419, -21.48168502],
[-12.43624419, -20.48168502]])
np.testing.assert_array_almost_equal(
expected_rate,
np.log10(self.model.continuum_seismicity(
threshold_moment,
self.strain_model.data['e1h'],
self.strain_model.data['e2h'],
self.strain_model.data['err'],
BIRD_GLOBAL_PARAMETERS['OSRnor'])))
开发者ID:atalayayele,项目名称:hmtk,代码行数:28,代码来源:test_shift_calculator.py
示例5: testCNCS
def testCNCS(self):
# CNCS_7860 is not an incoherent scatterer but for this test
# it doesn't matter
SA, Flux = MDNormSCDPreprocessIncoherent(Filename='CNCS_7860',
MomentumMin=1,
MomentumMax=1.5)
# Just compare 10 points of the Flux
flux_cmp = np.array([0.00000000e+00, 7.74945234e-04, 4.96143098e-03,
1.18914010e-02, 1.18049991e-01, 7.71872176e-01,
9.93078957e-01, 9.96312349e-01, 9.98450129e-01,
1.00000002e+00])
np.testing.assert_allclose(Flux.extractY()[0][::1000], flux_cmp)
self.assertEqual(Flux.getXDimension().name, 'Momentum')
self.assertEqual(Flux.getXDimension().getUnits(), 'Angstrom^-1')
self.assertEqual(Flux.blocksize(), 10000)
self.assertEqual(Flux.getNumberHistograms(), 1)
# Compare every 20-th bin of row 64
SA_cmp = np.array([0.11338311, 0.18897185, 0.15117748, 0.11338311, 0.03779437,
0.07558874, 0.15117748, 0.18897185, 0.03779437, 0.15117748,
0.11338311, 0.07558874, 0.03779437, 0. , 0.56691555,
0.26456059, 0.11338311, 0.07558874, 0.11338311, 0.])
np.testing.assert_allclose(SA.extractY().reshape((-1,128))[::20,64], SA_cmp)
self.assertEqual(SA.getXDimension().name, 'Momentum')
self.assertEqual(SA.getXDimension().getUnits(), 'Angstrom^-1')
self.assertEqual(SA.blocksize(), 1)
self.assertEqual(SA.getNumberHistograms(), 51200)
self.assertEqual(SA.getNEvents(), 51200)
开发者ID:DanNixon,项目名称:mantid,代码行数:29,代码来源:MDNormSCDPreprocessIncoherentTest.py
示例6: __init__
def __init__(self,data,p,q,formula):
# Initialize TSM object
super(EGARCHMReg,self).__init__('EGARCHMReg')
# Latent variables
self.p = p
self.q = q
self.max_lag = max(self.p,self.q)
self.z_no = self.p + self.q + 2
self._z_hide = 0 # Whether to cutoff variance latent variables from results
self.supported_methods = ["MLE","PML","Laplace","M-H","BBVI"]
self.default_method = "MLE"
self.multivariate_model = False
self.leverage = False
self.model_name = "EGARCHMReg(" + str(self.p) + "," + str(self.q) + ")"
# Format the data
self.is_pandas = True # This is compulsory for this model type
self.data_original = data
self.formula = formula
self.y, self.X = dmatrices(formula, data)
self.z_no += self.X.shape[1]*2
self.y_name = self.y.design_info.describe()
self.data_name = self.y_name
self.X_names = self.X.design_info.describe().split(" + ")
self.y = np.array([self.y]).ravel()
self.data = self.y
self.X = np.array([self.X])[0]
self.index = data.index
self.initial_values = np.zeros(self.z_no)
self._create_latent_variables()
开发者ID:ekote,项目名称:pyflux,代码行数:33,代码来源:egarchmreg.py
示例7: vertex_transform1
def vertex_transform1(vertex):
"""
This transform was applied on the original surface.
"""
return np.dot(rotation_matrix(np.array([0.0, 0.0, 1.0]), math.pi),
np.dot(rotation_matrix(np.array([1.0, 0.0, 0.0]), -math.pi / 1.6),
np.array([float(x) / 1.5 for x in vertex[:3]]) + np.array([0.0, -40.0, 20.0])))
开发者ID:fmelinscak,项目名称:tvb-data,代码行数:7,代码来源:scale_obj.py
示例8: init
def init():
global theMesh, theLight, theCamera, \
theScreen, resolution
initializeVAO()
glEnable(GL_CULL_FACE)
glEnable(GL_DEPTH_TEST)
# Add our object
# LIGHT
theLight = N.array((-0.577, 0.577, 0.577, 0.0),dtype=N.float32)
# OBJECT
phongshader = makeShader("phongshader.vert","phongshader.frag")
verts, elements = readOBJ("suzanne.obj")
suzanneVerts = getArrayBuffer(verts)
suzanneElements = getElementBuffer(elements)
suzanneNum = len(elements)
theMesh = coloredMesh(N.array((1.0, 0.5, 1.0, 1.0), dtype=N.float32),
suzanneVerts,
suzanneElements,
suzanneNum,
phongshader)
# CAMERA
width,height = theScreen.get_size()
aspectRatio = float(width)/float(height)
near = 0.01
far = 100.0
lens = 4.0 # "longer" lenses mean more telephoto
theCamera = Camera(lens, near, far, aspectRatio)
theCamera.moveBack(6)
开发者ID:geo7,项目名称:csci480,代码行数:30,代码来源:gm121.py
示例9: calculate_user_similarity
def calculate_user_similarity(user_rating_dict,user_list,restaurant_list,score_matrix,user_mean):
similarity_matrix = []
for row in range(len(user_list)):
similarity_vector = []
list1 = user_rating_dict[user_list[row]].keys()
mean1 = user_mean[row]
for col in range(row,len(user_list)):
list2 = user_rating_dict[user_list[col]].keys()
mean2 = user_mean[col]
join_list = list(set(list1+list2))
rating_vector1 = []
rating_vector2 = []
for item in join_list:
if item in list1:
rating_vector1.append(user_rating_dict[user_list[row]][item]-mean1)
else:
rating_vector1.append(score_matrix[row,restaurant_list.index(item)]-mean1)
if item in list2:
rating_vector2.append(user_rating_dict[user_list[col]][item]-mean2)
else:
rating_vector2.append(score_matrix[col,restaurant_list.index(item)]-mean2)
similarity = numpy.sum(numpy.array(rating_vector1)*numpy.array(rating_vector2))/sqrt(numpy.sum(numpy.square(rating_vector1))*numpy.sum(numpy.square(rating_vector2)))
similarity_vector.append(similarity)
similarity_matrix.append(similarity_vector)
similarity_matrix = numpy.array(similarity_matrix)
for col in range(len(user_list)):
for row in range(col,len(user_list)):
similarity_matrix[row,col] = similarity_matrix[col,row]
return similarity_matrix
开发者ID:raymondwqb,项目名称:Yelp_Recommendation-1,代码行数:29,代码来源:Yelp_recommender.py
示例10: test_array_richcompare_legacy_weirdness
def test_array_richcompare_legacy_weirdness(self):
# It doesn't really work to use assert_deprecated here, b/c part of
# the point of assert_deprecated is to check that when warnings are
# set to "error" mode then the error is propagated -- which is good!
# But here we are testing a bunch of code that is deprecated *because*
# it has the habit of swallowing up errors and converting them into
# different warnings. So assert_warns will have to be sufficient.
assert_warns(FutureWarning, lambda: np.arange(2) == "a")
assert_warns(FutureWarning, lambda: np.arange(2) != "a")
# No warning for scalar comparisons
with warnings.catch_warnings():
warnings.filterwarnings("error")
assert_(not (np.array(0) == "a"))
assert_(np.array(0) != "a")
assert_(not (np.int16(0) == "a"))
assert_(np.int16(0) != "a")
for arg1 in [np.asarray(0), np.int16(0)]:
struct = np.zeros(2, dtype="i4,i4")
for arg2 in [struct, "a"]:
for f in [operator.lt, operator.le, operator.gt, operator.ge]:
if sys.version_info[0] >= 3:
# py3
with warnings.catch_warnings() as l:
warnings.filterwarnings("always")
assert_raises(TypeError, f, arg1, arg2)
assert_(not l)
else:
# py2
assert_warns(DeprecationWarning, f, arg1, arg2)
开发者ID:EelcoHoogendoorn,项目名称:numpy,代码行数:30,代码来源:test_deprecations.py
示例11: test
def test(self):
with self.test_session() as sess:
m = tf.constant(np.array([
[1.0, 2.0],
[2.0, 0.0]
], dtype=np.float32))
l = linear(m, 4)
result = sess.run(l, {
'SimpleLinear/Matrix:0': np.array([
[1.0, 2.0],
[1.0, 2.0],
[1.0, 2.0],
[1.0, 2.0],
]),
'SimpleLinear/Bias:0': np.array([
0.0,
1.0,
2.0,
3.0,
]),
})
self.assertAllClose(result, np.array([
[5.0, 6.0, 7.0, 8.0],
[2.0, 3.0, 4.0, 5.0],
]))
print(result)
开发者ID:psyas,项目名称:character-aware-neural-language-models,代码行数:31,代码来源:test_linear.py
示例12: loadTrajectoryData
def loadTrajectoryData(inFile = UJILocDataFile):
with open(UJILocDataFile, 'r') as dataFile:
data = dataFile.read()
# 9-axis IMU data
# trajectory: dictionary with three elements
# N is number of samples in the trajectory (data taken at 10Hz)
# mag: Nx3 numpy array where each line has XYZ mag data
# gyro: Nx3 numpy array where each line has XYZ gyro vel data
# accel: Nx3 numpy array where each line has XYZ lin accelerometer data
segments = data.split("<", 2)
IMUDataStr = segments[0].split('\n')[:-1]
magArr = []
oriArr = []
accelArr = []
for i, lineStr in enumerate(IMUDataStr):
lineStr = lineStr.split(' ', 10)[:-1]
lineStr = [float(x) for x in lineStr]
magArr.append(lineStr[1:4]) # xyz mag data for sample
accelArr.append(lineStr[4:7]) # xyz accelerometer data for single samp
oriArr.append(lineStr[7:10]) # xyz gyro data for sample
# values initially are given as euler angles which are not good for imu-type calculations.
# so we fix em!
gyroArr = rawSensorStateProc.orientationToGyro(oriArr)
initOrientationMatrix = rawSensorStateProc.calcInitialOrientation(oriArr[0])
# IMUData = [{'mag': magArr, 'gyro': gyroArr, 'accel': accelArr}]
# process waypoint data
# each waypoint consists of a latitude coordinate, longitude coordinate,
# and index (what IMU dataopoint it represents)
waypoints = []
waypointStr = segments[1].split(">", 2)
numWaypoints = int(waypointStr[0])
waypointLns = waypointStr[1].lstrip().split('\n')
for i, lineStr in enumerate(waypointLns):
line = lineStr.split(' ', WAYPOINTS_ELEMS_PER_LINE)
line = [float(x) for x in line]
if i == 0:
waypoints.append({'lat': line[0], 'long': line[1], 'index': line[4]})
waypoints.append({'lat': line[2], 'long': line[3], 'index': line[5]})
seqLen = line[5]
traj = ({'waypoints': np.array(waypoints), 'mag': np.array(magArr), 'gyro': np.array(gyroArr),
'accel': np.array(accelArr), 'orientSensed': np.array(oriArr),
'initOrient': initOrientationMatrix, 'seqLen': seqLen})
return traj
# loadTrajectoryData()
开发者ID:noahjepstein,项目名称:Kalman-RNN,代码行数:60,代码来源:preProcessData.py
示例13: test_2d_complex_same
def test_2d_complex_same(self):
a = array([[1+2j,3+4j,5+6j],[2+1j,4+3j,6+5j]])
c = signal.fftconvolve(a,a)
d = array([[-3+4j,-10+20j,-21+56j,-18+76j,-11+60j],\
[10j,44j,118j,156j,122j],\
[3+4j,10+20j,21+56j,18+76j,11+60j]])
assert_array_almost_equal(c,d)
开发者ID:josef-pkt,项目名称:scipy,代码行数:7,代码来源:test_signaltools.py
示例14: setUp
def setUp(self):
x = numpy.array([ 8.375, 7.545, 8.828, 8.5 , 1.757, 5.928,
8.43 , 7.78 , 9.865, 5.878, 8.979, 4.732,
3.012, 6.022, 5.095, 3.116, 5.238, 3.957,
6.04 , 9.63 , 7.712, 3.382, 4.489, 6.479,
7.189, 9.645, 5.395, 4.961, 9.894, 2.893,
7.357, 9.828, 6.272, 3.758, 6.693, 0.993])
X = x.reshape(6, 6)
XX = x.reshape(3, 2, 2, 3)
m = numpy.array([0, 1, 0, 1, 0, 0,
1, 0, 1, 1, 0, 1,
0, 0, 0, 1, 0, 1,
0, 0, 0, 1, 1, 1,
1, 0, 0, 1, 0, 0,
0, 0, 1, 0, 1, 0])
mx = array(data=x, mask=m)
mX = array(data=X, mask=m.reshape(X.shape))
mXX = array(data=XX, mask=m.reshape(XX.shape))
m2 = numpy.array([1, 1, 0, 1, 0, 0,
1, 1, 1, 1, 0, 1,
0, 0, 1, 1, 0, 1,
0, 0, 0, 1, 1, 1,
1, 0, 0, 1, 1, 0,
0, 0, 1, 0, 1, 1])
m2x = array(data=x, mask=m2)
m2X = array(data=X, mask=m2.reshape(X.shape))
m2XX = array(data=XX, mask=m2.reshape(XX.shape))
self.d = (x, X, XX, m, mx, mX, mXX)
开发者ID:Sastria,项目名称:Sastria-Project,代码行数:30,代码来源:test_old_ma.py
示例15: lars_regression_noise_ipyparallel
def lars_regression_noise_ipyparallel(pars):
import numpy as np
import os
import sys
import gc
Y_name,C_name,noise_sn,idxs_C, idxs_Y=pars
Y=np.load(Y_name,mmap_mode='r')
Y=np.array(Y[idxs_Y,:])
C=np.load(C_name,mmap_mode='r')
C=np.array(C)
_,T=np.shape(C)
#sys.stdout = open(str(os.getpid()) + ".out", "w")
st=time.time()
As=[]
#print "*****************:" + str(idxs_Y[0]) + ',' + str(idxs_Y[-1])
sys.stdout.flush()
for y,px in zip(Y,idxs_Y):
#print str(time.time()-st) + ": Pixel" + str(px)
sys.stdout.flush()
c=C[idxs_C[px],:]
if np.size(c)>0:
sn=noise_sn[px]**2*T
_,_,a,_,_=lars_regression_noise(y, c.T, 1, sn)
if not np.isscalar(a):
a=a.T
As.append((px,idxs_C[px],a))
del Y
del C
gc.collect()
return As#As
开发者ID:ninehundred1,项目名称:Constrained_NMF,代码行数:35,代码来源:spatial.py
示例16: test_readXMLBIF
def test_readXMLBIF(self):
bn = XMLBIFParser.parse("primo2/tests/slippery.xbif")
nodes = bn.get_all_nodes()
self.assertTrue("slippery_road" in nodes)
self.assertTrue("sprinkler" in nodes)
self.assertTrue("rain" in nodes)
self.assertTrue("wet_grass" in nodes)
self.assertTrue("winter" in nodes)
self.assertEqual(len(nodes), 5)
slipperyNode = bn.get_node("slippery_road")
self.assertTrue("rain" in slipperyNode.parents)
sprinklerNode = bn.get_node("sprinkler")
self.assertTrue("winter" in sprinklerNode.parents)
rainNode = bn.get_node("rain")
self.assertTrue("winter" in rainNode.parents)
cpt = np.array([[0.8,0.1],[0.2,0.9]])
np.testing.assert_array_almost_equal(rainNode.cpd, cpt)
wetNode = bn.get_node("wet_grass")
self.assertTrue("sprinkler" in wetNode.parents)
self.assertTrue("rain" in wetNode.parents)
self.assertTrue("true" in wetNode.values)
cpt = np.array([[[0.95, 0.8],[0.1,0.0]], [[0.05, 0.2],[0.9, 1.0]]])
self.assertEqual(wetNode.get_probability("false", {"rain":["true"], "sprinkler":["false"]}),0.2)
self.assertEqual(wetNode.get_probability("true", {"rain":["false"], "sprinkler":["true"]}),0.1)
开发者ID:hbuschme,项目名称:PRIMO,代码行数:26,代码来源:IO_test.py
示例17: test3
def test3(self):
convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
instance = Huayno(convert_nbody)
instance.initialize_code()
instance.parameters.epsilon_squared = 0.00001 | units.AU**2
stars = datamodel.Stars(2)
star1 = stars[0]
star2 = stars[1]
star1.mass = units.MSun(1.0)
star1.position = units.AU(numpy.array((-1.0,0.0,0.0)))
star1.velocity = units.AUd(numpy.array((0.0,0.0,0.0)))
star1.radius = units.RSun(1.0)
star2.mass = units.MSun(1.0)
star2.position = units.AU(numpy.array((1.0,0.0,0.0)))
star2.velocity = units.AUd(numpy.array((0.0,0.0,0.0)))
star2.radius = units.RSun(100.0)
instance.particles.add_particles(stars)
for x in range(1,2000,10):
instance.evolve_model(x | units.day)
instance.particles.copy_values_of_all_attributes_to(stars)
stars.savepoint()
开发者ID:mherkazandjian,项目名称:amuse,代码行数:27,代码来源:test_huayno.py
示例18: measure_objects
def measure_objects(self, operand, workspace):
'''Performs the measurements on the requested objects'''
objects = workspace.get_objects(operand.operand_objects.value)
if objects.has_parent_image:
area_occupied = np.sum(objects.segmented[objects.parent_image.mask]>0)
perimeter = np.sum(outline(np.logical_and(objects.segmented != 0,objects.parent_image.mask)))
total_area = np.sum(objects.parent_image.mask)
else:
area_occupied = np.sum(objects.segmented > 0)
perimeter = np.sum(outline(objects.segmented) > 0)
total_area = np.product(objects.segmented.shape)
m = workspace.measurements
m.add_image_measurement(F_AREA_OCCUPIED%(operand.operand_objects.value),
np.array([area_occupied], dtype=float ))
m.add_image_measurement(F_PERIMETER%(operand.operand_objects.value),
np.array([perimeter], dtype=float ))
m.add_image_measurement(F_TOTAL_AREA%(operand.operand_objects.value),
np.array([total_area], dtype=float))
if operand.should_save_image.value:
binary_pixels = objects.segmented > 0
output_image = cpi.Image(binary_pixels,
parent_image = objects.parent_image)
workspace.image_set.add(operand.image_name.value,
output_image)
return[[operand.operand_objects.value,
str(area_occupied),str(perimeter),str(total_area)]]
开发者ID:anntzer,项目名称:CellProfiler,代码行数:26,代码来源:measureimageareaoccupied.py
示例19: condition_on_grades
def condition_on_grades(user="c6961489"):
c = new_conn.cursor()
models = [None, None, None, None, None, None]
for i in range(6):
c.execute('SELECT easiness, ret_reps, ret_reps_since_lapse, lapses, pred_grade, acq_reps from discrete_log where user_id="%s" and grade=%d' % (user, i))
x_train = np.array(c.fetchall())
c.execute('SELECT interval_bucket from discrete_log where user_id="%s" and grade=%d' % (user, i))
y_train = np.array(c.fetchall())[:,0]
clf = SVC()
clf.fit(x_train, y_train)
print clf.score(x_train, y_train)
models[i] = clf
print "====================="
c.execute('SELECT user_id from (select user_id, count(distinct grade) as cnt from discrete_log group by user_id) where cnt = 6 limit 5')
users = [row[0] for row in c.fetchall()]
scores = [0, 0, 0, 0, 0, 0]
for user in users:
for i in range(6):
c.execute('SELECT easiness, ret_reps, ret_reps_since_lapse, lapses, pred_grade, acq_reps from discrete_log where user_id="%s" and grade=%d' % (user, i))
x_train = np.array(c.fetchall())
c.execute('SELECT interval_bucket from discrete_log where user_id="%s" and grade=%d' % (user, i))
y_train = np.array(c.fetchall())[:,0]
scores[i] += models[i].score(x_train, y_train)
for i in range(6):
scores[i] /= len(users);
print scores[i]
开发者ID:sramas15,项目名称:Finding-Mnemosyne,代码行数:26,代码来源:rep_user.py
示例20: __init__
def __init__(self, num_neurons, prev_layer=None):
"""Constructs a layer with given number of neurons.
Args:
num_neurons: Number of neurons in this layer.
prev_layer: Previous layer which acts as input to this
layer. None for input layer.
"""
# x : Activation vector of the neurons.
# nets : Vector of weighted sum of inputs of the neurons.
# deltas : Delta error vector, used to adjust the weights.
self.x = np.array([0] * num_neurons)
self.nets = np.array([0] * num_neurons)
self.deltas = np.array([0] * num_neurons)
self.prev_layer = prev_layer
# If previous layer exists, create a weight matrix
# with random values.
if prev_layer:
self.weights = []
for i in range(num_neurons):
# Each neuron is connected to all neurons of previous layer
# plus a constant input of '1' (the weight of which is
# bias). So total number of weights = num_inputs + 1.
prev_x_len = len(prev_layer.x) + 1
w = [get_random_weight(prev_x_len) for _ in range(prev_x_len)]
self.weights.append(w)
self.weights = np.matrix(self.weights)
开发者ID:coders-circle,项目名称:batss,代码行数:33,代码来源:layer.py
注:本文中的numpy.array函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论