Esempio n. 1
0
        public void Run(int interationCount = 0)
        {
            var condition = new RegressionStopCondition(_precision, interationCount);

            while (condition.Check(ApproximationError))
            {
                MakeIteration();
                if (CurrentIteration <= MaxIterationCount)
                {
                    continue;
                }

                _success = false;
                break;
            }

            if (!InConstant.Exists(double.IsNaN) && !InConstant.Exists(double.IsInfinity))
            {
                return;
            }

            _success = false;
        }
Esempio n. 2
0
        /// <summary>
        /// Rebuilds the tree nodes
        /// </summary>
        /// <param name="node">Tree (root node)</param>
        /// <param name="replaceConstant">
        /// Replaces all of the constants by new variables when true.
        /// Replaces all of the new variables by calculated contants from _inContants list when false.
        /// </param>
        private void RebuildTree(INode node, bool replaceConstant)
        {
            if (node.HasChildren())
            {
                foreach (var child in node.Children)
                {
                    RebuildTree(child, replaceConstant);
                }
                return;
            }

            int   childIndex;
            INode newVar;

            if (node is Constant && replaceConstant)
            {
                InConstant.Add(Double.Parse(node.ToString()));
                childIndex = node.Parent.IndexOfChild(node);
                newVar     = VariableNode.Make <double>(_index, VarName + (InConstant.Count - 1));
                node.Parent.Children[childIndex] = newVar;
                _index++;
            }

            if (!(node is VariableNode) || replaceConstant)
            {
                return;
            }

            if (((VariableNode)node).Index < _index - InConstant.Count)
            {
                return;
            }

            childIndex = node.Parent.IndexOfChild(node);
            newVar     = new Constant <double>(InConstant[((VariableNode)node).Index - (_index - InConstant.Count)]);
            node.Parent.Children[childIndex] = newVar;
        }