質問するログイン新規登録

質問編集履歴

3

コードを間違えたため

2019/07/05 09:27

投稿

Bonziri
Bonziri

スコア16

title CHANGED
File without changes
body CHANGED
@@ -41,64 +41,6 @@
41
41
  これらは,記述コードより前でcsvファイルから読み込み済みです
42
42
  エラーが出ているのは最後の行のみです.
43
43
  ```ここに言語を入力
44
- import numpy as np
45
- import tensorflow as tf
46
- import keras
47
-
48
- ##重み(特殊な正規分布から発生する値)
49
- def weight(shape = []):
50
- initial = tf.truncated_normal(shape, stddev = 0.01)
51
- return tf.Variable(initial)
52
-
53
- ##バイアス
54
- def bias(dtype = tf.float32, shape = []):
55
- initial = tf.zeros(shape, dtype = dtype)
56
- return tf.Variable(initial)
57
-
58
- ##損失関数(交叉エントロピー)
59
- def loss(t, f):
60
- cross_entropy = tf.reduce_mean(-tf.reduce_sum(t * tf.log(f)))
61
- return cross_entropy
62
-
63
- ##正確性の尺度
64
- def accuracy(t, f):
65
- correct_prediction = tf.equal(tf.argmax(t, 1), tf.argmax(f, 1))
66
- accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
67
- return accuracy
68
-
69
- Q = 60
70
- P = 60
71
- R = 1
72
-
73
- sess = tf.InteractiveSession()
74
-
75
- X = tf.placeholder(dtype = tf.float32, shape = [None, Q])
76
- t = tf.placeholder(dtype = tf.float32, shape = [None, R])
77
-
78
- ##隠れ層
79
- ##活性化関数はシグモイド関数
80
- W1 = weight(shape = [Q, P])
81
- b1 = bias(shape = [P])
82
- f1 = tf.matmul(X, W1) + b1
83
- sigm = tf.nn.sigmoid(f1)
84
-
85
- ##出力層
86
- ##fはソフトマックス関数(出力を0~1に制限)
87
- W2 = weight(shape = [P, R])
88
- b2 = bias(shape = [R])
89
- f2 = tf.matmul(sigm, W2) + b2
90
- f = tf.nn.softmax(f2)
91
-
92
- loss = loss(t, f)
93
- acc = accuracy(t, f)
94
-
95
- ##BP法
96
- optimizer = tf.train.GradientDescentOptimizer(learning_rate = 0.95)
97
- train_step = optimizer.minimize(loss)
98
-
99
- ##Adam
100
- ##train_step = tf.train.AdamOptimizer().minimize(loss)
101
-
102
44
  ##学習を実行
103
45
  with tf.Session() as sess:
104
46
  init_op = tf.global_variables_initializer()

2

追記

2019/07/05 09:27

投稿

Bonziri
Bonziri

スコア16

title CHANGED
File without changes
body CHANGED
@@ -37,7 +37,7 @@
37
37
  ### 記述コード
38
38
  入力層:60,隠れ層:60,出力層:1 のNNを作成しようとしています
39
39
  入力データは(60,120)で60次元のデータを120個用意しており,内100個を学習データ,残り20個をテストデータにしています
40
- 出力データは(1,120)で1次元データを120個用意し,内100個を学習データ,残り20個をテストデータにしています
40
+ 出力データは(120,1)で1次元データを120個用意し,内100個を学習データ,残り20個をテストデータにしています
41
41
  これらは,記述コードより前でcsvファイルから読み込み済みです
42
42
  エラーが出ているのは最後の行のみです.
43
43
  ```ここに言語を入力

1

コードを間違えたため

2019/06/24 13:30

投稿

Bonziri
Bonziri

スコア16

title CHANGED
File without changes
body CHANGED
@@ -131,7 +131,7 @@
131
131
  batch_size = 10
132
132
  for epoch in range(num_epoch):
133
133
 
134
- ##sff_idx = np.random.permutation(num_data)
134
+ sff_idx = np.random.permutation(num_data)
135
135
 
136
136
  for idx in range(0, num_data, batch_size):
137
137
  batch_x = train_x[sff_idx[idx: idx + batch_size]]