Ejemplo n.º 1
0
 /// <summary>
 /// Checks if the given <paramref name="featureIndex"/> is fixed to the 'other' genome.
 /// </summary>
 /// <param name="featureIndex">
 /// The feature index.
 /// </param>
 /// <param name="currentGenomeType">
 /// The current genome type.
 /// </param>
 /// <param name="featureFixations">
 /// The feature fixations.
 /// </param>
 /// <returns>
 /// <c>True</c>, iff <paramref name="featureFixations"/> contains a fixation to the 'other' parent (for the current
 ///     <paramref name="featureIndex"/>).
 /// </returns>
 private static bool IsFixedToDifferentGenome(
     int featureIndex,
     TargetLeafGenomeFixation currentGenomeType,
     Dictionary <int, TargetLeafGenomeFixation> featureFixations)
 {
     return(featureFixations.ContainsKey(featureIndex) && featureFixations[featureIndex] != currentGenomeType);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if the given <paramref name="parentToCheck"/> can follow the current tree path.
        /// </summary>
        /// <param name="parents">
        /// The converted parent genomes.
        /// </param>
        /// <param name="tree">
        /// The tree.
        /// </param>
        /// <param name="currentNodeAndFixations">
        /// The current node and feature fixations.
        /// </param>
        /// <param name="parentToCheck">
        /// The parent to check.
        /// </param>
        /// <param name="indexSetsForCategoricalFeaturesInDoubleRepresentation">
        /// The index sets for categorical features in double representation.
        /// </param>
        /// <param name="queue">
        /// The queue of open nodes to traverse.
        ///     If the <paramref name="parentToCheck"/> can continue (i.e. the current node's feature is not fixed to the 'other'
        ///     parent),
        ///     the child node that is visited by <paramref name="parentToCheck"/> will be added (and fixed to the
        ///     <paramref name="parentToCheck"/>).
        /// </param>
        private static void AddTreeNodeAndFixationsIfParentCanContinue(
            ParentGenomesConverted parents,
            GenomePredictionTree tree,
            TreeNodeAndFixations currentNodeAndFixations,
            TargetLeafGenomeFixation parentToCheck,
            Dictionary <int, HashSet <int> > indexSetsForCategoricalFeaturesInDoubleRepresentation,
            List <TreeNodeAndFixations> queue)
        {
            var canParentToCheckContinue = CheckIfGenomeCanContinueAlone(currentNodeAndFixations, parentToCheck);

            if (!canParentToCheckContinue)
            {
                return;
            }

            var currentParent  = parents.GetParentToFollow(parentToCheck);
            var currentNode    = currentNodeAndFixations.CurrentNode;
            var parentGoesLeft = CheckIfParentGoesLeft(currentParent, currentNode);
            var nextNodeInPath = tree.Nodes[parentGoesLeft ? currentNode.LeftIndex : currentNode.RightIndex];
            var competitiveChildNodeAndFixation = new TreeNodeAndFixations(
                nextNodeInPath,
                currentNodeAndFixations.FixedIndicesInDoubleRepresentation);

            // now add fixation
            if (!indexSetsForCategoricalFeaturesInDoubleRepresentation.ContainsKey(currentNode.FeatureIndex))
            {
                competitiveChildNodeAndFixation.FixedIndicesInDoubleRepresentation[currentNode.FeatureIndex] = parentToCheck;
            }
            else
            {
                // fix all columns of a feature, when one of them is used for a split.
                var allFeatureIndices = indexSetsForCategoricalFeaturesInDoubleRepresentation[currentNode.FeatureIndex];

                foreach (var categoricalFeatureIndex in allFeatureIndices)
                {
                    competitiveChildNodeAndFixation.FixedIndicesInDoubleRepresentation[categoricalFeatureIndex] = parentToCheck;
                }
            }

            queue.Add(competitiveChildNodeAndFixation);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks if parent can continue alone.
        ///     I.e. the current node's split feature index is not fixed to the 'other' parent.
        /// </summary>
        /// <param name="currentNodeAndFixations">
        /// The current node and fixations.
        /// </param>
        /// <param name="parentToCheck">
        /// The parent to check.
        /// </param>
        /// <returns>
        /// <c>True</c>, iff the current node's split feature index is not fixed to the 'other' parent.
        /// </returns>
        private static bool CheckIfGenomeCanContinueAlone(TreeNodeAndFixations currentNodeAndFixations, TargetLeafGenomeFixation parentToCheck)
        {
            var currentFeatureIndex = currentNodeAndFixations.CurrentNode.FeatureIndex;

            return(!IsFixedToDifferentGenome(currentFeatureIndex, parentToCheck, currentNodeAndFixations.FixedIndicesInDoubleRepresentation));
        }
 /// <summary>
 /// Gets the parent to follow.
 /// </summary>
 /// <param name="computeFixationFor">
 /// The fixation to check.
 /// </param>
 /// <returns>
 /// The <see cref="GenomeDoubleRepresentation"/>.
 /// </returns>
 public GenomeDoubleRepresentation GetParentToFollow(TargetLeafGenomeFixation computeFixationFor)
 {
     return(computeFixationFor == TargetLeafGenomeFixation.FixedToCompetitiveParent
                ? this.CompetitiveParent
                : this.NonCompetitiveParent);
 }