/// <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);
        }
Ejemplo n.º 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>());
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 10
0
 /// @return OptimizingPoint	an minimizing point strategy.
 public override OptimizingPoint CreatePoint(double x, IOneVariableFunction f)
 {
     return(new MinimizingPoint(x, f));
 }
Ejemplo n.º 11
0
 /// Constructor method.
 /// @param func the function for which the derivative is computed.
 public FunctionDerivative(IOneVariableFunction func) : this(func, 0.000001)
 {
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 16
0
 /// @return DhbOptimizing.OptimizingPoint
 /// @param x double
 /// @param f IOneVariableFunction
 public abstract OptimizingPoint CreatePoint(double x, IOneVariableFunction f);
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 19
0
 protected FunctionalIterator(IOneVariableFunction func)
 {
     this.Function = func;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 22
0
 public BisectionZeroFinder(IOneVariableFunction func)
     : base(func)
 {
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 24
0
 /// @param func DhbInterfaces.OneVariableFunction
 public BisectionZeroFinder(IOneVariableFunction func) : base(func)
 {
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 26
0
 /// Constructor method.
 /// @param x double
 /// @param f DhbInterfaces.IOneVariableFunction
 public MinimizingPoint(double x, IOneVariableFunction f) : base(x, f)
 {
 }
Ejemplo n.º 27
0
 /// Generic constructor.
 /// @param func OneVariableFunction
 /// @param start double
 public FunctionalIterator(IOneVariableFunction func)
 {
     this.Function = func;
 }
Ejemplo n.º 28
0
 /// Constructor method.
 /// @param func the function for which the derivative is computed.
 public FunctionDerivative(IOneVariableFunction func)
     : this(func, 0.000001)
 {
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
        }