public void RecurseRead (string[] fileLines, ref int i) { string line = fileLines[i]; i++; string[] lineParts = line.Split(','); if (lineParts.Length == 1) { Classification = float.Parse(lineParts[0]); } else { BranchComponent = int.Parse(lineParts[0]); BranchValue = float.Parse(lineParts[1]); LeftBranch = new DecisionTree(); LeftBranch.RecurseRead(fileLines, ref i); RightBranch = new DecisionTree(); RightBranch.RecurseRead(fileLines, ref i); } }
public void Unload () { Root = null; }
public void Load () { Root = new DecisionTree(Filename); }
public BigDecisionTree(Dataset Dataset, int MaxTreeDepth, int CurrentDepth = 0) { Root = new DecisionTree(Dataset, MaxTreeDepth); Filename = "./trees/" + Now().ToString() + "." + RNG.Next(0, 65535); Root.Write(Filename); }
private void DoBranch(Dataset Dataset, int MaxTreeDepth, int CurrentDepth) { Dataset leftDataset; Dataset rightDataset; int timeout = 0; do { timeout++; if (timeout > 1000) { DetermineClassification(Dataset); } BranchComponent = RNG.Next(Dataset.Inputs[0].Count); float componentLow; float componentHigh; float componentRange; Dataset.GetInputComponentRange(BranchComponent, out componentLow, out componentHigh, out componentRange); BranchValue = (float)((RNG.NextDouble() * componentRange) + componentLow); leftDataset = new Dataset(); rightDataset = new Dataset(); Split(BranchComponent, BranchValue, Dataset, out leftDataset, out rightDataset); } while (leftDataset.Inputs.Count == 0 || rightDataset.Inputs.Count == 0); LeftBranch = new DecisionTree(leftDataset, MaxTreeDepth, CurrentDepth + 1); RightBranch = new DecisionTree(rightDataset, MaxTreeDepth, CurrentDepth + 1); }