当前位置: 首页>>代码示例>>C++>>正文


C++ Net::setWeight方法代码示例

本文整理汇总了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");
}
开发者ID:goddoe,项目名称:AwsomeNN,代码行数:79,代码来源:main.cpp


注:本文中的Net::setWeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。