Exemple #1
0
        private void AddSynapses()
        {
            Init();
            ClearNeurons(false);
            mv.GetNeuronAt(0, 0).Label = "Rd";
            mv.GetNeuronAt(1, 0).Label = "Clr";
            mv.GetNeuronAt(0, 0).AddSynapse(mv.GetNeuronAt(1, 0).id, 1);


            for (int i = 1; i < mv.Height; i++)
            {
                Neuron n0 = mv.GetNeuronAt(0, i);
                n0.Label = "I" + (i - 1).ToString();
                Neuron n1 = mv.GetNeuronAt(1, i);
                Neuron n2 = mv.GetNeuronAt(2, i);
                n2.Label    = "O" + (i - 1).ToString();
                n2.Model    = Neuron.modelType.LIF;
                n2.LeakRate = 0.9f;

                GetNeuron("Rd").AddSynapse(n1.id, 0.9f);
                GetNeuron("Clr").AddSynapse(n1.id, -1);
                GetNeuron("Clr").AddSynapse(n2.id, 0.5f);

                n0.AddSynapse(n1.id, 0.9f);
                n1.AddSynapse(n0.id, 1);
                n1.AddSynapse(n2.id, 0.5f);
            }
        }
        private void SetUpNeurons(int levelCount)
        {
            Neuron nIn = na.GetNeuronAt(1, 0);

            nIn.Label = "In";
            Neuron nRd = na.GetNeuronAt(0, 0);

            nRd.Label = "Rd";
            Neuron nClr = na.GetNeuronAt(2, 0);

            nClr.Label = "Clr";

            nRd.AddSynapse(nClr.id, 1);
            Neuron nLast = na.GetNeuronAt(0, na.Height - 1);


            for (int i = 0; i < levelCount; i++)
            {
                Neuron ni = na.GetNeuronAt(0, i + 1);
                ni.Clear();
                Neuron nm = na.GetNeuronAt(1, i + 1);
                ni.Clear();
                Neuron no = na.GetNeuronAt(2, i + 1);
                no.Clear();
            }

            for (int i = 0; i < levelCount; i++)
            {
                Neuron ni = na.GetNeuronAt(0, i + 1);
                ni.Model    = Neuron.modelType.LIF;
                ni.LeakRate = theLeakRate;
                Neuron nm = na.GetNeuronAt(1, i + 1);
                Neuron no = na.GetNeuronAt(2, i + 1);
                no.Label = "O" + i;

                ni.AddSynapse(nm.id, 1);
                nm.AddSynapse(no.id, 0.9f);
                no.AddSynapse(nm.id, 1);

                nClr.AddSynapse(no.id, -1f);
                nRd.AddSynapse(no.id, 0.9f);
                nLast.AddSynapse(no.id, -1f);

                float weight = GetWeight(4 + i);
                weight += .001f; //differentiates between < and =
                nIn.AddSynapse(ni.id, weight);

                for (int j = i + 1; j < levelCount; j++)
                {
                    ni.AddSynapse(na.GetNeuronAt(1, j + 1).id, -1f);
                }
                for (int j = 0; j < levelCount; j++)
                {
                    if (j != i)
                    {
                        ni.AddSynapse(na.GetNeuronAt(0, j + 1).id, -1f);
                    }
                }
            }
        }
        public override void Initialize()
        {
            pending.Clear();
            na.GetNeuronAt(0, 0).Label  = "Stop";
            na.GetNeuronAt(1, 0).Label  = "Done";
            na.GetNeuronAt(2, 0).Label  = "TurnTo";
            na.GetNeuronAt(3, 0).Model  = Neuron.modelType.FloatValue;
            na.GetNeuronAt(3, 0).Label  = "Theta";
            na.GetNeuronAt(4, 0).Label  = "MoveTo";
            na.GetNeuronAt(5, 0).Model  = Neuron.modelType.FloatValue;
            na.GetNeuronAt(5, 0).Label  = "R";
            na.GetNeuronAt(6, 0).Label  = "Scan";
            na.GetNeuronAt(9, 0).Label  = "Coll";
            na.GetNeuronAt(10, 0).Label = "CollAngle";
            na.GetNeuronAt(10, 0).Model = Neuron.modelType.FloatValue;

            //Connect Neurons to the UKS
            Neuron nUKSDone = GetNeuron("Module2DUKS", "Done");

            if (nUKSDone != null)
            {
                na.GetNeuronAt("Done").AddSynapse(nUKSDone.Id, 1);
            }
            Neuron nUKSStop = GetNeuron("UKSOut", "Stop");

            if (nUKSStop != null)
            {
                nUKSStop.AddSynapse(na.GetNeuronAt("Stop").Id, 1);
            }
        }
Exemple #4
0
        public void Neuron_RemoveSynapse_AllConnectionsRemoved_ValuesCorrect()
        {
            var inputNeuron  = new Neuron(null, 1);
            var outputNeuron = new Neuron(ActivationFunctions.LineairTruncated, 0);

            inputNeuron.AddSynapse(outputNeuron, 1);

            Assert.IsEmpty(inputNeuron.InputSynapses);
            Assert.AreEqual(1, inputNeuron.OutputSynapses.Count());
            Assert.AreEqual(1, outputNeuron.InputSynapses.Count());
            Assert.IsEmpty(outputNeuron.OutputSynapses);

            inputNeuron.SetValue(1);
            Assert.AreEqual(new Scalar(1), outputNeuron.GetValue());

            inputNeuron.RemoveSynapse(outputNeuron);

            Assert.IsEmpty(inputNeuron.InputSynapses);
            Assert.IsEmpty(inputNeuron.OutputSynapses);
            Assert.IsEmpty(outputNeuron.InputSynapses);
            Assert.IsEmpty(outputNeuron.OutputSynapses);

            Assert.AreEqual(new Scalar(0), outputNeuron.GetValue());
            Assert.AreEqual(new Scalar(1), inputNeuron.GetValue());
        }
        //fill this method in with code which will execute once
        //when the module is added, when "initialize" is selected from the context menu,
        //or when the engine restart button is pressed
        public override void Initialize()
        {
            na.BeginEnum();
            for (Neuron n = na.GetNextNeuron(); n != null; n = na.GetNextNeuron())
            {
                n.Label = "";
                n.DeleteAllSynapes();
            }

            Neuron n1 = na.GetNeuronAt(0);

            n1.Label = "good";
            Neuron n1Target = GetNeuron("Module2DUKS", "Positive");

            if (n1Target != null)
            {
                n1.AddSynapse(n1Target.Id, 1);
            }
            Neuron n2 = na.GetNeuronAt(1);

            n2.Label = "no";
            Neuron n2Target = GetNeuron("Module2DUKS", "Negative");

            if (n2Target != null)
            {
                n2.AddSynapse(n2Target.Id, 1);
            }
        }
