Esempio n. 1
0
        /// <summary>
        /// adds a new atom to the collection, placing it at
        /// a particular position within a continuous range
        /// </summary>
        public void Add(atom a, float position_within_range)
        {
            if (atom_position_within_range == null)
                atom_position_within_range = new ArrayList();

            Add(a);
            atom_position_within_range.Add(position_within_range);
        }
Esempio n. 2
0
        /// <summary>
        /// inserts the given atom into the atom ID index
        /// </summary>
        private void UpdateIndexAtomID(atom a, int atoms_index)
        {
            bool found = false;
            long ID = a.atom_ID;

            int i = 0;
            while ((i < index_atom_ID.Count) && (!found))
            {
                int idx = (int)index_atom_ID[i];
                atom a2 = (atom)atoms[idx];
                long a2_ID = a2.atom_ID;
                if (ID < a2_ID)
                {
                    index_atom_ID.Insert(i, atoms_index);
                    found = true;
                }
                i++;
            }

            if (!found)
                index_atom_ID.Add(atoms_index);
        }
Esempio n. 3
0
 /// <summary>
 /// removes an atom from the atom type index
 /// </summary>
 private void RemoveFromAtomTypeIndex(atom a)
 {
     int type = a.GetAtomTypeInt32();
     ArrayList typelist = (ArrayList)index_atom_type[type];
     typelist.Remove(a);  // warning: this is slow compared to RemoveAt
 }
Esempio n. 4
0
 /// <summary>
 /// removes an atom from the atom name index
 /// </summary>
 private void RemoveFromAtomNameIndex(atom a)
 {
     int index = atoms.IndexOf(a);
     if (index > -1)
     {
         index_atom_name.Remove((int)index);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// removes the given atom from the collection
 /// </summary>
 protected void RemoveMember(atom a)
 {
     int index = atoms.IndexOf(a);
     if (index > -1)
     {
         atoms.Remove(a);
         RemoveFromAtomTypeIndex(a);
         RemoveFromAtomNameIndex(a);
         RemoveFromAtomIDIndex(a);
         if (atom_position_within_range != null)
             atom_position_within_range.RemoveAt(index);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// adds a new member atom to the collection
 /// </summary>
 protected void AddMember(atom a)
 {
     atoms.Add(a);
     UpdateIndexAtomType(a);
     UpdateIndexAtomName(a, atoms.Count-1);
     UpdateIndexAtomID(a, atoms.Count-1);
 }
Esempio n. 7
0
 /// <summary>
 /// records the difference score for each evaluated candidate atom
 /// </summary>
 private void AddToWorkingSet(atom candidate, float diff)
 {
     working_set.Add(candidate);
     working_set_difference.Add(diff);
 }
Esempio n. 8
0
 /// <summary>
 /// adds a new atom to the collection
 /// </summary>
 public virtual void Add(atom a)
 {
     AddMember(a);
 }
Esempio n. 9
0
 /// <summary>
 /// adds a new atom to the matrix
 /// </summary>
 public void Add(atom a, int x, int y)
 {
     matrix[MatrixPositionToIndex(x, y)] = a;
     AddMember(a);
 }
Esempio n. 10
0
 /// <summary>
 /// removes an atom from the incoming or outgoing set
 /// </summary>
 private void RemoveFromSet(atom a, atomCollection atomset)
 {
     if (atomset != null)
     {
         atomset.Remove(a);
     }
 }
Esempio n. 11
0
 /// <summary>
 /// adds an atom to the incoming or outgoing set
 /// </summary>
 private void AddToSet(atom a, ref atomCollection atomset)
 {
     if (atomset == null) atomset = new atomCollection();
     atomset.Add(a);
 }
Esempio n. 12
0
 /// <summary>
 /// removes an atom from the outgoing set
 /// </summary>
 public void RemoveFromOutgoingSet(atom a)
 {
     RemoveFromSet(a, atoms_outgoing);
 }
Esempio n. 13
0
 /// <summary>
 /// removes an atom from the incoming set
 /// </summary>
 public void RemoveFromIncomingSet(atom a)
 {
     RemoveFromSet(a, atoms_incoming);
 }
Esempio n. 14
0
 /// <summary>
 /// adds an atom to the outgoing set
 /// </summary>
 public void AddToOutgoingSet(atom a)
 {
     AddToSet(a, ref atoms_outgoing);
 }
Esempio n. 15
0
 /// <summary>
 /// adds an atom to the incoming set
 /// </summary>
 public void AddToIncomingSet(atom a)
 {
     AddToSet(a, ref atoms_incoming);
 }
Esempio n. 16
0
        /// <summary>
        /// inserts the given atom into the atom name index
        /// </summary>
        private void UpdateIndexAtomName(atom a, int atoms_index)
        {
            bool found = false;
            String name = a.GetName();

            if (name != null)
            {
                if (name != "")
                {
                    int i = 0;
                    while ((i < index_atom_name.Count) && (!found))
                    {
                        int idx = (int)index_atom_name[i];
                        atom a2 = (atom)atoms[idx];
                        string a2_name = a2.GetName();
                        if (a2_name.CompareTo(name) > 0)
                        {
                            index_atom_name.Insert(i, atoms_index);
                            found = true;
                        }
                        i++;
                    }
                }
            }

            if (!found)
                index_atom_name.Add(atoms_index);
        }
Esempio n. 17
0
        /// <summary>
        /// inserts the given atom into the atom type index
        /// </summary>
        private void UpdateIndexAtomType(atom a)
        {
            int type = a.GetAtomTypeInt32();

            // add any new lists if needed
            for (int i = index_atom_type.Count; i <= type; i++)
                index_atom_type.Add(new ArrayList());

            ArrayList typelist = (ArrayList)index_atom_type[type];
            typelist.Add(a);
        }
Esempio n. 18
0
 /// <summary>
 /// returns the position within a continous range of the given atom
 /// the range is typically 0.0 - 1.0
 /// </summary>
 public float GetPositionWithinRange(atom a)
 {
     int index = atoms.IndexOf(a);
     return(GetPositionWithinRange(index));
 }
Esempio n. 19
0
 /// <summary>
 /// removes the given atom from the collection
 /// </summary>
 public virtual void Remove(atom a)
 {
     RemoveMember(a);
 }
Esempio n. 20
0
        /// <summary>
        /// returns a measure of the similarity between the two given atoms
        /// </summary>
        protected virtual float GetDifference(atom exemplar, atom candidate)
        {
            float exemplar_value = 0;
            float candidate_value = 0;
            float diff = 0;

            if (search_parameter == "weight")
            {
                exemplar_value = ((link)exemplar).GetWeight();
                candidate_value = ((link)candidate).GetWeight();
                diff = exemplar_value - candidate_value;
            }

            if (search_parameter == "importance")
            {
                int importance_level = search_parameter_index;
                exemplar_value = exemplar.GetImportance(importance_level);
                candidate_value = candidate.GetImportance(importance_level);
                diff = exemplar_value - candidate_value;
            }

            if (search_parameter == "energy")
            {
                exemplar_value = exemplar.GetEnergy();
                candidate_value = candidate.GetEnergy();
                diff = exemplar_value - candidate_value;
            }

            if (search_parameter == "average")
            {
                exemplar_value = exemplar.atom_value.GetAverage();
                candidate_value = candidate.atom_value.GetAverage();
                diff = exemplar_value - candidate_value;
            }

            if (search_parameter == "truth")
            {
                exemplar_value = exemplar.atom_value.GetValue();
                candidate_value = candidate.atom_value.GetValue();
                diff = exemplar_value - candidate_value;
            }

            // the start time of the candidate must be between the
            // start and end time of the exemplar
            if (search_parameter == "start time")
            {
                if ((exemplar.GetFlag(atom.FLAG_TEMPORAL)) && (exemplar.GetFlag(atom.FLAG_IS_NODE)))
                {
                    if ((candidate.GetFlag(atom.FLAG_TEMPORAL)) && (candidate.GetFlag(atom.FLAG_IS_NODE)))
                    {
                        nodeTemporal exemplarTemporal = (nodeTemporal)exemplar;
                        nodeTemporal candidateTemporal = (nodeTemporal)candidate;
                        TimeSpan time_diff = candidateTemporal.node_event.start_time.Subtract(exemplarTemporal.node_event.start_time);
                        if (time_diff.TotalSeconds >= 0)
                        {
                            if (candidateTemporal.node_event.start_time < exemplarTemporal.node_event.end_time)
                            {
                                diff = (float)time_diff.TotalSeconds;
                            }
                            else diff = INVALID;
                        }
                        else diff = INVALID;
                    }
                }
            }

            // the end time of the candidate must be between the
            // start and end time of the exemplar
            if (search_parameter == "end time")
            {
                if ((exemplar.GetFlag(atom.FLAG_TEMPORAL)) && (exemplar.GetFlag(atom.FLAG_IS_NODE)))
                {
                    if ((candidate.GetFlag(atom.FLAG_TEMPORAL)) && (candidate.GetFlag(atom.FLAG_IS_NODE)))
                    {
                        nodeTemporal exemplarTemporal = (nodeTemporal)exemplar;
                        nodeTemporal candidateTemporal = (nodeTemporal)candidate;
                        TimeSpan time_diff = candidateTemporal.node_event.start_time.Subtract(exemplarTemporal.node_event.start_time);
                        if (time_diff.TotalSeconds >= 0)
                        {
                            if (candidateTemporal.node_event.end_time < exemplarTemporal.node_event.end_time)
                            {
                                diff = (float)time_diff.TotalSeconds;
                            }
                            else diff = INVALID;
                        }
                        else diff = INVALID;
                    }
                }
            }

            // the start and end time of the candidate must be between the
            // start and end time of the exemplar
            if (search_parameter == "within time")
            {
                if ((exemplar.GetFlag(atom.FLAG_TEMPORAL)) && (exemplar.GetFlag(atom.FLAG_IS_NODE)))
                {
                    if ((candidate.GetFlag(atom.FLAG_TEMPORAL)) && (candidate.GetFlag(atom.FLAG_IS_NODE)))
                    {
                        nodeTemporal exemplarTemporal = (nodeTemporal)exemplar;
                        nodeTemporal candidateTemporal = (nodeTemporal)candidate;

                        TimeSpan time_diff = candidateTemporal.node_event.Within(exemplarTemporal.node_event);
                        if (time_diff != TimeSpan.Zero)
                            diff = (float)time_diff.TotalSeconds;
                        else
                            diff = INVALID;
                    }
                }
            }

            if (search_parameter == "activation")
            {
                float[] exemplar_values = exemplar.GetActivation();
                float[] candidate_values = candidate.GetActivation();
                int hits = 0;

                if ((exemplar_values != null) &&
                    (candidate_values != null))
                {
                    // compare each channel
                    for (int i = 0; i < exemplar_values.Length; i++)
                    {
                        if ((exemplar_values[i] != 0) &&
                            (candidate_values[i] != 0))
                        {
                            diff += (exemplar_values[i] - candidate_values[i]);
                            hits++;
                        }
                    }
                }

                if (hits == 0)
                    diff = INVALID;
                else
                    diff /= hits;  // average over all channels
            }

            float similarity = diff * diff;
            return(similarity);
        }