/// <summary>
        /// Accepts operation
        /// </summary>
        /// <param name="detector">Operation detector</param>
        /// <param name="type">Operation type</param>
        /// <returns>Operation</returns>
        public static IObjectOperation Accept(OneVariableFunctionDetector detector, object type)
        {
            if (type is IOneVariableFunction)
            {
                try
                {
                    IOneVariableFunction g = type as IOneVariableFunction;
                    return(new OneVariableReturn(OneVariableFuntionCompostion.Compose(g, detector.f)));
                }
                catch (Exception)
                {
                }
            }
            if (detector.f == null)
            {
                return(null);
            }
            if (type == null)
            {
                return(new OneVariableReturn(detector.f));
            }
            object t = detector.f.VariableType;

            if (!type.Equals(t))
            {
                return(null);
            }
            return(detector.f);
        }
예제 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="symbol">Symbol of variable</param>
        /// <param name="measure">Measure</param>
        /// <param name="detector">Detector of variables</param>
        internal VariableMeasurement(string symbol, IMeasurement measure, IVariableDetector detector)
        {
            this.symbol      = symbol;
            this.measurement = measure;
            this.detector    = detector;
            object par = measure.Type;

            if (par is IOneVariableFunction)
            {
                func = par as IOneVariableFunction;
                operationDetector = new OneVariableFunctionDetector(detector);
                funcwrapper       = new OneVariableFunctionDetector(func);
            }
            else if (par is Table2D)
            {
                table2D = par as Table2D;
            }
            else if (par is Table3D)
            {
                table3D = par as Table3D;
            }

            /*!!!   else if (par is FuncReturn)
             * {
             *     funcReturn = par as FuncReturn;
             *     //operationDetector = new FormulaEditor.Func.FuncDetector(detector,  )
             * }*/
            else
            {
                acceptor = this;
            }
            tree = new ObjectFormulaTree(this, new List <ObjectFormulaTree>());
        }
예제 #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="f">The f</param>
 /// <param name="g">The g</param>
 private OneVariableFuntionCompostion(IOneVariableFunction f, IOneVariableFunction g)
 {
     if (!f.ReturnType.Equals(g.VariableType))
     {
         throw new Exception();
     }
     this.f = f;
     this.g = g;
     fo     = f;
     go     = g;
 }
예제 #4
0
        /// Initializes internal parameters to start the iterative process.
        /// Assigns default derivative if necessary.
        public override void InitializeIterations()
        {
            if (_df == null)
            {
                _df = new FunctionDerivative(_f);
            }
            if (double.IsNaN(_result))
            {
                _result = 0;
            }
            int    n      = 0;
            Random random = new Random();

            while (DhbMath.Equal(_df.Value(_result), 0))
            {
                if (++n > MaximumIterations)
                {
                    break;
                }
                _result += random.NextDouble();
            }
        }