Exemple #6
0
        private void AddSynapse(string word, string nextWord)
        {
            word     = TrimPunctuation(word);
            nextWord = TrimPunctuation(nextWord);
            wordDictionary.TryGetValue(word, out int wordNeuronID);
            if (wordNeuronID == 0) // if there is no neuron for the word, add one
            {
                wordDictionary.Add(word, nextFreeNeuron);
                wordNeuronID = nextFreeNeuron++;
                na.GetNeuronAt(wordNeuronID).Label = word; //useful someday
            }
            wordDictionary.TryGetValue(nextWord, out int nextWordNeuronID);
            if (nextWordNeuronID == 0) // if there is no neuron for the word, add one
            {
                wordDictionary.Add(nextWord, nextFreeNeuron);
                nextWordNeuronID = nextFreeNeuron++;
                na.GetNeuronAt(nextWordNeuronID).Label = nextWord; //useful someday
            }
            Neuron  n      = na.GetNeuronAt(wordNeuronID);
            Neuron  nNext  = na.GetNeuronAt(nextWordNeuronID);
            Synapse s      = n.FindSynapse(nNext.id);
            float   weight = .1f;

            if (s != null)
            {
                weight += .1f;
            }
            n.AddSynapse(nNext.id, weight);
        }
Exemple #7
0
        //fill this method in with code which will execute once
        //when the module is added, when "initialize" is selected from the context menu,
        //or when the engine restart button is pressed
        public override void Initialize()
        {
            foreach (Neuron n in mv.Neurons)
            {
                n.Label = "";
                n.DeleteAllSynapes();
            }

            Neuron n1 = mv.GetNeuronAt(0);

            n1.Label = "good";
            Neuron n1Target = GetNeuron("Module2DUKS", "Positive");

            if (n1Target != null)
            {
                n1.AddSynapse(n1Target.Id, 1);
            }
            Neuron n2 = mv.GetNeuronAt(1);

            n2.Label = "no";
            Neuron n2Target = GetNeuron("Module2DUKS", "Negative");

            if (n2Target != null)
            {
                n2.AddSynapse(n2Target.Id, 1);
            }
        }
Exemple #8
0
        //fill this method in with code which will execute once
        //when the module is added, when "initialize" is selected from the context menu,
        //or when the engine restart button is pressed
        public override void Initialize()
        {
            AddLabel("Enable");
            Neuron n = AddLabel("Patterns");

            n.AddSynapse(n.id, 1);
            AddLabel("Output");
        }
Exemple #9
0
 void AddSynapse(Neuron source, Neuron dest, float weight)
 {
     if (source == null || dest == null)
     {
         return;
     }
     source.AddSynapse(dest.id, weight);
 }
Exemple #10
0
        //Fill this method in with code which will execute once
        //when the module is added, when "initialize" is selected from the context menu,
        //or when the engine restart button is pressed
        public override void Initialize()
        {
            Neuron n = na.GetNeuronAt(0, 0);

            n.Label = "FirstNeuron";
            Neuron n1 = na.GetNeuronAt(0, 1);

            n.AddSynapse(n1.Id, 0.5f);
        }
Exemple #11
0
        private void _createNode()
        {
            var newNode = new Neuron <TFunc>();

            _network.OutputLayer.Nodes.Add(newNode);
            foreach (INode inputNode in _network.InputLayer.Nodes)
            {
                newNode.AddSynapse(new Synapse(inputNode, inputNode.Output()));
            }
        }
Exemple #12
0
        public void Neuron_SetValue_GetValueWithNextNeuron(double value)
        {
            var inputNeuron  = new Neuron(null, 1);
            var outputNeuron = new Neuron(ActivationFunctions.LineairTruncated, 0);

            inputNeuron.AddSynapse(outputNeuron, 1);

            inputNeuron.SetValue(value);
            Assert.AreEqual(new Scalar(value), outputNeuron.GetValue());
        }
Exemple #13
0
        void AddSynapse(string source, int sourceRow, string dest, int destRow, float weight)
        {
            Neuron n1 = na.GetNeuronAt(Array.IndexOf(cols, source), sourceRow);
            Neuron n2 = na.GetNeuronAt(Array.IndexOf(cols, dest), destRow);

            if (n1 != null && n2 != null)
            {
                n1.AddSynapse(n2.Id, weight);
            }
        }
Exemple #14
0
        public double Neuron_SetValue_GetValueWithNextNeuron_WithPositiveBias(double value)
        {
            const double BIAS = 0.5;

            var inputNeuron  = new Neuron(null, 1);
            var outputNeuron = new Neuron(ActivationFunctions.LineairTruncated, BIAS);

            inputNeuron.AddSynapse(outputNeuron, 1);

            inputNeuron.SetValue(value);
            return(outputNeuron.GetValue());
        }
Exemple #15
0
        public void Neuron_SetValue_GetValueWithNextNeuron_WithWeightedSynapse(double value)
        {
            const double SYNAPSE_WEIGHT = 0.5;

            var inputNeuron  = new Neuron(null, 1);
            var outputNeuron = new Neuron(ActivationFunctions.LineairTruncated, 0);

            inputNeuron.AddSynapse(outputNeuron, SYNAPSE_WEIGHT);

            inputNeuron.SetValue(value);
            Assert.AreEqual(new Scalar(value * SYNAPSE_WEIGHT), outputNeuron.GetValue());
        }
