public void begin() { DecisionTree tree = new DecisionTree(); tree.AddNode(new DecisionNode(new List <VariableNode>() { new VariableNode("a", aCalled), new VariableNode("a", aCalled) }, new List <VariableTransformation>() { new VariableTransformation(new List <string>() { "a", "a" }, new List <string>() { "b" }) } , null)); tree.AddVariable(new VariableNode("b", bCalled)); //tree.EvaluteTree(); tree.EvaluateTree(); }
// // PRIVATE METHODS // private DecisionTree DecisionTreeLearning(DataSet ds, IList <string> attributeNames, ConstantDecisonTree defaultTree) { if (ds.Count == 0) { return(defaultTree); } if (this.AllExamplesHaveSameClassification(ds)) { return(new ConstantDecisonTree(ds.GetExample(0).TargetValue())); } if (attributeNames.Count == 0) { return(this.MajorityValue(ds)); } string chosenAttribute = this.ChooseAttribute(ds, attributeNames); var tree = new DecisionTree(chosenAttribute); ConstantDecisonTree m = this.MajorityValue(ds); IList <string> values = ds.GetPossibleAttributeValues(chosenAttribute); foreach (string v in values) { DataSet filtered = ds.MatchingDataSet(chosenAttribute, v); IList <string> newAttribs = Util.Util.RemoveFrom(attributeNames, chosenAttribute); DecisionTree subTree = this.DecisionTreeLearning(filtered, newAttribs, m); tree.AddNode(v, subTree); } return(tree); }
private void InitializeDecisionTree(StreamingContext context) { decisionTree = new DecisionTree(); // Decision tree DecisionTreeNode startNode = decisionTree.AddNode(decisionTree.root, (x => x[1] != null), null); { DecisionTreeNode targetNode = decisionTree.AddNode(startNode, (x => x[1] is GameObject && (x[1] as GameObject).IsVisible), null); { decisionTree.AddNode(targetNode, (x => (Matrix.CreateFromQuaternion((x[0] as EnemyController).Owner.GlobalRotation).Forward - Vector3.Normalize((x[1] as GameObject).GlobalPosition - (x[0] as EnemyController).Owner.GlobalPosition)).LengthSquared() > 0.05f), new TurnToTarget(Turn)); DecisionTreeNode shootingNode = decisionTree.AddNode(targetNode, (x => x[2] != null && (x[2] as GameObject).GetComponent <Weapon>() != null && (x[2] as GameObject).GetComponent <Weapon>().getAmmo() > 0), null); { DecisionTreeNode shootingRangeNode = decisionTree.AddNode(shootingNode, (x => ((x[0] as EnemyController).Owner.GlobalPosition - (x[1] as GameObject).GlobalPosition).Length() < shootingRange), null); { DecisionTreeNode canShootNode = decisionTree.AddNode(shootingRangeNode, (x => !(x[2] as GameObject).GetComponent <Weapon>().IsLocked), null); { decisionTree.AddNode(canShootNode, (x => (x[1] as GameObject).Name.Equals("Player") && Vector3.Dot(Vector3.Normalize((x[1] as GameObject).GetComponent <Rigidbody>().Velocity), Matrix.CreateFromQuaternion((x[0] as EnemyController).Owner.GlobalRotation).Forward) < 0.1f), new PerformAction(Shoot)); decisionTree.AddNode(canShootNode, (x => (x[1] as GameObject).Name.Equals("HologramPlayback") && Vector3.Dot(((x[1] as GameObject).LocalToWorldMatrix.Forward), Matrix.CreateFromQuaternion((x[0] as EnemyController).Owner.GlobalRotation).Forward) < 0.1f), new PerformAction(Shoot)); decisionTree.AddNode(canShootNode, (x => true), new PerformAction(MoveForward)); } decisionTree.AddNode(shootingRangeNode, (x => ((x[0] as EnemyController).Owner.GlobalPosition - (x[1] as GameObject).GlobalPosition).Length() < range), new PerformAction(StopMoving)); } decisionTree.AddNode(shootingNode, (x => true), new PerformAction(MoveForward)); } DecisionTreeNode meleeNode = decisionTree.AddNode(targetNode, (x => ((x[0] as EnemyController).Owner.GlobalPosition - (x[1] as GameObject).GlobalPosition).Length() < meleeRange), null); { decisionTree.AddNode(meleeNode, (x => (x[0] as EnemyController).CanAttack), new PerformAction(Attack)); decisionTree.AddNode(meleeNode, (x => true), new PerformAction(StopMoving)); } decisionTree.AddNode(targetNode, (x => true), new PerformAction(MoveForward)); } DecisionTreeNode patrolNode = decisionTree.AddNode(startNode, (x => x[1] is Vector3?), null); { decisionTree.AddNode(patrolNode, (x => ((x[0] as EnemyController).Owner.GlobalPosition - (x[1] as Vector3?).Value).Length() < meleeRange), new PerformAction(PickNextPatrolTarget)); decisionTree.AddNode(patrolNode, (x => (Matrix.CreateFromQuaternion((x[0] as EnemyController).Owner.GlobalRotation).Forward - Vector3.Normalize((x[1] as Vector3?).Value - (x[0] as EnemyController).Owner.GlobalPosition)).LengthSquared() > 0.05f), new TurnToTarget(Turn)); decisionTree.AddNode(patrolNode, (x => true), new PerformAction(MoveForward)); } } decisionTree.AddNode(decisionTree.root, (x => true), new PerformAction(StopMoving)); }