예제 #5
0
 IObjectOperation IOperationAcceptor.Accept(object type)
 {
     /**!!!!        if (funcReturn != null)
      *      {
      *          IOperationDetector d = new FormulaEditor.Func.FuncDetector(funcReturn, measurement.Parameter());
      *      }
      */
     if (func != null)
     {
         func        = measurement.Parameter() as IOneVariableFunction;
         funcwrapper = new OneVariableFunctionDetector(func);
         return(OneVariableFunctionDetector.Accept(funcwrapper, type));
     }
     if (table2D != null)
     {
         return(table2D);
     }
     if (table3D != null)
     {
         return(table3D);
     }
     return(this);
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="f">The detected function</param>
 public OneVariableFunctionDetector(IOneVariableFunction f)
 {
     this.f = f;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="f">The function to return</param>
 internal OneVariableReturn(IOneVariableFunction f)
 {
     this.f = f;
 }
예제 #8
0
 /// @param func DhbInterfaces.OneVariableFunction
 /// @param x1 location at which the function yields a negative value
 /// @param x2 location at which the function yields a positive value
 public BisectionZeroFinder(IOneVariableFunction func, double x1, double x2)
     : this(func)
 {
     this.NegativeX = x1;
     this.PositiveX = x2;
 }
예제 #9
0
 /// Constructor method.
 /// @param func the function for which the derivative is computed.
 /// @param precision the relative step used to compute the derivative.
 public FunctionDerivative(IOneVariableFunction func, double precision)
 {
     _f = func;
     _relativePrecision = precision;
 }
예제 #10
0
 /// @return OptimizingPoint	an minimizing point strategy.
 public override OptimizingPoint CreatePoint(double x, IOneVariableFunction f)
 {
     return(new MinimizingPoint(x, f));
 }
예제 #11
0
 /// Constructor method.
 /// @param func the function for which the derivative is computed.
 public FunctionDerivative(IOneVariableFunction func) : this(func, 0.000001)
 {
 }
예제 #12
0
 /// Initializes internal parameters to start the iterative process.
 /// Assigns default derivative if necessary.
 public override void InitializeIterations()
 {
     if (_df == null)
         _df = new FunctionDerivative(Function);
     if (double.IsNaN(_result))
         _result = 0;
     int n = 0;
     var random = new Random();
     while (DhbMath.Equal(_df.Value(_result), 0))
     {
         if (++n > MaximumIterations)
             break;
         _result += random.NextDouble();
     }
 }
예제 #13
0
 /// Constructor method.
 /// @param func the function for which the zero will be found.
 /// @param start the initial value for the search.
 public NewtonZeroFinder(IOneVariableFunction func, double start) : base(func)
 {
     StartingValue = start;
 }
예제 #14
0
 /// Constructor method.
 /// @param func the function for which the zero will be found.
 /// @param start the initial value for the search.
 public NewtonZeroFinder(IOneVariableFunction func, double start)
     : base(func)
 {
     StartingValue = start;
 }
예제 #15
0
 /// Constructor method.
 /// @param func the function for which the zero will be found.
 /// @param dFunc derivative of func.
 /// @param start the initial value for the search.
 public NewtonZeroFinder(IOneVariableFunction func,
                             IOneVariableFunction dFunc, double start)
     : this(func, start)
 {
     this.Derivative = dFunc;
 }
예제 #16
0
 /// @return DhbOptimizing.OptimizingPoint
 /// @param x double
 /// @param f IOneVariableFunction
 public abstract OptimizingPoint CreatePoint(double x, IOneVariableFunction f);
예제 #17
0
 /// Constructor method
 /// @param x double	position at which the goal function is evaluated.
 /// @param f IOneVariableFunction	function to optimize.
 public OptimizingPoint(double x, IOneVariableFunction f)
 {
     _position = x;
     _value    = f.Value(x);
 }
예제 #18
0
 /// <summary>
 /// Composition g * f;
 /// </summary>
 /// <param name="f">The f</param>
 /// <param name="g">The g</param>
 /// <returns>The composition</returns>
 static public IOneVariableFunction Compose(IOneVariableFunction f, IOneVariableFunction g)
 {
     return(new OneVariableFuntionCompostion(f, g));
 }
예제 #19
0
 protected FunctionalIterator(IOneVariableFunction func)
 {
     this.Function = func;
 }
예제 #20
0
 /// Constructor method.
 /// @param func the function for which the zero will be found.
 /// @param dFunc derivative of func.
 /// @param start the initial value for the search.
 public NewtonZeroFinder(IOneVariableFunction func,
                         IOneVariableFunction dFunc, double start) : this(func, start)
 {
     this.Derivative = dFunc;
 }
예제 #21
0
 /// Constructor method
 /// @param func IOneVariableFunction
 /// @param pointCreator OptimizingPointFactory	a factory to create
 ///													strategy points
 public OneVariableFunctionOptimizer(IOneVariableFunction func,
                                     OptimizingPointFactory pointCreator)
     : base(func)
 {
     _pointFactory = pointCreator;
 }
예제 #22
0
 public BisectionZeroFinder(IOneVariableFunction func)
     : base(func)
 {
 }
예제 #23
0
 /// @return double	contribution to chi^2 sum against
 ///												a theoretical function
 /// @param f DhbInterfaces.OneVariableFunction
 public double Chi2Contribution(IOneVariableFunction f)
 {
     double residue = _yValue - f.Value(_xValue);
     return residue * residue * _weight;
 }
예제 #24
0
 /// @param func DhbInterfaces.OneVariableFunction
 public BisectionZeroFinder(IOneVariableFunction func) : base(func)
 {
 }
예제 #25
0
 /// Constructor method.
 /// @param func the function for which the derivative is computed.
 /// @param precision the relative step used to compute the derivative.
 public FunctionDerivative(IOneVariableFunction func, double precision)
 {
     _f = func;
     _relativePrecision = precision;
 }
예제 #26
0
 /// Constructor method.
 /// @param x double
 /// @param f DhbInterfaces.IOneVariableFunction
 public MinimizingPoint(double x, IOneVariableFunction f) : base(x, f)
 {
 }
예제 #27
0
 /// Generic constructor.
 /// @param func OneVariableFunction
 /// @param start double
 public FunctionalIterator(IOneVariableFunction func)
 {
     this.Function = func;
 }
예제 #28
0
 /// Constructor method.
 /// @param func the function for which the derivative is computed.
 public FunctionDerivative(IOneVariableFunction func)
     : this(func, 0.000001)
 {
 }
예제 #29
0
 /// @param func DhbInterfaces.OneVariableFunction
 /// @param x1 location at which the function yields a negative value
 /// @param x2 location at which the function yields a positive value
 public BisectionZeroFinder(IOneVariableFunction func, double x1, double x2)
     : this(func)
 {
     this.NegativeX = x1;
     this.PositiveX = x2;
 }
예제 #30
0
        /// @return double	contribution to chi^2 sum against
        ///												a theoretical function
        /// @param f DhbInterfaces.OneVariableFunction
        public double Chi2Contribution(IOneVariableFunction f)
        {
            double residue = _yValue - f.Value(_xValue);

            return(residue * residue * _weight);
        }