本文整理汇总了Python中pylab.rand函数的典型用法代码示例。如果您正苦于以下问题:Python rand函数的具体用法?Python rand怎么用?Python rand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rand函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, phase_potrait, network, info=None, position=None):
self.system = phase_potrait
self.network = network
self.CYCLES = 10
self.info = info
self.initial_condition = self.system.load_initial_condition(pl.rand(), pl.rand(), pl.rand())
self.fig = pl.figure('Voltage Traces', figsize=(6, 2), facecolor='#EEEEEE')
self.ax = self.fig.add_subplot(111, frameon=False, yticks=[])
self.li_b, = self.ax.plot([], [], 'b-', lw=2.)
self.li_g, = self.ax.plot([], [], 'g-', lw=2.)
self.li_r, = self.ax.plot([], [], 'r-', lw=2.)
self.li_y, = self.ax.plot([], [], 'y-', lw=2.)
self.ax.set_xlabel(r'time (sec.)', fontsize=20)
self.ax.set_xticklabels(np.arange(0., 1., 0.1), fontsize=15)
self.ax.set_yticklabels(np.arange(0., 1., 0.1), fontsize=15)
self.ax.set_xlim(0., 100.)
self.ax.set_ylim(-0.06-0.18, 0.04)
self.fig.tight_layout()
self.key_func_dict = dict(u=traces.increase_cycles, i=traces.decrease_cycles)
self.fig.canvas.mpl_connect('key_press_event', self.on_key)
self.fig.canvas.mpl_connect('axes_enter_event', self.focus_in)
if not position == None:
try:
self.fig.canvas.manager.window.wm_geometry(position)
except:
pass
开发者ID:jusjusjus,项目名称:Motiftoolbox,代码行数:34,代码来源:traces.py
示例2: check
def check():
gamma = 0.01
X = matrix(rand(64,10))
S = matrix(rand(64,10))
args = (S, X, gamma)
x0 = rand(4096,)
return check_grad(f_l2_wd, g_l2_wd, x0, *args)
开发者ID:jackculpepper,项目名称:sparsenet-python,代码行数:7,代码来源:sparsenet.py
示例3: datagen
def datagen(N):
"""
Produces N pairs of training data and desired output;
each sample of training data contains -1 in its first position,
this corresponds to the interpretation of the threshold as first
element of the weight vector
"""
fun1 = lambda x1,x2: -2*x1**3-x2+.5*x1**2
fun2 = lambda x1,x2: x1**2*x2+2*x1*x2+1
fun3 = lambda x1,x2: .5*x1*x2**2+x2**2-2*x1**2
rarr1 = rand(1,N)
rarr2 = rand(1,N)
teacher = sign(rand(1,N)-.5)
idplus = (teacher<0)
idminus = -idplus
rarr1[idplus] = rarr1[idplus]-1
y1=fun1(rarr1,rarr2)
y2=fun2(rarr1,rarr2)
y3=fun3(rarr1,rarr2)
x=transpose(concatenate((-ones((1,N)),y1,y2)))
return x, teacher[0]
开发者ID:albert4git,项目名称:aTest,代码行数:29,代码来源:datagen.py
示例4: step
def step(self):
# if not tumbling, pick random number. If less than RUN_P, move RUN_R in direction of orientation. else, start tumbling.
# if tumbling, pick random number. If greater than TUMBLE_P, rotate by TUMBLE_R. else, stop tumbling.
# matplotlib has (0,0) in the upper left - adapt trig accordingly...
if not self.TUMBLE:
p = rand()
if p < self.run_p:
self.xy[0] = (self.xy[0] + RUN_R*np.sin(self.th*np.pi/180.))%self.frame_lim
self.xy[1] = (self.xy[1] - RUN_R*np.cos(self.th*np.pi/180.))%self.frame_lim
else:
self.TUMBLE = True
if self.TUMBLE:
p = rand()
if p > self.tumble_p:
q = rand()
if q > 0.5:
self.th = (self.th + TUMBLE_R)%360
else:
self.th = (self.th - TUMBLE_R)%360
else:
self.TUMBLE = False
开发者ID:ebuchman,项目名称:Bacteria,代码行数:25,代码来源:run_and_tumble.py
示例5: computeTraces
def computeTraces(self, initial_condition=None, plotit=True):
if initial_condition == None:
initial_condition = self.system.load_initial_condition(pl.rand(), pl.rand())
V_i = fh.integrate_three_rk4(
initial_condition,
self.network.coupling_strength,
self.system.dt/float(self.system.stride),
self.system.N_output(self.CYCLES),
self.system.stride)
t = self.system.dt*np.arange(V_i.shape[0])
if plotit:
ticks = np.asarray(t[::t.size/10], dtype=int)
self.li_b.set_data(t, V_i[:, 0])
self.li_g.set_data(t, V_i[:, 1]-2.)
self.li_r.set_data(t, V_i[:, 2]-4.)
self.ax.set_xticks(ticks)
self.ax.set_xticklabels(ticks)
self.ax.set_xlim(t[0], t[-1])
self.fig.canvas.draw()
return t, V_i
开发者ID:denizalacam,项目名称:Motiftoolbox,代码行数:25,代码来源:traces.py
示例6: normal_test_case
def normal_test_case():
'''
Runs a test case with simulated data from a normal distribution.
'''
obs, fa, dur = [], [], []
for n in range(15):
d, f, o = make_test_data(
5, split=min(plt.rand()*50+120, 170),
intercept=plt.rand()*50 + 225,
slope1=1 + plt.randn()/0.75, slope2=plt.randn()/.75)
obs.append(o+n)
fa.append(f)
dur.append(d)
plt.plot(f, d, 'o', alpha=0.1)
dur, fa, obs = (np.hstack(dur)[:, np.newaxis],
np.hstack(fa)[:, np.newaxis],
np.hstack(obs)[:, np.newaxis])
dur_mean = dur.mean()
dur_std = dur.std()
dur = (dur-dur_mean)/dur_std
m = normal_model(dur, fa, obs)
trace = sample_model(m, 5000)
predict(trace, 5, 2500, {'mean': dur_mean, 'std': dur_std})
plt.figure()
traceplot(trace, 2, 2500)
return dur, fa, obs, (dur_mean, dur_std), trace
开发者ID:nwilming,项目名称:mcmodels,代码行数:29,代码来源:fixdur.py
示例7: create_N
def create_N(_n,_xmax,_ymax):
_nodes = []
for i in range(_n):
_tmpx = pylab.rand()*_xmax
_tmpy = pylab.rand()*_ymax
_nodes.append((_tmpx, _tmpy))
return _nodes
开发者ID:hmgaspar,项目名称:TSP,代码行数:7,代码来源:tsp_ga_choice.py
示例8: __init__
def __init__(self, phase_potrait, network, info=None, position=None):
win.window.__init__(self, position)
self.system = phase_potrait
self.network = network
self.info = info
self.CYCLES = 10
self.initial_condition = self.system.load_initial_condition(pl.rand(), pl.rand())
self.ax = self.fig.add_subplot(111, frameon=False, yticks=[])
self.li_b, = self.ax.plot([], [], 'b-', lw=2.)
self.li_g, = self.ax.plot([], [], 'g-', lw=2.)
self.li_r, = self.ax.plot([], [], 'r-', lw=2.)
self.ax.set_xlabel(r'time (sec.)', fontsize=20)
self.ax.set_xticklabels(np.arange(0., 1., 0.1), fontsize=15)
self.ax.set_yticklabels(np.arange(0., 1., 0.1), fontsize=15)
self.ax.set_xlim(0., 100.)
self.ax.set_ylim(-5.5, 1.5)
#self.fig.tight_layout()
self.key_func_dict = dict(u=traces.increase_cycles, i=traces.decrease_cycles)
self.fig.canvas.mpl_connect('key_press_event', self.on_key)
self.fig.canvas.mpl_connect('axes_enter_event', self.focus_in)
开发者ID:RamiJacob,项目名称:Motiftoolbox,代码行数:27,代码来源:traces.py
示例9: computeTraces
def computeTraces(self, initial_condition=None, plotit=True):
if initial_condition == None:
initial_condition = self.system.load_initial_condition(pl.rand(), pl.rand())
V_i = fh.integrate_three_rk4(
initial_condition,
self.network.coupling_strength,
self.system.dt/float(self.system.stride),
self.system.N_output(self.CYCLES),
self.system.stride)
t = self.system.dt*np.arange(V_i.shape[0])
if plotit:
ticks = np.asarray(t[::t.size/10], dtype=int)
xscale, yscale = t[-1], 2.
for (i, li) in enumerate([self.li_b, self.li_g, self.li_r]):
tj, Vj = tl.adjustForPlotting(t, V_i[:, i], ratio=xscale/yscale, threshold=0.05*xscale)
li.set_data(tj, Vj-i*2)
self.ax.set_xticks(ticks)
self.ax.set_xticklabels(ticks)
self.ax.set_xlim(t[0], t[-1])
self.fig.canvas.draw()
return t, V_i
开发者ID:jusjusjus,项目名称:Motiftoolbox,代码行数:28,代码来源:traces.py
示例10: __init__
def __init__(self, system, network, info=None, position=None):
win.window.__init__(self, position)
self.system = system
self.network = network
self.info = info
self.CYCLES = 8
self.state = system.load_initial_condition( pl.rand(), pl.rand() )
self.initial_condition = self.system.load_initial_condition(pl.rand(), pl.rand())
self.running = False
self.pulsed = 0
self.ax = self.fig.add_subplot(111, frameon=False, yticks=[])
self.li_b, = self.ax.plot([], [], 'b-', lw=1.)
self.li_g, = self.ax.plot([], [], 'g-', lw=1.)
self.li_r, = self.ax.plot([], [], 'r-', lw=1.)
self.ax.set_xlabel(r'time (sec.)', fontsize=20)
self.ax.set_xticklabels(np.arange(0., 1., 0.1), fontsize=15)
self.ax.set_yticklabels(np.arange(0., 1., 0.1), fontsize=15)
self.ax.set_xlim(0., 100.)
self.ax.set_ylim(-0.06-0.12, 0.04)
self.key_func_dict = dict(u=traces.increase_cycles, i=traces.decrease_cycles)
self.fig.canvas.mpl_connect('button_press_event', self.on_click)
self.fig.canvas.mpl_connect('axes_enter_event', self.focus_in)
开发者ID:powerpuffgirl87,项目名称:Motiftoolbox,代码行数:28,代码来源:traces.py
示例11: test_add_out_of_center_l
def test_add_out_of_center_l(plot=False, color=1):
# use the same data for both experiments:
num_imgs = 200
color_mult = [1, 3][color]
img_res = 15
padding = 4
targ_pix = img_res ** 2 * color_mult
img_pix = (img_res + 2 * padding) ** 2 * color_mult
inputs = rand(num_imgs, img_pix) < 0.1
targets = rand(num_imgs, targ_pix) * 0.4
inputs[1:] *= 0
# targets = g.rand(num_imgs,targ_pix)
ans = [None] * 2
print "a"
for (i, gx) in enumerate([g, gc]):
conv.g = gx # wonderful. This seems to work. At least.
conv._cu = gx._cudamat
a = gx.garray(inputs)
ans[i] = conv.add_out_of_center_l(a, gx.garray(targets), color=color).asarray()
print "b"
print abs(ans[0] - ans[1]).max()
if plot:
if not color:
from pylab import show, subplot
subplot(221)
show(inputs[0])
subplot(223)
show(ans[0][0])
subplot(224)
show(ans[1][0])
else:
from pylab import show, subplot
r = img_pix / color_mult
subplot(331)
show(inputs[0][:r])
r = ans[0].shape[1] / 3
subplot(332)
show(ans[0][0][:r])
subplot(334)
show(ans[1][0][:r])
subplot(335)
show(ans[1][0][r : 2 * r])
subplot(336)
show(ans[1][0][2 * r : 3 * r])
开发者ID:barapa,项目名称:HF-RNN,代码行数:57,代码来源:test_conv2.py
示例12: sim_time
def sim_time(i):
n = pylab.randint(N_MIN, N_MAX)
alpha = pylab.rand()
net = random_network(n)
r = ne_capacity(net)*((1-MIN_DEMAND)*pylab.rand() + MIN_DEMAND)
tic = time.clock()
optimal_stackelberg(net,r,alpha)
val = (n,time.clock() - tic)
print val
return val
开发者ID:flyerae,项目名称:AGT-stackelberg,代码行数:10,代码来源:bm2.py
示例13: make_2DLinearSeparable_Dataset
def make_2DLinearSeparable_Dataset(n):
xb = (rand(n)*2-1)/2-0.5
yb = (rand(n)*2-1)/2+0.5
xr = (rand(n)*2-1)/2+0.5
yr = (rand(n)*2-1)/2-0.5
inputs = []
for i in range(len(xb)):
inputs.append([xb[i],yb[i],1])
inputs.append([xr[i],yr[i],-1])
return inputs
开发者ID:jamesbondo,项目名称:mypy,代码行数:10,代码来源:generateData.py
示例14: genererDonnees
def genererDonnees(n):
xb=(pl.rand(n)*2-1)/2-0.5
yb=(pl.rand(n)*2-1)/2+0.5
xr=(pl.rand(n)*2-1)/2+0.5
yr=(pl.rand(n)*2-1)/2-0.5
donnees=[]
for i in range(len(xb)):
donnees.append(((xb[i],yb[i]),-1))
donnees.append(((xr[i],yr[i]),1))
return donnees
开发者ID:JulianHurst,项目名称:Apprentissage,代码行数:10,代码来源:Perceptron_noy.py
示例15: genererDonnees
def genererDonnees(n):
"Generer un jeu de donnees 2D lineairement separable de taille n"
xb=(rand(n)*2-1)/2-0.5
yb=(rand(n)*2-1)/2+0.5
xr=(rand(n)*2-1)/2+0.5
yr=(rand(n)*2-1)/2-0.5
donnees=[]
for i in range (len(xb)):
donnees.append(((xb[i],yb[i]),False))
donnees.append(((xr[i],yr[i]),True))
return donnees
开发者ID:laiaga,项目名称:TPSM1,代码行数:11,代码来源:perceptron_binaire.py
示例16: gen_data
def gen_data(n):
xb = (rand(n)*2-1)/2-0.5
yb = (rand(n)*2-1)/2+0.5
inputs = [[xb[i], yb[i]] for i in xrange(len(xb))]
targets = [[i] for i in repeat(1, len(xb))]
xr = (rand(n)*2-1)/2+0.5
yr = (rand(n)*2-1)/2-0.5
inputs = inputs + [[xr[i], yr[i]] for i in xrange(len(xr))]
targets = targets + [[i] for i in repeat(0, len(xr))]
return np.array(inputs), np.array(targets)
开发者ID:Augustles,项目名称:machine-learning,代码行数:12,代码来源:perceptron.py
示例17: choose_patches
def choose_patches(IMAGES, L, batch_size=1000):
sz = int(sqrt(L))
imsz = shape(IMAGES)[0]
num_images = shape(IMAGES)[2]
BUFF = 4
X = matrix(zeros([L,batch_size],'d'))
for i in range(batch_size):
j = int(floor(num_images * rand()))
r = sz/2+BUFF+int(floor((imsz-sz-2*BUFF)*rand()))
c = sz/2+BUFF+int(floor((imsz-sz-2*BUFF)*rand()))
X[:,i] = reshape(IMAGES[r-sz/2:r+sz/2,c-sz/2:c+sz/2,j],[L,1])
return X
开发者ID:jackculpepper,项目名称:sparsenet-python,代码行数:13,代码来源:util.py
示例18: generateData
def generateData(n):
"""
generates a 2D linearly separable dataset with n samples.
The third element of the sample is the label
"""
xb = (rand(n)*2-1)/2-0.5
yb = (rand(n)*2-1)/2+0.5
xr = (rand(n)*2-1)/2+0.5
yr = (rand(n)*2-1)/2-0.5
inputs = []
for i in range(len(xb)):
inputs.append(((xb[i],yb[i]),0))
inputs.append(((xr[i],yr[i]),1))
return inputs
开发者ID:laiaga,项目名称:TPSM1,代码行数:14,代码来源:TP3_perceptron.py
示例19: generateData
def generateData(m, type_):
data = []
if type_ == "own-ns":
feature_1_c1 = (rand(m)*3-1)/2 - 0.1
feature_2_c1 = (rand(m)*3-1)/4 + 0.2
feature_1_c2 = (rand(m)*2-1)/2 + 0.2
feature_2_c2 = (rand(m)*3-1)/2 - 0.1
for i in range(m):
data.append([feature_1_c1[i], feature_2_c1[i], 1])
for i in range(m):
data.append([feature_1_c2[i], feature_2_c2[i], -1])
elif type_ == "own-s":
feature_1_c1 = (rand(m)*2-1)/2 - 0.6
feature_2_c1 = (rand(m)*2-1)/2 + 0.6
feature_1_c2 = (rand(m)*2-1)/2 + 0.6
feature_2_c2 = (rand(m)*2-1)/2 - 0.6
for i in range(m):
data.append([feature_1_c1[i], feature_2_c1[i], 1])
for i in range(m):
data.append([feature_1_c2[i], feature_2_c2[i], -1])
return data
开发者ID:shalinc,项目名称:ML-Support-Vector-Machine,代码行数:32,代码来源:svm.py
示例20: make2DLinearSeparableDataset
def make2DLinearSeparableDataset(n):
"""
generates a 2D linearly separable dataset with n samples.
The third element of the sample is the label
"""
xb = (rand(n)*2-1)/2-0.5
yb = (rand(n)*2-1)/2+0.5
xr = (rand(n)*2-1)/2+0.5
yr = (rand(n)*2-1)/2-0.5
inputs = []
for i in range(len(xb)):
inputs.append([xb[i],yb[i],1])
inputs.append([xr[i],yr[i],-1])
return inputs
开发者ID:jamesbondo,项目名称:mypy,代码行数:14,代码来源:generateData.py
注:本文中的pylab.rand函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论