Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import tensorflow as tf
  2. from tensorflow.python.training import rmsprop,ftrl
  3.  
  4. n = 10
  5.  
  6.  
  7. x = tf.Variable(tf.zeros([n,n]),trainable = True)
  8.  
  9.  
  10. col = tf.Variable(tf.zeros([n,3]), trainable = True)
  11.  
  12. maxs = tf.Variable(tf.zeros([3]), trainable = True)
  13.  
  14.  
  15. temp = tf.Variable(1.)
  16.  
  17. @tf.function
  18. def f_x():
  19.  
  20.  
  21. col[0][0] = 1.
  22. col[0][1] = 1.
  23. col[0][2] = 1.
  24.  
  25.  
  26. for i in range(1,n):
  27. temp = 1.
  28. for j in range(i):
  29. if (x[j][i] <= 1.):
  30. if (temp<1.+col[j][0]):
  31. temp = 1.+col[j][0]
  32. col[i][0] =temp
  33.  
  34. temp = 1.
  35. for j in range(i):
  36. if (x[j][i] < 0.) or (x[j][i] > 1.):
  37. if (temp < 1.+col[j][1]):
  38. temp =1.+col[j][1]
  39. col[i][1] =temp
  40.  
  41. temp = 1.
  42. for j in range(i):
  43. if (x[j][i] >=0.):
  44. if (temp<1.+col[j][2]):
  45. temp=1.+col[j][2]
  46. col[i][2]=temp
  47.  
  48.  
  49.  
  50. maxs[0]=0.
  51. maxs[1]=0.
  52. maxs[2]=0.
  53.  
  54. for i in range(n):
  55. for j in range(3):
  56. if (maxs[j]<col[i][j]):
  57. maxs[j]=col[i][j]
  58.  
  59. return maxs[0]*maxs[1]*maxs[2]
  60.  
  61. for _ in range(100):
  62. print([x.numpy(), f_x().numpy()])
  63. opt = ftrl.FtrlOptimizer(0.1).minimize(f_x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement