private void CheckAnswerValidation()
        {
            _answ = _right - _left;

            _fxList.Add(FunctionHolder.GetAimFunctionResult(_xm));
            _xList.Add(_xm);

            if (_answ < _epsilon)
            {
                for (int i = 1; i < _fxList.Count; i++)
                {
                    Debug.WriteLine($"i = {i}\n" +
                                    $"x = {String.Format("{0:F16}", _xList.ElementAt(i))}\n" +
                                    $"F(x) = {String.Format("{0:F16}", _fxList.ElementAt(i))}\n" +
                                    $"____________________________________________________________");
                }

                Debug.WriteLine($"x = {_xList.ElementAt(_xList.Count - 1)}\n" +
                                $"fmin =  {FunctionHolder.GetAimFunctionResult(_xm)}");
            }
            else
            {
                AssignX1X2();
            }
        }
Ejemplo n.º 2
0
        private void AssignFunction()
        {
            _xiPlusOne = _xi - (FunctionHolder.GetFunctionDerivative(_xi) / FunctionHolder.GetFunctionDoubleDerivative(_xi));

            _xList.Add(_xi);
            _xiPlusOneList.Add(_xiPlusOne);

            CheckAnswerValidation();
        }
 private void CheckAnswerValidation()
 {
     if (_answer < _epsilon)
     {
         for (int i = 0; i < _xList.Count; i++)
         {
             Debug.WriteLine($"i = {i}\n" +
                             $"x = {String.Format("{0:F16}", _xList.ElementAt(i))}\n" +
                             $"F(x) = {String.Format("{0:F16}", _fxList.ElementAt(i))}\n" +
                             $"____________________________________________________________");
         }
         Debug.WriteLine($"x = {_xList.ElementAt(_xList.Count - 1)}\n" +
                         $"answer is {FunctionHolder.GetAimFunctionResult(_answer)}\n");
     }
     else
     {
         Check();
     }
 }
Ejemplo n.º 4
0
        public IType GetReturnType()
        {
            FunctionHolder fh = Peek();
            IType          result;

            try
            {
                result = fh.SqlFunction.ReturnType(fh.FirstValidColumnType, mapping);
            }
            catch (ArgumentNullException)
            {
                result = null;
            }
            if (result == null)
            {
                // magnify the exception
                throw new QueryException(string.Format("Can't extract the type of one parameter of a HQL function: expression->{{{0}}}; check aliases.", fh.PathExpressionParser.ProcessedPath));
            }
            return(result);
        }
Ejemplo n.º 5
0
        public void Pop()
        {
            IType firstReturnType;

            try
            {
                // Example in nested functions
                // abs(max(a.BodyWeight))
                // To know the ReturnType of "abs" we must know the ReturnType of "max" and the ReturnType of "max"
                // depend on the type of property "a.BodyWeight"
                FunctionHolder fh = Peek();
                firstReturnType = fh.SqlFunction.ReturnType(fh.FirstValidColumnType, mapping);
                stack.Pop();
            }
            catch (InvalidOperationException ex)
            {
                throw new QueryException("Parsing HQL: Pop on empty functions stack.", ex);
            }
            if (stack.Count > 0)
            {
                Peek().FirstValidColumnType = firstReturnType;
            }
        }
        private void Check()
        {
            if (FunctionHolder.GetAimFunctionResult(_x2) < FunctionHolder.GetAimFunctionResult(_x1))
            {
                _left   = _x1;
                _answer = _right - _left;
                _x1     = _x2;
                _x2     = _left + (_r * _answer);
                _xList.Add(_answer);
                _fxList.Add(FunctionHolder.GetAimFunctionResult(_answer));
                CheckAnswerValidation();
            }
            else
            {
                _right = _x2;

                _answer = _right - _left;
                _x2     = _x1;
                _x1     = _right - (_r * _answer);
                _xList.Add(_answer);
                _fxList.Add(FunctionHolder.GetAimFunctionResult(_answer));
                CheckAnswerValidation();
            }
        }
Ejemplo n.º 7
0
        private void CheckAnswerValidation()
        {
            if (Math.Abs(_xi - _xiPlusOne) < _epsilon)
            {
                for (int i = 1; i < _xList.Count; i++)
                {
                    Debug.WriteLine($"i = {i}\n" +
                                    $"x = {String.Format("{0:F16}", _xList.ElementAt(i))}\n" +
                                    $"F(x) = {String.Format("{0:F16}", _xiPlusOneList.ElementAt(i))}\n" +
                                    $"____________________________________________________________\n");
                }

                Debug.WriteLine($"ATS:" +
                                $"x = {String.Format("{0:F16}", _xiPlusOneList.ElementAt(_xList.Count - 1))}\n" +
                                $"F(x) = {String.Format("{0:F16}", FunctionHolder.GetAimFunctionResult(_xiPlusOneList.ElementAt(_xiPlusOneList.Count - 1)))}\n" +
                                $"____________________________________________________________\n");
            }
            else
            {
                _i++;
                _xi = _xiPlusOne;
                AssignFunction();
            }
        }
        private void Check()
        {
            if (FunctionHolder.GetAimFunctionResult(_x1) < FunctionHolder.GetAimFunctionResult(_xm))
            {
                _right = _xm;
                _xm    = _x1;

                CheckAnswerValidation();
            }
            else if (FunctionHolder.GetAimFunctionResult(_x2) < FunctionHolder.GetAimFunctionResult(_xm))
            {
                _left = _xm;
                _xm   = _x2;

                CheckAnswerValidation();
            }
            else
            {
                _left  = _x1;
                _right = _x2;

                CheckAnswerValidation();
            }
        }