def block_generator(blocks, depth, limits, sparsity, jitter, empty):
    output_blocks = []
    for b in range(blocks):
        output_blocks.append([])
        b_limits = (int(norm(limits[0], jitter)), int(norm(limits[1], jitter)))
        current = b_limits[0]
        output_blocks[b].append(
            [b_limits[0]] +
            [10 if rand() < empty else randint(11, 127) for i in range(depth)])
        while forb(current, b_limits[1],
                   40) >= 0:  # While we have not passed the upper limit
            current = (current + (sparsity + 1)) % 1024
            output_blocks[b].append([current] + [
                10 if rand() < empty else randint(11, 127)
                for i in range(depth)
            ])
        if b % 2 == 1:
            output_blocks[b] = output_blocks[b][::-1]

    return output_blocks
Exemple #2
0
 def init_weights(self, act):
     ret = []
     for n, layer in enumerate(act[:-1]):
         layer = layer[0]
         ret.append([])
         next_layer = act[n + 1][0]
         for node_1 in range(len(layer)):
             ret[-1].append([])
             for node_2 in range(len(next_layer)):
                 ret[-1][-1].append(norm(0, 1))
     return ret
Exemple #3
0
	def genEnsemble(self, phase = 'allyears'):
		from random import normalvariate as norm
		from numpy import zeros
		sd = self.hindcast_error[phase].std()
		mn = self.hindcast_error[phase].mean()
		n = len(self.hindcast[phase])
		ensemble = zeros((1000,n))
		for i in range(n):
			for j in range(1000):
				y = norm(mn, sd)
				ensemble[j,i] = self.hindcast[phase][i] + y
		self.ensemble[phase] = ensemble
		return
Exemple #4
0
def brownian_bridge(ti, tf, bi, bf, n):
    """
    simulation d'un pont brownien sur [ti,tf], 
    avec les valeurs extrèmes bi et bf
    et n points par unité de temps
    sortie : 
    - T   : positions temporelles des échantillons
    - B   : valeurs des échantillons
    """
    n        = int(n*(tf-ti))     # nombre de points
    T        = linspace(ti,tf,n)  # points d'échantillonnage
    pas      = (tf-ti)/(n-1.)     # pas d'échantillonnage
    B        = zeros(n)           # initialisation du brownien
    B[0]     = bi                 # valeur initiale
    B[n-1]   = bf                 # valeur finale
    t1       = ti
    for k in range(1,n-1):               # construction du pont en ti+k*pas
        m = moy(t1,tf,B[k-1],bf,t1+pas)  # sur les intervalle [ti+(k-1)*pas,tf]
        v = var(t1,tf,B[k-1],bf,t1+pas)  # avec les valeurs limites B[k-1],et bf
        B[k] = m+sqrt(v)*norm(0,1)
        t1  += pas
    return T, B
Exemple #5
0
def int_range(mean, std_dev=None, max_std_dev=2):
    "Return an random integer normally distributed around mean, with the given std dev."
    if std_dev is None:
        std_dev = mean / 4.0
    mean += 0.5
    return int(min(mean+std_dev*max_std_dev, max(norm(mean, std_dev), mean-std_dev*max_std_dev)))