public Form1() { serializer = new XmlSerializer(typeof(Alphabet)); example = new TestSymbol(); InitializeComponent(); AddEventHandlers(); AddBehavior(); }
/// <summary> /// <para>Learns symbol example</para> /// </summary> /// <param name="example"></param> public void Train(TestSymbol example) { for (int i = 0; i < 256; i++) { for (int j = 0; j < 256; j++) { if (example.Data[i, j]) { if (Data[i][j] <= 10) { this.Data[i][j]++; } } } } }
/// <summary> /// <para>Determines which symbol was drawen and its grade</para> /// </summary> /// <param name="example"></param> /// <returns></returns> public Tuple <char, BindingList <Tuple <char, float> > > Recognize(TestSymbol example) { char resultSymbol = '-'; short resultGrade = 0; short tempGrade = 0; var resultListSum = 0; var finalList = new BindingList <Tuple <char, float> >(); BindingList <Tuple <char, short> > resultList = new BindingList <Tuple <char, short> >(); foreach (Symbol s in Symbols) { tempGrade = s.Test(example); resultList.Add(new Tuple <char, short>(s.Name, tempGrade)); if (tempGrade > resultGrade) { resultGrade = tempGrade; resultSymbol = s.Name; } } foreach (Tuple <char, short> t in resultList) { resultListSum += t.Item2; } foreach (Tuple <char, short> t in resultList) { float probability = 100; try { probability = (float)((float)t.Item2 / (float)resultListSum); } catch (Exception) { } finalList.Add(new Tuple <char, float>(t.Item1, probability)); } return(new Tuple <char, BindingList <Tuple <char, float> > >(resultSymbol, finalList)); }
/// <summary> /// <para>Tests specified symbol from the alphabet</para> /// </summary> /// <param name="name"></param> /// <param name="example"></param> public void TestSymbol(char name, TestSymbol example) { Symbol symbol = Symbols.Where(x => x.Name == name).FirstOrDefault(); symbol.Test(example); }