\r
/**\r
* <p>\r
- * 隠れ層の出力。\r
- * </p>\r
- */\r
- private double[] hiddenOut = new double[SimpleNN.HIDDEN];\r
-\r
- /**\r
- * <p>\r
* ニューラル・ネットワークの状態(閾値、重み)を初期化します。\r
* </p>\r
*/\r
* \r
* @param input\r
* 入力データ。\r
- * @return 演算結果。\r
+ * @param output\r
+ * 順方向演算の結果を格納する配列。\r
+ * @param hiddenOutput\r
+ * 順方向演算の過程の隠れ層出力を格納する配列。\r
*/\r
- public double[] forwardNeuralNet(double[] input) {\r
+ public void forwardNeuralNet(double[] input, double[] output, double[] hiddenOutput) {\r
double[] out = new double[SimpleNN.OUTPUT];\r
double[] hidden = new double[SimpleNN.HIDDEN];\r
\r
for (int i = 0; i < SimpleNN.INPUT; i++) {\r
hidden[j] += input[i] * this.weightInHidden[i][j];\r
}\r
- this.hiddenOut[j] = this.sigmoid(hidden[j]);\r
+ hiddenOutput[j] = this.sigmoid(hidden[j]);\r
}\r
\r
// 出力層出力の計算\r
for (int k = 0; k < SimpleNN.OUTPUT; k++) {\r
out[k] = -this.thresholdOut[k];\r
for (int j = 0; j < SimpleNN.HIDDEN; j++) {\r
- out[k] += this.hiddenOut[j] * this.weightHiddenOut[j][k];\r
+ out[k] += hiddenOutput[j] * this.weightHiddenOut[j][k];\r
}\r
- out[k] = this.sigmoid(out[k]);\r
+ output[k] = this.sigmoid(out[k]);\r
}\r
-\r
- return out;\r
}\r
\r
/**\r
* 順方向演算の入力データ。\r
* @param output\r
* 順方向演算の結果。\r
+ * @param hiddenOutput\r
+ * 順方向演算の過程の隠れ層出力を格納する配列。\r
* @param teach\r
* 教師信号。\r
*/\r
- public void backwardNeuralNet(double[] input, double[] output, double[] teach) {\r
+ public void backwardNeuralNet(double[] input, double[] output, double[] hiddenOutput, double[] teach) {\r
int i;\r
int j;\r
int k;\r
for (k = 0; k < SimpleNN.OUTPUT; k++) {\r
tempError += outputError[k] * this.weightHiddenOut[j][k];\r
}\r
- hiddenError[j] = this.hiddenOut[j] * (1.0 - this.hiddenOut[j]) * tempError;\r
+ hiddenError[j] = hiddenOutput[j] * (1.0 - hiddenOutput[j]) * tempError;\r
}\r
\r
// 重みの補正\r
for (k = 0; k < SimpleNN.OUTPUT; k++) {\r
for (j = 0; j < SimpleNN.HIDDEN; j++) {\r
- this.weightHiddenOut[j][k] += SimpleNN.ALPHA * outputError[k] * this.hiddenOut[j];\r
+ this.weightHiddenOut[j][k] += SimpleNN.ALPHA * outputError[k] * hiddenOutput[j];\r
}\r
}\r
for (j = 0; j < SimpleNN.HIDDEN; j++) {\r
int r;\r
int x;\r
\r
+ double[] hiddenOutput = new double[SimpleNNApplet.HIDDEN];\r
+\r
String string;\r
\r
// 外部サイクルエラー累計\r
// 内部サイクル\r
\r
// 順方向演算\r
- this.recognizeOut = this.simpleNN.forwardNeuralNet(this.sampleIn);\r
+ this.simpleNN.forwardNeuralNet(this.sampleIn, this.recognizeOut, hiddenOutput);\r
\r
// 逆方向演算(バックプロパゲーション)\r
- this.simpleNN.backwardNeuralNet(this.sampleIn, this.recognizeOut, this.teach);\r
+ this.simpleNN.backwardNeuralNet(this.sampleIn, this.recognizeOut, hiddenOutput, this.teach);\r
}\r
\r
// 内部二乗誤差の計算\r
this.sampleIn = this.sampleArray[q];\r
\r
// 順方向演算\r
- this.recognizeOut = this.simpleNN.forwardNeuralNet(this.sampleIn);\r
+ this.simpleNN.forwardNeuralNet(this.sampleIn, this.recognizeOut, hiddenOutput);\r
\r
// 結果の表示\r
g.setColor(Color.black);\r
Graphics g = this.getGraphics();\r
\r
// 順方向演算\r
- this.recognizeOut = this.simpleNN.forwardNeuralNet(this.writtenIn);\r
+ this.simpleNN.forwardNeuralNet(this.writtenIn, this.recognizeOut, new double[SimpleNNApplet.HIDDEN]);\r
\r
// 結果の表示\r
for (int k = 0; k < SimpleNNApplet.OUTPUT; k++) {\r