Exemple #16
0
        public override void Fire()
        {
            Init();  //be sure to leave this here
            if (words.Count > 0)
            {
                string word = words[0];
                na.BeginEnum();
                for (Neuron n = na.GetNextNeuron(); n != null; n = na.GetNextNeuron())
                {
                    if (n.Label == word)
                    {
                        n.SetValue(1);
//                        n.CurrentCharge = 1;
                        break;
                    }
                    else if (n.Label == "")
                    {
                        //the word has not been heard before, add it
                        n.Label         = word;
                        n.CurrentCharge = 1;
                        //connection to UKS
                        ModuleUKSN nmUKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN));
                        if (nmUKS != null)
                        {
                            List <Thing> words = nmUKS.Labeled("Word").Children;
                            Thing        w     = nmUKS.Valued(word, words);
                            if (w == null)
                            {
                                string label = "w" + char.ToUpper(word[0]) + word.Substring(1);
                                w = nmUKS.AddThing(label, new Thing[] { nmUKS.Labeled("Word") }, word);
                            }
                            Neuron n1 = nmUKS.GetNeuron(w);
                            if (n1 != null)
                            {
                                n.AddSynapse(n1.Id, 1);
                            }
                            //TODO: add a synapse to the speakwords module as well
                        }
                        break;
                    }
                }
                words.RemoveAt(0);
            }
        }
Exemple #17
0
        //fill this method in with code which will execute once
        //when the module is added, when "initialize" is selected from the context menu,
        //or when the engine restart button is pressed
        public override void Initialize()
        {
            if (mv == null)
            {
                return;
            }
            for (int i = 1; i < mv.Height; i++)
            {
                for (int j = 0; j < mv.Width; j++)
                {
                    mv.GetNeuronAt(j, i).Model = Neuron.modelType.Color;
                }
            }
            Neuron n1 = mv.GetNeuronAt(0, 0);

            n1.Model = Neuron.modelType.IF;
            n1.Label = "Enable";
            n1.AddSynapse(n1.id, 1);
            n1.SetValue(1);

            n1       = mv.GetNeuronAt(1, 0);
            n1.Model = Neuron.modelType.FloatValue;
            n1.Label = "X";
            n1.SetValue(0);

            n1       = mv.GetNeuronAt(2, 0);
            n1.Model = Neuron.modelType.FloatValue;
            n1.Label = "Y";
            n1.SetValue(0);

            n1       = mv.GetNeuronAt(3, 0);
            n1.Model = Neuron.modelType.FloatValue;
            n1.Label = "Scale";
            n1.SetValue(0);

            n1       = mv.GetNeuronAt(4, 0);
            n1.Model = Neuron.modelType.FloatValue;
            n1.Label = "Rot";
            n1.SetValue(0);
        }
Exemple #18
0
        private void SetUpNeurons(int levelCount)
        {
            Neuron nRd = mv.GetNeuronAt(0, 0);

            nRd.Label = "Rd";
            Neuron nIn = mv.GetNeuronAt(1, 0);

            nIn.Label = "In";
            Neuron nIn1 = mv.GetNeuronAt(2, 0);

            nIn1.Label = "In1";
            Neuron nClr = mv.GetNeuronAt(3, 0);

            nClr.Label = "Clr";

            nRd.AddSynapse(nClr.id, 1);
            nIn.AddSynapse(nIn1.id, 1);

            for (int i = 0; i < levelCount; i++)
            {
                Neuron ni = mv.GetNeuronAt(0, i + 1);
                ni.Clear();
                Neuron ni1 = mv.GetNeuronAt(1, i + 1);
                ni1.Clear();
                Neuron nm = mv.GetNeuronAt(2, i + 1);
                ni.Clear();
                Neuron no = mv.GetNeuronAt(3, i + 1);
                no.Clear();
                no.model    = Neuron.modelType.LIF;
                no.LeakRate = 0.13f;
                Neuron noP = mv.GetNeuronAt(4, i + 1);
                noP.Clear();
                Neuron noN = mv.GetNeuronAt(5, i + 1);
                noN.Clear();
            }

            Neuron nLast  = mv.GetNeuronAt(0, mv.Height - 1);
            Neuron nLast1 = mv.GetNeuronAt(1, mv.Height - 1);

            nLast.AddSynapse(nIn1.id, 0.5f);
            nLast1.AddSynapse(nIn1.id, 0.5f);

            for (int i = 0; i < levelCount; i++)
            {
                Neuron ni = mv.GetNeuronAt(0, i + 1);
                ni.Model    = Neuron.modelType.LIF;
                ni.LeakRate = theLeakRate;
                Neuron ni1 = mv.GetNeuronAt(1, i + 1);
                ni1.Model    = Neuron.modelType.LIF;
                ni1.LeakRate = theLeakRate;
                Neuron nm  = mv.GetNeuronAt(2, i + 1);
                Neuron no  = mv.GetNeuronAt(3, i + 1);
                Neuron noP = mv.GetNeuronAt(4, i + 1);
                Neuron noN = mv.GetNeuronAt(5, i + 1);
                noP.Label = "O" + i;
                noN.Label = "O-" + i;


                ni.AddSynapse(nm.id, 1);
                ni1.AddSynapse(nm.id, 1);
                nm.AddSynapse(no.id, 0.1f);
                no.AddSynapse(nm.id, 1);
                nClr.AddSynapse(noN.id, 1f);
                no.AddSynapse(noN.id, -1f);
                no.AddSynapse(noP.id, 1f);


                nClr.AddSynapse(no.id, -1f);
                nRd.AddSynapse(no.id, 0.99f);

                float weight = GetWeight(4 + i);
                weight += .001f; //differentiates between < and =
                nIn.AddSynapse(ni.id, weight);
                nIn1.AddSynapse(ni1.id, weight);

                for (int j = 0; j < levelCount; j++)
                {
                    if (j != i)
                    {
                        ni.AddSynapse(mv.GetNeuronAt(0, j + 1).id, -1f);
                        ni1.AddSynapse(mv.GetNeuronAt(1, j + 1).id, -1f);
                    }
                }
            }
        }
