Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Neural Dot Net Pt 3 The Adaline Network

, 23 Oct 2003
A neural network library in C#.
neural_dot_net_2002.zip
Neural Dot Net 2002
App.ico
bin
Debug
AdalineWordFile.dat
adalinewordWorkingFile.wrk
adword.trn
App.ico
BackpropagationWorkingFile.wrk
Lin2Var.trn
Neural Dot Net 2002.exe
Neural Net Library.dll
SelfOrganizingNetworkOne.trn
SelfOrganizingNetworkOne.wrk
SelfOrganizingNetworkOneTest.tst
SharpUtils.dll
SharpUtils.pdb
equations.Bak
Neural Dot Net 2002.csproj.user
Neural Net Library
bin
Debug
Neural Net Library.csproj.user
Neural Net Library.suo
obj
Debug
Neural Net Library.projdata
temp
TempPE
SharpUtils
bin
Debug
obj
Debug
SharpUtils.projdata
temp
TempPE
SharpUtils.csproj.user
SharpUtils.suo
neural_network_first_release.zip
Neural Network First release
3e5b39da.jpg
3e5b3ee8.jpg
3e65d686.jpg
3e65d687.jpg
Adaline.png
AdalineOneOptions.png
AdalineTwoOptions.jpg
AdalineWordClassDiagram.png
Adalinewordpattern.png
Addwordtoadalinetwofile.png
Backpropagationclasses.png
BackPropagationOneDiagram.png
backpropagationoneoptions.png
BackPropagationWordDiagram.png
BackPropagationWordOptions.png
BackPropagationWordPattern.png
Basic.png
BasicLinkWorks.png
BasicNetworkTester Overview.png
BasicNeuronComponent.png
changedBasicClassDiagram.png
equationTest.jpg
equationwithbias.jpg
function.jpg
Generating a given File.png
Inside Adaline Transition Function.png
Inside Self Organizing network run.png
Inside The Adaline Run Function Plus Bias.png
Inside The Adaline Run Function.png
learn For the self organizing network.png
Learning For the Backpropagation Network.png
LogViewer
LogViewer.csproj.user
Neural Net Library
Adaline.png
Adalinewordpattern.png
BackPropagation.emf
Basic.png
librarytobackprop.png
Neural Net Library.csproj.user
Pattern.png
Thumbs.db
Neural Net Test
App.ico
bin
Debug
AdalineWordFile.dat
adalinewordWorkingFile.wrk
adword.trn
AxInterop.SHDocVw.dll
BackpropagationWorkingFile.wrk
Interop.SHDocVw.dll
Lin2Var.trn
LogViewer.dll
Neural Net Library.dll
Neural Net Test.exe
SelfOrganizingNetworkOne.trn
SelfOrganizingNetworkOne.wrk
SelfOrganizingNetworkOneTest.tst
SharpUtils.dll
Neural Net Test.csproj.user
NeuralNetTesterPackages.png
Pattern.png
SelfOrganizingNetworkDiagram.png
SelfOrganizingNetworkOneClasses.png
selfOrganizingnetworkoneoptions.png
SelfOrganizingNetworkTwoOptions.png
selforganizingnetworkword.png
Setting Options For a Given Network.png
SharpUtils
SharpUtils.csproj.user
Testing a Given Network.png
Thumbs.db
Train Network Interaction.png
Training a given Network.png
TransferEq.jpg
TransferFunctionlogic.jpg
Transferfunctionwithbias.jpg

using System;
using System.Xml;
using System.Text;
using System.IO;

namespace SharpUtils
{
	/// <summary>
	/// Logger class future implementation that will allow the writing of logging messages to the 
	/// registry or an xml file will be implementated for Log Viewer ( Part of Researcher and NN )
	/// </summary>
	public class Logger
	{
		private bool bLogToEventViewer;
		private bool bLogToXMLFile;
		private bool bUseTimeStamp;
		private string strFileName;
		private SimpleEventLog simpleEventLog;

		private XmlTextWriter xmlWriter;

		private bool bUseEventLog;
		private bool bUseXMLFile;

		/// <summary>
		/// log to the event viewer
		/// </summary>
		public bool LogToEventViewer
		{
			get
			{
				return bLogToEventViewer;
			}
			set
			{
				bLogToEventViewer = value;
			}
		}

		/// <summary>
		/// log to an xml file
		/// </summary>
		public bool LogToXMLFile 
		{
			get
			{
				return bLogToXMLFile;
			}
			set
			{
				bLogToXMLFile = value;
			}
		}

