package GUI; import java.io.IOException; import java.util.ArrayList; import java.util.Vector; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; import Exceptions.UnsupportedFileTypeException; import Experiment.Dataset; import Experiment.Experiment; import Experiment.SingleDataExperiment; import Learners.*; import Preprocessors.*; public class Main { public static ArrayList experiments; public static ArrayList learners; public static ArrayList preprocessors; public static ArrayList progress; public static String currentDataset; public static int currentID; private static MainGUI inst; public static void main(String[] args) { experiments = new ArrayList(); progress = new ArrayList(); learners = new ArrayList(); initializeLearners(); preprocessors = new ArrayList(); initializePreprocessors(); currentDataset = ""; SwingUtilities.invokeLater(new Runnable() { public void run() { inst = new MainGUI(); inst.setLocationRelativeTo(null); inst.setVisible(true); } }); } public static void newExperiment(SingleDataExperiment e) { progress.add(0); experiments.add(e); } public static SingleDataExperiment getExperiment() { for (SingleDataExperiment e : experiments) { if (e.getDataset().equals(currentDataset)) return e; } return null; } public static void startExperiment(SwingWorker worker) { worker.execute(); } public static void setCurrentExperiment(String datasetName) { currentDataset = datasetName; currentID = getExperiment().getID(); } public static void setProgress(int id, int value) { progress.set(id, value); } public static int getProgress() { return progress.get(currentID); } public static void initializeLearners() { learners.add(new kNearestNeighbors(1)); learners.add(new kNearestNeighbors(2)); learners.add(new kNearestNeighbors(4)); learners.add(new kNearestNeighbors(8)); learners.add(new kNearestNeighbors(16)); } public static void initializePreprocessors() { preprocessors.add(new BasicPreprocessor()); preprocessors.add(new BasicPreprocessor2()); } public static String[] getLearners() { Vector v = new Vector(); for (Learner l : learners) { v.add(l.getName()); } String[] s = new String[v.size()]; v.copyInto(s); return s; } public static String[] getPreprocessors() { Vector v = new Vector(); for (Preprocessor p : preprocessors) { v.add(p.getName()); } String[] s = new String[v.size()]; v.copyInto(s); return s; } public static Learner findLearner(String learnerName) { for (Learner l : learners) { if (l.getName().equals(learnerName)) return l; } return null; } public static Preprocessor findPreprocessor(String preprocessorName) { for (Preprocessor p : preprocessors) { if (p.getName().equals(preprocessorName)) return p; } return null; } public static double runUnitTest(Learner l, Preprocessor p, String testData, String datasetFile) { Dataset d = new Dataset(datasetFile); try { d.writeTest(testData, "./temp/test.csv"); p.preprocess(datasetFile, "./temp/test.csv", "./temp/trainp.csv"); return l.estimate("./temp/trainp.csv", "./temp/test.csv"); } catch (IOException e) {e.printStackTrace();} catch (UnsupportedFileTypeException e) {e.printStackTrace();} return 0.0; } }