質問編集履歴

3

コードを間違えたため

2019/07/05 09:27

投稿

Bonziri
Bonziri

スコア16

test CHANGED
File without changes
test CHANGED
@@ -84,122 +84,6 @@
84
84
 
85
85
  ```ここに言語を入力
86
86
 
87
- import numpy as np
88
-
89
- import tensorflow as tf
90
-
91
- import keras
92
-
93
-
94
-
95
- ##重み(特殊な正規分布から発生する値)
96
-
97
- def weight(shape = []):
98
-
99
- initial = tf.truncated_normal(shape, stddev = 0.01)
100
-
101
- return tf.Variable(initial)
102
-
103
-
104
-
105
- ##バイアス
106
-
107
- def bias(dtype = tf.float32, shape = []):
108
-
109
- initial = tf.zeros(shape, dtype = dtype)
110
-
111
- return tf.Variable(initial)
112
-
113
-
114
-
115
- ##損失関数(交叉エントロピー)
116
-
117
- def loss(t, f):
118
-
119
- cross_entropy = tf.reduce_mean(-tf.reduce_sum(t * tf.log(f)))
120
-
121
- return cross_entropy
122
-
123
-
124
-
125
- ##正確性の尺度
126
-
127
- def accuracy(t, f):
128
-
129
- correct_prediction = tf.equal(tf.argmax(t, 1), tf.argmax(f, 1))
130
-
131
- accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
132
-
133
- return accuracy
134
-
135
-
136
-
137
- Q = 60
138
-
139
- P = 60
140
-
141
- R = 1
142
-
143
-
144
-
145
- sess = tf.InteractiveSession()
146
-
147
-
148
-
149
- X = tf.placeholder(dtype = tf.float32, shape = [None, Q])
150
-
151
- t = tf.placeholder(dtype = tf.float32, shape = [None, R])
152
-
153
-
154
-
155
- ##隠れ層
156
-
157
- ##活性化関数はシグモイド関数
158
-
159
- W1 = weight(shape = [Q, P])
160
-
161
- b1 = bias(shape = [P])
162
-
163
- f1 = tf.matmul(X, W1) + b1
164
-
165
- sigm = tf.nn.sigmoid(f1)
166
-
167
-
168
-
169
- ##出力層
170
-
171
- ##fはソフトマックス関数(出力を0~1に制限)
172
-
173
- W2 = weight(shape = [P, R])
174
-
175
- b2 = bias(shape = [R])
176
-
177
- f2 = tf.matmul(sigm, W2) + b2
178
-
179
- f = tf.nn.softmax(f2)
180
-
181
-
182
-
183
- loss = loss(t, f)
184
-
185
- acc = accuracy(t, f)
186
-
187
-
188
-
189
- ##BP法
190
-
191
- optimizer = tf.train.GradientDescentOptimizer(learning_rate = 0.95)
192
-
193
- train_step = optimizer.minimize(loss)
194
-
195
-
196
-
197
- ##Adam
198
-
199
- ##train_step = tf.train.AdamOptimizer().minimize(loss)
200
-
201
-
202
-
203
87
  ##学習を実行
204
88
 
205
89
  with tf.Session() as sess:

2

追記

2019/07/05 09:27

投稿

Bonziri
Bonziri

スコア16

test CHANGED
File without changes
test CHANGED
@@ -76,7 +76,7 @@
76
76
 
77
77
  入力データは(60,120)で60次元のデータを120個用意しており,内100個を学習データ,残り20個をテストデータにしています
78
78
 
79
- 出力データは(1,120)で1次元データを120個用意し,内100個を学習データ,残り20個をテストデータにしています
79
+ 出力データは(120,1)で1次元データを120個用意し,内100個を学習データ,残り20個をテストデータにしています
80
80
 
81
81
  これらは,記述コードより前でcsvファイルから読み込み済みです
82
82
 

1

コードを間違えたため

2019/06/24 13:30

投稿

Bonziri
Bonziri

スコア16

test CHANGED
File without changes
test CHANGED
@@ -264,7 +264,7 @@
264
264
 
265
265
 
266
266
 
267
- ##sff_idx = np.random.permutation(num_data)
267
+ sff_idx = np.random.permutation(num_data)
268
268
 
269
269
 
270
270