Exemple #19
0
        //fill this method in with code which will execute once
        //when the module is added, when "initialize" is selected from the context menu,
        //or when the engine restart button is pressed
        public override void Initialize()
        {
            ClearNeurons();
            for (int x = 0; x < mv.Width; x += 2)
            {
                for (int y = 0; y < mv.Height; y += 2)
                {
                    //three internal neurons
                    Neuron valueNeuron = mv.GetNeuronAt(x + 1, y);
                    if (valueNeuron == null)
                    {
                        continue;
                    }
                    valueNeuron.Label = "#";
                    Neuron liveNeuron = mv.GetNeuronAt(x, y);
                    if (liveNeuron == null)
                    {
                        continue;
                    }
                    liveNeuron.Label = "+";
                    Neuron dieNeuron = mv.GetNeuronAt(x, y + 1);
                    if (dieNeuron == null)
                    {
                        continue;
                    }
                    dieNeuron.Label     = "-";
                    liveNeuron.Model    = Neuron.modelType.LIF;
                    dieNeuron.Model     = Neuron.modelType.LIF;
                    liveNeuron.LeakRate = 1;
                    dieNeuron.LeakRate  = 1;
                    //three internal synapses
                    try { liveNeuron.AddSynapse(valueNeuron.Id, 1); } catch { }
                    try
                    {
                        dieNeuron.AddSynapse(valueNeuron.Id, -1);
                    }
                    catch { }
                    try
                    {
                        valueNeuron.AddSynapse(liveNeuron.Id, .4f);
                    }
                    catch { }
                    // add live & die synapses to the 8 surrounding neurons
                    // may be better to rewrite this without relying on try catch blocks.
                    // bottom row
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x + 2, y).Id, .4f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x + 2, y + 1).Id, .3f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x + 2, y + 2).Id, .4f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x + 2, y + 2 + 1).Id, .3f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x + 2, y - 2).Id, .4f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x + 2, y - 2 + 1).Id, .3f); } catch { }

                    // middle row
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x, y + 2).Id, .4f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x, y + 2 + 1).Id, .3f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x, y - 2).Id, .4f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x, y - 2 + 1).Id, .3f); } catch { }

                    // top row
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x - 2, y).Id, .4f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x - 2, y + 1).Id, .3f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x - 2, y + 2).Id, .4f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x - 2, y + 2 + 1).Id, .3f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x - 2, y - 2).Id, .4f); } catch { }
                    try { valueNeuron.AddSynapse(mv.GetNeuronAt(x - 2, y - 2 + 1).Id, .3f); } catch { }
                }
            }
        }
        public override void Fire()
        {
            Init();  //be sure to leave this here
            if (synth == null)
            {
                return;
            }

            bool paused = true;

            for (int i = 1; i < na.NeuronCount; i++)
            {
                Neuron n = na.GetNeuronAt(i);
                if (n.Fired())
                {
                    if (n.Label.Length == 1)
                    {
                        phraseToSpeak += n.Label;
                        paused         = false;
                    }
                    if (n.Synapses.Count == 0)
                    {
                        //if a neuron fired and it has no connection, connect it to the knowledge store
                        //connection to KB
                        ModuleUKSN nmKB = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN));
                        if (nmKB != null)
                        {
                            string       label    = "pn" + n.Label;
                            List <Thing> phonemes = nmKB.Labeled("Phoneme").Children;
                            Thing        pn       = nmKB.Labeled(label, phonemes);
                            if (pn == null) //this should always be null
                            {
                                pn = nmKB.AddThing(label, new Thing[] { nmKB.Labeled("Phoneme") }, pn);
                            }
                            Neuron n1 = nmKB.GetNeuron(pn);
                            if (n1 != null)
                            {
                                n.AddSynapse(n1.Id, 1);
                                n1.SetValue(1);
                            }
                        }
                    }
                }
            }
            if (phonemesToFire != "")
            {
                char c     = phonemesToFire[0];
                bool fired = false;
                for (int i = 0; i < na.NeuronCount; i++)
                {
                    Neuron n = na.GetNeuronAt(i);
                    if (n.Label == c.ToString())
                    {
                        n.SetValue(1);
                        fired = true;
                        break;
                    }
                }
                if (!fired)
                {
                    Utils.Noop();
                }
                phonemesToFire = phonemesToFire.Substring(1);
            }

            if (paused && phraseToSpeak != "")
            {
                if (dlg != null)
                {
                    ((ModuleSpeakPhonemesDlg)dlg).SetLabel(phraseToSpeak);
                }

                if (na.GetNeuronAt("Enable").Fired())
                {
                    ModuleSpeechIn msi = (ModuleSpeechIn)FindModuleByType(typeof(ModuleSpeechIn));
                    if (msi != null)
                    {
                        msi.PauseRecognition(); //if there is a recognizer active
                    }
                    //synth.SpeakAsync(phraseToSpeak + ".");
                    //phraseToSpeak = "";

                    PromptBuilder pb1 = new PromptBuilder();
                    if (typedIn)
                    {
                        pb1.StartVoice("Microsoft David Desktop");
                        pb1.StartStyle(new PromptStyle(PromptRate.Medium));
                    }
                    else
                    {
                        pb1.StartVoice("Microsoft Zira Desktop");
                        pb1.StartStyle(new PromptStyle(PromptRate.ExtraSlow));
                    }

                    pb1.AppendTextWithPronunciation("not used", phraseToSpeak);
                    pb1.EndStyle();
                    pb1.EndVoice();
                    string x = pb1.ToXml();
                    Debug.WriteLine(debugString(phraseToSpeak));
                    //synth.Speak(pb1);
                    synth.SpeakAsync(pb1);
                }
                //string heard = GetPronunciationFromText("", phraseToSpeak); //it would be nice to hear what was said but it doesn't work with this engine
                phraseToSpeak = "";
                typedIn       = false;
            }
        }
