Ejemplo n.º 1
0
        public void causalInference_EntropyMinimize_Trivial4()
        {
            Linearizer linearizer = new Linearizer();

            linearizer.random = new Random(42);

            float terminationPropability = 0.1f;
            NonanytimeEntropyMinimizer entropyMinimizer = new NonanytimeEntropyMinimizer(linearizer, terminationPropability);

            entropyMinimizer.random = new Random(42);


            CausalSetSystemBlock testCausalBlock = new CausalSetSystemBlock();

            // fill it
            testCausalBlock.nodes.Add(new CausalSetNode());
            testCausalBlock.indirectionArray.Add(testCausalBlock.getNewIndirectionNumber());
            testCausalBlock.nodes[0].globalIndex = 0;

            testCausalBlock.nodes.Add(new CausalSetNode());
            testCausalBlock.indirectionArray.Add(testCausalBlock.getNewIndirectionNumber());
            testCausalBlock.nodes[1].globalIndex = 1;

            testCausalBlock.nodes.Add(new CausalSetNode());
            testCausalBlock.indirectionArray.Add(testCausalBlock.getNewIndirectionNumber());
            testCausalBlock.nodes[2].globalIndex = 2;

            // 1 -> 0
            // 1 -> 2
            testCausalBlock.nodes[1].next = new CausalIndirectionIndex[] { new CausalIndirectionIndex(0) };
            testCausalBlock.nodes[2].next = new CausalIndirectionIndex[] { new CausalIndirectionIndex(0) };

            entropyMinimizer.entry(testCausalBlock);


            entropyMinimizer.anytimeInvoke();



            long energyOfLinearization;
            GlobalLinearization linearization = entropyMinimizer.getBestGlobalLinearizationAndEnergy(out energyOfLinearization);

            Assert.AreEqual(energyOfLinearization, 3);

            Assert.IsTrue(linearization.linearization[2] == 0);
            if (linearization.linearization[1] == 1)
            {
                Assert.IsTrue(linearization.linearization[0] == 2);
            }
            else if (linearization.linearization[1] == 2)
            {
                Assert.IsTrue(linearization.linearization[0] == 1);
            }
            else
            {
                throw new Exception("first element must be 1 or 2!");
            }

            entropyMinimizer.finish();
        }
Ejemplo n.º 2
0
        public void CausalInference_EntropyMinimize_Tunnel0()
        {
            Linearizer linearizer = new Linearizer();

            linearizer.random = new Random(42);

            float terminationPropability = 0.1f;
            NonanytimeEntropyMinimizer entropyMinimizer = new NonanytimeEntropyMinimizer(linearizer, terminationPropability);

            entropyMinimizer.random = new Random(42);

            CausalSetSystemBlock testCausalBlock = new CausalSetSystemBlock();


            // fill it
            testCausalBlock.nodes.Add(new CausalSetNode());
            testCausalBlock.indirectionArray.Add(testCausalBlock.getNewIndirectionNumber());
            testCausalBlock.nodes[0].globalIndex = 0;

            testCausalBlock.nodes.Add(new CausalSetNode());
            testCausalBlock.indirectionArray.Add(testCausalBlock.getNewIndirectionNumber());
            testCausalBlock.nodes[1].globalIndex = 1;

            testCausalBlock.nodes.Add(new CausalSetNode());
            testCausalBlock.indirectionArray.Add(testCausalBlock.getNewIndirectionNumber());
            testCausalBlock.nodes[2].globalIndex = 2;

            testCausalBlock.nodes.Add(new CausalSetNode());
            testCausalBlock.indirectionArray.Add(testCausalBlock.getNewIndirectionNumber());
            testCausalBlock.nodes[3].globalIndex = 3;

            testCausalBlock.nodes.Add(new CausalSetNode());
            testCausalBlock.indirectionArray.Add(testCausalBlock.getNewIndirectionNumber());
            testCausalBlock.nodes[4].globalIndex = 4;

            // 2 -> 0
            // 3 -> 4
            // 3 -> 1
            // 3 -> 0
            // 0 -> 1
            // 4 -> 1

            testCausalBlock.nodes[2].next = new CausalIndirectionIndex[] { new CausalIndirectionIndex(0) };
            testCausalBlock.nodes[3].next = new CausalIndirectionIndex[] { new CausalIndirectionIndex(4), new CausalIndirectionIndex(1), new CausalIndirectionIndex(0) };
            testCausalBlock.nodes[0].next = new CausalIndirectionIndex[] { new CausalIndirectionIndex(1) };
            testCausalBlock.nodes[4].next = new CausalIndirectionIndex[] { new CausalIndirectionIndex(1) };

            entropyMinimizer.entry(testCausalBlock);

            entropyMinimizer.anytimeInvoke();


            // target sequence with minimal energy  is 2 3 0 4 1

            long energyOfLinearization;
            GlobalLinearization linearization = entropyMinimizer.getBestGlobalLinearizationAndEnergy(out energyOfLinearization);

            Assert.AreEqual(energyOfLinearization, 11);

            Assert.IsTrue(linearization.linearization[0] == 2);
            Assert.IsTrue(linearization.linearization[1] == 3);
            Assert.IsTrue(linearization.linearization[2] == 0);
            Assert.IsTrue(linearization.linearization[3] == 4);
            Assert.IsTrue(linearization.linearization[4] == 1);

            entropyMinimizer.finish();
        }