⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pnn.cpp

📁 神经网络vc源代码神经网络的VC++代码呀
💻 CPP
字号:
/*
    nn-utility (Provides neural networking utilities for c++ programmers)
    Copyright (C) 2003 Panayiotis Thomakos

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
*/
//To contact the author send an email to panthomakos@users.sourceforge.net

/*Demonstrates an operational PNN for two dimensions.*/

#include <nn-utility.h>

using namespace nn_utility;
nn_utility_functions<float> derived;

//classify the results
void classify( nn_utility_functions<float>::VECTOR result ){
	cout << "Resulting group that point was closer to: " <<
		( result[0] > result[1] ? "group 1" : "group 0" );
}

int main(){
	//define the layer and set it's values
	PNN *hidden1 = new PNN();
	hidden1->definef( 2, 5, -.5, -.5, .5, .5, .5, .2, .3, .2, .3, .1 );
	//set the bias vector with 0.1
	derived.ClearVector( hidden1->weight, 5, 0.1 );
	
	//define the second layer and set it's values
	PNN *hidden2 = new PNN();
	hidden2->define( 5, 2 );
	derived.LoadVectorf( hidden2->weight, 2, 0.5, 1.0/3.0 );

	//First 2 nodes of layer 2 recieve input from first 2 nodes of layer 1 only
	//Last 3 nodes of layer 2 recieve input from last 3 nodes of layer 1 only
	//View the MANUAL file for more information
	hidden2->SetBinary( 1, 0,	//node 1 of layer 1: ( node 1 of layer 2, node 2 of layer 2 )
			    1, 0,	//node 2 of layer 1: ...
			    0, 1,	//node 3 of layer 1: ...
			    0, 1,	//node 4 of layer 1: ...
			    0, 1 );	//node 5 of layer 1: ...

	//create buffers
	layer<float> *ppHidden1 = hidden1;
	layer<float> *ppHidden2 = hidden2;

	//connect the layers
	derived.Insert( &ppHidden1, &ppHidden2 );
	
	//create an input and FINAL vector
	nn_utility_functions<float>::VECTOR input, FINAL;
	//load the input
	derived.LoadVectorf( input, 2, 0.0, 0.0 );
	
	//Test:
	hidden1->FeedForward( input, FINAL );
	cout << "Input Vector: "; derived.PrintVector( input, 2 );
	cout << "Feedforward sigmoid fires: "; derived.PrintVector( FINAL, 2 );
	classify( FINAL );
	
	cout << '\n';
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -