Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tensorflow as tf
- from tensorflow.python.training import rmsprop,ftrl
- n = 10
- x = tf.Variable(tf.zeros([n,n]),trainable = True)
- col = tf.Variable(tf.zeros([n,3]), trainable = True)
- maxs = tf.Variable(tf.zeros([3]), trainable = True)
- temp = tf.Variable(1.)
- @tf.function
- def f_x():
- col[0][0] = 1.
- col[0][1] = 1.
- col[0][2] = 1.
- for i in range(1,n):
- temp = 1.
- for j in range(i):
- if (x[j][i] <= 1.):
- if (temp<1.+col[j][0]):
- temp = 1.+col[j][0]
- col[i][0] =temp
- temp = 1.
- for j in range(i):
- if (x[j][i] < 0.) or (x[j][i] > 1.):
- if (temp < 1.+col[j][1]):
- temp =1.+col[j][1]
- col[i][1] =temp
- temp = 1.
- for j in range(i):
- if (x[j][i] >=0.):
- if (temp<1.+col[j][2]):
- temp=1.+col[j][2]
- col[i][2]=temp
- maxs[0]=0.
- maxs[1]=0.
- maxs[2]=0.
- for i in range(n):
- for j in range(3):
- if (maxs[j]<col[i][j]):
- maxs[j]=col[i][j]
- return maxs[0]*maxs[1]*maxs[2]
- for _ in range(100):
- print([x.numpy(), f_x().numpy()])
- opt = ftrl.FtrlOptimizer(0.1).minimize(f_x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement