Exemplo n.º 1
0
        public void TestActivationSpreading()
        {
            // make a collection
            atomCollection collection = new atomCollection();

            // add some nodes to the collection
            const int no_of_nodes = 4;
            for (int i = 0; i < no_of_nodes; i++)
            {
                node n = new node();
                collection.Add(n);
            }

            // link the nodes together
            for (int i = 0; i < no_of_nodes; i++)
            {
                node n1 = (node)collection.Get(i);
                for (int j = 0; j < no_of_nodes; j++)
                {
                    if (i != j)
                    {
                        node n2 = (node)collection.Get(j);
                        n1.AddIncomingLink("hebbian", n2, new truthvalue(0.5f));
                    }
                }
            }

            // set an initial activation on channel 0
            node activated1 = (node)collection.Get(0);
            activated1.SetActivation(1.0f, 0);

            // set an initial activation on channel 1
            node activated2 = (node)collection.Get(no_of_nodes-1);
            activated2.SetActivation(1.0f, 1);

            // create an activation spreading agent
            agentActivationSpreading spread = new agentActivationSpreading(collection);

            // run the agent until it completes
            spread.Run();
            while (spread.running) spread.Run();

            Assert.IsTrue(activated1.GetActivation(0) < 1.0f, "activation level 0 has changed");
            Assert.IsTrue(activated2.GetActivation(1) < 1.0f, "activation level 1 has changed");

            node activated3 = (node)collection.Get(1);
            Assert.IsTrue(activated3.GetActivation(0) > 0, "activation level 0 has spread");
            Assert.IsTrue(activated3.GetActivation(1) > 0, "activation level 1 has spread");
        }
Exemplo n.º 2
0
        /// <summary>
        /// adds a link to this node
        /// </summary>
        public bool AddIncomingLink(String link_type,
		                            node source,
		                            truthvalue weight)
        {
            bool success = false;
            link lnk = null;

            if (!linkTemporal.IsTemporalLinkType(link_type))
                lnk = new link(source, this, weight);
            else
                lnk = new linkTemporal(source, this, weight);

            success = lnk.SetLinkType(link_type);
            if (success)
                AddIncomingLink(lnk);
            return(success);
        }
Exemplo n.º 3
0
        /// <summary>
        /// adds a link to this node
        /// </summary>
        public bool AddOutgoingLink(String link_type,
		                            node destination,
		                            truthvalue weight)
        {
            bool success = false;
            link lnk = null;

            if (!linkTemporal.IsTemporalLinkType(link_type))
                lnk = new link(this, destination, weight);
            else
                lnk = new linkTemporal(this, destination, weight);

            success = lnk.SetLinkType(link_type);
            if (success)
                AddOutgoingLink(lnk);
            return(success);
        }
Exemplo n.º 4
0
 public override atom Clone()
 {
     node cpy = new node();
     return(cpy);
 }
Exemplo n.º 5
0
        /// <summary>
        /// creates a list of concepts along a continuous range
        /// </summary>
        public void CreateRange(String[] name, bool ascending_order)
        {
            Clear();
            for (int i = 0; i < name.Length; i++)
            {
                // create a new node with this name
                node n = new node();
                n.SetName(name[i]);

                // get a position within the range of values
                float range_position = i / (float)name.Length;
                if (!ascending_order) range_position = 1.0f - range_position;

                // add the node
                Add(n, range_position);
            }
        }
Exemplo n.º 6
0
 public linkTemporal(node source, node destination, truthvalue weight)
     : base(source, destination, weight)
 {
     SetFlag(atom.FLAG_TEMPORAL);
 }
Exemplo n.º 7
0
 public ownership(node thingOwned, node personOwner)
     : base(personOwner, thingOwned, null)
 {
     SetLinkType("ownership");
     atom_value = new truthvalue();
 }
Exemplo n.º 8
0
        public void TestSearch()
        {
            // make a collection
            atomCollection search_collection = new atomCollection();

            // add some nodes to the collection
            const int no_of_nodes = 10;
            for (int i = 0; i < no_of_nodes; i++)
            {
                node n = new node();
                n.SetImportance(1.0f - (i / (float)no_of_nodes), atom.SHORT_TERM_IMPORTANCE);
                search_collection.Add(n);
            }

            // create a search agent
            agentSearch seeker = new agentSearch(search_collection, "importance",
                                                 atom.SHORT_TERM_IMPORTANCE);

            // create an exemplar to match against
            node exemplar = new node();
            exemplar.SetImportance(0.7f, atom.SHORT_TERM_IMPORTANCE);

            // link the exemplar to the the search agent
            bool link_added = seeker.AddIncomingLink("hebbian", exemplar, new truthvalue());
            Assert.IsTrue(link_added, "Link created");

            // run the agent until it completes
            seeker.Run();
            while (seeker.running) seeker.Run();
            atomCollection search_results = seeker.GetSearchResults();

            // check that some results were produced
            Assert.IsNotNull(search_results, "search results were returned");
            if (search_results != null)
            {
                // check that the number of nodes is what we expect
                Assert.AreEqual(search_results.Count(), no_of_nodes, "expected number of nodes in the search pool");

                //check that the results are sorted
                int i = 1;
                bool in_order = true;

                while ((i < search_results.Count()) && (in_order))
                {
                    if (seeker.GetDifference(i) < seeker.GetDifference(i - 1)) in_order = false;
                    i++;
                }
                Assert.IsTrue(in_order, "search results are sorted in ascending order of difference from the exemplar");
            }
        }
Exemplo n.º 9
0
        public void TestAssociativeLearning()
        {
            // make a collection
            atomCollection collection = new atomCollection();

            // add some nodes to the collection
            const int no_of_nodes = 5;
            for (int i = 0; i < no_of_nodes; i++)
            {
                node n = new node();
                collection.Add(n);
            }

            // link the nodes together
            for (int i = 0; i < no_of_nodes; i++)
            {
                node n1 = (node)collection.Get(i);
                for (int j = 0; j < no_of_nodes; j++)
                {
                    if (i != j)
                    {
                        node n2 = (node)collection.Get(j);
                        n1.AddIncomingLink("hebbian", n2, new truthvalue());
                    }
                }
            }

            // create a learning agent
            agentAssociativeLearning learner = new agentAssociativeLearning(collection);

            // run the agent until it completes
            learner.Run();
            while (learner.running) learner.Run();
        }
Exemplo n.º 10
0
        /// <summary>
        /// constructor
        /// </summary>
        public link(node source, node destination, truthvalue weight,
		            String linkTypeStr)
        {
            int linkType = GetLinkTypeInt32(linkTypeStr);
            initLink(source, destination, weight, linkType);
        }
Exemplo n.º 11
0
        /// <summary>
        /// constructor
        /// </summary>
        public link(node source, node destination, truthvalue weight,
		            int linkType)
        {
            initLink(source, destination, weight, linkType);
        }
Exemplo n.º 12
0
 /// <summary>
 /// constructor
 /// </summary>
 public link(node source, node destination, truthvalue weight)
 {
     int linkType = GetLinkTypeInt32("inheritance");
     initLink(source, destination, weight, linkType);
 }
Exemplo n.º 13
0
        private void initLink(node source, 
                              node destination, 
                              truthvalue weight,
                              int linkType)
        {
            SetAtomType("link");
            SetFlag(atom.FLAG_IS_LINK);

            // set the link properties
            AddToIncomingSet(source);
            AddToOutgoingSet(destination);
            atom_value = weight;

            // update the node links
            source.AddOutgoingLink(this);
            destination.AddIncomingLink(this);

            link_type = (byte)linkType;
        }