/// <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); }
/// <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>()); }
/// <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; }
/// 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(); } }
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; }
/// @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; }
/// 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; }
/// @return OptimizingPoint an minimizing point strategy. public override OptimizingPoint CreatePoint(double x, IOneVariableFunction f) { return(new MinimizingPoint(x, f)); }
/// Constructor method. /// @param func the function for which the derivative is computed. public FunctionDerivative(IOneVariableFunction func) : this(func, 0.000001) { }
/// 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(); } }
/// 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; }
/// 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; }
/// @return DhbOptimizing.OptimizingPoint /// @param x double /// @param f IOneVariableFunction public abstract OptimizingPoint CreatePoint(double x, IOneVariableFunction f);
/// 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); }
/// <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)); }
protected FunctionalIterator(IOneVariableFunction func) { this.Function = func; }
/// Constructor method /// @param func IOneVariableFunction /// @param pointCreator OptimizingPointFactory a factory to create /// strategy points public OneVariableFunctionOptimizer(IOneVariableFunction func, OptimizingPointFactory pointCreator) : base(func) { _pointFactory = pointCreator; }
public BisectionZeroFinder(IOneVariableFunction func) : base(func) { }
/// @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; }
/// @param func DhbInterfaces.OneVariableFunction public BisectionZeroFinder(IOneVariableFunction func) : base(func) { }
/// Constructor method. /// @param x double /// @param f DhbInterfaces.IOneVariableFunction public MinimizingPoint(double x, IOneVariableFunction f) : base(x, f) { }
/// Generic constructor. /// @param func OneVariableFunction /// @param start double public FunctionalIterator(IOneVariableFunction func) { this.Function = func; }
/// @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); }