package edu.hawaii.jmotif.performance.olive; import java.util.HashMap; import java.util.List; import java.util.Map; import edu.hawaii.jmotif.performance.UCRGenericClassifier; import edu.hawaii.jmotif.performance.UCRUtils; import edu.hawaii.jmotif.text.SAXCollectionStrategy; import edu.hawaii.jmotif.text.TextUtils; import edu.hawaii.jmotif.text.WordBag; /** * Helper-runner for test. * * @author psenin * */ public class UCROliveWebProper extends UCRGenericClassifier { // data locations // private static final String TRAINING_DATA = "data/OliveOil/OliveOil_TRAIN"; private static final String TEST_DATA = "data/OliveOil/OliveOil_TEST"; // SAX parameters to try // private static final int[][] params = { { 400,58,3, NOREDUCTION }, { 400,58,3, EXACT }, { 400,58,3, CLASSIC }, { 51,9,11, NOREDUCTION }, { 51,9,11, EXACT }, { 51,9,11, CLASSIC }, { 460,52,13, NOREDUCTION }, { 460,52,13, EXACT }, { 460,52,13, CLASSIC }, }; /** * Runnable. * * @throws Exception if error occurs. */ public static void main(String[] args) throws Exception { // making training and test collections // Map<String, List<double[]>> trainData = UCRUtils.readUCRData(TRAINING_DATA); Map<String, List<double[]>> testData = UCRUtils.readUCRData(TEST_DATA); // iterate over parameters // for (int[] p : params) { // converting back from easy encoding int WINDOW_SIZE = p[0]; int PAA_SIZE = p[1]; int ALPHABET_SIZE = p[2]; SAXCollectionStrategy strategy = SAXCollectionStrategy.CLASSIC; if (EXACT == p[3]) { strategy = SAXCollectionStrategy.EXACT; } else if (NOREDUCTION == p[3]) { strategy = SAXCollectionStrategy.NOREDUCTION; } // making training bags collection List<WordBag> bags = TextUtils.labeledSeries2WordBags(trainData, PAA_SIZE, ALPHABET_SIZE, WINDOW_SIZE, strategy); // getting TFIDF done HashMap<String, HashMap<String, Double>> tfidf = TextUtils.computeTFIDF(bags); // classifying int testSampleSize = 0; int positiveTestCounter = 0; for (String label : tfidf.keySet()) { List<double[]> testD = testData.get(label); for (double[] series : testD) { positiveTestCounter = positiveTestCounter + TextUtils.classify(label, series, tfidf, PAA_SIZE, ALPHABET_SIZE, WINDOW_SIZE, strategy); testSampleSize++; } } // accuracy and error double accuracy = (double) positiveTestCounter / (double) testSampleSize; double error = 1.0d - accuracy; // report results System.out.println(toLogStr(p, accuracy, error)); } } }