/* ========================================== *
* Filename: bpnet.h *
* Author: James Matthews. *
* *
* Description: *
* This is a tiny neural network that uses *
* back propagation for weight adjustment. *
* ========================================== */#include <math.h>#include <stdlib.h>#include <time.h>#defineBP_LEARNING(float)(0.5)// The learning coefficient.classCBPNet{public:
CBPNet();
~CBPNet(){};
floatTrain(float, float, float);
floatRun(float, float);
private:
floatm_fWeights[3][3]; // Weights for the 3 neurons.floatSigmoid(float); // The sigmoid function.};
CBPNet::CBPNet(){srand((unsigned)(time(NULL)));
for(inti=0;i<3;i++){for(intj=0;j<3;j++){// For some reason, the Microsoft rand() function// generates a random integer. So, I divide by the// number by MAXINT/2, to get a num between 0 and 2,// the subtract one to get a num between -1 and 1.m_fWeights[i][j] = (float)(rand())/(32767/2) - 1;
}}}floatCBPNet::Train(floati1, floati2, floatd){// These are all the main variables used in the // routine. Seems easier to group them all here.floatnet1, net2, i3, i4, out;
// Calculate the net values for the hidden layer neurons.net1 = 1 * m_fWeights[0][0] + i1 * m_fWeights[1][0] +
i2 * m_fWeights[2][0];
net2 = 1 * m_fWeights[0][1] + i1 * m_fWeights[1][1] +
i2 * m_fWeights[2][1];
// Use the hardlimiter function - the Sigmoid.i3 = Sigmoid(net1);
i4 = Sigmoid(net2);
// Now, calculate the net for the final output layer.net1 = 1 * m_fWeights[0][2] + i3 * m_fWeights[1][2] +
i4 * m_fWeights[2][2];
out = Sigmoid(net1);
// We have to calculate the deltas for the two layers.// Remember, we have to calculate the errors backwards// from the output layer to the hidden layer (thus the// name 'BACK-propagation').floatdeltas[3];
deltas[2] = out*(1-out)*(d-out);
deltas[1] = i4*(1-i4)*(m_fWeights[2][2])*(deltas[2]);
deltas[0] = i3*(1-i3)*(m_fWeights[1][2])*(deltas[2]);
// Now, alter the weights accordingly.floatv1 = i1, v2 = i2;
for(inti=0;i<3;i++){// Change the values for the output layer, if necessary.if(i == 2){v1 = i3;
v2 = i4;
}m_fWeights[0][i] += BP_LEARNING*1*deltas[i];
m_fWeights[1][i] += BP_LEARNING*v1*deltas[i];
m_fWeights[2][i] += BP_LEARNING*v2*deltas[i];
}returnout;
}floatCBPNet::Sigmoid(floatnum){return(float)(1/(1+exp(-num)));
}floatCBPNet::Run(floati1, floati2){// I just copied and pasted the code from the Train() function,// so see there for the necessary documentation.floatnet1, net2, i3, i4;
net1 = 1 * m_fWeights[0][0] + i1 * m_fWeights[1][0] +
i2 * m_fWeights[2][0];
net2 = 1 * m_fWeights[0][1] + i1 * m_fWeights[1][1] +
i2 * m_fWeights[2][1];
i3 = Sigmoid(net1);
i4 = Sigmoid(net2);
net1 = 1 * m_fWeights[0][2] + i3 * m_fWeights[1][2] +
i4 * m_fWeights[2][2];
returnSigmoid(net1);
}//---#include <iostream.h>#include"bpnet.h"#defineBPM_ITER2000voidmain(){CBPNetbp;
for(inti=0;i<BPM_ITER;i++){bp.Train(0,0,0);
bp.Train(0,1,1);
bp.Train(1,0,1);
bp.Train(1,1,0);
}cout << "0,0 = " << bp.Run(0,0) << endl;
cout << "0,1 = " << bp.Run(0,1) << endl;
cout << "1,0 = " << bp.Run(1,0) << endl;
cout << "1,1 = " << bp.Run(1,1) << endl;
}
先生们!
那么,我们应该向神经网络的 输入端输入什么呢?我们应该选择什么误差函数?
从内容上看,没有多少人感兴趣。许多人认为这与软件....。
我建议你从不同时期的回归线的斜率开始。 而且你可以从不同的TF开始。:)
错误的功能 - 最大的利润。
从内容上看,没有多少人感兴趣。很多人认为是软件....。
是的,有很多神经元的线程在进行。而且到处都是灌水者用愚蠢的软件请求和几十条 "我和我和我 "的信息堵塞任何讨论。
所以没有地方可以正确地讨论它。也许有一个严格控制的论坛,在那里他们会射杀那些傻瓜?如果你说了一句话,你就会受到训斥;如果你说了两句离题的话,你就会被永远忽略。
布衣, 你有很多地方可以玩,也许你心里有一个地方?
从内容上看,没有多少人感兴趣。很多人认为这是关于软件....。
哦,伙计!!!,这么多关于神经元的话题。而到处都是灌水者用愚蠢的软件请求和几十条 "我和我和我 "的信息堵塞任何讨论。
所以没有地方可以正确地讨论它。也许有一个严格控制的论坛,在那里他们会射杀那些傻瓜?如果你说了一句话,你就会受到训斥;如果你说了两句离题的话,你就会被永远忽略。
布衣, 你有很多地方可以玩,也许你知道一个地方?
我已经开了一个论坛,我现在要去那里吃点东西 :)而且我邀请大家进行实际讨论。我自己也要击落灌水器。 :)
http://www.fxreal.ru/forums/index.php
我正在把我从不同地方的发现一点一点地转移到那里。
一个简单的非网络的例子
微软可视化C++ 6.0
网络学习XOR操作
另一个简单的网络!
微软可视化C++ 6.0
这个版本允许你添加层 - 改变层中的神经元数量
最初,在源头有3层
在输入端有2个神经元--在隐藏层有2个,在输出端有1个!
//创建一个3层的神经网来解决XOR问题,在前两层有2个节点,
//在输出层有一个节点。
CBPNet XOR( 3 /* 数层 */, 2 /* 输入 */,2 /* 隐藏 */,1 /* 输出 */ ) 。
//将神经元连接起来
//
// O - 输出
// // \
// O O - 隐藏
// ||
// || X
// |/ \
// O - 输入
//
例如,如果你把3个神经元放在隐藏层,结果会变得更准确
CBPNet XOR( 3 /* 数层 */, 2 /* 输入 */,3 /* 隐藏 */,1 /* 输出 */ ) 。
增加层数也需要增加隐藏层的神经元数量。
CBPNet XOR( 4 /* 数层 */, 2 /* 输入 */,20 /* 隐藏 1 */ ,5 /* 隐藏 2 */ ,1 /* 输出 */ ) 。
当增加层数时,你还需要添加一个调用
//对隐藏层和输出层施加偏置
XOR.SetBias(POINT2D(0,1),BIAS_GLOBAL );
XOR.SetBias( POINT2D(1,1),BIAS_GLOBAL );
XOR.SetBias( POINT2D(1,1),BIAS_GLOBAL );
XOR.SetBias( POINT2D(0,2), BIAS_GLOBAL ) ;
我成功地得到了结果,但网络的学习速度要慢得多!
我已经开了一个论坛,我现在要去那里吃点东西 :)而且我邀请大家进行实际讨论。我自己也要击落灌水器。 :)
和一个绝对漂亮的教程!
它的效果非常好。你也可以尝试以模式识别的形式,教网络一个乘法表。
如:in[0]=2;in[1]=2;out_des[0]=4;etc.....
和一个绝对漂亮的教程!
先生们!
那么,我们应该向神经网络的 输入端输入什么?我们应该选择什么误差函数?
从内容上看,没有多少人感兴趣。许多人认为这与软件....。
我建议你从不同时期的回归线的斜率开始。 而且你可以从不同的TF开始。:)
职能错误 - 最大利润。
也许使用误差功能 会更好--不是最大利润,而是解除联系(预测和Close[0]之间的差异)。