Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #f(x,y)=(x-y^2)/(x+y+1) interval <0,2>,<0,2>
- import numpy as np
- import tensorflow as tf
- from keras.layers import Dense, Activation
- from keras.models import Sequential
- def funkcia(x, y):
- return (x - y**2)/(x + y + 1)
- model = Sequential()
- model.add(Dense(32, activation='tanh', input_dim=2))
- model.add(Dense(1, activation='tanh'))
- model.compile(optimizer='rmsprop',
- loss='binary_crossentropy',
- metrics=['accuracy'])
- # generovanie data a labels
- #data = []
- #for i in np.arange(0.0, 20.0, 0.2):
- # for j in np.arange(0.0, 20.0, 0.2):
- # data.append([i,j])
- data = np.random.random((1000, 2))
- #print(np.matrix(data))
- labels = []
- for i in range(len(data)):
- labels.append(funkcia(data[i][0], data[i][1]))
- dataMax = np.max(data)
- labelsMax = np.max(labels)
- maximum = max(dataMax, labelsMax)
- data = data / maximum
- labels = labels / maximum
- #print(np.matrix(labels))
- # Train the model, iterating on the data in batches of 32 samples
- model.fit(data, labels, epochs=150, batch_size=100)
- _, accuracy = model.evaluate(data, labels)
- print('Accuracy: %.2f' % (accuracy*100))
- #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- # Experimenty
- # web: https://www.tensorflow.org/guide/keras
- #aa=model.weights
- #print(aa)
Add Comment
Please, Sign In to add comment