Esempio n. 1
0
        //did the neuron associated with a thing fire?
        //firing at least minPastCycles but not more than maxPastCycles ago
        public bool Fired(Thing t, long maxPastCycles = 1, bool firedInput = true, long minPastCycles = 0)
        {
            int        i        = UKS.IndexOf(t);
            ModuleView naModule = na;

            if (!firedInput)
            {
                naModule = GetOutputModule();
                if (naModule == null)
                {
                    return(false);
                }
            }
            Neuron n = naModule.GetNeuronAt(i);

            if (n == null)
            {
                return(false);
            }
            long timeSinceLastFire = MainWindow.theNeuronArray.Generation - n.LastFired;
            bool retVal            = timeSinceLastFire <= maxPastCycles;

            if (retVal)
            {
                retVal = timeSinceLastFire >= minPastCycles;
            }
            return(retVal);
        }
Esempio n. 2
0
        public override void DeleteThing(Thing t)
        {
            int i = UKS.IndexOf(t);

            base.DeleteThing(t);
            //because we removed a node, any external synapses to related neurons need to be adjusted to point to the right place
            //on any neurons which might have shifted.
            if (i > -1)
            {
                for (int j = i + 1; j < na.NeuronCount; j++)
                {
                    Neuron targetNeuron = na.GetNeuronAt(j - 1);
                    Neuron sourceNeuron = na.GetNeuronAt(j);
                    MainWindow.thisWindow.theNeuronArrayView.MoveOneNeuron(sourceNeuron, targetNeuron);
                }
                //repeat this process for the output array
                ModuleView naModule = theNeuronArray.FindAreaByLabel("KBOut");
                if (naModule != null)
                {
                    for (int j = i + 1; j < naModule.NeuronCount; j++)
                    {
                        Neuron targetNeuron = naModule.GetNeuronAt(j - 1);
                        Neuron sourceNeuron = naModule.GetNeuronAt(j);
                        MainWindow.thisWindow.theNeuronArrayView.MoveOneNeuron(sourceNeuron, targetNeuron);
                    }
                }
            }
            UpdateNeuronLabels();
        }
Esempio n. 3
0
        /// <summary>
        /// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// </summary>

        //execute the debugging commands if the associated neuron fired
        private void ShowReferences()
        {
            for (int i = firstThing; i < na.NeuronCount && i < UKS.Count; i++)
            {
                Neuron n = na.GetNeuronAt(i);
                if (NeuronFired("Parent"))
                {
                    if (n.Fired())
                    {
                        foreach (Thing t in UKS[i].Parents)
                        {
                            int j = UKS.IndexOf(t);
                            if (j >= 0)
                            {
                                SetNeuronValue("KBOut", j, 1);
                            }
                        }
                    }
                }
                if (NeuronFired("Ref"))
                {
                    if (n.Fired())
                    {
                        foreach (Link l in UKS[i].References)
                        {
                            int j = UKS.IndexOf(l.T);
                            if (j >= 0)
                            {
                                SetNeuronValue("KBOut", j, 1);
                            }
                        }
                    }
                }
                if (NeuronFired("Max"))
                {
                    if (n.Fired())
                    {
                        Link Max = new Link {
                            weight = -1
                        };
                        foreach (Link l in UKS[i].References)
                        {
                            if (l.Value() > Max.weight)
                            {
                                Max = l;
                            }
                        }
                        if (Max.weight > -1)
                        {
                            int j = UKS.IndexOf(Max.T);
                            if (j >= 0)
                            {
                                SetNeuronValue("KBOut", j, 1);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        //return neuron associated with KB thing
        public Neuron GetNeuron(Thing t, bool input = true)
        {
            int i = UKS.IndexOf(t);

            if (i == -1)
            {
                return(null);
            }
            return(GetNeuron(i, input));
        }
Esempio n. 5
0
        //fire the neuron associated with a KB thing
        public void Fire(Thing t, bool fireInput = true) //false fires the neuron in the output array
        {
            int i = UKS.IndexOf(t);

            if (i == -1)
            {
                return;
            }
            Neuron n = GetNeuron(i, fireInput);

            n.SetValue(1);
            t.useCount++;
        }
Esempio n. 6
0
        //did the neuron associated with a thing fire?
        //firing at least minPastCycles but not more than maxPastCycles ago
        public bool Fired(Thing t, long maxPastCycles = 1, bool firedInput = true, long minPastCycles = 0)
        {
            int    i = UKS.IndexOf(t);
            Neuron n = GetNeuron(i, firedInput);

            if (n == null)
            {
                return(false);
            }
            long timeSinceLastFire = MainWindow.theNeuronArray.Generation - n.LastFired;
            bool retVal            = timeSinceLastFire <= maxPastCycles;

            if (retVal)
            {
                retVal = timeSinceLastFire >= minPastCycles;
            }
            return(retVal);
        }
Esempio n. 7
0
        //fire the neuron associated with a KB thing
        public void Fire(Thing t, bool fireInput = true) //false fires the neuron in the output array
        {
            int i = UKS.IndexOf(t);

            if (i == -1)
            {
                return;
            }
            if (fireInput)
            {
                SetNeuronValue(null, i, 1);
            }
            else
            {
                SetNeuronValue("KBOut", i, 1);
            }

            t.useCount++;
        }
Esempio n. 8
0
        public override void DeleteThing(Thing t)
        {
            int i = UKS.IndexOf(t);

            base.DeleteThing(t);
            //because we removed a node, any external synapses to related neurons need to be adjusted to point to the right place
            //on any neurons which might have shifted.
            if (i > -1)
            {
                for (int j = i + 1; j < UKS.Count; j++)
                {
                    Neuron sourceNeuron = GetNeuron(j, false);
                    Neuron targetNeuron = PrevNeuron(sourceNeuron);
                    MainWindow.thisWindow.theNeuronArrayView.MoveOneNeuron(sourceNeuron, targetNeuron);
                    sourceNeuron = GetNeuron(j, true);
                    targetNeuron = PrevNeuron(sourceNeuron);
                    MainWindow.thisWindow.theNeuronArrayView.MoveOneNeuron(sourceNeuron, targetNeuron);
                }
            }
            UpdateNeuronLabels();
        }
Esempio n. 9
0
        //return neuron associated with KB thing
        public Neuron GetNeuron(Thing t, bool input = true)
        {
            int i = UKS.IndexOf(t);

            if (i == -1)
            {
                return(null);
            }
            if (input)
            {
                return(na.GetNeuronAt(i));
            }
            else
            {
                ModuleView na1 = theNeuronArray.FindAreaByLabel("KBOut");
                if (na1 == null)
                {
                    return(null);
                }
                return(na1.GetNeuronAt(i));
            }
        }
Esempio n. 10
0
        //this returns the most recent firing regardless of how long ago it was
        Thing MostRecentFired(Thing t)
        {
            if (t == null)
            {
                return(null);
            }
            Thing retVal  = null;
            long  firedAt = 0;

            foreach (Thing child in t.Children)
            {
                int    i = UKS.IndexOf(child);
                Neuron n = GetNeuron(i);
                if (n != null)
                {
                    if (n.LastFired > firedAt)
                    {
                        retVal  = child;
                        firedAt = n.LastFired;
                    }
                }
            }
            return(retVal);
        }