Esempio n. 1
0
        public ISymbolicExpressionTree Parse(string str)
        {
            ISymbolicExpressionTreeNode root  = programRootSymbol.CreateTreeNode();
            ISymbolicExpressionTreeNode start = startSymbol.CreateTreeNode();
            var allTokens = GetAllTokens(str).ToArray();
            ISymbolicExpressionTreeNode mainBranch = ParseS(new Queue <Token>(allTokens));

            // only a main branch was given => insert the main branch into the default tree template
            root.AddSubtree(start);
            start.AddSubtree(mainBranch);
            return(new SymbolicExpressionTree(root));
        }
Esempio n. 2
0
        /// <summary>
        /// Transforms the tree model to a symbolic regression model
        /// </summary>
        /// <returns>A new symbolic regression model which matches the tree model</returns>
        public SymbolicRegressionModel CreateSymbolicRegressionModel()
        {
            var rootSy    = new ProgramRootSymbol();
            var startSy   = new StartSymbol();
            var varCondSy = new VariableCondition()
            {
                IgnoreSlope = true
            };
            var constSy = new Constant();

            var startNode = startSy.CreateTreeNode();

            startNode.AddSubtree(CreateSymbolicRegressionTreeRecursive(tree, 0, varCondSy, constSy));
            var rootNode = rootSy.CreateTreeNode();

            rootNode.AddSubtree(startNode);
            return(new SymbolicRegressionModel(TargetVariable, new SymbolicExpressionTree(rootNode), new SymbolicDataAnalysisExpressionTreeLinearInterpreter()));
        }
        public ISymbolicExpressionTree Import(string str)
        {
            str = str.Replace("(", " ( ").Replace(")", " ) ");
            ISymbolicExpressionTreeNode root       = programRootSymbol.CreateTreeNode();
            ISymbolicExpressionTreeNode start      = startSymbol.CreateTreeNode();
            ISymbolicExpressionTreeNode mainBranch = ParseSexp(new Queue <Token>(GetTokenStream(str)));

            if (mainBranch.Symbol is ProgramRootSymbol)
            {
                // when a root symbol was parsed => use main branch as root
                root = mainBranch;
            }
            else
            {
                // only a main branch was given => insert the main branch into the default tree template
                root.AddSubtree(start);
                start.AddSubtree(mainBranch);
            }
            return(new SymbolicExpressionTree(root));
        }