		/// <summary>
		/// use a time stamp on all messages
		/// </summary>
		public bool UseTimeStamp
		{
			get
			{
				return bUseTimeStamp;
			}
			set
			{
				bUseTimeStamp = value;
			}
		}


		/// <summary>
		/// Filename of the xml file to use
		/// </summary>
		public string FileName
		{
			get
			{
				return strFileName;
			}
			set
			{
				strFileName = value;
			}
		}

		/// <summary>
		/// get the current time
		/// </summary>
		public string TimeStamp
		{
			get
			{
				return DateTime.Now.ToLocalTime().ToString();
			}
		}

		/// <summary>
		/// default constructor
		/// </summary>
		public Logger()
		{
			//
			// TODO: Add constructor logic here
			//

			LogToEventViewer = false;
			LogToXMLFile = false;
			UseTimeStamp = false;
			bUseEventLog = false;
			bUseXMLFile = false;
		}


		/// <summary>
		/// constructor 
		/// </summary>
		/// <param name="eventLogName">name of the event log</param>
		/// <param name="clearEventLog">clear the event log on startup</param>
		/// <param name="xmlFileName">name of the xml file to write to</param>
		/// <param name="documentName">name of the xml document</param>
		public Logger( string eventLogName, bool clearEventLog, string xmlFileName, string documentName )
		{
			if( eventLogName != null && eventLogName.Length > 0 )
			{
				simpleEventLog = new SimpleEventLog( eventLogName, clearEventLog );
				bUseEventLog = true;
			}

			if( xmlFileName != null && xmlFileName.Length > 0 )
			{
				FileName = xmlFileName;
				xmlWriter = new XmlTextWriter( FileName, System.Text.Encoding.UTF8 );
				xmlWriter.WriteStartDocument();
				xmlWriter.WriteStartElement( documentName );
				bUseXMLFile = true;
				UseTimeStamp = false;
			}
		}



		/// <summary>
		/// constructor with timestamp
		/// </summary>
		/// <param name="eventLogName">name of the event log</param>
		/// <param name="clearEventLog">clear the event log on startup</param>
		/// <param name="xmlFileName">name of the xml file to write to</param>
		/// <param name="documentName">name of the xml document</param>
		/// <param name="useTimeStamp">true to add a timestamp to each message</param>
		public Logger( string eventLogName, bool clearEventLog, string xmlFileName, string documentName, bool useTimeStamp ) 
			: this( eventLogName, clearEventLog, xmlFileName, documentName )
		{
			UseTimeStamp = useTimeStamp;
		}


		/// <summary>
		/// constructor for just using the event log
		/// </summary>
		/// <param name="eventLogName">name of the event Log</param>
		/// <param name="clearEventLog">clear the event log on startup</param>
		public Logger( string eventLogName, bool clearEventLog )
		{
			if( eventLogName != null && eventLogName.Length > 0 )
			{
				simpleEventLog = new SimpleEventLog( eventLogName, clearEventLog );
				bUseEventLog = true;
				bUseXMLFile = false;
				UseTimeStamp = false;
			}
		}

		/// <summary>
		/// constructor for just using the xml file
		/// </summary>
		/// <param name="xmlFileName">xml file to name</param>
		/// <param name="documentName">name of the xml document</param>
		public Logger( string xmlFileName, string documentName )
		{
			if( xmlFileName != null && xmlFileName.Length > 0 )
			{
				FileName = xmlFileName;
				FileStream stream;  
				FileInfo info = new FileInfo( xmlFileName );
				if( info.Exists == true )
				{
					info.Delete();
					stream = new FileStream( xmlFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite, 8, true );
					xmlWriter = new XmlTextWriter( stream, System.Text.Encoding.UTF8 );

				}
				else
				{
					stream = new FileStream( xmlFileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite, 8, true );
					xmlWriter = new XmlTextWriter( stream, System.Text.Encoding.UTF8 );
				}

				xmlWriter.WriteStartDocument();
				xmlWriter.WriteStartElement( documentName );
	
				bUseXMLFile = true;
				bUseEventLog = false;
				UseTimeStamp = false;
			}
		}

		/// <summary>
		/// constructor for event log with timestamp 
		/// </summary>
		/// <param name="eventLogName">name of the event log</param>
		/// <param name="clearEventLog">true to clear the event log on start up</param>
		/// <param name="useTimeStamp">use a timestamp in each message</param>
		public Logger( string eventLogName, bool clearEventLog, bool useTimeStamp ) : this( eventLogName, clearEventLog )
		{
			UseTimeStamp = useTimeStamp;
		}


