public ConvexBound UpperBound(Vector initialVector, double threshold)
        {
            ClosestPointFromPoint closestPoint = (point, nodeId) =>
            {
                var currentSum = Compute(point);
                if (currentSum <= 0.0000000001)
                {
                    return(threshold);
                }

                var desiredSum = threshold;
                var mulBy      = Math.Sqrt(threshold / currentSum);
                var result     = point * mulBy;
                return(result);
            };

            return(ConvexBoundBuilder.Create(MonitoredFunction.Function, Compute, ConvexBound.Type.UpperBound, threshold)
                   .WithDistanceNorm(2, closestPoint)
                   .ToConvexBound());
        }
Esempio n. 2
0
        public ConvexBound LowerBound(Vector initialVector, double threshold)
        {
            if (threshold <= 0)
            {
                ClosestPointFromPoint closestPoint = (pt, nodeId) => double.MaxValue;
                return(ConvexBoundBuilder.Create(MonitoredFunction.Function, Compute, ConvexBound.Type.LoweBound, double.NegativeInfinity)
                       .WithDistanceNorm(1, closestPoint)
                       .WithDistanceNorm(2, closestPoint)
                       .ToConvexBound());
            }

            var currentNorm  = Compute(initialVector);
            var newPointNorm = threshold;
            var mulBy        = Math.Sqrt(newPointNorm / currentNorm);
            var point        = initialVector * mulBy;

            var constantPart  = -currentNorm;
            var parameters    = initialVector * 2;
            var lineHalfPlane = LineHalfPlane.Create(parameters, constantPart, threshold, Dimension);

            return(lineHalfPlane.ToConvexLowerBound(MonitoredFunction.Function, threshold));
        }
 public ConvexBoundBuilder WithDistanceNorm(int norm, ClosestPointFromPoint closestPointFunction)
 {
     this.GetClosestPointOfNorm[norm] = closestPointFunction;
     return(this);
 }