private void Serialize_Recursive(StringBuilder sb, TextIdMapper classToClassId, TextIdMapper wordToWordId, int depth) { // If is is a leaf node, ... if (TrueBranch == null && FalseBranch == null) { string path = GetPath(wordToWordId); sb.AppendFormat("{0} {1}", path, FeatureVectors.Count); double[] distribution = GetDistributionByClass(); for (int i = 0; i < distribution.Length; i++) { sb.AppendFormat(" {0} {1}", classToClassId[i], distribution[i]); } sb.AppendLine(); } // If it is not a leaf node, ... else { if (FalseBranch != null) { FalseBranch.Serialize_Recursive(sb, classToClassId, wordToWordId, depth + 1); } if (TrueBranch != null) { TrueBranch.Serialize_Recursive(sb, classToClassId, wordToWordId, depth + 1); } } }
public override string ToString() { var builder = new StringBuilder(); builder.Append("if "); builder.Append(Condition); builder.Append(" then"); var ts = TrueBranch.ToString(); if (!string.IsNullOrWhiteSpace(ts)) { builder.Append(" "); builder.Append(ts); } var fs = FalseBranch.ToString(); if (!string.IsNullOrWhiteSpace(fs)) { builder.Append(" else "); builder.Append(fs); } builder.Append(" end"); return(builder.ToString()); }
/** * This is where the decision tree algorithm is located: it * recursively walks down the tree until it reaches the final * item to return (which is an action). */ public virtual IDecisionTreeNode <T> MakeDecision() { // Choose a branch based on the getBranch method if (GetBranch()) { // Make sure its not null before recursing. if (TrueBranch == null) { return(null); } else { return(TrueBranch.MakeDecision()); } } else { // Make sure its not null before recursing. if (FalseBranch == null) { return(null); } else { return(FalseBranch.MakeDecision()); } } }
public override string AST(int depth = 0) { return($"{Spaces(depth)}[{Name}\n" + $"{Expression.AST(depth + 1)}" + $"{TrueBranch.AST(depth + 1)}" + (FalseBranch is NoOpNode ? "" : $"{FalseBranch.AST(depth + 1)}") + $"{Spaces(depth)}]\n"); }
public override int GetHashCode() { return(unchecked ( Condition.GetHashCode() * TrueBranch.GetHashCode() * FalseBranch.GetHashCode() )); }
public override Node Clone() { return(new BasicBlock() { TrueBranch = TrueBranch?.Clone() as BasicBlock, FalseBranch = FalseBranch?.Clone() as BasicBlock, TerminatingBlock = TerminatingBlock, Instructions = Instructions?.Clone() as Instructions, }); }
public override DataType staticTypeCheck() { if (Predicate.staticTypeCheck() != DataType.BooleanType) { Log.Error("Type mismatch - predicate must evaluate to boolean", Filename, Line, Position); } TrueBranch.staticTypeCheck(); FalseBranch?.staticTypeCheck(); return(DataType.NoneType); }
internal DecisionTreeNode FindLeaf(FeatureVector vector) { // TODO: Make this less binary dependent. if (vector.Features[f_i] > 0 && TrueBranch != null) { return(TrueBranch.FindLeaf(vector)); } else if (FalseBranch != null) { return(FalseBranch.FindLeaf(vector)); } else { return(this); } }
public override string ToString() { var builder = new StringBuilder(); builder.Append("if(").Append(Condition.ToString()).Append(") {").Append(Environment.NewLine); builder.Append(TrueBranch.ToString()).Append(Environment.NewLine); builder.Append("}"); if (FalseBranch != null) { builder.Append(" else {").Append(Environment.NewLine); builder.Append(FalseBranch.ToString()).Append(Environment.NewLine); builder.Append("}"); } return(builder.ToString()); }
/// <summary> /// Converts to string. /// </summary> /// <returns> /// A <see cref="string" /> that represents this instance. /// </returns> public override string ToString() => $@"PRUNE ({Condition}, { TrueBranch.ToString()}) [{Location}];";
public Value Evaluate(Dictionary <string, IExpression> env) { var test = Test.Evaluate(env) as Value <bool>; return(test.Raw ? TrueBranch.Evaluate(env) : ElseBranch.Evaluate(env)); }
public void AddTrueBranchStmt(CILNode node) { TrueBranch.Add(node); }
public override string toSyntaxGraph() { return(String.Format("[IF [CONDITION {0}] [THEN {1}] [ELSE {2}]]", Predicate.toSyntaxGraph(), TrueBranch.toSyntaxGraph(), FalseBranch?.toSyntaxGraph() ?? "NULL")); }
public override string GenerateCode(ICodeGenerationContext context) { return($"{Condition.GenerateCode(context)} ? {TrueBranch.GenerateCode(context)} : {FalseBranch.GenerateCode(context)}"); }