示例#1
0
        private ISymbolicExpressionTreeNode GenTreeShiftStdDist(string variable, double m_org, double s_org, double m_tar, double s_tar)
        {
            // x - m_org
            var substractionNode = new Subtraction().CreateTreeNode();
            var xNode            = CreateVariableTreeNode(variable, "x");
            var m_orgNode        = CreateConstantTreeNode("m_org", m_org);

            substractionNode.AddSubtree(xNode);
            substractionNode.AddSubtree(m_orgNode);

            // (x - m_org) / s_org
            var divisionNode = new Division().CreateTreeNode();
            var s_orgNode    = CreateConstantTreeNode("s_org", s_org);

            divisionNode.AddSubtree(substractionNode);
            divisionNode.AddSubtree(s_orgNode);

            // ((x - m_org) / s_org ) * s_tar
            var multiplicationNode = new Multiplication().CreateTreeNode();
            var s_tarNode          = CreateConstantTreeNode("s_tar", s_tar);

            multiplicationNode.AddSubtree(divisionNode);
            multiplicationNode.AddSubtree(s_tarNode);

            // ((x - m_org) / s_org ) * s_tar + m_tar
            var additionNode = new Addition().CreateTreeNode();
            var m_tarNode    = CreateConstantTreeNode("m_tar", m_tar);

            additionNode.AddSubtree(multiplicationNode);
            additionNode.AddSubtree(m_tarNode);

            return(additionNode);
        }
示例#2
0
        // helper

        private ISymbolicExpressionTreeNode GenerateModelForLinearTransformation()
        {
            var linearTransformation = (LinearTransformation)transformation;
            var kValue = linearTransformation.Multiplier;
            var dValue = linearTransformation.Addend;

            // k * x
            var multiplicationNode = new Multiplication().CreateTreeNode();
            var kNode = CreateConstantTreeNode("k", kValue);
            var xNode = CreateVariableTreeNode(column, "x");

            multiplicationNode.AddSubtree(kNode);
            multiplicationNode.AddSubtree(xNode);

            // ( k * x ) + d
            var additionNode = new Addition().CreateTreeNode();
            var dNode        = CreateConstantTreeNode("d", dValue);

            additionNode.AddSubtree(multiplicationNode);
            additionNode.AddSubtree(dNode);

            return(additionNode);
        }
    private static ISymbolicRegressionSolution CreateSymbolicSolution(List<IRegressionModel> models, double nu, IRegressionProblemData problemData) {
      var symbModels = models.OfType<ISymbolicRegressionModel>();
      var lowerLimit = symbModels.Min(m => m.LowerEstimationLimit);
      var upperLimit = symbModels.Max(m => m.UpperEstimationLimit);
      var interpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter();
      var progRootNode = new ProgramRootSymbol().CreateTreeNode();
      var startNode = new StartSymbol().CreateTreeNode();

      var addNode = new Addition().CreateTreeNode();
      var mulNode = new Multiplication().CreateTreeNode();
      var scaleNode = (ConstantTreeNode)new Constant().CreateTreeNode(); // all models are scaled using the same nu
      scaleNode.Value = nu;

      foreach (var m in symbModels) {
        var relevantPart = m.SymbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0); // skip root and start
        addNode.AddSubtree((ISymbolicExpressionTreeNode)relevantPart.Clone());
      }

      mulNode.AddSubtree(addNode);
      mulNode.AddSubtree(scaleNode);
      startNode.AddSubtree(mulNode);
      progRootNode.AddSubtree(startNode);
      var t = new SymbolicExpressionTree(progRootNode);
      var combinedModel = new SymbolicRegressionModel(problemData.TargetVariable, t, interpreter, lowerLimit, upperLimit);
      var sol = new SymbolicRegressionSolution(combinedModel, problemData);
      return sol;
    }