		/// <summary>
		/// constructor for xml file using time stamp
		/// </summary>
		/// <param name="xmlFileName">name of the xml file</param>
		/// <param name="documentName">document name for the xml file</param>
		/// <param name="useTimeStamp">use a time stamp in each message</param>
		public Logger( string xmlFileName, string documentName, bool useTimeStamp ) : this( xmlFileName, documentName )
		{
			UseTimeStamp = useTimeStamp;
		}


		/// <summary>
		/// copy constructor
		/// </summary>
		/// <param name="log"></param>
		public Logger( Logger log )
		{
			this.LogToEventViewer = log.LogToEventViewer;
			this.LogToXMLFile = log.LogToXMLFile;
			this.FileName = log.FileName;
			this.UseTimeStamp = log.UseTimeStamp;
			this.xmlWriter = log.xmlWriter;
		}


		/// <summary>
		/// destructor
		/// </summary>
		~Logger()
		{
			try
			{
				if( xmlWriter != null )
					xmlWriter.Close();
			}
			catch( ObjectDisposedException )
			{
				
			}
		}


		/// <summary>
		/// close the logger
		/// </summary>
		public void Close()
		{
			if( bUseEventLog == true )
			{
				simpleEventLog.Close();
			}

			if( bUseXMLFile == true )
			{
				xmlWriter.Flush();
				xmlWriter.WriteEndElement();
				xmlWriter.WriteEndDocument();
				xmlWriter.Close();
			}
		}

		/// <summary>
		/// write an xml message
		/// </summary>
		/// <param name="dblPriority">priority level</param>
		/// <param name="message">error message</param>
		/// <param name="type">type ie node name</param>
		private void WriteXML( DebugLevelSet dblPriority, string message, string type )
		{
			StringBuilder strString = new StringBuilder();
			if( UseTimeStamp == true )
			{
				strString.Append( TimeStamp + " " );
			}

			strString.Append( message );

			xmlWriter.WriteStartElement( type );
			if( UseTimeStamp == true )
			{
				xmlWriter.WriteElementString( "Time", TimeStamp );
			}

			xmlWriter.WriteElementString( "Priority", dblPriority.ToString() );
			xmlWriter.WriteElementString( "Message", strString.ToString() );

			xmlWriter.WriteEndElement();

		}

		/// <summary>
		/// write an event log message
		/// </summary>
		/// <param name="dblPriority">priority level</param>
		/// <param name="message">error message</param>
		private void WriteEventLog( DebugLevelSet dblPriority, string message )
		{
			StringBuilder strString = new StringBuilder();
			if( UseTimeStamp == true )
			{
				strString.Append( TimeStamp + " " );
			}

			strString.Append( message );

			switch( dblPriority )
			{
				case DebugLevelSet.All : simpleEventLog.WriteInformation( strString.ToString() ); break;
				case DebugLevelSet.Errors : simpleEventLog.WriteError( strString.ToString() ); break;
				case DebugLevelSet.WarningsAndErrors : simpleEventLog.WriteWarning( strString.ToString() ); break;
			}
		}

		/// <summary>
		/// log a message
		/// </summary>
		/// <param name="dblPriority">debug level set priority</param>
		/// <param name="message">message to log</param>
		public void Log( DebugLevelSet dblPriority, string message )
		{

			lock( this )
			{
				/// probably wont use this for xml but allow it anyway
				if( bUseXMLFile == true )
				{
					WriteXML( dblPriority, message, dblPriority.ToString() );
				}

				if( dblPriority < DebugLevelSet.Warning && bUseEventLog == true )
				{
					WriteEventLog( dblPriority, message );
				}
			}
		}


		/// <summary>
		/// log a message
		/// </summary>
		/// <param name="dblPriority">debug level set priority</param>
		/// <param name="message">actual message to log</param>
		/// <param name="type">class or category name</param>
		public void Log( DebugLevelSet dblPriority, string message, string type )
		{
			lock( this )
			{
				if( bUseXMLFile == true )
				{
					WriteXML( dblPriority, message, type );
				}


				/// if higher or equal to warning can't log in event viewer
				if( dblPriority >= DebugLevelSet.Warning )
				{
					WriteEventLog( dblPriority, message );
				}
			}
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

pseudonym67

United Kingdom United Kingdom
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150326.1 | Last Updated 24 Oct 2003
Article Copyright 2003 by pseudonym67
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid