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

📄 test1-bio.cpp

📁 neural network 一个演示原理的代码
💻 CPP
字号:
#include "stdafx.h"
#include "aine.h"
#include "ne-neuron.h"
#include "ne-data.h"

using namespace aine;

extern ofstream tron;

static double Inverse( const double v )
{
	return v > 1.0 ? 0.0 : 1.0;
}

static double Inverse2( const double v )
{
	return v > 1.0 ? 0.0 : v;
}
namespace Biologic
{
	int EORTest( const string )
	{
		cout << "create a sample meural Process of EOR reduced method" << endl;
		tron << "create a sample meural Process of EOR reduced method" << endl;

		double in[4][2] =
		{	{	0.0 , 0.0	} ,
			{	1.0 , 0.0	} ,
			{	0.0 , 1.0	} ,
			{	1.0 , 1.0	} 
		};

		Neuron n1 , n2;

		n1.ConnectWith( &n2 );
		n2.ConnectWith ( &n2 );
		n2.axon[0]->SetCallBack( Inverse2 );

		cout << "Tracing EOR:" << endl;
		tron << "Tracing EOR:" << endl;
		for( int i = 0 ; i < 40 ; i++ )
		{
			const int at = i >= 4 ? (int)Random( 0 , 4 , true ) : i;
			n1.SetInputValue( in[at][0] );
			n2.SetInputValue( in[at][1] );

			cout << i << ") " << in[at][0]  << " EOR " << in[at][1] << " : " ;
			tron << i << ") " << in[at][0]  << " EOR " << in[at][1] << " : " ;

			n1.Depolarization();
				cout << in[at][0]  << " OR " << in[at][1] << " ---> " << (int)(n2.ActionPotential() ? 1 : 0) << " --> ";
				tron << in[at][0]  << " OR " << in[at][1] << " ---> " << (int)(n2.ActionPotential() ? 1 : 0) << " --> ";

			n2.Depolarization();
			cout << (int)(n2.ActionPotential() ? 1 : 0) << endl;
			tron << (int)(n2.ActionPotential() ? 1 : 0);
			if( n2.ActionPotential() )
				if( in[at][0] == in[at][1] ) 
					tron << " **** ERROR *** ";
			tron << endl;
		}
		return 0;
	}

	int BoolTest( const string )
	{
		cout << "create a sample meural Process of boolean operators with less neurons" << endl;
		tron << "\n\ncreate a sample meural Process of boolean operators with less neurons" << endl;

		Neuron	n1 , n2;
		double in[4][2] =
		{	{	0.0 , 0.0	} ,
			{	1.0 , 0.0	} ,
			{	0.0 , 1.0	} ,
			{	1.0 , 1.0	} 
		};
		n1.ConnectWith( &n2 );
		n2.ConnectWith( &n2 );
		cout << "Tracing OR:" << endl;
		tron << "Tracing OR:" << endl;
		for( int i = 0 ; i < 40 ; i++ )
		{
			const int at = i >= 4 ? (int)Random( 0 , 4 , true ) : i;
			n1.SetInputValue( in[at][0] );
			n2.SetInputValue( in[at][1] );

			n1.Depolarization();

			cout << i << ") " << in[at][0]  << " OR " << in[at][1] << " ---> " << (int)(n2.ActionPotential() ? 1 : 0) << endl;
			tron << i << ") " << in[at][0]  << " OR " << in[at][1] << " ---> " << (int)(n2.ActionPotential() ? 1 : 0);
			if( n2.ActionPotential() )
				if( !(in[at][0] || in[at][1]) )
					tron << " **** ERROR *** ";
			tron << endl;
		}
		cout << endl;
		tron << endl;


		cout << "Tracing AND:" << endl;
		tron << "Tracing AND:" << endl;
		n2.SetThreshold( 1.5 );
		for( int i = 0 ; i < 40 ; i++ )
		{
			const int at = i >= 4 ? (int)Random( 0 , 4 , true ) : i;
			n1.SetInputValue( in[at][0] );
			n2.SetInputValue( in[at][1] );

			n1.Depolarization();

			cout << i << ") " << in[at][0]  << " AND " << in[at][1] << " ---> " << (int)(n2.ActionPotential() ? 1 : 0) << endl;
			tron << i << ") " << in[at][0]  << " AND " << in[at][1] << " ---> " << (int)(n2.ActionPotential() ? 1 : 0);
			if( n2.ActionPotential() )
				if( !(in[at][0] && in[at][1]) )
					tron << " **** ERROR *** ";
			tron << endl;
		}
		cout << endl;
		tron << endl;

		Neuron trigger , _not;
		n2.SetThreshold( 0.0 );
		n2.ConnectWith( &trigger );
		trigger.ConnectWith( &_not );
		trigger.axon[0]->SetCallBack( Inverse );

		cout << "Tracing NOR:" << endl;
		tron << "Tracing NOR:" << endl;
		for( int i = 0 ; i < 40 ; i++ )
		{
			const int at = i >= 4 ? (int)Random( 0 , 4 , true ) : i;
			n1.SetInputValue( in[at][0] );
			n2.SetInputValue( in[at][1] );
			trigger.SetInputValue( 1.0 );

			n1.Depolarization();

			trigger.SetInputValue( 1.0 );
			n2.Depolarization();
			trigger.Depolarization();

			cout << i << ") " << in[at][0]  << " NOR " << in[at][1] << " ---> " << (int)(_not.ActionPotential() ? 1 : 0) << endl;
			tron << i << ") " << in[at][0]  << " NOR " << in[at][1] << " ---> " << (int)(_not.ActionPotential() ? 1 : 0);
			if( _not.ActionPotential() )
				if( in[at][0] || in[at][1] )
					tron << " **** ERROR *** ";
			tron << endl;
			
			_not.Refractory();
		}
		cout << endl;
		tron << endl;

		n2.SetThreshold( 1.5 );
		cout << "Tracing NAND:" << endl;
		tron << "Tracing NAND:" << endl;
		for( int i = 0 ; i < 40 ; i++ )
		{
			const int at = i >= 4 ? (int)Random( 0 , 4 , true ) : i;
			n1.SetInputValue( in[at][0] );
			n2.SetInputValue( in[at][1] );

			n1.Depolarization();

			cout << i << ") " << in[at][0]  << " AND " << in[at][1] << " ---> " << (int)(n2.ActionPotential() ? 1 : 0) << endl;
			tron << i << ") " << in[at][0]  << " AND " << in[at][1] << " ---> " << (int)(n2.ActionPotential() ? 1 : 0);
			if( n2.ActionPotential() )
				if( !(in[at][0] && in[at][1]) )
					tron << " **** ERROR *** ";
			tron << "\t";

			trigger.SetInputValue( 1.0 );
			n2.Depolarization();
			trigger.Depolarization();

			cout << i << ") " << in[at][0]  << " NAND " << in[at][1] << " ---> " << (int)(_not.ActionPotential() ? 1 : 0) << endl;
			tron << i << ") " << in[at][0]  << " NAND " << in[at][1] << " ---> " << (int)(_not.ActionPotential() ? 1 : 0);
			if( _not.ActionPotential() )
				if( (in[at][0] && in[at][1]) )
					tron << " **** ERROR *** ";
			tron << endl;
			
			_not.Refractory();
		}
		cout << endl;
		tron << endl;

		return 0;
	}
}

⌨️ 快捷键说明

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