Exemple #21
0
 //fill this method in with code which will execute once
 //when the module is added, when "initialize" is selected from the context menu,
 //or when the engine restart button is pressed
 public override void Initialize()
 {
     ClearNeurons();
     for (int x = 0; x < na.Width; x += 2)
     {
         for (int y = 0; y < na.Height; y += 2)
         {
             //three internal neurons
             Neuron valueNeuron = na.GetNeuronAt(x + 1, y);
             if (valueNeuron == null)
             {
                 continue;
             }
             valueNeuron.Label = "#";
             Neuron liveNeuron = na.GetNeuronAt(x, y);
             if (liveNeuron == null)
             {
                 continue;
             }
             liveNeuron.Label = "+";
             Neuron dieNeuron = na.GetNeuronAt(x, y + 1);
             if (dieNeuron == null)
             {
                 continue;
             }
             dieNeuron.Label     = "-";
             liveNeuron.Model    = Neuron.modelType.LIF;
             dieNeuron.Model     = Neuron.modelType.LIF;
             liveNeuron.LeakRate = 1;
             dieNeuron.LeakRate  = 1;
             //three internal synapses
             try { liveNeuron.AddSynapse(valueNeuron.Id, 1); } catch { }
             try
             {
                 dieNeuron.AddSynapse(valueNeuron.Id, -1);
             }
             catch { }
             try
             {
                 valueNeuron.AddSynapse(liveNeuron.Id, .4f);
             }
             catch { }
             //add live & die synapses to the 8 surrounding neurons
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x + 2, y).Id, .4f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x + 2, y + 1).Id, .3f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x + 2, y + 2).Id, .4f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x + 2, y + 2 + 1).Id, .3f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x + 2, y - 2).Id, .4f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x + 2, y - 2 + 1).Id, .3f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x, y + 2).Id, .4f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x, y + 2 + 1).Id, .3f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x, y - 2).Id, .4f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x, y - 2 + 1).Id, .3f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x - 2, y).Id, .4f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x - 2, y + 1).Id, .3f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x - 2, y + 2).Id, .4f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x - 2, y + 2 + 1).Id, .3f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x - 2, y - 2).Id, .4f); } catch { }
             try { valueNeuron.AddSynapse(na.GetNeuronAt(x - 2, y - 2 + 1).Id, .3f); } catch { }
         }
     }
 }
Exemple #22
0
        public override void Initialize()
        {
            ClearNeurons();
            Neuron n0 = na.GetNeuronAt(1, 1);

            n0.Label = "'1'";
            n0.AddSynapse(n0.Id, 1, Synapse.modelType.Fixed);
            n0.SetValue(1);
            na.GetNeuronAt(0, 1).Label = "clr";
            for (int i = 0; i < cols.Length; i++)
            {
                Neuron n = na.GetNeuronAt(i, 0);
                n.Label = cols[i];
            }
            //put in the vertical synapses for the columns which need them
            for (int i = 0; i < cols.Length; i++)
            {
                if (cols[i] == "this" || cols[i] == "this" ||
                    cols[i] == "attrib" || cols[i] == "parent" ||
                    cols[i] == "child" || cols[i] == "next" || cols[i] == "nMtch" || cols[i] == "head" ||
                    cols[i] == "anyAttr" || cols[i] == "allAttr" ||
                    cols[i] == "recur" || cols[i] == "head" ||
                    cols[i] == "match" ||
                    cols[i] == "say")
                {
                    Neuron n  = na.GetNeuronAt(i, 0);
                    Neuron n1 = na.GetNeuronAt(i, 1);
                    n.AddSynapse(n1.Id, -1, Synapse.modelType.Fixed);
                    n0.AddSynapse(n1.Id, 1, Synapse.modelType.Fixed);
                    for (int j = 2; j < na.Height; j++)
                    {
                        n1.AddSynapse(na.GetNeuronAt(i, j).Id, -1, Synapse.modelType.Fixed);
                    }
                }
            }
            //make the clr neuron clear all the input neurons
            Neuron nClr = na.GetNeuronAt("clr");

            for (int j = 2; j < na.Height; j++)
            {
                nClr.AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "in"), j).Id, -1, Synapse.modelType.Fixed);
            }
            na.GetNeuronAt("recur").AddSynapse(nClr.Id, 1, Synapse.modelType.Fixed);

            //put in all the horizontal synapses
            for (int j = 2; j < na.Height; j++)
            {
                na.GetNeuronAt(Array.IndexOf(cols, "in"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "in"), j).Id, 1, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "in"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "thing"), j).Id, 10, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "thing"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "theNeuronArray"), j).Id, 1, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "thing"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "attrib"), j).Id, 1, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "thing"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "anyAttr"), j).Id, 1, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "thing"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "allAttr"), j).Id, 1, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "thing"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "parent"), j).Id, 1, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "thing"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "child"), j).Id, 1, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "thing"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "next"), j).Id, 1, Synapse.modelType.Fixed);


                na.GetNeuronAt(Array.IndexOf(cols, "theNeuronArray"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "out"), j).Id, 1, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "alt"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "out"), j).Id, 1, Synapse.modelType.Fixed);
                //na.GetNeuronAt(Array.IndexOf(cols, "out"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "in"), j).Id, -1, false);
                na.GetNeuronAt(Array.IndexOf(cols, "out"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "recur"), j).Id, 1, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "recur"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "in"), j).Id, 2, Synapse.modelType.Fixed); //2 because the out is suppressing
                na.GetNeuronAt(Array.IndexOf(cols, "match"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "thing"), j).Id, 1, Synapse.modelType.Fixed);



                na.GetNeuronAt(Array.IndexOf(cols, "out"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "say"), j).Id, 1, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "out"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "0"), j).Id, 1, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "0"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "say"), j).Id, -1, Synapse.modelType.Fixed);

                na.GetNeuronAt(Array.IndexOf(cols, "next"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "in"), j).Id, -1, Synapse.modelType.Fixed);
                na.GetNeuronAt(Array.IndexOf(cols, "next"), j).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "thing"), j).Id, -30, Synapse.modelType.Fixed);
            }
            //make som coluimns into an always-fire
            na.GetNeuronAt(Array.IndexOf(cols, "next"), 0).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "next"), 0).Id, 1, Synapse.modelType.Fixed);
            na.GetNeuronAt(Array.IndexOf(cols, "say"), 0).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "say"), 0).Id, 1, Synapse.modelType.Fixed);
            na.GetNeuronAt(Array.IndexOf(cols, "attrib"), 0).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "attrib"), 0).Id, 1, Synapse.modelType.Fixed);
            na.GetNeuronAt(Array.IndexOf(cols, "match"), 0).AddSynapse(na.GetNeuronAt(Array.IndexOf(cols, "match"), 0).Id, 1, Synapse.modelType.Fixed);

            //na.GetNeuronAt(0, 2).Label = "Attribute";
            //na.GetNeuronAt(0, 3).Label = "Thing";
            //na.GetNeuronAt(0, 4).Label = "Sequence";
            //na.GetNeuronAt("say").SetValue(1);
            //if (naOut != null)
            //{
            //    na.GetNeuronAt(Array.IndexOf(cols, "say"), 2).AddSynapse(GetSpokenWord("Attribute").Id, 1, false);
            //    na.GetNeuronAt(Array.IndexOf(cols, "say"), 3).AddSynapse(GetSpokenWord("Thing").Id, 1, false);
            //    na.GetNeuronAt(Array.IndexOf(cols, "say"), 4).AddSynapse(GetSpokenWord("Sequence").Id, 1, false);
            //}
            Test();
        }
