LukacikPavel

Untitled

Oct 14th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 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(32, activation='tanh', input_dim=2))
  14. model.add(Dense(1, activation='tanh'))
  15. model.compile(optimizer='rmsprop',
  16. loss='binary_crossentropy',
  17. metrics=['accuracy'])
  18.  
  19. # generovanie data a labels
  20. #data = []
  21.  
  22. #for i in np.arange(0.0, 20.0, 0.2):
  23. # for j in np.arange(0.0, 20.0, 0.2):
  24. # data.append([i,j])
  25.  
  26. data = np.random.random((1000, 2))
  27.  
  28. #print(np.matrix(data))
  29.  
  30. labels = []
  31. for i in range(len(data)):
  32. labels.append(funkcia(data[i][0], data[i][1]))
  33.  
  34. dataMax = np.max(data)
  35. labelsMax = np.max(labels)
  36. maximum = max(dataMax, labelsMax)
  37.  
  38. data = data / maximum
  39. labels = labels / maximum
  40.  
  41. #print(np.matrix(labels))
  42.  
  43. # Train the model, iterating on the data in batches of 32 samples
  44. model.fit(data, labels, epochs=150, batch_size=100)
  45.  
  46. _, accuracy = model.evaluate(data, labels)
  47. print('Accuracy: %.2f' % (accuracy*100))
  48. #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  49. # Experimenty
  50. # web: https://www.tensorflow.org/guide/keras
  51.  
  52. #aa=model.weights
  53. #print(aa)
  54.  
  55.  
Add Comment
Please, Sign In to add comment