def __init__( self, shape, **kwargs ): self.shape = shape self.posecells = zeros(shape) #NOTE: might not need if gaussian_filter works self.kernel_3d = self.diff_gaussian( PC_E_DIM, PC_I_DIM, PC_E_SIGMA, PC_I_SIGMA, order=3 ) self.kernel_2d = self.diff_gaussian( PC_E_DIM, PC_I_DIM, PC_E_SIGMA, PC_I_SIGMA, order=2 ) self.kernel_1d = self.diff_gaussian( PC_E_DIM, PC_I_DIM, PC_E_SIGMA, PC_I_SIGMA, order=1 ) self.kernel_1d_sep = self.diff_gaussian_separable( PC_E_DIM, PC_I_DIM, PC_E_SIGMA, PC_I_SIGMA ) self.global_inhibition = PC_GLOBAL_INHIB self.pc_vtrans_scale = PC_CELL_X_SIZE self.pc_vrot_scale = 2.0*pi/shape[2]#PC_C_SIZE_TH #TODO: maybe change everything to float32 to make it go faster? #self.conv = Convolution( im=self.posecells, fil=self.kernel_1d, sep=True, type=float64 ) #self.conv = Convolution( im=self.posecells, fil=self.kernel_1d_sep, sep=True, type=float64 ) self.conv = Convolution( im=self.posecells, fil=self.kernel_3d, sep=False, type=float64 ) filter = self.diff_gaussian_offset_2d( PC_E_SIGMA, PC_I_SIGMA, shape=(7,7), origin=(0,0) ) #self.conv.new_filter( self.kernel_2d, dim=2 ) self.conv.new_filter( filter, dim=2 ) self.filter_dict_2d = self.build_diff_gaussian_set_2d( PC_E_SIGMA, PC_I_SIGMA, shape=(7,7), precision=1 ) self.filter_dict_2d_precision = 10 # multiple the decimal by this number to get the right key
def __init__( self, input_dim=(1, 28, 28), conv_param={ 'filter_num': 30, 'filter_size': 5, 'pad': 0, 'stride': 1 }, hidden_size=100, output_size=10, weight_init_std=0.01 ): # 畳み込み層のハイパーパラメータ filter_num = conv_param['filter_num'] filter_size = conv_param['filter_size'] filter_pad = conv_param['pad'] filter_stride = conv_param['stride'] input_size = input_dim[1] conv_output_size = (input_size - filter_size + 2 * filter_pad) / filter_stride + 1 pool_output_size = int( filter_num * (conv_output_size / 2) * (conv_output_size / 2) ) # 重みパラメータ self.params = {} self.params['W1'] = weight_init_std * \ np.random.randn(filter_num, input_dim[0], filter_size, filter_size) self.params['b1'] = np.zeros(filter_num) self.params['W2'] = weight_init_std * \ np.random.randn(pool_output_size, hidden_size) self.params['b2'] = np.zeros(hidden_size) self.params['W3'] = weight_init_std * \ np.random.randn(hidden_size, output_size) self.params['b3'] = np.zeros(output_size) # レイヤー self.layers = OrderedDict() self.layers['Conv1'] = Convolution( self.params['W1'], self.params['b1'], conv_param['stride'], conv_param['pad'] ) self.layers['Relu1'] = Relu() self.layers['Pool1'] = Pooling(pool_h=2, pool_w=2, stride=2) self.layers['Affine2'] = Affine(self.params['W2'], self.params['b2']) self.layers['Relu2'] = Relu() self.layers['Affine3'] = Affine(self.params['W3'], self.params['b3']) self.last_layer = Softmax()
def resol_spectrum (self,E,a,b,ordering,plot_this=False): if (ordering < -1) or (ordering > 1): print('Error: set ordering = 1 for NO, -1 for IO, 0 for both') return -1 Reactor_Spectrum.unosc_spectrum(self,E) Oscillation_Prob.eval_prob(self,E,0) self.norm_osc_spect_N = self.norm_spectrum_un * self.prob_E_N self.norm_osc_spect_I = self.norm_spectrum_un * self.prob_E_I #Evis = E - 0.8 ### class Convolution conv = Convolution() print('\n...adding experimental resolution via numerical convolution...') print('\nIt might take a while') self.resol_N = conv.numerical_conv(self.norm_osc_spect_N,E,a=a,b=b) self.resol_I = conv.numerical_conv(self.norm_osc_spect_I,E,a=a,b=b) if plot_this: fig = plt.figure() #fig.suptitle(r'Antineutrino spectrum') ax = fig.add_subplot(111) ax.legend() ax.grid() ax.set_xlabel(r'$\text{E}_{\text{vis}}$ [\si{MeV}]') ax.set_ylabel(r'N($\bar{\nu}$) [arb. unit]') ax.set_ylim(-0.005,0.095) ax.set_title(r'Antineutrino spectrum' + '\nwith finite energy resolution') if ordering == 1: # NO ax.plot(E-0.8,self.resol_N,'b',linewidth=1,label='NO') ax.legend() fig.savefig('AntineutrinoSpectrum/resol_spectrum_N.pdf',format='pdf',transparent=True) print('\nThe plot has been saved in AntineutrinoSpectrum/resol_spectrum_N.pdf') if ordering == -1: # IO ax.plot(E-0.8,self.resol_I,'r',linewidth=1,label='IO') ax.legend() fig.savefig('AntineutrinoSpectrum/resol_spectrum_I.pdf',format='pdf',transparent=True) print('\nThe plot has been saved in AntineutrinoSpectrum/resol_spectrum_I.pdf') if ordering == 0: # both NO and IO ax.plot(E-0.8,self.resol_N,'b',linewidth=1,label='NO') ax.plot(E-0.8,self.resol_I,'r--',linewidth=1,label='IO') ax.legend() fig.savefig('AntineutrinoSpectrum/resol_spectrum.pdf', format='pdf', transparent=True) print('\nThe plot has been saved in AntineutrinoSpectrum/resol_spectrum.pdf') return self.resol_N, self.resol_I
def createConvolution(self): width = 1280 height = 720 window_width = 50 window_height = 40 # Break image into 18 vertical layers since image height is 720 margin = 100 # How much to slide left and right for searching print("warped shape: ", warped.shape) rough_lane_width = 897 return Convolution(width = width, height = height, window_width = window_width, window_height = window_height, margin = margin, rough_lane_width = rough_lane_width)
def Convolution(x, args, name): """ Create a convolutional layer with :param x: the placeholder for the tensor :param args: the arguments for the convolution (filter, strides, padding) :param name: a label for the operation :return: a convolved tensor """ from convolution import Convolution return Convolution(x, args, name)
def __init__(self): '''Get the four layer's kernels, create the correlations and a convolution wrapper. :const MIN_IMG_WIDTH: Minimum image width for which to use NumPy/SciPy for convolution ''' self.kernels = DifferenceOfGaussians() self.correlations = Correlation(self.kernels.full_kernels) self.convolver = Convolution() self.MIN_IMG_WIDTH = 256
def __init__(self): output_size = 10 hidden_size = 12 self.modules = [ Reshape((28, 28), (28, 28, 1)), Convolution((28, 28, 1), 5, 8), # to 24 MaxPool(2), # to 12 Pad(1), # to 14 Convolution((14, 14, 8), 3, 16), #to 12 MaxPool(2), # to 6 Convolution((6, 6, 16), 3, 24), # to 4 MaxPool(2), # to 2 Reshape((2,2,24),(2 * 2 * 24,)), MatrixMult([2 * 2 * 24, hidden_size]), MatrixAdd([hidden_size]), Relu(), MatrixMult([hidden_size, output_size]), Softmax(), ]
def plotDefaults(self): self.convolution = Convolution() self.plotUpdate() self.updateSlider() self.tminXInput.setText('{}'.format(self.convolution.getMinRangeX())) self.tminHInput.setText('{}'.format(self.convolution.getMinRangeH())) self.tmaxXInput.setText('{}'.format(self.convolution.getMaxRangeX())) self.tmaxHInput.setText('{}'.format(self.convolution.getMaxRangeH())) self.XFunctionInput.setText('{}'.format(self.convolution.getXFunctionString())) self.HFunctionInput.setText('{}'.format(self.convolution.getHFunctionString()))
def __init__(self): super().__init__() self.title = 'La construction de la convolution' self.left = 50 self.top = 50 self.width = 1600 self.height = 900 self.sliderTimeFactor = 10 self.modeEcho = True self.convolution = Convolution() self.initUI() self.plotDefaults()
def convoluteWavs(self, wav): BLOCKSIZE = 1024 def preprocess(): if self.audioData.shape[0] < wav.audioData.shape[0]: audioSize = self.audioData.shape[0] if audioSize % BLOCKSIZE != 0: lastblock = self.audioData[( self.audioData.shape[0] - (self.audioData.shape[0] % BLOCKSIZE)):] temp = self.audioData[:( self.audioData.shape[0] - (self.audioData.shape[0] % BLOCKSIZE))] self.audioData = np.concatenate( (temp, WavProcessing.pad(len(lastblock), lastblock, BLOCKSIZE))) resultConv = np.zeros((self.audioData.shape[0], 2), dtype=np.int16) elif self.audioData.shape[0] >= wav.audioData.shape[0]: audioSize = wav.audioData.shape[0] if audioSize % BLOCKSIZE != 0: lastblock = wav.audioData[( wav.audioData.shape[0] - (wav.audioData.shape[0] % BLOCKSIZE)):] temp = wav.audioData[:( wav.audioData.shape[0] - (wav.audioData.shape[0] % BLOCKSIZE))] wav.audioData = np.concatenate( (temp, WavProcessing.pad(len(lastblock), lastblock, BLOCKSIZE))) resultConv = np.zeros((wav.audioData.shape[0], 2), dtype=np.int16) return resultConv, Matrix.ceil(audioSize, BLOCKSIZE) resultConv, nblocks = preprocess() for i in xrange(nblocks): start = BLOCKSIZE * i end = BLOCKSIZE * (i + 1) conv = Convolution( Matrix(self.audioData[start:end, 0].tolist(), 0), Matrix(wav.audioData[start:end, 0].tolist(), 0), Convolution.CIRCULAR) resultConv[start:end] = conv.convolute() self.audioData = resultConv[:] conv._plot()
def __init__(self, name, size, dt=0.1, wrap=True, tau=0.64, h=0, model='cnft', th=0.75, iExc=1.25, iInh=0.7, wExc=0.1, wInh=10, alpha=10, mapSize=1., **kwargs): super(MapDNF, self).__init__(name, size, dt=dt, wrap=wrap, tau=tau, h=h, model=model, th=th, **kwargs) self.act = ActivationMap(name + "_activation", size, dt=dt, model=model, th=th) self.lat = Convolution(name + "_lateral", size, dt=dt, wrap=wrap) self.kernel = LateralWeightsMap(name + "_kernel", mapSize=mapSize, globalSize=size, wrap=wrap, iExc=iExc, iInh=iInh, wExc=wExc, wInh=wInh, alpha=alpha) self.act.addChildren(field=self) self.addChildren(lat=self.lat) self.lat.addChildren(source=self.act, kernel=self.kernel) self.kernel.compute()
from MLP import MLP from convolution import Convolution, Pooling, Model from mnist import loadData if __name__ == '__main__': trainX, trainY, testX, testY, valX, valY = loadData() model = Model() model.add_layer(Convolution(16, 1, 3, 1)) model.add_layer(Pooling(2, 2)) model.add_layer(MLP(784, 128, 10, activation='sigmoid')) model.feed_forward(trainX[0])
def __init__(self): self.kernels = DifferenceOfGaussians() self.correlations = Correlation(self.kernels.full_kernels) self.convolver = Convolution() self.MIN_IMG_WIDTH = 256
h3 = self.i(h3) h4 = self.i(h4) h3_square = h3 * h3 h4_square = h4 * h4 summed = numpy.add(h3_square, h4_square) img = numpy.sqrt(summed) img = self.f(summed) self.set(img) self.set(self.normalize(self.get())) def i(self, img): return img / 255 def f(self, img): return img * 255 if __name__ == "__main__": import sys first = Convolution(sys.argv[1]) second = Convolution(sys.argv[1]) first.apply_def('h3') second.apply_def('h4') i = ConvolutionSquare(sys.argv[1]) i.apply_multiplication(first, second) i.save_to_file("output.png")
def __init__(self,num_filt=64): Neural_Network.__init__(self) self.conv = Convolution(num_filt)
def __init__(self, n_filters, filter_shape,weight_scale,weight_decay): self.n_filters = n_filters self.filter_shape = filter_shape self.weight_scale = weight_scale self.weight_decay = weight_decay self.conv_ob = Convolution()