Ejemplo n.º 1
0
 public void SynapseProximalCtorTest()
 {
     for (int testNum = 0; testNum < Global.Tests.TestNumLoops; testNum++)
     {
         Column          col = new Column(0, 0, 1);
         SynapseProximal syn = new SynapseProximal(col);
         Assert.AreSame(syn.ColumnConnected, col);
         Assert.IsTrue(syn.Permanence >= 0.0);
         Assert.IsTrue(syn.Permanence <= 1.0);
         Assert.IsFalse(syn.IsActive);
     }
 }
Ejemplo n.º 2
0
        public void SynapseProximalOverrideTest()
        {
            for (int testNum = 0; testNum < Global.Tests.TestNumLoops; testNum++)
            {
                Column          col = new Column(0, 0, 3);
                SynapseProximal syn = new SynapseProximal(col);
                syn.OverridePermanence(1.0);

                //test override active
                syn.Override(true, 0);
                Assert.IsTrue(syn.IsActive);
                Assert.IsTrue(col.Cells[0].IsActive);
                Assert.IsTrue(col.Cells[1].IsActive);
                Assert.IsTrue(col.Cells[2].IsActive);

                syn.Override(false, 0);
                Assert.IsFalse(syn.IsActive);
                Assert.IsFalse(col.Cells[0].IsActive);
                Assert.IsFalse(col.Cells[1].IsActive);
                Assert.IsFalse(col.Cells[2].IsActive);

                //test override permanence
                syn.OverridePermanence(-0.5);
                Assert.IsTrue(syn.Permanence == 0);
                syn.OverridePermanence(9999.99);
                Assert.IsTrue(syn.Permanence == 1.0);
                syn.OverridePermanence(NetConfigData.SynapsePermanenceThreshold + 0.01);
                Assert.IsTrue(syn.Permanence > NetConfigData.SynapsePermanenceThreshold);
                Assert.IsTrue(syn.Permanence <= 1.0);

                //test override of connected column
                syn.Override(true, 0);
                Assert.IsTrue(col.IsActive);
                syn.Override(false, 0);
                Assert.IsFalse(col.IsActive);
            }
        }
Ejemplo n.º 3
0
        public void SynapseProximalUpdateTest()
        {
            Random rnd = Global.rnd;

            NetConfigData.SetDefaults();

            for (int testNum = 0; testNum < Global.Tests.TestNumLoops; testNum++)
            {
                Column          col = new Column(0, 0, rnd.Next(1, 10));
                SynapseProximal syn = new SynapseProximal(col);

                //active column
                col.OverrideActive(true, 0);
                syn.OverridePermanence(NetConfigData.SynapsePermanenceThreshold + NetConfigData.SynapsePermanenceIncrease);
                syn.Update();
                Assert.IsTrue(syn.IsActive);

                //drop permanence
                col.OverrideActive(true, 0);
                syn.OverridePermanence(NetConfigData.SynapsePermanenceThreshold - 2 * NetConfigData.SynapsePermanenceIncrease);
                syn.Update();
                Assert.IsFalse(syn.IsActive);                   //false on first update
                syn.Update();
                Assert.IsTrue(syn.IsActive);                    //true on second update

                //column not active
                col.OverrideActive(false, 0);
                syn.OverridePermanence(NetConfigData.SynapsePermanenceThreshold + NetConfigData.SynapsePermanenceIncrease);
                syn.Update();
                Assert.IsFalse(syn.IsActive);

                //column active
                col.OverrideActive(true, 0);
                syn.OverridePermanence(NetConfigData.SynapsePermanenceThreshold + NetConfigData.SynapsePermanenceIncrease);
                syn.Update();
                Assert.IsTrue(syn.IsActive);

                //random permanence, column active
                col.OverrideActive(true, 0);
                syn.OverridePermanence(rnd.NextDouble());
                syn.Update();
                if (syn.Permanence >= NetConfigData.SynapsePermanenceThreshold)
                {
                    Assert.IsTrue(syn.IsActive);
                }
                else
                {
                    Assert.IsFalse(syn.IsActive);
                }

                //random permanence, column not active
                col.OverrideActive(false, 0);
                syn.OverridePermanence(rnd.NextDouble());
                syn.Update();
                if (syn.Permanence >= NetConfigData.SynapsePermanenceThreshold)
                {
                    Assert.IsFalse(syn.IsActive);
                }
                else
                {
                    Assert.IsFalse(syn.IsActive);
                }
            }
        }
