Exemplo n.º 1
0
    def windolf_sampling(self, params, layer):
	a = np.abs(params)
	alpha = np.angle(params)

	if layer=='visible':
	    rates = np.abs(self.clamp)
	    phases = vm(alpha, a*rates / self.sigma_sq)
	    return rates*np.exp(1j*phases)
	else:
	    bessels = bessel(a - self.biases)/ self.sigma_sq
	    custom_kernel = np.ones((self.pool_size, self.pool_size))
	    sum_bessels = conv(bessels, custom_kernel, mode='valid')
	    # Downsample
	    sum_bessels = sum_bessels[0::self.pool_stride, 0::self.pool_stride]
	    
	    bessel_sftmx_denom = 1.0 + sum_bessels
	    upsampled_denom = bessel_sftmx_denom.repeat(self.pool_stride, axis=0).repeat(self.pool_stride, axis=1)    
	    hid_cat_P = bessels / upsampled_denom
	    pool_P = 1.0 - 1.0 / bessel_sftmx_denom
		
	    hid_rates, pool_rates = self._dbn_maxpool_sample_helper(hid_cat_P, pool_P)
	    hid_phases = vm(alpha, a*hid_rates / self.sigma_sq)
	    hid_samples = hid_rates*np.exp(1j*hid_phases)
	    pool_phases = np.sum(imx.view_as_blocks(hid_phases, (self.pool_size, self.pool_size)), axis=(2,3))
	    pool_samples = pool_rates*np.exp(1j*pool_phases)
	    return hid_samples, pool_samples
    def pc_shift(self):

        self_bs, self_ks = self.shift_mean_var(self.positions)

        if self._interp is None:
            bs = self_bs
            ks = self_ks

        else:
            s_b = self._interp_values['shift_b']
            s_k = self._interp_values['shift_k']
            other_bs, other_ks = self._interp.shift_mean_var(self.positions)

            bs = (1 - s_b) * self_bs + s_b * other_bs
            ks = (1 - s_k) * self_ks + s_k * other_ks

        new_positions = []
        for x, b, k in zip(self.positions, bs, ks):
            d = vm(0, k)
            y = d + x + b
            new_positions.append(y)
        new_positions = np.array(new_positions)
        new_positions[new_positions < -np.pi] += 2 * np.pi
        new_positions[new_positions >= np.pi] -= 2 * np.pi

        return new_positions
Exemplo n.º 3
0
    def windolf_sampling(self, params, layer):
	a = np.abs(params)
	alpha = np.angle(params)

	if layer=='visible':
	    rates = np.abs(self.clamp)
	else:
	    b = bessel(a - self.biases)	/ self.sigma_sq
	    ber_P = b / (1.0 + b)
	    rates = 1*(np.random.rand(1, self.out_shape, self.out_shape) < ber_P)
	
	phases = vm(alpha, a*rates / self.sigma_sq)
	return rates*np.exp(1j*phases)
Exemplo n.º 4
0
    def windolf_sampling(self, params, layer):
	a = np.abs(params)
	alpha = np.angle(params)

	if layer=='visible':
	    rates = np.abs(self.clamp)
	    #phases = np.where(rates>0, vm(alpha, rates*a / self.sigma_sq), np.angle(self.v_run[-1]))
	else:
	    b = bessel(a - self.biases)	/ self.sigma_sq
	    ber_P = b / (1.0 + b)
	    rates = 1*(np.random.rand(self.out_shape) < ber_P)
	    #phases = np.where(rates > 0, vm(alpha, rates*a / self.sigma_sq), np.angle(self.h_run[-1]))
	phases = vm(alpha, rates*a / self.sigma_sq)
	return rates*np.exp(1j*phases)
Exemplo n.º 5
0
    def windolf_sampling(self, params, layer):
	a = np.abs(params)
	alpha = np.angle(params)

	if layer=='visible':
	    rates = np.abs(self.clamp)
	    phases = vm(alpha, a*rates / self.sigma_sq)
	    return rates * np.exp(1j * phases)
	else:
	    b = bessel(a - self.biases)	/ self.sigma_sq
	    sum_bessels = np.array([np.sum(b[i*int(self.hid_shape / 2.0):(i+1)*int(self.hid_shape / 2.0), :]) for i in range(2)])
	    bessel_sftmx_denom = 1.0 + sum_bessels
	    upsampled_denom = np.ones((self.hid_shape, self.hid_shape))
	    for i in range(2):
	        upsampled_denom[i*int(self.hid_shape / 2.0):(i+1)*int(self.hid_shape / 2.0), :] *= bessel_sftmx_denom[i]
		
	    hid_cat_P = b / upsampled_denom
	    pool_P = 1.0 - 1.0 / bessel_sftmx_denom
	    hid_rates, pool_rates = self._dbn_maxpool_sample_helper(hid_cat_P, pool_P)
	    hid_phases = vm(alpha, a*hid_rates / self.sigma_sq)
	    hid_samples = hid_rates*np.exp(1j*hid_phases)
	    pool_phases = np.array([np.sum(hid_phases[:,i*(self.hid_shape / 2):(i+1)*(self.hid_shape / 2)], axis=(1,2)) for i in range(2)])
	    pool_samples = pool_rates*np.exp(1j*pool_phases)
	    return hid_samples, pool_samples
Exemplo n.º 6
0
    def windolf_sampling(self, params, layer):
        a = np.abs(params)
        alpha = np.angle(params)

        if layer == 'visible':
            rates = np.abs(self.clamp)
        elif layer == 'hidden':
            ipdb.set_trace()
            b = bessel(a - self.biases) / self.sigma_sq
            ber_P = b / (1.0 + b)
            rates = 1 * (np.random.rand(3, self.out_shape, self.out_shape) <
                         ber_P)
        elif layer == 'final':
            b = bessel(a - self.f_biases) / self.sigma_sq
            ber_P = b / (1.0 + b)
            rates = 1 * (np.random.rand(3) < ber_P)
        phases = vm(alpha, a * rates / self.sigma_sq)
        return rates * np.exp(1j * phases)