/** * Populates test and training datasets. * * <p>Note: (1) assumes a 50:50 split, (2) training data set is stored in the dataArray structure * in which the input data is stored, (3) method called from application class as same training * and test sets may be required if using (say) "hill climbing" approach to maximise accuracy, (4) * method is not called from constructor partly for same reason as 3 but also because the input * data set may (given a particular application) first require ordering and possibly also pruning * and recasting (see recastClassifiers method). * * @param test myDataset Class where examples are stored to build the classifier * @param dataBase DataBase Class to store the examples to work with the algorithm and some other * useful information */ public void testDataSet(myDataset test, DataBase dataBase) { int i, j, k; int[] example; short value; // Determine size of training and test sets. setNumRowsInTrainingSet(); numRowsInTestSet = test.getnData(); // Dimension and populate test set testDataArray = new short[numRowsInTestSet][]; for (i = 0; i < numRowsInTestSet; i++) { example = test.getExample(i); testDataArray[i] = new short[dataBase.numVariablesUsed() + 1]; value = 1; for (j = 0, k = 0; j < example.length; j++) { if (dataBase.numLabels(j) > 1) { testDataArray[i][k] = (short) example[j]; testDataArray[i][k] += value; value += dataBase.numLabels(j); // System.out.print (testDataArray[i][k] + " "); k++; } } testDataArray[i][k] = (short) test.getOutputAsInteger(i); testDataArray[i][k] += value; // System.out.print (testDataArray[i][k] + " "); // System.out.println (""); } }
/** * Parameters Constructor * * @param dataBase Set of training data which is necessary to generate a rule * @param train Training data set with information to construct the rule base (mainly, the * training examples) */ public RuleBase(DataBase dataBase, myDataset train) { this.ruleBase = new ArrayList<Rule>(); this.dataBase = dataBase; this.train = train; this.n_variables = dataBase.numVariables(); this.fitness = 0; this.totalLabels = new int[this.n_variables]; for (int i = 0; i < this.n_variables; i++) this.totalLabels[i] = dataBase.numLabels(i); }