Ejemplo n.º 4
0
        public void ColumnUpdate_ColumnLevelTest()
        {
            Random rnd = Global.rnd;

            NetConfigData.SetDefaults();

            for (int testNum = 0; testNum < Global.Tests.TestNumLoops; testNum++)
            {
                Debug.WriteLine("ColumnUpdateBasalTest testNum=" + testNum.ToString());

                //Layer
                int layerColumnsX         = rnd.Next(1, 10);
                int layerColumnsY         = layerColumnsX > 1 ? rnd.Next(1, 10) : rnd.Next(2, 10);
                int layerNumCellsInColumn = rnd.Next(1, 5);
                //layerColumnsX = 2;
                //layerColumnsY = 4;
                //layerNumCellsInColumn = 2;
                Layer lr = new Layer(layerColumnsX, layerColumnsY, layerNumCellsInColumn);

                //InputPlane
                int ipColumnsX = rnd.Next(1, 20);
                int ipColumnsY = rnd.Next(1, 20);
                //ipColumnsX = 4;
                //ipColumnsY = 12;
                InputPlane ip = new InputPlane(ipColumnsX, ipColumnsY);

                // create synapses
                //lr.ConnectProximal(ip, 1, 1);
                //lr.ConnectBasal(1, 1);
                lr.ZoneSizePercProximal     = 1.0;
                lr.ZoneCoveragePercProximal = 1.0;
                lr.ZoneSizePercBasal        = 1.0;
                lr.ZoneCoveragePercBasal    = 1.0;
                lr.ConnectColumns(ip);                  //uses Leyer.ZoneSizePercProximal, ZoneCoveragePercProximal, Basal

                lr.OverrideBasalPermanences(1.0);
                lr.OverrideProximalPermanences(1.0);
                lr.OverrideProximalDendriteActivationThreshold(Global.DENDRITE_INITIAL_ACTIVATION_THRESHOLD);
                lr.OverrideBasalDendriteActivationThreshold(Global.DENDRITE_INITIAL_ACTIVATION_THRESHOLD);
                lr.InhibitionEnabled = false;

                int lrNumColumns = lr.NumColumnsX * lr.NumColumnsY;
                int ipNumColumns = ip.NumColumnsX * ip.NumColumnsY;

                foreach (List <Column> colRow in lr.Columns)
                {
                    foreach (Column col in colRow)
                    {
                        col.CreateProximalSynapses(lr, ip, double.MaxValue, 1);
                        col.CreateBasalSynapses(lr, double.MaxValue, 1);
                        Assert.AreEqual(col.ProximalDendrite.Synapses.Count, ipNumColumns);

                        //need to implement following tests:
                        //
                        //1. col Active 0  Predicting 0
                        //2. col Active 0  Predicting 1
                        //3. col Active 1  Predicting 0
                        //4. col Active 1  Predicting 1
                        //
                        //with following variants:
                        //
                        //a. due to EXTERNAL factors
                        //
                        // Active		- InputPlane Activations 0
                        // Predicting	- own Layer Predicting 0
                        //
                        //b. due to INTERNAL factors
                        //
                        // Active		- ProximalDendrite
                        //					- due number of ProximalSynapses to InputPlane columns
                        //					- due to ProximalSynapses Permanence values
                        //
                        // Predicting	- BasalDendrite
                        //					- due to number of BasalSynapses to own Layer columns
                        //					- due to BasalSynapses Permanence values

                        lr.Override(false, false);
                        lr.OverrideProximalInputOverlap(0);
                        Assert.IsFalse(col.IsActive);
                        Assert.IsFalse(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 0);
                        col.Update_Basal();
                        Assert.IsFalse(col.IsActive);
                        Assert.IsFalse(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 0);

                        lr.Override(true, false);
                        lr.OverrideProximalInputOverlap(1);
                        Assert.IsTrue(col.IsActive);
                        Assert.IsFalse(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 1);
                        col.Update_Proximal();
                        List <Column> neighbours = lr.GetColumnsFromCentre_WithThreshold(col.X, col.Y, double.MaxValue, true, 1);
                        col.Update_Activation(neighbours, false);
                        col.Update_Basal();
                        Assert.IsTrue(col.IsActive);
                        Assert.IsFalse(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, col.ProximalDendrite.Synapses.Count);

                        lr.Override(false, true);
                        lr.OverrideProximalInputOverlap(1);
                        Assert.IsFalse(col.IsActive);
                        Assert.IsTrue(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 1);
                        col.Update_Proximal();
                        neighbours = lr.GetColumnsFromCentre_WithThreshold(col.X, col.Y, double.MaxValue, true, 1);
                        col.Update_Activation(neighbours, false);
                        col.Update_Basal();
                        Assert.IsFalse(col.IsActive);
                        Assert.IsFalse(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 0);

                        lr.Override(true, true);
                        lr.OverrideProximalInputOverlap(1);
                        Assert.IsTrue(col.IsActive);
                        Assert.IsTrue(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 1);
                        col.Update_Proximal();
                        neighbours = lr.GetColumnsFromCentre_WithThreshold(col.X, col.Y, double.MaxValue, true, 1);
                        col.Update_Activation(neighbours, false);
                        col.Update_Basal();
                        Assert.IsTrue(col.IsActive);
                        Assert.IsTrue(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, col.ProximalDendrite.Synapses.Count);

                        //IsActive - Proximal Synapses Active OFF
                        lr.Override(true, true);
                        lr.OverrideProximalInputOverlap(1);
                        foreach (SynapseProximal syn in col.ProximalDendrite.Synapses)
                        {
                            syn.ColumnConnected.OverrideActive(false, 2);
                        }
                        Assert.IsTrue(col.IsActive);
                        Assert.IsTrue(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 1);
                        col.Update_Proximal();
                        neighbours = lr.GetColumnsFromCentre_WithThreshold(col.X, col.Y, double.MaxValue, true, 1);
                        col.Update_Activation(neighbours, false);
                        col.Update_Basal();
                        Assert.IsFalse(col.IsActive);
                        Assert.IsFalse(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 0);

                        //IsPredicting - Basal ConnectedCells Active OFF
                        lr.Override(true, true);
                        lr.OverrideProximalInputOverlap(1);
                        foreach (Cell cell in col.Cells)
                        {
                            foreach (SynapseBasal syn in cell.BasalDendrite.Synapses)
                            {
                                syn.ColumnConnected.OverridePredicting(false, 2);
                            }
                        }
                        Assert.IsTrue(col.IsActive);
                        Assert.IsTrue(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 1);
                        col.Update_Proximal();
                        neighbours = lr.GetColumnsFromCentre_WithThreshold(col.X, col.Y, double.MaxValue, true, 1);
                        col.Update_Activation(neighbours, false);
                        col.Update_Basal();
                        Assert.IsTrue(col.IsActive);
                        Assert.IsFalse(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, col.ProximalDendrite.Synapses.Count);

                        // Active		- ProximalDendrite
                        //				- due number of ProximalSynapses to InputPlane
                        lr.Override(true, true);
                        lr.OverrideProximalInputOverlap(1);
                        col.ProximalDendrite.OverrideActivationThreshold(col.ProximalDendrite.Synapses.Count - rnd.Next(0, 5));
                        while (col.ProximalDendrite.Synapses.Count >= col.ProximalDendrite.ActivationThreshold &&
                               col.ProximalDendrite.Synapses.Count > 1)                                  //leave at least 1 synapse
                        {
                            SynapseProximal syn = col.ProximalDendrite.Synapses[0];
                            col.ProximalDendrite.Synapses.Remove(syn);
                        }
                        Assert.IsTrue(col.IsActive);
                        Assert.IsTrue(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 1);
                        col.Update_Proximal();
                        neighbours = lr.GetColumnsFromCentre_WithThreshold(col.X, col.Y, double.MaxValue, true, 1);
                        col.Update_Activation(neighbours, false);
                        col.Update_Basal();
                        Assert.IsTrue(col.IsActive);
                        Assert.IsTrue(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, col.ProximalDendrite.Synapses.Count);                         //all remaining synapses

                        //lr.ConnectProximal(ip, 1, 1);
                        //lr.ConnectBasal(1, 1);
                        lr.ZoneSizePercProximal     = 1.0;
                        lr.ZoneCoveragePercProximal = 1.0;
                        lr.ZoneSizePercBasal        = 1.0;
                        lr.ZoneCoveragePercBasal    = 1.0;
                        lr.ConnectColumns(ip);
                        lr.OverrideProximalPermanences(NetConfigData.SynapsePermanenceThreshold);
                        lr.OverrideProximalDendriteActivationThreshold(Global.DENDRITE_INITIAL_ACTIVATION_THRESHOLD);

                        // Active		- ProximalDendrite
                        //				- due to ProximalSynapses Permanence values
                        lr.Override(true, true);
                        lr.OverrideProximalInputOverlap(0);
                        lr.InhibitionEnabled = false;
                        col.ProximalDendrite.OverridePermanence(NetConfigData.SynapsePermanenceThreshold
                                                                - 2 * NetConfigData.SynapsePermanenceIncrease);
                        Assert.IsTrue(col.IsActive);
                        Assert.IsTrue(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 0);

                        col.Update_Proximal();
                        neighbours = lr.GetColumnsFromCentre_WithThreshold(col.X, col.Y, double.MaxValue, true, 0);
                        col.Update_Activation(neighbours, false);
                        col.Update_Basal();
                        Assert.IsFalse(col.IsActive);                                   //first update - false
                        Assert.IsFalse(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 0);

                        col.Update_Proximal();
                        neighbours = lr.GetColumnsFromCentre_WithThreshold(col.X, col.Y, double.MaxValue, true, 0);
                        col.Update_Activation(neighbours, false);
                        col.Update_Basal();
                        Assert.IsTrue(col.IsActive);                                   //second update - true //*********************** FAILS HERE
                        Assert.IsTrue(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, col.ProximalDendrite.Synapses.Count);

                        lr.OverrideProximalPermanences(NetConfigData.SynapsePermanenceThreshold);

                        // Predicting	- BasalDendrite
                        //				- due to number of BasalSynapses to own Layer columns
                        lr.Override(true, true);
                        lr.OverrideProximalInputOverlap(0);
                        foreach (Cell cell in col.Cells)
                        {
                            cell.BasalDendrite.OverrideActivationThreshold(cell.BasalDendrite.Synapses.Count
                                                                           - rnd.Next(0, 5));
                            while (cell.BasalDendrite.Synapses.Count >= cell.BasalDendrite.ActivationThreshold)
                            {
                                SynapseBasal syn = cell.BasalDendrite.Synapses[0];
                                cell.BasalDendrite.Synapses.Remove(syn);
                            }
                        }
                        Assert.IsTrue(col.IsActive);
                        Assert.IsTrue(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 0);
                        col.Update_Proximal();
                        neighbours = lr.GetColumnsFromCentre_WithThreshold(col.X, col.Y, double.MaxValue, true, 0);
                        col.Update_Activation(neighbours, false);
                        col.Update_Basal();
                        Assert.IsTrue(col.IsActive);
                        Assert.IsFalse(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, col.ProximalDendrite.Synapses.Count);

                        //lr.ConnectBasal(1, 1);
                        //lr.ConnectProximal(ip, 1, 1);
                        lr.ZoneSizePercProximal     = 1.0;
                        lr.ZoneCoveragePercProximal = 1.0;
                        lr.ZoneSizePercBasal        = 1.0;
                        lr.ZoneCoveragePercBasal    = 1.0;
                        lr.ConnectColumns(ip);
                        lr.OverrideBasalPermanences(NetConfigData.SynapsePermanenceThreshold);
                        lr.OverrideBasalDendriteActivationThreshold(Global.DENDRITE_INITIAL_ACTIVATION_THRESHOLD);

                        // Predicting	- BasalDendrite
                        //				- due to BasalSynapses Permanence values
                        lr.Override(true, true);
                        lr.OverrideProximalInputOverlap(0);
                        foreach (Cell cell in col.Cells)
                        {
                            cell.BasalDendrite.OverridePermanence(NetConfigData.SynapsePermanenceThreshold - 2 * NetConfigData.SynapsePermanenceIncrease);
                        }
                        Assert.IsTrue(col.IsActive);
                        Assert.IsTrue(col.IsPredicting);
                        Assert.AreEqual(col.InputOverlap, 0);
                        col.Update_Proximal();
                        neighbours = lr.GetColumnsFromCentre_WithThreshold(col.X, col.Y, double.MaxValue, true, 0);
                        col.Update_Activation(neighbours, false);
                        col.Update_Basal();
                        Assert.IsTrue(col.IsActive);
                        Assert.IsFalse(col.IsPredicting);                               //first update - false
                        Assert.AreEqual(col.InputOverlap, col.ProximalDendrite.Synapses.Count);
                        col.Update_Proximal();
                        col.Update_Activation(neighbours, false);
                        col.Update_Basal();
                        Assert.IsTrue(col.IsActive);
                        Assert.IsTrue(col.IsPredicting);                               //second update - true
                        Assert.AreEqual(col.InputOverlap, col.ProximalDendrite.Synapses.Count);
                    }
                }
            }
        }