tensorflowで乱数を発生させているが,固定することが出来ない.
ハイパーパラメータである学習率を4通り考慮した.4回ループを回すことになるが,固定されているはずの乱数が各ループでずれてしまっている.
今後,グリッドサーチを行おうと考えているのでとても困っています.どのように解決すべきでしょうか.
質問・プログラミングについて初心者でりますがお願いします.
発生している問題・エラーメッセージ
0.01 [[-0.01278295] [ 0.00424424] [ 0.01260157] [ 0.00272857] [ 0.00025477] [-0.00312508] [-0.00225875] [-0.00445066] [ 0.00055921] [-0.00066416] [ 0.00816493] [ 0.00378237]] 0.05 [[-0.00315907] [-0.00032044] [ 0.00632677] [ 0.01084339] [ 0.0176496 ] [-0.00058672] [ 0.00848717] [ 0.00399379] [ 0.00903138] [-0.00502061] [-0.00796483] [-0.00799216]] 0.1 [[ 0.00535443] [ 0.00195984] [-0.00651257] [-0.00675841] [-0.01028436] [-0.01944688] [-0.00674361] [ 0.00747328] [-0.00119065] [-0.00600063] [-0.00499562] [ 0.01717699]] 0.25 [[ 0.01153731] [-0.0178353 ] [ 0.00059123] [ 0.01206309] [ 0.00179897] [-0.00935876] [ 0.00936141] [-0.00026272] [ 0.01812616] [-0.00089715] [ 0.00351766] [-0.00794965]] [<matplotlib.lines.Line2D at 0x1023ffd0>]
該当のソースコード
import numpy as np import tensorflow as tf %matplotlib inline import matplotlib.pyplot as plt with tf.Graph().as_default(): randomseed=1234 #np.random.seed(randomseed) tf.set_random_seed(randomseed) n_in = 20 n_hidden = 12 #n_hidden = [1,2,3,4,5,6,7,8,9,10] n_out = 1 #学習回数 epochs=10 #epochs=[] #学習率 #LEARNING_RATE=0.01 LEARNING_RATE=[0.01,0.05,0.10,0.25] for learn in LEARNING_RATE: randomseed=1234 #np.random.seed(randomseed) tf.set_random_seed(randomseed) #学習 #学習モデルの設定 #tensorflowの定義 x = tf.placeholder(dtype= tf.float32, shape=[None,n_in], name='x') t = tf.placeholder(dtype= tf.float32, shape=[None,n_out], name='t') #入力層から中間層 w21 = tf.Variable(tf.truncated_normal([n_in, n_hidden], stddev=0.01)) b21 = tf.Variable(tf.zeros([n_hidden])) h21 = tf.nn.sigmoid(tf.matmul(x, w21) + b21) #中間層から出力層 w32 = tf.Variable(tf.truncated_normal([n_hidden, n_out], stddev=0.01)) b32 = tf.Variable(tf.zeros([n_out])) y = tf.nn.sigmoid(tf.matmul(h21, w32) + b32) #2乗誤差 loss = tf.reduce_sum(tf.square(y - t)) #最急降下法 train_step = tf.train.GradientDescentOptimizer(learn).minimize(loss) #ここまでモデルの定義 #モジュールのインストール with tf.Session() as sess: randomseed=1234 #np.random.seed(randomseed) tf.set_random_seed(randomseed) sess.run(tf.global_variables_initializer()) randomseed=1234 #np.random.seed(randomseed) tf.set_random_seed(randomseed) loss_cal=[] print(learn) print(sess.run(w32)) for _ in range(epochs): y_out, _ = sess.run([loss, train_step], feed_dict = { x: inputdata[:], t: outputdata[:] })
試したこと
どこに乱数固定のプログラムを書いたとしても固定されない.
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。