Simple backpropagation neural net
Code: "neural_net_4.java". Programming language: Java DMelt Version 1. Last modified: 10/30/2015. License: Pro
https://datamelt.org/code/cache/neural_net_4_4968.java
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.



/*
 *	Demo of a Backpropagation Net
 *	(Java application)
 *	Written in 1997 by Jochen Froehlich.
 */



import jhpro.nnet.*;


public class neural_net_4 {


	static BackpropagationNet bpn;



	/*

	 * compares two patterns and returns an accuracy value

	 */

	static String compare ( String recallPattern, String targetPattern ) {

		int acc = 0, len = recallPattern.length();

		char[] rp, tp = new char[len];

		rp = recallPattern.toCharArray();

		tp = targetPattern.toCharArray();

		for ( int i=0; i1.0) ? "2 bad" : String.valueOf((1.0-neterror)*100)+"%";

		sb.append( "\n\rminerror: " + bpn.getMinimumError() + "\n\rneterror: " + neterror + "\n\raccuracy: " + acc + "\n\rtime    : " + bpn.getElapsedTime() + " sec" );

		sb.append( "\n\r-----------------------------------------------------" );

		System.out.println( sb );

	}





	/*

	 * here's the action...

	 */

	public static void main ( String[] args ) {

		System.out.println( "\n\n\rDEMO OF A BACKPROPAGATION NET\n\r" );

			bpn = new BackpropagationNet();



			System.out.print( "Reading conversion file ..." );

			bpn.readConversionFile( "ascii2bin.cnv" );	// 1 ascii value -> 6 binary values

			System.out.println( "OK" );



			System.out.print( "Creating neuron layers ..." );

			bpn.addNeuronLayer( 10 );	// input layer for towns (must be 10, see pattern file)

			bpn.addNeuronLayer( 4 );	// hidden layer (number of neurons may vary)

										// (more hidden layers are possible)

			bpn.addNeuronLayer( 7 );	// output layer for countrys (must be 7, see pattern file)

			System.out.println( "OK" );



			System.out.print( "Connecting neuron layers ..." );

			bpn.connectLayers();

			System.out.println( "OK" );



			System.out.println( "\n\rNet structure:" );

			for ( int i=0; i

Ads help maintain this website.