LukacikPavel

domacaNeuronky

Oct 14th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #f(x,y)=(x-y^2)/(x+y+1) interval <0,2>,<0,2>
  2.  
  3. import numpy as np
  4. import tensorflow as tf
  5.  
  6. from keras.layers import Dense, Activation
  7. from keras.models import Sequential
  8.  
  9. def funkcia(x, y):
  10. return (x - y**2)/(x + y + 1)
  11.  
  12. model = Sequential()
  13. model.add(Dense(4, activation='tanh', input_dim=2))
  14. model.add(Dense(3, activation='tanh'))
  15. model.add(Dense(1, activation='tanh'))
  16. model.compile(optimizer='rmsprop',
  17. loss='binary_crossentropy',
  18. metrics=['accuracy'])
  19.  
  20. # generovanie data a labels
  21. data = []
  22.  
  23. for i in np.arange(0.0, 10.0, 0.2):
  24. for j in np.arange(0.0, 10.0, 0.2):
  25. data.append([i,j])
  26.  
  27. #data = np.random.random((1000, 2))
  28.  
  29. #print(np.matrix(data))
  30.  
  31. labels = []
  32. for i in range(len(data)):
  33. labels.append(funkcia(data[i][0], data[i][1]))
  34.  
  35. dataMax = np.max(data)
  36. labelsMax = np.max(labels)
  37. maximum = max(dataMax, labelsMax)
  38.  
  39. data = data / maximum
  40. labels = labels / maximum
  41.  
  42. #print(np.matrix(labels))
  43.  
  44. #aa=model.weights
  45. #print(aa)
  46.  
  47. # Train the model, iterating on the data in batches of 32 samples
  48. model.fit(data, labels, epochs=100, batch_size=32)
  49.  
  50. #aa=model.weights
  51. #print(aa)
  52.  
  53. _, accuracy = model.evaluate(data, labels)
  54. print('Accuracy: %.2f' % (accuracy*100))
  55. #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  56. # Experimenty
  57. # web: https://www.tensorflow.org/guide/keras
  58.  
  59. #aa=model.weights
  60. #print(aa)
  61.  
  62.  
Add Comment
Please, Sign In to add comment