public static DataSet ReadData(string fileName) { TextReader textReader = new StreamReader(@fileName); string temp = textReader.ReadLine().Trim(); int total = int.Parse(temp); temp = textReader.ReadLine().Trim(); int[] tempIntArray = stringToIntArray(temp, new char[] { '\t', ' ' }); int numberOfInputNodes = tempIntArray[0]; int numberOfOutputNodes = tempIntArray[1]; double [,] inputdata = new double[total, numberOfInputNodes]; double [,] desiredOutputs = new double [total, numberOfOutputNodes]; for (int i = 0; i < total; i++) { temp = textReader.ReadLine().Trim(); double[] tempDoubleArray = stringToDoubleArray(temp, new char[] {'\t', ' ' }); for (int j = 0; j < numberOfInputNodes; j++) { inputdata[i, j] = tempDoubleArray[j]; } for (int j = 0; j < numberOfOutputNodes; j++) { desiredOutputs[i, j] = tempDoubleArray[numberOfInputNodes + j]; } } DataSet result = new DataSet(inputdata, desiredOutputs); return result; }
public PoptvrSystem(DataSet dataset, ClusterSetting clusterSetting, ClusterFacadeInterface clusterFacade, Settings settings) { this.dataset = dataset; this.clusterSetting = clusterSetting; this.clusterFacade = clusterFacade; this.appConfig = new AppConfig(settings); }
public PoptvrModel(DataSet dataset, ClusterSetting clusterSetting) { this.dataset = dataset; this.clusterSetting = clusterSetting; this.numberOfInputs = this.dataset.NumberOfInputNodes; this.numberOfOutputs = this.dataset.NumberOfOutputNodes; this.inputClusterSize = this.clusterSetting.InputClusterSize; this.outputClusterSize = this.clusterSetting.OutputClusterSize; buildRULES(); buildPOPTVR(); }
public MlvqFacade(DataSet dataset, ClusterSetting clusterSetting) { this.clusterSetting = clusterSetting; this.dataset = dataset; }
// inclusive "from", exclusive "to" public DataSet subset(int from, int to) { double[,] inputdata = new double[to - from, this.numberOfInputNodes]; double[,] desiredOutputs = new double [to - from, this.numberOfOutputNodes]; for (int i = 0; i < to - from; i++) { for (int j = 0; j < this.numberOfInputNodes; j++) { inputdata[i,j] = this.inputdata[i + from,j]; } for (int j = 0; j < this.numberOfOutputNodes; j++) { desiredOutputs[i, j] = this.desiredOutputs[i + from, j]; } } DataSet result = new DataSet(inputdata, desiredOutputs); return result; }
public static string POPTest(PoptvrModel poptvr, DataSet dataset) { Console.WriteLine("POPTest ...."); string resultString = ""; int correct = 0; int[] ruleNodes = new int[(int)Math.Pow(poptvr.inputClusterSize, dataset.NumberOfInputNodes)]; int[] classTotal = new int[dataset.NumberOfOutputNodes]; int[] classCorrect = new int[dataset.NumberOfOutputNodes]; for (int i = 0; i < dataset.TotalNumberOfRecords; i++) { bool correctFlag = false; poptvr.forwardFeed(SystemFunctions.getArrayAtRow(dataset.Inputdata, i)); poptvr.maxRuleNode(ruleNodes); double max = poptvr.OutputLayer[0].Output; int maxIndex = 0; for (int j = 0; j < dataset.NumberOfOutputNodes; j++) { resultString += String.Format("{0:F3}\t", poptvr.OutputLayer[j].Output); if (max < poptvr.OutputLayer[j].Output) { max = poptvr.OutputLayer[j].Output; maxIndex = j; } } for (int j = 0; j < dataset.NumberOfOutputNodes; j++) { // calculate the total no. in each class if (dataset.DesiredOutputs[i, j] == 1.0) { classTotal[j]++; } // calculate the correct no. in each class, overall correct if (j == maxIndex) { if (dataset.DesiredOutputs[i, j] == 1.0) { correct++; classCorrect[j]++; correctFlag = true; } } } if (correctFlag) { resultString += "\n"; } else { resultString += "X\n"; } } for (int i = 0; i < dataset.NumberOfOutputNodes; i++) { resultString += String.Format("Class [{0:D}]:\t{1:F3}\tpercent\n", i, ((double)classCorrect[i] * 100.0) / (double)classTotal[i]); } resultString += String.Format("Overall:\t {0:F3}\tpercent\n", (correct * 100.0) / dataset.TotalNumberOfRecords); int totalRulesFired = 0; for (int i = 0; i < ruleNodes.Length; i++) { if (ruleNodes[i] != 0) { totalRulesFired++; } resultString += String.Format("ruleNode {0:D}:\t{1:D}\n", i, ruleNodes[i]); } resultString += String.Format("Total Rules Fired:\t{0:D}\n", totalRulesFired); return resultString; }
public void popLearn(DataSet dataset) { this.dataset = dataset; popLearn(); }
public static PoptvrModel RuleReduction(PoptvrModel poptvr, DataSet dataset, AppConfig appConfig) { Console.WriteLine("Start RSPOP reduction ..."); double[] CO = new double[dataset.NumberOfOutputNodes * poptvr.OutputClusterSize]; double[] COr = new double[dataset.NumberOfOutputNodes * poptvr.OutputClusterSize]; string res = "Removed from total " + poptvr.RuleLayer.Length + "\n"; for (int k = 0; k < poptvr.RuleLayer.Length; k++) { for (int i = 0; i < dataset.TotalNumberOfRecords; i++) { Console.Write("at condition " + k + "\t" + "record " + i + "\n"); poptvr.forwardFeed(SystemFunctions.getArrayAtRow(dataset.Inputdata, i)); for (int j = 0; j < dataset.NumberOfOutputNodes * poptvr.OutputClusterSize; j++) { CO[j] = poptvr.ConsequenceLayer[j].Output; } for (int l = 0; l < poptvr.InputClusterSize; l++) { bool deterioration = false; poptvr.RuleLayer[k].PointBlocked = true; poptvr.RuleLayer[k].PointBlockedAt = l; poptvr.forwardFeed(SystemFunctions.getArrayAtRow(dataset.Inputdata, i)); for (int j = 0; j < dataset.NumberOfOutputNodes * poptvr.OutputClusterSize; j++) { COr[j] = poptvr.ConsequenceLayer[j].Output; if (COr[j] < CO[j]) { deterioration = true; } else { for (int m = 0; m < CO.Length; m++) { if (COr[j] > CO[m]) { deterioration = true; break; } } } if (deterioration) { break; } } if (!deterioration) { res += (l + " is remove at " + k + "\n"); poptvr.RuleLayer[k].PointBlocked = false; } if (deterioration) { poptvr.RuleLayer[k].PointBlocked = false; } } } } FileWriter fileWriter = new FileWriter(appConfig); fileWriter.WriteToFile(appConfig.getOutputFolder() + "Removed Rule.txt", res); return poptvr; }
public void PopTest(DataSet dataset) { string result = PoptvrModel.POPTest(this.poptvr, dataset); FileWriter fileWriter = new FileWriter(this.appConfig); fileWriter.WritePopTestOutput(result); }
public PoptvrSystem(DataSet dataset, ClusterSetting clusterSetting, ClusterFacadeInterface clusterFacade) { this.dataset = dataset; this.clusterSetting = clusterSetting; this.clusterFacade = clusterFacade; }