本文整理汇总了Python中pylab.rand函数的典型用法代码示例。如果您正苦于以下问题:Python rand函数的具体用法?Python rand怎么用?Python rand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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]
示例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
示例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
示例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
示例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
示例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)
示例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
示例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)
示例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])
示例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
示例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
示例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
示例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