Exemple #1
0
        public void PatternTest2()
        {
            PatDict = new PatternDictionary <char, int>('X', '*')
            {
                { "*", 1 },
                { "A*", 2 },
                { "AB*", 3 },
                { "AC*", 4 },
                { "aksjdf;oiajdfkjas*", 5 },
                { "", 6 }
            };

            var finds = PatDict.Collect("A");

            Assert.AreEqual(2, finds.Count);
            Assert.IsTrue(finds.Contains(1));
            Assert.IsTrue(finds.Contains(2));

            finds = PatDict.Collect("AB");
            Assert.AreEqual(3, finds.Count);
            Assert.IsTrue(finds.Contains(1));
            Assert.IsTrue(finds.Contains(2));
            Assert.IsTrue(finds.Contains(3));

            finds = PatDict.Collect("aksjdf;oiajdfkjas");
            Assert.AreEqual(2, finds.Count);
            Assert.IsTrue(finds.Contains(1));
            Assert.IsTrue(finds.Contains(5));

            finds = PatDict.Collect("aksjdf;oiajdfkjas_hey!!!!");
            Assert.AreEqual(2, finds.Count);
            Assert.IsTrue(finds.Contains(1));
            Assert.IsTrue(finds.Contains(5));
        }
Exemple #2
0
        void TeachBtnClick(object sender, EventArgs e)
        {
            string sizeStr         = teachingSetSizeTextBox.Text;
            int    teachingSetSize = 100;

            try
            {
                teachingSetSize = Convert.ToInt32(sizeStr);
                if (teachingSetSize <= 0)
                {
                    throw new FormatException();
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Teaching set size should be a positive integer", "Wrong Teaching Set Size");
                return;
            }
            oneLayerNetwork.SetRandomWeights();
            IList <NetworkTeachingPair> teachingSet = PatternDictionary.GetInstance().GenerateTeachingSetOfSize(teachingSetSize);

            oneLayerNetwork.Teach(teachingSet, Commons.TEACHING_RATIO);
            errorProbabilityTextBox.Text = oneLayerNetwork.CalculateErrorProbability(teachingSet).ToString();
            //oneLayerNetwork.TeachContinuously(teachingSet, Commons.TEACHING_RATIO);
            MessageBox.Show("Taught successfully.", "Neural Network Training Completed");
        }
Exemple #3
0
 private static void SetCustomSettings()
 {
     PatternDictionary.SetOutputSize(PatternRecognitionCommons.ONE_LAYER_NETWORK_DIM);
     TeachingUtils.LoadPatternDictionaryFromFile(PatternRecognitionCommons.DICTIONARY_FILE_NAME);
     XmlConfigurator.Configure();
     SetLocaleSettings();
 }
Exemple #4
0
        private void LoadSavedPatterns()
        {
            ICollection <string> keys = PatternDictionary.GetInstance().Entries.Keys;

            foreach (string key in keys)
            {
                patternListBox.Items.Add(key);
            }
        }
Exemple #5
0
 /// <summary>
 /// Construct a new instance for reply handling.
 /// </summary>
 /// <param name="sender">The function to send messages with.</param>
 /// <param name="handle">The handle to receive messages with.</param>
 /// <param name="genericInstance">An instance of the type
 /// <typeparamref name="TContent"/> that will pattern match a single
 /// item of the same type.</param>
 /// <param name="genericSeries">An instance of the type
 /// <typeparamref name="TContent"/> that will pattern match a series of
 /// items of the same type.</param>
 public BlockingReplyHandling(SendMessageDelegate <IEnumerable <TContent> > sender,
                              ref Action <IEnumerable <TContent> > handle,
                              TContent genericInstance, TContent genericSeries)
 {
     Patterns    = new PatternDictionary <TContent, TaskCompletionSource <IEnumerable <TContent> > >(genericInstance, genericSeries);
     this.handle = handle;
     this.sender = sender;
     handle     += OnReceived;
 }
Exemple #6
0
        /// <summary>
        /// Construct a new instance for reply handling.
        /// </summary>
        /// <param name="sender">The function to send messages with.</param>
        /// <param name="handle">The handle to receive messages with.</param>
        /// <param name="genericInstance">An instance of the type
        /// <typeparamref name="TContent"/> that will pattern match a single
        /// item of the same type.</param>
        /// <param name="genericSeries">An instance of the type
        /// <typeparamref name="TContent"/> that will pattern match a series of
        /// items of the same type.</param>
        public AsyncReplyHandling(SendMessageDelegate <IEnumerable <TContent> > sender,
                                  ref EventHandler <MessageReceivedArgs <IEnumerable <TContent> > > handle,
                                  TContent genericInstance, TContent genericSeries)
        {
            Patterns = new PatternDictionary <TContent, TaskCompletionSource <IEnumerable <TContent> > >(genericInstance, genericSeries);

            this.sender = sender;
            handle     += OnReceived;
        }
Exemple #7
0
        public void PatternTest0()
        {
            PatDict = new PatternDictionary <char, int>('X', '*')
            {
                { "hey", 0 }
            };
            var finds = PatDict.Collect("hey");

            Assert.AreEqual(1, finds.Count);
        }
Exemple #8
0
        void ShowBtnClick(object sender, EventArgs e)
        {
            object selectedItem = patternsComboBox.SelectedItem;

            if (selectedItem != null && selectedItem.ToString().Trim().Length != 0)
            {
                string patternName           = selectedItem.ToString();
                NetworkTeachingPair dictPair = PatternDictionary.GetInstance().GetTeachingPairForPattern(patternName);
                patternInput.LoadPattern(dictPair.Input);
            }
        }
Exemple #9
0
        void PatternListBoxSelectedIndexChanged(object sender, EventArgs e)
        {
            object selectedItem = patternListBox.SelectedItem;

            if (selectedItem != null)
            {
                string   patternName = selectedItem.ToString();
                double[] pattern     = PatternDictionary.GetInstance().GetTeachingPairForPattern(patternName).Input;
                patternInputLabelTable.LoadPattern(pattern);
                patternNameTextBox.Text = patternName;
            }
        }
Exemple #10
0
        void CorrectBtnClick(object sender, EventArgs e)
        {
            object selectedItem = patternsComboBox.SelectedItem;

            if (selectedItem != null && selectedItem.ToString().Trim().Length != 0)
            {
                string patternName                 = selectedItem.ToString();
                NetworkTeachingPair dictPair       = PatternDictionary.GetInstance().GetTeachingPairForPattern(patternName);
                double[]            currentPattern = patternInput.GetNetworkInput();
                oneLayerNetwork.Teach(new NetworkTeachingPair(currentPattern, dictPair.Output), Commons.TEACHING_RATIO);
                MessageBox.Show("Taught successfully.", "Correction Completed");
            }
        }
Exemple #11
0
        void RecognizeBtnClick(object sender, EventArgs e)
        {
            PatternDictionary dict = PatternDictionary.GetInstance();

            double[] input       = patternInput.GetNetworkInput();
            double[] output      = oneLayerNetwork.FireSignal(input);
            string   patternName = dict.FindPatternName(output);

            recognizedByOneLayerTextBox.Text = patternName != null ? patternName : "Not recognized properly";
            output      = twoLayerNetwork.FireSignal(input);
            patternName = dict.FindPatternName(output);
            recognizedByTwoLayerTextBox.Text = patternName != null ? patternName : "Not recognized properly";
        }
Exemple #12
0
        public void PatternTest3()
        {
            PatDict = new PatternDictionary <char, int>('X', '*')
            {
                { "*", 1 },
                { "*A", 2 },
                { "A*", 3 }
            };
            var finds = PatDict.Collect("A");

            Assert.AreEqual(3, finds.Count);
            Assert.IsTrue(finds.Contains(1) && finds.Contains(2) && finds.Contains(3));
        }
Exemple #13
0
        /// <summary>
        /// Construct a new WhileMatching construct utilizing an existing PatternDictionary.
        /// </summary>
        /// <param name="dict">The pattern dictionary to match from.</param>
        /// <param name="toCall">The TaskCompletionSource to trigger on match.</param>
        /// <param name="patterns">The set of patterns to match.</param>
        public WhileMatching(PatternDictionary <TContent, TaskCompletionSource <IEnumerable <TContent> > > dict,
                             TaskCompletionSource <IEnumerable <TContent> > toCall,
                             params IEnumerable <TContent>[] patterns)
        {
            this.dict     = dict;
            this.patterns = patterns;
            this.toCall   = toCall;

            foreach (var p in patterns)
            {
                dict.Add(p, toCall);
            }
        }
Exemple #14
0
        /// <summary>
        /// Construct a new WhileMatching construct with pattern recognition particular
        /// to the defined <paramref name="genericPiece"/> and
        /// <paramref name="genericSeries"/>.
        /// </summary>
        /// <param name="genericPiece">Defines a generic piece in the patterns.</param>
        /// <param name="genericSeries">Defines a generic series in the patterns.</param>
        /// <param name="toCall">The TaskCompletionSource to trigger on call.</param>
        /// <param name="patterns">The set of patterns to match.</param>
        public WhileMatching(TContent genericPiece,
                             TContent genericSeries,
                             TaskCompletionSource <IEnumerable <TContent> > toCall,
                             params IEnumerable <TContent>[] patterns)
        {
            dict          = new PatternDictionary <TContent, TaskCompletionSource <IEnumerable <TContent> > >(genericPiece, genericSeries);
            this.patterns = patterns;
            this.toCall   = toCall;

            foreach (var p in patterns)
            {
                dict.Add(p, toCall);
            }
        }
Exemple #15
0
        public void PatternTest4()
        {
            PatDict = new PatternDictionary <char, int>('X', '*')
            {
                { "*X*X*", 1 }
            };

            var finds = PatDict.Collect("A");

            Assert.AreEqual(0, finds.Count);

            var finds2 = PatDict.Collect("AA");

            Assert.AreEqual(1, finds2.Count);
            Assert.IsTrue(finds2.Contains(1));
        }
Exemple #16
0
        public void PatternTest7()
        {
            PatDict = new PatternDictionary <char, int>('X', '*')
            {
                { "A*A*X*", 1 }
            };

            var finds = PatDict.Collect("AAB");

            Assert.AreEqual(1, finds.Count);
            Assert.IsTrue(finds.Contains(1));

            finds = PatDict.Collect("AAAAAAACCCCCAAAABBBB");
            Assert.AreEqual(1, finds.Count);
            Assert.IsTrue(finds.Contains(1));
        }
Exemple #17
0
        public void PatternTest1()
        {
            PatDict = new PatternDictionary <char, int>('X', '*')
            {
                { "", 0 },
                { "0X 12 23 34", 1 },
                { "01 12 2X 34", 2 },
                { "XX XX XX XX", 3 }
            };

            var finds = PatDict.Collect("01 12 23 34");

            Assert.AreEqual(3, finds.Count);
            Assert.IsTrue(finds.Contains(1));
            Assert.IsTrue(finds.Contains(2));
            Assert.IsTrue(finds.Contains(3));

            finds = PatDict.Collect("FF FF FF FF");
            Assert.AreEqual(1, finds.Count);
            Assert.IsTrue(finds.Contains(3));
        }
Exemple #18
0
        void RemovePatternBtnClick(object sender, EventArgs e)
        {
            object selectedItem = patternListBox.SelectedItem;

            if (selectedItem != null)
            {
                string       patternName  = selectedItem.ToString();
                DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove the selected pattern?", "Remove Pattern", MessageBoxButtons.YesNoCancel);
                switch (dialogResult)
                {
                case DialogResult.Yes:
                    PatternDictionary.GetInstance().RemovePattern(patternName);
                    patternListBox.Items.Remove(patternName);
                    patternInputLabelTable.Clear();
                    break;

                default: return;
                }
            }
            else
            {
                MessageBox.Show("Please select pattern to remove first.", "Remove Pattern");
            }
        }
Exemple #19
0
        void PutPatternBtnClick(object sender, EventArgs e)
        {
            string patternName = patternNameTextBox.Text;

            if (patternName == null || patternName.Trim(' ').Length == 0)
            {
                MessageBox.Show("Pattern name is empty. Please fill the field.", "Can't add pattern");
            }
            else
            {
                double[] input = patternInputLabelTable.GetNetworkInput();
                PatternDictionary.GetInstance().PutPattern(patternName, input);
                if (log.IsDebugEnabled)
                {
                    log.Debug(input.GetContentsString());
                }
                if (!patternListBox.Items.Contains(patternName))
                {
                    patternListBox.Items.Add(patternName);
                }
            }
            patternNameTextBox.Text = "";
            patternInputLabelTable.SetColor(Commons.BACK_COLOR);
        }
Exemple #20
0
 private void FillPatternComboBox()
 {
     patternsComboBox.Items.Clear();
     patternsComboBox.Items.AddRange(PatternDictionary.GetInstance().Entries.Keys.ToArray());
 }