Guest User

Untitled

a guest
May 22nd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. def plotArray(w):
  2. plt.imshow(w, cmap=cm.gray);
  3. plt.colorbar();
  4. plt.show();
  5.  
  6. k=30;
  7. n=1000;
  8. X = np.random.randint(0, k, [1000, 1, 2, 1]);
  9. Y = np.zeros([1000, 1]);
  10. epochs=50;
  11.  
  12. #Harder AND
  13. for i in range(0, n):
  14. if X[i, 0, 0, 0] > k/2 and X[i, 0, 1, 0] > k/2:
  15. Y[i] = 1;
  16.  
  17. (X_train, X_test, Y_train, Y_test) = skl_ms.train_test_split(X, Y);
  18.  
  19. model = Sequential([Conv2D(1, kernel_size=[1,2], activation='sigmoid', input_shape=[1, 2, 1]),
  20. Reshape(target_shape=(1,))]);
  21.  
  22. plot_model(model, to_file='logic_model.png', show_shapes=True, show_layer_names=True);
  23.  
  24. model.compile(optimizer='nadam', loss='mse');
  25.  
  26. print(model.summary());
  27.  
  28. model.fit(x=X_train, y=Y_train, epochs=epochs, batch_size=30);
  29.  
  30.  
  31. #Generate a plot to see what the model predictions are as a function of input 1
  32. #and input 2
  33. A=np.zeros([k, k]);
  34. for i in range(0, k):
  35. for j in range(0, k):
  36. b = np.array([i, j]);
  37. b = b.reshape([1, 1, 2, 1]);
  38.  
  39. A[i, j] = model.predict(b);
  40.  
  41. plotArray(A);
Add Comment
Please, Sign In to add comment