обратно

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.awt.image.*;

public class Teach{
  
  public static void main(String args[])
  {

	FileOutputStream logFile;

	int IDEAL_X, IDEAL_Y;
	int razb_y, razb_x;
	int kol_neuronov;
	int i, j, k;
	int kol_priznakov, kol_shriftov;
	boolean teach_one_more;
	Image2Obraz o[];
	Obraz2Vector vector [];

	kol_neuronov = 4;
	kol_priznakov = 10;
	kol_shriftov = 5;


	IDEAL_X = 300;
	IDEAL_Y = 300;
	razb_y = 4;
	razb_x = 4;

	o = new Image2Obraz [kol_shriftov*kol_priznakov];
	vector = new Obraz2Vector[kol_shriftov*kol_priznakov];

	for ( i = 0; i < kol_shriftov; i ++ )
		for ( j = 0; j < kol_priznakov; j ++ )
		{
			o[i*kol_priznakov+j] = new Image2Obraz("JPG\\" + i + j + ".jpg", "OBR\\" + i + j +".obr" , IDEAL_X, IDEAL_Y );
			vector[i*kol_priznakov+j] = new Obraz2Vector( o[i*kol_priznakov+j].obraz, IDEAL_Y, IDEAL_X, "REZ\\" + i + j +".raz", razb_y, razb_x);
		}


	Perseptron p;
	p = new Perseptron( vector[0].X_len, kol_neuronov );

	p.load (p.matrix_vesov, p.high, p.width, "Vesa.pers", "vesa" );
	p.load (p.matrix_otvetov, p.width, kol_priznakov, "Otvet.pers", "otvet" );

	teach_one_more = true;

	k = 1;
  try{ 
	logFile = new FileOutputStream("log.pers");

	while (teach_one_more)
	{
		teach_one_more = false;
		System.out.print(k + "-я итерация: ");

		for ( i = 0; i < kol_shriftov; i ++ )
			for ( j = 0; j < kol_priznakov; j ++ )
				if ( ! p.input ( vector[i*kol_priznakov+j].X, j  ) )
				{
					teach_one_more = true;
					System.out.print("0");
					logFile.write('0');
				}
				else
				{
					System.out.print("1");
					logFile.write('1');
				}

		System.out.println("");
		logFile.write(13);
		logFile.write(10);

		k ++;
	}
   } 
   catch(IOException e) 
   {System.out.println("Чего-то с файлом log.pers");System.exit(0);}
	
	p.save ();

	System.exit(0);
  }
}

 обратно