本文整理汇总了C++中Net::setWeight方法的典型用法代码示例。如果您正苦于以下问题:C++ Net::setWeight方法的具体用法?C++ Net::setWeight怎么用?C++ Net::setWeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Net
的用法示例。
在下文中一共展示了Net::setWeight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MLP
void MLP(int argc, char* argv[])
{
/****************************/
Trainer trainer;
trainer.parseData("./sample.txt");
Net *net = new Net();
try
{
net = new Net(2);
net->push_back_layer(50);
net->push_back_layer(30);
net->push_back_layer(20);
net->push_back_layer(1);
net->setWeight();
}
catch(exception e)
{
printf("%s\n", e.what());
exit(0);
}
printf("*************************************************\n");
printf("MLP Learning Start!\n");
printf("size = %d\n", trainer.m_input.size());
int count =0;
for(int i = 0 ; i < trainer.m_input.size(); ++i)
{
net->feedforward(trainer.m_input[i]);
net->backprob(trainer.m_target[i]);
if( (count++) % 5000 == 0)
printf("count: %d\n", count);
}
printf("learing done!\n");
printf("*************************************************\n");
char save_path[2048] = "./first_net.txt";
printf("Your neural network is saved \"%s\"\n", save_path);
net->save("first_net.txt");
// if you wants load your network, use code below!
// net->load("first_net.txt");
printf("*************************************************\n");
// this is for test!
printf("Test your self!\n");
printf("type like\n");
printf("input: 1.0 1.0\n");
printf("then you can get near 0, because 1.0 XOR 1.0 is 0!\n");
printf("input: 1.0 0.0\n");
printf("then you can get near 1, because 1.0 XOR 0.0 is 1!\n");
printf("! means not factorial this times! :-)\n");
printf("if you wants to quit the program type 100 0\n\n");
while(true)
{
float input[2];
printf("input : ");
scanf("%f %f", &input[0], &input[1]);
if(input[0] == 100.0)
break;
net->feedforward(input);
printf("result : %f\n\n", (float)(net->m_layersActivation.back()[0]));
}
delete net;
printf("bye ;-)\n");
}