/// <summary>
        /// Manejador del evento RecognizingCharacteristicChecked de la base de datos de caracteres.
        /// </summary>
        /// <param name="sender">El objeto que envio el evento.</param>
        /// <param name="args">Los argumentos del evento.</param>
        private void OnProcessingStepDone(object sender,
                                          StepDoneArgs args)
        {
            MessageLogSentInvoker(args.Message);

            SuspendByStep();
        }
        /// <summary>
        /// Creates a <see cref="TristateCheckVector"/> instance for a given
        /// <c>FloatBitmap</c> object.
        /// </summary>
        /// <param name="image">
        /// A <see cref="FloatBitmap"/> for which the vector is created.
        /// </param>
        /// <returns>
        /// The <see cref="TristateCheckVector"/> for the image.
        /// </returns>
        private TristateCheckVector CreateVector(FloatBitmap image)
        {
            // We create the receptors list.
            if (receptors == null)
            {
                receptors = Receptor.GenerateList(40);
            }

            TristateCheckVector vector = new TristateCheckVector();

            TristateValue checkValue;

            foreach (Receptor receptor in receptors)
            {
                checkValue =
                    receptor.CheckBressard(image)?
                    TristateValue.True:TristateValue.False;

                vector.Values.Add(checkValue);
                StepDoneArgs args =
                    new StepDoneArgs(String.Format("Comprobando receptor {0}: {1}",
                                                   String.Format("({0}, {1}) -> ({2}, {3})",
                                                                 receptor.X0, receptor.Y0,
                                                                 receptor.X1, receptor.Y1),
                                                   checkValue));

                StepDoneInvoker(args);
                Thread.Sleep(20);
            }

            foreach (BinaryCharacteristic characteristic in characteristics)
            {
                checkValue =
                    characteristic.Apply(image)?
                    TristateValue.True
                                                : TristateValue.False;

                vector.Values.Add(checkValue);

                StepDoneArgs args =
                    new StepDoneArgs(String.Format("Comprobando característica {0}: {1}",
                                                   characteristic.GetType().ToString(),
                                                   checkValue));

                StepDoneInvoker(args);
                Thread.Sleep(20);
            }

            return(vector);
        }
Esempio n. 3
0
        /// <summary>
        /// Con este metodos almacenamos un nuevo simbolo en la base de
        /// datos.
        ///
        /// Lanza <c>DuplicateSymbolException</c> si ya existe un simbolo
        /// con la misma etiqueta y caracteristicas binarias en la base de datos.
        /// </summary>
        /// <param name="bitmap">
        /// La imagen cuyas caracteristicas aprenderemos.
        /// </param>
        /// <param name="symbol">
        /// El simbolo que representa a la imagen.
        ///</param>
        public override bool Learn(MathTextBitmap bitmap, MathSymbol symbol)
        {
            if (characteristics == null)
            {
                characteristics = CharacteristicFactory.CreateCharacteristicList();
            }

            CharacteristicNode node = rootNode;
            bool characteristicValue;

            FloatBitmap processedBitmap = bitmap.LastProcessedImage;

            // Recorremos las caracteristicas, y vamos creando el arbol segun
            // vamos necesitando nodos.
            foreach (BinaryCharacteristic bc in characteristics)
            {
                if (characteristicValue = bc.Apply(processedBitmap))
                {
                    if (node.TrueTree == null)
                    {
                        node.TrueTree = new CharacteristicNode();
                    }

                    node = node.TrueTree;
                }
                else
                {
                    if (node.FalseTree == null)
                    {
                        node.FalseTree = new CharacteristicNode();
                    }
                    node = node.FalseTree;
                }

                StepDoneArgs a =
                    CreateStepDoneArgs(bc, characteristicValue, null);

                this.StepDoneInvoker(a);
            }

            return(node.AddSymbol(symbol));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a <c>CharacteristicVector</c> instance for a given
        /// <c>FloatBitmap</c> object.
        /// </summary>
        /// <param name="image">
        /// A <see cref="FloatBitmap"/>
        /// </param>
        /// <returns>
        /// A <see cref="CharacteristicVector"/>
        /// </returns>
        private CheckVector CreateVector(FloatBitmap image)
        {
            CheckVector vector = new CheckVector();
            bool        characteristicValue;

            foreach (BinaryCharacteristic bc in characteristics)
            {
                characteristicValue = bc.Apply(image);

                vector.Values.Add(characteristicValue);

                StepDoneArgs args =
                    new StepDoneArgs(String.Format("Comprobando {0}: {1}",
                                                   bc.GetType(),
                                                   characteristicValue));

                StepDoneInvoker(args);
            }

            return(vector);
        }
        /// <summary>
        /// Metodo que maneja el evento provocado al completarse un paso
        /// del proceso durante el aprendizaje.
        /// </summary>
        /// <param name="sender">
        /// A <see cref="System.Object"/>
        /// </param>
        /// <param name="arg">
        /// A <see cref="ProcessingStepDoneArgs"/>
        /// </param>
        private void OnLearningStepDone(object sender, StepDoneArgs args)
        {
            Application.Invoke(sender,
                               args,
                               delegate(object resender, EventArgs a)
            {
                if (stepByStep)
                {
                    nextButtonsHB.Sensitive = true;
                    btnNext.IsFocus         = true;
                }

                StepDoneArgs arg  = (StepDoneArgs)a;
                btnNext.Sensitive = true;
                LogLine(arg.Message);
            });

            if (stepByStep)
            {
                learningThread.Suspend();
            }
        }
		/// <summary>
		/// Creates a <c>CharacteristicVector</c> instance for a given
		/// <c>FloatBitmap</c> object.
		/// </summary>
		/// <param name="image">
		/// A <see cref="FloatBitmap"/>
		/// </param>
		/// <returns>
		/// A <see cref="CharacteristicVector"/>
		/// </returns>
		private CheckVector CreateVector(FloatBitmap image)
		{
			CheckVector vector = new CheckVector();
			bool characteristicValue;
			
			foreach(BinaryCharacteristic bc in characteristics)
			{
				characteristicValue = bc.Apply(image);
				
				vector.Values.Add(characteristicValue);
				
				StepDoneArgs args = 
					new StepDoneArgs(String.Format("Comprobando {0}: {1}", 
					                               bc.GetType(), 
					                               characteristicValue));
				
				StepDoneInvoker(args);
			}
			
			return vector;
		}