def conv_detector(X): n_detectors_layer_1 = 20 n_detectors_layer_2 = 30 n = X.shape[0] input = pad(X) w1 = init_weights((n_detectors_layer_1, 1, 4, 4), name="weights_layer_1", scale=0.1) w2 = init_weights((n_detectors_layer_2, n_detectors_layer_1, 4, 4), name="weights_layer_2") h1 = rectify(conv2d(input.reshape((n, 1, 7, 16)), w1, border_mode='valid', subsample=(1, 4))) input_2 = h1.reshape((n, n_detectors_layer_1, 1, 16)) h2 = rectify(conv2d(pad(input_2, axis=3).reshape((n, n_detectors_layer_1, 7, 16)), w2, border_mode='valid', subsample=(1, 4))) output = h2.reshape((n, 4*4*n_detectors_layer_2)) return output, [w1, w2]
def jet_detector(X): n_detectors_layer_1 = 5 n_jets_layer_1 = 4 n_detectors_layer_2 = 5 n_jets_layer_2 = 4 # Takes 16 dim vector, applies W to it, returns resultant vector def apply_detector(W, jet, n_jets): map_i = [] for start, end in zip(range(0, 16, n_jets), range(4, 16+4, n_jets)): map_i.append(rectify(T.dot(W, jet[start:end]))) return T.concatenate(map_i, axis=0) detectors_layer_1 = [] # Initialize weights for i in range(n_detectors_layer_1): detectors_layer_1.append(init_weights((4, 4), name="weights_layer_1_{0}".format(i)), scale=0.1) maps_layer_1 = [] for W in detectors_layer_1: map_i = apply_detector(W, X.T, n_jets_layer_1) maps_layer_1.append(map_i) detectors_layer_2 = [] # Initialize weights for i in range(n_detectors_layer_2): detectors_layer_2.append(init_weights((4, 4), name="weights_layer_2_{0}".format(i))) maps_layer_2 = [] for map in maps_layer_1: for W in detectors_layer_2: map_i = apply_detector(W, map, n_jets_layer_2) maps_layer_2.append(map_i) jet_detector_output = T.concatenate(maps_layer_2, axis=0) params = detectors_layer_1 + detectors_layer_2 return jet_detector_output.T, params
# trX, trY = load_data() trX = trX[0:500000] trY = trY[0:500000] # vX, vY = load_data('valid') vX = vX[0:10000] vY = vY[0:10000] X = T.fmatrix() Y = T.fmatrix() w_h = theano.shared(floatX(np.random.randn(*(28, 300)) * 0.1)) b_h = theano.shared(value=np.zeros((300, ), dtype=theano.config.floatX), name='b_h', borrow=True) w_h2 = init_weights((300, 300)) b_h2 = theano.shared(value=np.zeros((300, ), dtype=theano.config.floatX), name='b_h2', borrow=True) w_h3 = init_weights((300, 300)) b_h3 = theano.shared(value=np.zeros((300, ), dtype=theano.config.floatX), name='b_h3', borrow=True) w_h4 = init_weights((300, 300)) b_h4 = theano.shared(value=np.zeros((300, ), dtype=theano.config.floatX), name='b_h4', borrow=True) w_o = theano.shared(floatX(np.random.randn(*(300, 1)) * 0.001)) b_o = theano.shared(value=np.zeros((1, ), dtype=theano.config.floatX), name='b_o', borrow=True)
epochs = 5 X = T.fmatrix('X') epsilon = T.fmatrix() # Make random crop from X crop_mask, updates = theano.scan(fn=random_crop, sequences=[X]) crop_X = X * crop_mask # Creating the masks reconstruction_dims, updates = theano.scan(fn=MASK_blanking, sequences=[crop_X]) prediction_dims = crop_mask - reconstruction_dims # model(input_data, epsilon, w_h, mu_w, sig_w, w_h2, w_o, b_h, mu_b, sig_b, b_h2, b_o): # Initialize Weights weights_layer_1 = init_weights((n_visible_units, n_hidden_units), name='weights_layer_1') bias_layer_1 = init_biases(n_hidden_units, name='bias_layer_1') weights_layer_mu = init_weights((n_hidden_units, n_z), name='weights_layer_mu') bias_layer_mu = init_biases(n_z, name='bias_layer_mu') weights_layer_sig = init_weights((n_hidden_units, n_z), name='weights_layer_sig') bias_layer_sig = init_biases(n_z, name='bias_layer_sig') weights_layer_2 = init_weights((n_z, n_hidden_units), name='weights_layer_2') bias_layer_2 = init_biases(n_hidden_units, name='bias_layer_2') weights_layer_y = init_weights((n_hidden_units, n_visible_units), name='weights_layer_y') bias_layer_y = init_biases(n_visible_units, name='bias_layer_y') # Build Model model_input = crop_X * reconstruction_dims X_hat, mu, sig = model(model_input, epsilon, weights_layer_1, weights_layer_mu, weights_layer_sig, weights_layer_2, weights_layer_y, bias_layer_1, bias_layer_mu, bias_layer_sig, bias_layer_2, bias_layer_y)
output = T.nnet.sigmoid(T.dot(h1, w_o) + b_y) return output # Define parameters learning_rate = 0.1 n_hidden_units = 100 n_visible_units = 784 blank_proportion = .1 alpha = .5 batch_size = 100 epochs = 10 X = T.fmatrix('X') # Initialize Weights weights_layer_1 = init_weights((n_visible_units, n_hidden_units), name='weights_layer_1') bias_layer_1 = init_biases(n_hidden_units, name='bias_layer_1') weights_layer_y = init_weights((n_hidden_units, n_visible_units), name='weights_layer_y') bias_layer_y = init_biases(n_visible_units, name='bias_layer_y') # Build Model X_hat = model(X, weights_layer_1, weights_layer_y, bias_layer_1, bias_layer_y) # Loss L = - T.sum(X * T.log(X_hat) + (1 - X) * T.log(1 - X_hat), axis=1) loss = T.mean(L) # Parameter Updating params = [weights_layer_y, bias_layer_y, weights_layer_1, bias_layer_1] updates = sgd(loss, params, lr=learning_rate)
return output # Define parameters learning_rate = 0.1 n_hidden_units = 100 n_visible_units = 784 blank_proportion = .1 alpha = .5 batch_size = 100 epochs = 10 X = T.fmatrix('X') # Initialize Weights weights_layer_1 = init_weights((n_visible_units, n_hidden_units), name='weights_layer_1') bias_layer_1 = init_biases(n_hidden_units, name='bias_layer_1') weights_layer_y = init_weights((n_hidden_units, n_visible_units), name='weights_layer_y') bias_layer_y = init_biases(n_visible_units, name='bias_layer_y') # Build Model X_hat = model(X, weights_layer_1, weights_layer_y, bias_layer_1, bias_layer_y) # Loss L = -T.sum(X * T.log(X_hat) + (1 - X) * T.log(1 - X_hat), axis=1) loss = T.mean(L) # Parameter Updating params = [weights_layer_y, bias_layer_y, weights_layer_1, bias_layer_1] updates = sgd(loss, params, lr=learning_rate)
x = np.zeros((112, )) x[48:64] = np.arange(16) x = x.reshape(-1, 1, 7, 16) f(x).shape jets = T.fmatrix('Jets') lepton_missing_E = T.fmatrix('lepton_and_missing_energy') high_level = T.fmatrix('high_level') n_input_units = 28 n_hidden_units = 300 n_output_units = 1 # Initialize Weights w_h = init_weights((n_input_units, n_hidden_units), name='weights_layer_1', scale=0.1) b_h = init_biases(n_hidden_units, name='bias_layer_1') w_h2 = init_weights((n_hidden_units, n_hidden_units), name='weights_layer_2') b_h2 = init_biases(n_hidden_units, name='bias_layer_2') w_h3 = init_weights((n_hidden_units, n_hidden_units), name='weights_layer_3') b_h3 = init_biases(n_hidden_units, name='bias_layer_3') w_h4 = init_weights((n_hidden_units, n_hidden_units), name='weights_layer_4') b_h4 = init_biases(n_hidden_units, name='bias_layer_4') w_o = init_weights((n_hidden_units, n_output_units), name='weights_layer_y', scale=0.001) b_o = init_biases(n_output_units, name='bias_layer_y') noise_h, noise_h2, noise_h3, noise_h4, noise_py_x = model( X, w_h, w_h2, w_h3, w_h4, w_o, b_h, b_h2, b_h3, b_h4, b_o, 0.8,
trX = trX[0:500000] trY = trY[0:500000] # vX, vY = load_data('valid') vX = vX[0:10000] vY = vY[0:10000] jets = T.fmatrix('jets') other_features = T.fmatrix('other_features') Y = T.fmatrix() w_h = theano.shared(floatX(np.random.randn(*(12, 100)) * 0.1), name="fc_weights_layer_1") b_h = theano.shared(value=np.zeros((100, ), dtype=theano.config.floatX), name='b_h', borrow=True) w_h2 = init_weights((100, 100), name="fc_weights_layer_2") b_h2 = theano.shared(value=np.zeros((100, ), dtype=theano.config.floatX), name='b_h2', borrow=True) w_h3 = init_weights((580, 300), name="fc_weights_layer_3") b_h3 = theano.shared(value=np.zeros((300, ), dtype=theano.config.floatX), name='b_h3', borrow=True) w_h4 = init_weights((300, 300), name="fc_weights_layer_4") b_h4 = theano.shared(value=np.zeros((300, ), dtype=theano.config.floatX), name='b_h4', borrow=True) w_o = theano.shared(floatX(np.random.randn(*(300, 1)) * 0.001), name="fc_weights_layer_o") b_o = theano.shared(value=np.zeros((1, ), dtype=theano.config.floatX), name='b_o',