Esempio n. 1
0
 public StepFunction(StepFunction <double> steps)
 {
     evaluator = steps;
     abscissae = steps.Pillars;
     values    = steps.Values;
     leftValue = steps.LeftValue;
 }
Esempio n. 2
0
 public StepFunction(double[] abscissae, double[] values, double leftValue)
 {
     evaluator      = new StepFunction <double>(abscissae, values, leftValue);
     this.abscissae = abscissae;
     this.values    = values;
     this.leftValue = leftValue;
 }
        public override RrFunction Add(RrFunction other)
        {
            var cst = other as ConstantRrFunction;

            if (cst != null)
            {
                return(RrFunctions.Constant(Value + cst.Value));
            }

            var step = other as StepFunction;

            if (step != null)
            {
                return(StepFunction.Add(step, this));
            }

            var spline = other as SplineInterpoler;

            if (spline != null)
            {
                return(SplineInterpoler.Add(spline, this));
            }

            return(base.Add(other));
        }
Esempio n. 4
0
 public WeightedStepFunction(RrFunction weight, double[] abscissae, double[] values, double leftValue)
 {
     this.weight    = weight;
     this.abscissae = abscissae;
     this.values    = values;
     this.leftValue = leftValue;
     stepEval       = new StepFunction <double>(abscissae, values, leftValue);
 }
Esempio n. 5
0
        private static RrFunction BinaryOp(StepFunction left, StepFunction right,
                                           Func <double, double, double> binaryOp)
        {
            var mergedAbscissae = left.abscissae.Union(right.abscissae).OrderBy(p => p).ToArray();
            var multValues      = mergedAbscissae.Map(p => binaryOp(left.Eval(p), right.Eval(p)));
            var multLeftValue   = binaryOp(left.Eval(double.NegativeInfinity), right.Eval(double.NegativeInfinity));

            return(new StepFunction(mergedAbscissae, multValues, multLeftValue));
        }
Esempio n. 6
0
        public static RrFunction Add(StepFunction step, ConstantRrFunction cst)
        {
            if (DoubleUtils.EqualZero(cst.Value))
            {
                return(step);
            }

            var shiftedValues = step.values.Map(v => v + cst.Value);

            return(new StepFunction(step.abscissae, shiftedValues, step.leftValue + cst.Value));
        }
Esempio n. 7
0
        public static RrFunction Mult(StepFunction step, ConstantRrFunction cst)
        {
            if (DoubleUtils.MachineEquality(cst.Value, 1.0))
            {
                return(step);
            }

            if (DoubleUtils.EqualZero(cst.Value))
            {
                return(RrFunctions.Zero);
            }

            var multValues = step.values.Map(v => v * cst.Value);

            return(new StepFunction(step.abscissae, multValues, step.leftValue * cst.Value));
        }
Esempio n. 8
0
        public override RrFunction Integral(double basePoint)
        {
            var weightIntegral = weight.Integral(basePoint);

            var    stepPartVals = new double[abscissae.Length];
            double prev         = 0.0;

            for (int i = 0; i < abscissae.Length; i++)
            {
                prev           += weightIntegral.Eval(abscissae[i]) * (values[i] - (i > 0 ? values[i - 1] : leftValue));
                stepPartVals[i] = -prev;
            }

            RrFunction stepPart = new StepFunction(abscissae, stepPartVals, 0.0);

            var unbasedResult = new WeightedStepFunction(weightIntegral, abscissae, values, leftValue) + stepPart;

            return(unbasedResult - unbasedResult.Eval(basePoint));
        }
        public override RrFunction Mult(RrFunction other)
        {
            var cst = other as ConstantRrFunction;

            if (cst != null)
            {
                return(ProductRrFunctions.Mult(this, cst));
            }

            var exp = other as ExpRrFunction;

            if (exp != null)
            {
                return(ProductRrFunctions.Mult(exp, this));
            }

            var step = other as StepFunction;

            if (step != null)
            {
                return(StepFunction.Mult(step, this));
            }

            var spline = other as SplineInterpoler;

            if (spline != null)
            {
                return(SplineInterpoler.Mult(spline, this));
            }

            var lc = other as LinearCombinationRrFunction;

            if (lc != null)
            {
                return(ProductRrFunctions.Mult(lc, this));
            }

            return(base.Mult(other));
        }
Esempio n. 10
0
 public static RrFunction Add(StepFunction left, StepFunction right)
 {
     return(BinaryOp(left, right, (l, r) => l + r));
 }
Esempio n. 11
0
 public static RrFunction Mult(StepFunction leftStep, StepFunction rightStep)
 {
     return(BinaryOp(leftStep, rightStep, (l, r) => l * r));
 }