public void UpdateFromChildren()
        {
            if (this.lowerChild == null || this.upperChild == null)
            {
                this.depthFromLeaves = 0;
                this.totalError      = 0;
                return;
            }
            double lowerError = this.lowerChild.totalError;
            double upperError = this.upperChild.totalError;
            double difference;
            IDatapoint <ScoreType> nextPoint     = this.upperChild.minPoint;
            IDatapoint <ScoreType> previousPoint = this.lowerChild.maxPoint;

            if (nextPoint != null && previousPoint != null)
            {
                double nextScore     = this.scoreHandler.ConvertToDistribution(nextPoint.Item).Mean;
                double previousScore = this.scoreHandler.ConvertToDistribution(previousPoint.Item).Mean;
                difference  = Math.Abs(nextScore - previousScore);
                difference *= difference;
            }
            else
            {
                difference = 0;
            }
            this.totalError = lowerError + difference + upperError;

            this.depthFromLeaves = Math.Max(this.lowerChild.depthFromLeaves, this.upperChild.depthFromLeaves) + 1;
        }
Example #2
0
        // adds a datapoint and does not consider splitting
        private void AddPointNowWithoutSplitting(IDatapoint <SummaryType> newDatapoint)
        {
            // keep track of the outputs we've observed
            this.itemSummary = this.scoreHandler.Combine(this.itemSummary, newDatapoint.Item);
            //this.scores = this.scores.Plus(newDatapoint.Score);
#if CACHE_STDDEV
            int i;
            for (i = 0; i < this.inputs.Length; i++)
            {
                this.inputs[i] = this.inputs[i].Plus(newDatapoint.InputCoordinates[i]);
            }
#endif

            // if this datapoint falls outside our promised boundary, then expand our boundary to include it
            if (this.observedBoundary == null)
            {
                this.observedBoundary = new HyperBox <SummaryType>(newDatapoint);
            }
            else
            {
                this.observedBoundary.ExpandToInclude(newDatapoint);
            }
            if (this.currentBoundary == null)
            {
                this.currentBoundary = new HyperBox <SummaryType>(newDatapoint);
            }
            else
            {
                this.currentBoundary.ExpandToInclude(newDatapoint);
            }
            // add it to our set
            //this.datapointsByOutput.Add(newDatapoint, Distribution.MakeDistribution(newDatapoint.Output, 0, 1));
            this.datapoints.Add(newDatapoint);
            //if (this.datapointsByInput != null)
            //    this.datapointsByInput.Add(newDatapoint, newDatapoint);

            /*
             * foreach (SimpleInterpolationBox box in this.simpleChildren)
             * {
             *  box.AddDatapoint(newDatapoint);
             * }
             */
            if (this.lowerChild != null)
            {
                if (newDatapoint.InputCoordinates[this.splitDimension] > this.lowerChild.currentBoundary.Coordinates[this.splitDimension].HighCoordinate)
                {
                    this.upperChild.AddDatapoint(newDatapoint);
                }
                else
                {
                    this.lowerChild.AddDatapoint(newDatapoint);
                }
#if MIN_SPLIT_COUNTS
                this.UpdateSplitCounts();
#endif
            }
        }
        public HyperBox(IDatapoint <SummaryType> onlyPoint)
        {
            this.Coordinates = new FloatRange[onlyPoint.NumInputDimensions];
            int i;

            for (i = 0; i < onlyPoint.NumInputDimensions; i++)
            {
                this.Coordinates[i] = new FloatRange(onlyPoint.InputCoordinates[i], true, onlyPoint.InputCoordinates[i], true);
            }
        }
Example #4
0
        public static Datapoint <T> From <T>(IDatapoint val)
            where T : struct
        {
            if (!(val is Datapoint <T>))
            {
                throw new ArgumentException($"Cannot create a Datapoint<{typeof(T).Name}> from the provided {val.GetType().Name}!");
            }

            return(Operator.Convert <IDatapoint, Datapoint <T> >(val));
        }
        public void AddDatapoint(IDatapoint <SummaryType> newDatapoint)
        {
            if (newDatapoint.NumInputDimensions != this.root.NumDimensions)
            {
                throw new ArgumentException("the number of dimensions is incorrect");
            }
            this.root.AddDatapoint(newDatapoint);

            // Inform the root node that it may now be allowed to delegate the intensive analysis to a further descendent
            this.updateNumExemptSplits();
        }
        public void ExpandToInclude(IDatapoint <SummaryType> newPoint)
        {
            int i;

            for (i = 0; i < this.NumDimensions; i++)
            {
                if (this.Coordinates[i] == null)
                {
                    this.Coordinates[i] = new FloatRange(newPoint.InputCoordinates[i]);
                }
                else
                {
                    this.Coordinates[i].ExpandToInclude(newPoint.InputCoordinates[i]);
                }
            }
        }
Example #7
0
 public bool RemoveDatapoint(IDatapoint <SummaryType> datapoint)
 {
     if (this.pendingDatapoints.Contains(datapoint))
     {
         this.pendingDatapoints.Remove(datapoint);
         return(true);    // removed successfully
     }
     if (!this.datapoints.Remove(datapoint))
     {
         return(false);   // datapoint was not removed
     }
     this.itemSummary = this.scoreHandler.Remove(this.itemSummary, datapoint.Item);
     // We should update the observed boundary here, but it's not too much of a problem if we don't
     // Furthermore, the only project that currently (2012-10-20) uses this project will always re-insert the datapoint with the same inputs anyway
     if (this.lowerChild != null)
     {
         this.lowerChild.RemoveDatapoint(datapoint);
     }
     if (this.upperChild != null)
     {
         this.upperChild.RemoveDatapoint(datapoint);
     }
     return(true);
 }
 public IDatapoint <ScoreType> Combine(IDatapoint <ScoreType> a, IDatapoint <ScoreType> b)
 {
     return(null);
 }
 public void RemoveDatapoint(IDatapoint <SummaryType> datapoint)
 {
     this.root.RemoveDatapoint(datapoint);
 }
Example #10
0
 // adds a datapoint
 public void AddDatapoint(IDatapoint <SummaryType> newDatapoint)
 {
     this.pendingDatapoints.Add(newDatapoint);
 }
Example #11
0
 public bool Contains(IDatapoint <SummaryType> datapoint)
 {
     return(this.Contains(datapoint.InputCoordinates));
 }