protected IEnumerable <double> CalculateReplacementValues(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
                                                                  IDataset dataset, IEnumerable <int> rows)
        {
            //optimization: constant nodes return always the same value
            ConstantTreeNode             constantNode     = node as ConstantTreeNode;
            BinaryFactorVariableTreeNode binaryFactorNode = node as BinaryFactorVariableTreeNode;
            FactorVariableTreeNode       factorNode       = node as FactorVariableTreeNode;

            if (constantNode != null)
            {
                yield return(constantNode.Value);
            }
            else if (binaryFactorNode != null)
            {
                // valid replacements are either all off or all on
                yield return(0);

                yield return(1);
            }
            else if (factorNode != null)
            {
                foreach (var w in factorNode.Weights)
                {
                    yield return(w);
                }
                yield return(0.0);
            }
            else
            {
                var rootSymbol  = new ProgramRootSymbol().CreateTreeNode();
                var startSymbol = new StartSymbol().CreateTreeNode();
                rootSymbol.AddSubtree(startSymbol);
                startSymbol.AddSubtree((ISymbolicExpressionTreeNode)node.Clone());

                var tempTree = new SymbolicExpressionTree(rootSymbol);
                // clone ADFs of source tree
                for (int i = 1; i < sourceTree.Root.SubtreeCount; i++)
                {
                    tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone());
                }
                yield return(interpreter.GetSymbolicExpressionTreeValues(tempTree, dataset, rows).Median());

                yield return(interpreter.GetSymbolicExpressionTreeValues(tempTree, dataset, rows).Average()); // TODO perf
            }
        }
Example #2
0
 private void FormatBinaryFactor(BinaryFactorVariableTreeNode node, StringBuilder strBuilder)
 {
     strBuilder.AppendFormat(CultureInfo.InvariantCulture, "EvaluateBinaryFactor({0}, \"{1}\", {2})", VariableName2Identifier(node.VariableName), node.VariableValue, node.Weight);
 }
 private BinaryFactorVariableTreeNode(BinaryFactorVariableTreeNode original, Cloner cloner)
     : base(original, cloner)
 {
     variableValue = original.variableValue;
 }