Exemple #23
0
        public override void Fire()
        {
            Init();  //be sure to leave this here

            //Do any hebbian synapse adjustment
            if (GetNeuron("Learning") is Neuron nlearing && nlearing.Fired())
            {
                for (int i = 0; i < mv.Height; i++)
                {
                    if (mv.GetNeuronAt(0, i) is Neuron n)
                    {
                        if (n.LastFired > MainWindow.theNeuronArray.Generation - 4)
                        {
                            waitingForInput = 0;
                            //adjust the incoming synapse weights
                            int firedCount = 0;
                            for (int j = 0; j < n.synapsesFrom.Count; j++)
                            {
                                Synapse s = n.synapsesFrom[j];
                                if (s.model != Synapse.modelType.Fixed)
                                {
                                    Neuron nSource = MainWindow.theNeuronArray.GetNeuron(s.TargetNeuron);
                                    if (nSource.LastFired > MainWindow.theNeuronArray.Generation - 4)
                                    {
                                        firedCount++;
                                    }
                                }
                            }
                            //if no inputs fired, things might not work so skip for now
                            if (firedCount == 0)
                            {
                                continue;
                            }


                            for (int j = 0; j < n.synapsesFrom.Count; j++)
                            {
                                Synapse s = n.synapsesFrom[j];
                                if (s.model != Synapse.modelType.Fixed)
                                {
                                    Neuron nSource = MainWindow.theNeuronArray.GetNeuron(s.TargetNeuron);
                                    if (nSource.LastFired > MainWindow.theNeuronArray.Generation - 4)
                                    {
                                        nSource.AddSynapse(n.id, (s.weight + targetWeightPos) / 2, s.model);
                                    }
                                    else
                                    {
                                        nSource.AddSynapse(n.id, (s.weight + targetWeightNeg) / 2, s.model);
                                    }
                                }
                            }

                            //clear partial charges from others
                            for (int k = 0; k < mv.Height; k++)
                            {
                                if (mv.GetNeuronAt(0, k) is Neuron n5)
                                {
                                    n5.currentCharge = 0;
                                    n5.Update();
                                }
                            }
                            break;
                        }
                    }
                }

                Neuron nRdOut = GetNeuron("RdOut");
                if ((MainWindow.theNeuronArray.Generation % 36) == 0)
                {
                    waitingForInput = maxTries; //countdown tries to read
                    //fire rdOut
                    nRdOut.currentCharge = 1;
                    nRdOut.Update();
                }
                if (waitingForInput > 1 && (MainWindow.theNeuronArray.Generation % 6) == 0)
                {
                    waitingForInput--;
                    nRdOut.currentCharge = 1;
                    nRdOut.Update();
                }
                //if we get here, no neuron has fired yet
                if (waitingForInput == 1 && (MainWindow.theNeuronArray.Generation % 6) == 0)
                {
                    waitingForInput--;
                    //if we've tried enough, learn a new pattern
                    //1) select the neuron to use 2) fire it

                    long   oldestFired  = long.MaxValue;
                    Neuron oldestNeuron = null;
                    for (int i = 0; i < mv.Height; i++)
                    {
                        if (mv.GetNeuronAt(0, i) is Neuron n2)
                        {
                            if (n2.LastFired < oldestFired)
                            {
                                oldestFired  = n2.LastFired;
                                oldestNeuron = n2;
                            }
                        }
                    }
                    if (oldestNeuron != null)
                    {
                        oldestNeuron.CurrentCharge = 1;
                        oldestNeuron.Update();
                        //zero out the old synapses
                        List <Synapse> prevSynapses = new List <Synapse>();
                        for (int j = 0; j < oldestNeuron.synapsesFrom.Count; j++)
                        {
                            prevSynapses.Add(oldestNeuron.synapsesFrom[j]);
                        }
                        oldestNeuron.DeleteAllSynapes(false);
                        for (int j = 0; j < prevSynapses.Count; j++)
                        {
                            float theWeight = prevSynapses[j].weight;
                            if (prevSynapses[j].model != Synapse.modelType.Fixed)
                            {
                                theWeight = 0;
                            }
                            theNeuronArray.GetNeuron(prevSynapses[j].targetNeuron).AddSynapse(
                                oldestNeuron.id, theWeight, prevSynapses[j].model);
                        }
                    }
                }
            }
Exemple #24
0
        public override void Initialize()
        {
            Neuron nEnable = na.GetNeuronAt(0);

            nEnable.Label = "Enable";
            Neuron nDisable = na.GetNeuronAt(1);

            nDisable.Label = "Disable";
            nEnable.AddSynapse(nDisable.Id, -1);
            nDisable.AddSynapse(nDisable.Id, 1);
            //nDisable.CurrentCharge = 1;
            for (int i = 2; i < na.NeuronCount; i++)
            {
                Neuron n = na.GetNeuronAt(i);
                nDisable.AddSynapse(n.Id, -1);
            }

            Neuron nStop = na.GetNeuronAt(2);

            nStop.Label = "Stop";
            Neuron nGo = na.GetNeuronAt(3);

            nGo.Label = "Go";
            Neuron nLeft = na.GetNeuronAt(4);

            nLeft.Label = "Left";
            Neuron nRight = na.GetNeuronAt(5);

            nRight.Label = "Right";
            nStop.AddSynapse(nGo.Id, -1);
            nGo.AddSynapse(nGo.Id, 1);
            Neuron nFwd = GetNeuron("ModuleMove", "^");

            if (nFwd != null)
            {
                nGo.AddSynapse(nFwd.Id, 1);
            }
            Neuron nKBGo = GetNeuron("KBOut", "Go");

            if (nKBGo != null)
            {
                nKBGo.AddSynapse(nGo.Id, 1);
            }
            Neuron nKBStop = GetNeuron("KBOut", "Stop");

            if (nKBStop != null)
            {
                nKBStop.AddSynapse(nStop.Id, 1);
            }
            Neuron nL = GetNeuron("ModuleTurn", "<");
            Neuron nR = GetNeuron("ModuleTurn", ">");

            if (nL != null)
            {
                nLeft.AddSynapse(nL.Id, 1);
            }
            if (nR != null)
            {
                nRight.AddSynapse(nR.Id, 1);
            }
            Neuron nLTurn = GetNeuron("KBOut", "LTurn");

            if (nLTurn != null)
            {
                nLTurn.AddSynapse(nLeft.Id, 1);
            }
            Neuron nRTurn = GetNeuron("KBOut", "RTurn");

            if (nRTurn != null)
            {
                nRTurn.AddSynapse(nRight.Id, 1);
            }
            nStop.AddSynapse(nLeft.Id, -1);
            nStop.AddSynapse(nRight.Id, -1);
            nLeft.AddSynapse(nLeft.Id, 1);
            nRight.AddSynapse(nRight.Id, 1);
        }
Exemple #25
0
        public override void Fire()
        {
            Init();  //be sure to leave this here
            if (synth == null)
            {
                return;
            }

            if (GetNeuronValue("Cancel") == 1)
            {
                synth.SpeakAsyncCancelAll();
            }
            if (GetNeuronValue("Validate") == 1)
            {
                if (!validating)
                {
                    hitWords.Clear();
                    missWords.Clear();
                    missPhrase.Clear();
                    hit  = 0;
                    miss = 0;
                }
                validating = true;
            }
            else
            {
                if (validating)
                {
                    if (hit + miss == 0)
                    {
                        Debug.WriteLine("No Validation Data");
                    }
                    else
                    {
                        Debug.WriteLine("Validation: " + hit + " / " + miss + " = " + 100 * hit / (hit + miss));
                        Debug.WriteLine("Validation: " + hitWords.Count + " / " + missWords.Count + " = " + 100 * hitWords.Count / (hitWords.Count + missWords.Count));
                    }
                }
                validating = false;
            }

            bool paused = true;

            for (int i = 3; i < na.NeuronCount; i++)
            {
                Neuron n = na.GetNeuronAt(i);
                if (n.Fired())
                {
                    if (n.Label.Length == 1)
                    {
                        phraseToSpeak += n.Label;
                        paused         = false;
                    }
                    if (n.Synapses.Count == 0)
                    {
                        //connect it to the knowledge store
                        //connection to KB
                        //ModuleUKS2 nmKB = (ModuleUKS2)FindModuleByName("AudibleUKS");
                        if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS)
                        {
                            string       label    = "pn" + n.Label;
                            List <Thing> phonemes = UKS.Labeled("Phoneme").Children;
                            Thing        pn       = UKS.Labeled(label, phonemes);
                            if (pn == null) //this should always be null
                            {
                                pn = UKS.AddThing(label, new Thing[] { UKS.Labeled("Phoneme") }, pn);
                            }
                            Neuron n1 = UKS.GetNeuron(pn);
                            Neuron n2 = UKS.GetNeuron(pn, false);
                            if (n1 != null)
                            {
                                n.AddSynapse(n1.Id, 1);
                                n1.SetValue(1);
                                n2.AddSynapse(n.Id, 1);
                            }
                        }
                    }
                }
            }
            if (phonemesToFire != "")
            {
                char c     = phonemesToFire[0];
                bool fired = false;
                if (c != ' ')
                {
                    for (int i = 0; i < na.NeuronCount; i++)
                    {
                        Neuron n = na.GetNeuronAt(i);
                        if (n.Label == c.ToString())
                        {
                            n.SetValue(1);
                            fired = true;
                            break;
                        }
                    }
                    if (!fired)
                    {
                        Neuron n = AddLabel(c.ToString());
                        //connect it to the knowledge store
                        //connection to KB
                        //ModuleUKS2 nmKB = (ModuleUKS2)FindModuleByName("AudibleUKS");
                        if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS)
                        {
                            string       label    = "pn" + n.Label;
                            List <Thing> phonemes = UKS.Labeled("Phoneme").Children;
                            Thing        pn       = UKS.Labeled(label, phonemes);
                            if (pn == null) //this should always be null
                            {
                                pn = UKS.AddThing(label, new Thing[] { UKS.Labeled("Phoneme") }, pn);
                            }
                            Neuron n1 = UKS.GetNeuron(pn);
                            Neuron n2 = UKS.GetNeuron(pn, false);
                            if (n1 != null)
                            {
                                n.AddSynapse(n1.Id, 1);
                                n2.AddSynapse(n.Id, 1);
                                n.SetValue(1);
                            }
                        }
                    }
                }
                phonemesToFire = phonemesToFire.Substring(1);
            }

            if (paused && phraseToSpeak != "")
            {
                if (dlg != null)
                {
                    ((ModuleSpeakPhonemes2Dlg)dlg).SetLabel(phraseToSpeak);
                }

                if (na.GetNeuronAt("Enable").Fired())
                {
                    ModuleSpeechIn msi = (ModuleSpeechIn)FindModuleByType(typeof(ModuleSpeechIn));
                    if (msi != null)
                    {
                        msi.PauseRecognition(); //if there is a recognizer active
                    }
                    //synth.SpeakAsync(phraseToSpeak + ".");
                    //phraseToSpeak = "";

                    PromptBuilder pb1 = new PromptBuilder();
                    if (typedIn)
                    {
                        pb1.StartVoice("Microsoft David Desktop");
                        pb1.StartStyle(new PromptStyle(PromptRate.Medium));
                    }
                    else
                    {
                        pb1.StartVoice("Microsoft Zira Desktop");
                        pb1.StartStyle(new PromptStyle(PromptRate.Slow));
                    }

                    pb1.AppendTextWithPronunciation("not used", phraseToSpeak.Trim());
                    pb1.EndStyle();
                    pb1.EndVoice();
                    string x = pb1.ToXml();
                    Debug.WriteLine(debugString(phraseToSpeak));
                    //synth.Speak(pb1);
                    synth.SpeakAsync(pb1);
                }
                //string heard = GetPronunciationFromText("", phraseToSpeak); //it would be nice to hear what was said but it doesn't work with this engine
                phraseToSpeak = "";
                typedIn       = false;
            }
        }
        private void AddSynapses()
        {
            Init();
            ClearNeurons(false);
            mv.GetNeuronAt(0, 0).Label = "In";

            int chainWidth  = 0;
            int chainHeight = 0;

            int theCount = 0;

            if (mv.Height > mv.Width)
            {
                chainWidth  = mv.Width - 2;
                chainHeight = mv.Height;
                //add the count neuron labels
                theCount = mv.Height;
                for (int j = 0; j < theCount; j++)
                {
                    mv.GetNeuronAt(mv.Width - 1, j).Label    = (j + 1).ToString();
                    mv.GetNeuronAt(mv.Width - 2, j).Label    = "i" + (j + 1).ToString();
                    mv.GetNeuronAt(mv.Width - 2, j).Model    = Neuron.modelType.LIF;
                    mv.GetNeuronAt(mv.Width - 2, j).LeakRate = 1f;
                }
            }
            else
            {
                chainHeight = mv.Height - 2;
                chainWidth  = mv.Width;
                //add the count neuron labels
                theCount = mv.Width;
                for (int j = 0; j < theCount; j++)
                {
                    mv.GetNeuronAt(j, mv.Height - 1).Label    = (j + 1).ToString();
                    mv.GetNeuronAt(j, mv.Height - 2).Label    = "i" + (j + 1).ToString();
                    mv.GetNeuronAt(j, mv.Height - 2).Model    = Neuron.modelType.LIF;
                    mv.GetNeuronAt(j, mv.Height - 2).LeakRate = 1f;
                }
            }

            //add the synapses for the chain
            for (int i = 0; i < chainHeight; i++)
            {
                for (int j = 0; j < chainWidth - 1; j++)
                {
                    mv.GetNeuronAt(j, i).AddSynapse(mv.GetNeuronAt(j + 1, i).id, 1);
                }
                if (i < chainHeight - 1)
                {
                    mv.GetNeuronAt(chainWidth - 1, i).AddSynapse(mv.GetNeuronAt(0, i + 1).id, 1);
                }
            }

            //add the synapses to the count neurons
            for (int k = 0; k < theCount; k++)
            {
                float  theWeight = 1 / (float)(k + 1);
                Neuron target    = GetNeuron("i" + (k + 1).ToString());
                for (int i = 0; i < chainHeight; i++)
                {
                    for (int j = 0; j < chainWidth; j++)
                    {
                        mv.GetNeuronAt(j, i).AddSynapse(target.id, theWeight);
                    }
                }
            }

            for (int k = 0; k < theCount; k++)
            {
                Neuron source = GetNeuron("i" + (k + 1).ToString());
                Neuron target = GetNeuron((k + 1).ToString());
                source.AddSynapse(target.id, 1);
                for (int j = k - 1; j >= 0; j--)
                {
                    target = GetNeuron((j + 1).ToString());
                    source.AddSynapse(target.id, -1);
                }
            }
        }
Exemple #27
0
        //fill this method in with code which will execute once
        //when the module is added, when "initialize" is selected from the context menu,
        //or when the engine restart button is pressed
        public override void Initialize()
        {
            base.Initialize();
            foreach (Neuron n in na.Neurons())
            {
                n.DeleteAllSynapes();
            }
            ModuleView na1 = theNeuronArray.FindAreaByLabel("KBOut");

            if (na1 != null)
            {
                foreach (Neuron n in na1.Neurons())
                {
                    n.DeleteAllSynapes();
                }
            }

            //since we are inserting at 0, these are in reverse order
            UKS.Insert(0, new Thing {
                Label = "Sleep"
            });
            UKS.Insert(0, new Thing {
                Label = "Max"
            });
            UKS.Insert(0, new Thing {
                Label = "Ref"
            });
            UKS.Insert(0, new Thing {
                Label = "Parent"
            });
            firstThing  = 4;
            EventCount  = 0;
            phraseCount = 0;

            //add connections from speakPhonemes to this module

            ModuleView naPhonemes = theNeuronArray.FindAreaByLabel("ModuleSpeakPhonemes");

            if (naPhonemes != null)
            {
                Neuron n2 = GetNeuron(Labeled("SayRnd"));
                Neuron n3 = naPhonemes.GetNeuronAt("BabyTalk");
                if (n2 != null && n3 != null)
                {
                    n3.AddSynapse(n2.Id, 1);
                }
                Thing parent = Labeled("Vowel");
                foreach (Neuron n in naPhonemes.Neurons())
                {
                    if (n.Label == "Conson.")
                    {
                        parent = Labeled("Consonant");
                    }
                    if (n.Label.Length == 1)
                    {
                        string label = "spk" + n.Label;
                        Thing  pn    = AddThing(label, new Thing[] { parent });
                        Neuron n1    = GetNeuron(pn, false);
                        if (n1 != null)
                        {
                            n1.AddSynapse(n.Id, 1);
                        }
                    }
                }
            }

            UpdateNeuronLabels();
        }