List of usage examples for java.util ArrayList add
public boolean add(E e)
From source file:jsdp.app.control.clqg.univariate.CLQG.java
public static void main(String args[]) { /******************************************************************* * Problem parameters// w w w . j a va2 s. co m */ int T = 20; // Horizon length double G = 1; // Input transition double Phi = 1; // State transition double R = 1; // Input cost double Q = 1; // State cost double Ulb = -1; // Action constraint double Uub = 20; // Action constraint double noiseStd = 5; // Standard deviation of the noise double[] noiseStdArray = new double[T]; Arrays.fill(noiseStdArray, noiseStd); double truncationQuantile = 0.975; // Random variables Distribution[] distributions = IntStream.iterate(0, i -> i + 1).limit(noiseStdArray.length) .mapToObj(i -> new NormalDist(0, noiseStdArray[i])) .toArray(Distribution[]::new); double[] supportLB = IntStream.iterate(0, i -> i + 1).limit(T) .mapToDouble(i -> NormalDist.inverseF(0, noiseStdArray[i], 1 - truncationQuantile)).toArray(); double[] supportUB = IntStream.iterate(0, i -> i + 1).limit(T) .mapToDouble(i -> NormalDist.inverseF(0, noiseStdArray[i], truncationQuantile)).toArray(); double initialX = 0; // Initial state /******************************************************************* * Model definition */ // State space double stepSize = 0.5; //Stepsize must be 1 for discrete distributions double minState = -25; double maxState = 100; StateImpl.setStateBoundaries(stepSize, minState, maxState); // Actions Function<State, ArrayList<Action>> buildActionList = (Function<State, ArrayList<Action>> & Serializable) s -> { StateImpl state = (StateImpl) s; ArrayList<Action> feasibleActions = new ArrayList<Action>(); double maxAction = Math.min(Uub, (StateImpl.getMaxState() - Phi * state.getInitialState()) / G); double minAction = Math.max(Ulb, (StateImpl.getMinState() - Phi * state.getInitialState()) / G); for (double actionPointer = minAction; actionPointer <= maxAction; actionPointer += StateImpl .getStepSize()) { feasibleActions.add(new ActionImpl(state, actionPointer)); } return feasibleActions; }; Function<State, Action> idempotentAction = (Function<State, Action> & Serializable) s -> new ActionImpl(s, 0.0); ImmediateValueFunction<State, Action, Double> immediateValueFunction = (initialState, action, finalState) -> { ActionImpl a = (ActionImpl) action; StateImpl fs = (StateImpl) finalState; double inputCost = Math.pow(a.getAction(), 2) * R; double stateCost = Math.pow(fs.getInitialState(), 2) * Q; return inputCost + stateCost; }; // Random Outcome Function RandomOutcomeFunction<State, Action, Double> randomOutcomeFunction = (initialState, action, finalState) -> { double realizedNoise = ((StateImpl) finalState).getInitialState() - ((StateImpl) initialState).getInitialState() * Phi - ((ActionImpl) action).getAction() * G; return realizedNoise; }; /******************************************************************* * Solve */ // Sampling scheme SamplingScheme samplingScheme = SamplingScheme.NONE; int maxSampleSize = 50; double reductionFactorPerStage = 1; // Value Function Processing Method: backward recursion double discountFactor = 1.0; int stateSpaceLowerBound = 10000000; float loadFactor = 0.8F; BackwardRecursionImpl recursion = new BackwardRecursionImpl(OptimisationDirection.MIN, distributions, supportLB, supportUB, immediateValueFunction, randomOutcomeFunction, buildActionList, idempotentAction, discountFactor, samplingScheme, maxSampleSize, reductionFactorPerStage, stateSpaceLowerBound, loadFactor, HashType.THASHMAP); System.out.println("--------------Backward recursion--------------"); StopWatch timer = new StopWatch(); OperatingSystemMXBean osMBean; try { osMBean = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class); long nanoBefore = System.nanoTime(); long cpuBefore = osMBean.getProcessCpuTime(); timer.start(); recursion.runBackwardRecursionMonitoring(); timer.stop(); long cpuAfter = osMBean.getProcessCpuTime(); long nanoAfter = System.nanoTime(); long percent; if (nanoAfter > nanoBefore) percent = ((cpuAfter - cpuBefore) * 100L) / (nanoAfter - nanoBefore); else percent = 0; System.out.println( "Cpu usage: " + percent + "% (" + Runtime.getRuntime().availableProcessors() + " cores)"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(); double ETC = recursion.getExpectedCost(initialX); StateDescriptorImpl initialState = new StateDescriptorImpl(0, initialX); double action = recursion.getOptimalAction(initialState).getAction(); System.out.println("Expected total cost (assuming an initial state " + initialX + "): " + ETC); System.out.println("Optimal initial action: " + action); System.out.println("Time elapsed: " + timer); System.out.println(); }
From source file:unalcol.termites.boxplots.ECALAgentsRight.java
/** * For testing from the command line./*from ww w . j av a 2 s.c om*/ * * @param args ignored. */ public static void main(final String[] args) { double pf = 0; ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pf1 = new ArrayList<>(); ArrayList<Double> pf3 = new ArrayList<>(); ArrayList<Double> pf5 = new ArrayList<>(); ArrayList<Double> pf7 = new ArrayList<>(); ArrayList<Double> pf9 = new ArrayList<>(); ArrayList<Double> pf01 = new ArrayList<>(); pf0.add(0.0); pf1.add(1.0E-4); pf3.add(1.0E-3); pf5.add(1.0E-2); pf7.add(4.0E-4); pf9.add(9.0E-4); pf01.add(1.0E-3); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final ECALAgentsRight demo = new ECALAgentsRight("Round Number", pf0); final ECALAgentsRight demo1 = new ECALAgentsRight("Round Number", pf1); final ECALAgentsRight demo2 = new ECALAgentsRight("Round Number", pf3); final ECALAgentsRight demo3 = new ECALAgentsRight("Round Number", pf5); final ECALAgentsRight demo4 = new ECALAgentsRight("Round Number", pf7); final ECALAgentsRight demo5 = new ECALAgentsRight("Round Number", pf9); final ECALAgentsRight demo6 = new ECALAgentsRight("Round Number", pf01); // double pf = Double.valueOf(args[0]); // System.out.println("pf:" + args[0]); /* double pf = 0; ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pfg1 = new ArrayList<>(); ArrayList<Double> pfg2 = new ArrayList<>(); ArrayList<Double> pfg3 = new ArrayList<>(); pf0.add(0.0); pfg1.add(1.0E-4); pfg1.add(3.0E-4); pfg2.add(5.0E-4); pfg2.add(7.0E-4); pfg3.add(9.0E-4); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final RoundNumber2 demo = new RoundNumber2("Round Number", pf0); final RoundNumber2 demo1 = new RoundNumber2("Round Number", pfg1); final RoundNumber2 demo2 = new RoundNumber2("Round Number", pfg2); final RoundNumber2 demo3 = new RoundNumber2("Round Number", pfg3); */ //demo.pack(); //RefineryUtilities.centerFrameOnScreen(demo); //demo.setVisible(true); }
From source file:unalcol.termites.boxplots.ECALRoundNumber.java
/** * For testing from the command line.//w w w . j a va2 s . co m * * @param args ignored. */ public static void main(final String[] args) { double pf = 0; ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pf1 = new ArrayList<>(); ArrayList<Double> pf3 = new ArrayList<>(); ArrayList<Double> pf5 = new ArrayList<>(); ArrayList<Double> pf7 = new ArrayList<>(); ArrayList<Double> pf9 = new ArrayList<>(); ArrayList<Double> pf01 = new ArrayList<>(); pf0.add(0.0); pf1.add(1.0E-4); pf3.add(1.0E-3); pf5.add(1.0E-2); pf7.add(4.0E-4); pf9.add(9.0E-4); pf01.add(1.0E-3); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final ECALRoundNumber demo = new ECALRoundNumber("Round Number", pf0); final ECALRoundNumber demo1 = new ECALRoundNumber("Round Number", pf1); final ECALRoundNumber demo2 = new ECALRoundNumber("Round Number", pf3); final ECALRoundNumber demo3 = new ECALRoundNumber("Round Number", pf5); final ECALRoundNumber demo4 = new ECALRoundNumber("Round Number", pf7); final ECALRoundNumber demo5 = new ECALRoundNumber("Round Number", pf9); final ECALRoundNumber demo6 = new ECALRoundNumber("Round Number", pf01); // double pf = Double.valueOf(args[0]); // System.out.println("pf:" + args[0]); /* double pf = 0; ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pfg1 = new ArrayList<>(); ArrayList<Double> pfg2 = new ArrayList<>(); ArrayList<Double> pfg3 = new ArrayList<>(); pf0.add(0.0); pfg1.add(1.0E-4); pfg1.add(3.0E-4); pfg2.add(5.0E-4); pfg2.add(7.0E-4); pfg3.add(9.0E-4); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final RoundNumber2 demo = new RoundNumber2("Round Number", pf0); final RoundNumber2 demo1 = new RoundNumber2("Round Number", pfg1); final RoundNumber2 demo2 = new RoundNumber2("Round Number", pfg2); final RoundNumber2 demo3 = new RoundNumber2("Round Number", pfg3); */ //demo.pack(); //RefineryUtilities.centerFrameOnScreen(demo); //demo.setVisible(true); }
From source file:unalcol.termites.boxplots.RoundNumber2.java
/** * For testing from the command line./*ww w . j a v a2 s . c om*/ * * @param args ignored. */ public static void main(final String[] args) { double pf = 0; ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pf1 = new ArrayList<>(); ArrayList<Double> pf3 = new ArrayList<>(); ArrayList<Double> pf5 = new ArrayList<>(); ArrayList<Double> pf7 = new ArrayList<>(); ArrayList<Double> pf9 = new ArrayList<>(); ArrayList<Double> pf01 = new ArrayList<>(); pf0.add(0.0); pf1.add(1.0E-4); pf3.add(3.0E-4); pf5.add(5.0E-4); pf7.add(7.0E-4); pf9.add(9.0E-4); pf01.add(1.0E-3); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final RoundNumber2 demo = new RoundNumber2("Round Number", pf0); final RoundNumber2 demo1 = new RoundNumber2("Round Number", pf1); final RoundNumber2 demo2 = new RoundNumber2("Round Number", pf3); final RoundNumber2 demo3 = new RoundNumber2("Round Number", pf5); final RoundNumber2 demo4 = new RoundNumber2("Round Number", pf7); final RoundNumber2 demo5 = new RoundNumber2("Round Number", pf9); final RoundNumber2 demo6 = new RoundNumber2("Round Number", pf01); // double pf = Double.valueOf(args[0]); // System.out.println("pf:" + args[0]); /* double pf = 0; ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pfg1 = new ArrayList<>(); ArrayList<Double> pfg2 = new ArrayList<>(); ArrayList<Double> pfg3 = new ArrayList<>(); pf0.add(0.0); pfg1.add(1.0E-4); pfg1.add(3.0E-4); pfg2.add(5.0E-4); pfg2.add(7.0E-4); pfg3.add(9.0E-4); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final RoundNumber2 demo = new RoundNumber2("Round Number", pf0); final RoundNumber2 demo1 = new RoundNumber2("Round Number", pfg1); final RoundNumber2 demo2 = new RoundNumber2("Round Number", pfg2); final RoundNumber2 demo3 = new RoundNumber2("Round Number", pfg3); */ //demo.pack(); //RefineryUtilities.centerFrameOnScreen(demo); //demo.setVisible(true); }
From source file:unalcol.termites.boxplots.RoundNumberGlobal.java
/** * For testing from the command line.//from w w w. j a va 2 s .co m * * @param args ignored. */ public static void main(final String[] args) { if (args.length > 0) { experimentsDir = args[0]; } aMode = new String[args.length - 1]; for (int i = 1; i < args.length; i++) { aMode[i - 1] = args[i]; } // double pf = Double.valueOf(args[0]); // System.out.println("pf:" + args[0]); /* SASO Paper */ /* double pf = 0; ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pfg1 = new ArrayList<>(); ArrayList<Double> pfg2 = new ArrayList<>(); ArrayList<Double> pfg3 = new ArrayList<>(); pf0.add(0.0); pfg1.add(1.0E-4); pfg1.add(3.0E-4); pfg2.add(5.0E-4); pfg2.add(7.0E-4); pfg3.add(9.0E-4); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final RoundNumber1 demo = new RoundNumber1("Round Number", pf0); final RoundNumber1 demo1 = new RoundNumber1("Round Number", pfg1); final RoundNumber1 demo2 = new RoundNumber1("Round Number", pfg2); final RoundNumber1 demo3 = new RoundNumber1("Round Number", pfg3); //demo.pack(); //RefineryUtilities.centerFrameOnScreen(demo); //demo.setVisible(true); */ double pf = 0; ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pf1 = new ArrayList<>(); ArrayList<Double> pf3 = new ArrayList<>(); ArrayList<Double> pf5 = new ArrayList<>(); ArrayList<Double> pf7 = new ArrayList<>(); ArrayList<Double> pf9 = new ArrayList<>(); ArrayList<Double> pf01 = new ArrayList<>(); pf0.add(0.0); pf1.add(1.0E-4); pf3.add(3.0E-4); pf5.add(5.0E-4); pf7.add(7.0E-4); pf9.add(9.0E-4); pf01.add(1.0E-3); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final RoundNumberGlobal demo = new RoundNumberGlobal("Round Number", pf0); final RoundNumberGlobal demo1 = new RoundNumberGlobal("Round Number", pf1); final RoundNumberGlobal demo2 = new RoundNumberGlobal("Round Number", pf3); final RoundNumberGlobal demo3 = new RoundNumberGlobal("Round Number", pf5); final RoundNumberGlobal demo4 = new RoundNumberGlobal("Round Number", pf7); final RoundNumberGlobal demo5 = new RoundNumberGlobal("Round Number", pf9); final RoundNumberGlobal demo6 = new RoundNumberGlobal("Round Number", pf01); //demo.pack(); //RefineryUtilities.centerFrameOnScreen(demo); //demo.setVisible(true); }
From source file:akori.Impact.java
static public void main(String[] args) throws IOException { String PATH = "E:\\Trabajos\\AKORI\\datosmatrizgino\\"; String PATHIMG = "E:\\NetBeansProjects\\AKORI\\Proccess_1\\ImagesPages\\"; for (int i = 1; i <= 32; ++i) { for (int k = 1; k <= 15; ++k) { System.out.println("Matrix " + i + "-" + k); BufferedImage img = null; try { img = ImageIO.read(new File(PATHIMG + i + ".png")); } catch (IOException ex) { ex.getStackTrace();//from ww w . jav a 2 s.c om } int ymax = img.getHeight(); int xmax = img.getWidth(); double[][] imagen = new double[ymax][xmax]; BufferedReader in = null; try { in = new BufferedReader(new FileReader(PATH + i + "-" + k + ".txt")); } catch (FileNotFoundException ex) { ex.getStackTrace(); } String linea; ArrayList<String> lista = new ArrayList<String>(); HashMap<String, String> lista1 = new HashMap<String, String>(); try { for (int j = 0; (linea = in.readLine()) != null; ++j) { String[] datos = linea.split(","); int x = (int) Double.parseDouble(datos[1]); int y = (int) Double.parseDouble(datos[2]); if (x >= xmax || y >= ymax || x <= 0 || y <= 0) { continue; } lista.add(x + "," + y); } } catch (Exception ex) { ex.getStackTrace(); } try { in.close(); } catch (IOException ex) { ex.getStackTrace(); } Iterator iter = lista.iterator(); int[][] matrix = new int[lista.size()][2]; for (int j = 0; iter.hasNext(); ++j) { String xy = (String) iter.next(); String[] datos = xy.split(","); matrix[j][0] = Integer.parseInt(datos[0]); matrix[j][1] = Integer.parseInt(datos[1]); } for (int j = 0; j < matrix.length; ++j) { int std = 50; int x = matrix[j][0]; int y = matrix[j][1]; imagen[y][x] += 1; double aux; normalMatrix(imagen, y, x, std); } FileWriter fw = new FileWriter(PATH + "Matrix" + i + "-" + k + ".txt"); BufferedWriter bw = new BufferedWriter(fw); for (int j = 0; j < imagen.length; ++j) { for (int t = 0; t < imagen[j].length; ++t) { if (t + 1 == imagen[j].length) bw.write(imagen[j][t] + ""); else bw.write(imagen[j][t] + ","); } bw.write("\n"); } bw.close(); } } }
From source file:interpolation.Polyfit.java
public static void main(String[] args) { final ArrayList<Pair<Integer, Double>> mts = loadsimple( new File("/Users/varunkapoor/Documents/Ines_Fourier/Cell39.txt")); final ArrayList<Pair<Integer, Double>> mtspoly = new ArrayList<Pair<Integer, Double>>(); double[] x = new double[mts.size()]; double[] y = new double[mts.size()]; int i = 0;//from w ww . ja v a 2 s.co m for (Pair<Integer, Double> point : mts) { x[i] = point.getA(); y[i] = point.getB(); i++; } int degree = 20; Polyfit regression = new Polyfit(x, y, degree); for (double t = x[0]; t <= x[x.length - 1]; ++t) { double poly = regression.predict(t); mtspoly.add(new ValuePair<Integer, Double>((int) t, poly)); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(Tracking.drawPoints(mtspoly, new double[] { 1, 1, 1 }, "Function fit")); dataset.addSeries(Tracking.drawPoints(mts, new double[] { 1, 1, 1 }, "Original Data")); JFreeChart chart = Tracking.makeChart(dataset); Tracking.display(chart, new Dimension(500, 400)); Tracking.setColor(chart, i, new Color(255, 0, 0)); Tracking.setStroke(chart, i, 0.5f); for (int j = degree; j >= 0; --j) System.out.println(regression.GetCoefficients(j) + " *x power " + j); }
From source file:unalcol.termites.boxplots.ECALinfoCollected.java
/** * For testing from the command line.// w w w . j a v a 2s .co m * * @param args ignored. */ public static void main(final String[] args) { //double pf = Double.valueOf(args[0]); // System.out.println("pf:" + args[0]); //double pf = 0; /* For the Paper */ /* ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pfg1 = new ArrayList<>(); ArrayList<Double> pfg2 = new ArrayList<>(); ArrayList<Double> pfg3 = new ArrayList<>(); pf0.add(0.0); pfg1.add(1.0E-4); pfg1.add(3.0E-4); pfg2.add(5.0E-4); pfg2.add(7.0E-4); pfg3.add(9.0E-4); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final InformationCollected1 demo = new InformationCollected1("Information Collected", pf0); final InformationCollected1 demo1 = new InformationCollected1("Information Collected", pfg1); final InformationCollected1 demo2 = new InformationCollected1("Information Collected", pfg2); final InformationCollected1 demo3 = new InformationCollected1("Information Collected", pfg3); //demo.pack(); //RefineryUtilities.centerFrameOnScreen(demo); //demo.setVisible(true); **/ /* Main with all Pictures by pf */ ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pf1 = new ArrayList<>(); ArrayList<Double> pf3 = new ArrayList<>(); ArrayList<Double> pf5 = new ArrayList<>(); ArrayList<Double> pf7 = new ArrayList<>(); ArrayList<Double> pf9 = new ArrayList<>(); ArrayList<Double> pf01 = new ArrayList<>(); /* For the Paper */ pf0.add(0.0); pf1.add(1.0E-4); pf3.add(3.0E-4); pf5.add(4.0E-4); pf7.add(1.0E-2); pf9.add(1.0E-5); pf01.add(1.0E-3); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final ECALinfoCollected demo = new ECALinfoCollected("Information Collected", pf0); final ECALinfoCollected demo1 = new ECALinfoCollected("Information Collected", pf1); final ECALinfoCollected demo2 = new ECALinfoCollected("Information Collected", pf3); final ECALinfoCollected demo3 = new ECALinfoCollected("Information Collected", pf5); final ECALinfoCollected demo4 = new ECALinfoCollected("Information Collected", pf7); final ECALinfoCollected demo5 = new ECALinfoCollected("Information Collected", pf9); final ECALinfoCollected demo6 = new ECALinfoCollected("Information Collected", pf01); }
From source file:unalcol.termites.boxplots.HybridRoundNumberReport.java
/** * For testing from the command line./*from w ww . jav a 2s. c o m*/ * * @param args ignored. */ public static void main(final String[] args) { // double pf = Double.valueOf(args[0]); // System.out.println("pf:" + args[0]); /* SASO Paper */ /* double pf = 0; ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pfg1 = new ArrayList<>(); ArrayList<Double> pfg2 = new ArrayList<>(); ArrayList<Double> pfg3 = new ArrayList<>(); pf0.add(0.0); pfg1.add(1.0E-4); pfg1.add(3.0E-4); pfg2.add(5.0E-4); pfg2.add(7.0E-4); pfg3.add(9.0E-4); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final RoundNumber1 demo = new RoundNumber1("Round Number", pf0); final RoundNumber1 demo1 = new RoundNumber1("Round Number", pfg1); final RoundNumber1 demo2 = new RoundNumber1("Round Number", pfg2); final RoundNumber1 demo3 = new RoundNumber1("Round Number", pfg3); //demo.pack(); //RefineryUtilities.centerFrameOnScreen(demo); //demo.setVisible(true); */ double pf = 0; ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pf1 = new ArrayList<>(); ArrayList<Double> pf3 = new ArrayList<>(); ArrayList<Double> pf5 = new ArrayList<>(); ArrayList<Double> pf7 = new ArrayList<>(); ArrayList<Double> pf9 = new ArrayList<>(); ArrayList<Double> pf01 = new ArrayList<>(); pf0.add(0.0); //pf1.add(1.0E-4); pf3.add(3.0E-4); //pf5.add(5.0E-4); pf7.add(7.0E-4); //pf9.add(9.0E-4); //pf01.add(1.0E-3); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final HybridRoundNumberReport demo = new HybridRoundNumberReport("Round Number", pf0); //final HybridRoundNumberReport demo1 = new HybridRoundNumberReport("Round Number", pf1); final HybridRoundNumberReport demo2 = new HybridRoundNumberReport("Round Number", pf3); //final HybridRoundNumberReport demo3 = new HybridRoundNumberReport("Round Number", pf5); final HybridRoundNumberReport demo4 = new HybridRoundNumberReport("Round Number", pf7); //final HybridRoundNumberReport demo5 = new HybridRoundNumberReport("Round Number", pf9); //final HybridRoundNumberReport demo6 = new HybridRoundNumberReport("Round Number", pf01); //demo.pack(); //RefineryUtilities.centerFrameOnScreen(demo); //demo.setVisible(true); }
From source file:at.tuwien.aic.Main.java
/** * Main entry point/*from w ww .ja v a 2s. c om*/ * * @param args */ @SuppressWarnings("empty-statement") public static void main(String[] args) throws IOException, InterruptedException { try { System.out.println(new java.io.File(".").getCanonicalPath()); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } TweetCrawler tc = null; try { tc = TweetCrawler.getInstance(); } catch (UnknownHostException ex) { logger.severe("Could not connect to mongoDb"); exitWithError(2); return; } int action; while (true) { action = getDecision("The following actions can be executed", new String[] { "Subscribe to topic", "Query topic", "Test preprocessing", "Recreate the evaluation model", "Quit the application" }, "What action do you want to execute?"); switch (action) { case 1: tc.collectTweets(new DefaultTweetHandler() { @Override public boolean isMatch(String topic) { return true; } }, getNonEmptyString( "Which topic do you want to subscribe to (use spaces to specify more than one keyword)?") .split(" ")); System.out.println("Starting to collection tweets"); System.out.println("Press enter to quit collecting"); while (System.in.read() != 10) ; tc.stopCollecting(); break; case 2: System.out.println("Enter tweet"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String tweet = br.readLine(); //double prediction = ClassifyTweet.classifyTweets(c, tweet, 2); System.exit(0); //classifyTopic(); break; case 3: int subAction = getDecision("The following preprocessing steps are available", new String[] { "Stop word removal", "Stemming", "Both" }, "What do you want to test?"); switch (subAction) { case 1: stopWords(); break; case 2: stem(); break; case 3: stem(stopWords()); default: break; } break; case 4: //ClassifyTweet.classifyTweetArff(c, "resources/unlabeled.arff", "resources/train.arff"); ArrayList<String> tweets = new ArrayList<>(); ArrayList<String> processedTweets = new ArrayList<>(); //Positive Tweets tweets.add( "#Office365 is the fastest growing business in Microsofts history, one out of four enterprise clients owns #Office365 in the past 12 months"); tweets.add("oh yeah back to microsoft word it's great haha"); tweets.add( "Microsoft Visual Studio 2013 Ultimate: excellent tool, but a bit pricey at $13K - http://t.co/qbc4MHeOrF"); tweets.add( "Apple 'absolutely' plans to release new product types this year - Design Week: Design WeekApple 'absolutely' p... http://t.co/EK4rIbaHa0"); tweets.add( "RT @ReformedBroker: \"Apple can't innovate.\" Motherf***er you're watching a movie on a 4 ounce plate of glass."); tweets.add( "What's the best brand of shoes?! Lol. There's too damn many, what do you prefer. Me is some Adidas."); tweets.add( "I want ?? @AdorableWords: Tribal/Aztec pattern Nike free runs ?? http://t.co/WBxT8CNsPN?"); tweets.add( "I achieved the Streak Week trophy with my Nike+ FuelBand. #nikeplus http://t.co/OgtpRcoSvp"); tweets.add("RT @DriveOfAthletes: Retweet for Nike! Favorite for UA! http://t.co/sKZ8hb27xH"); //Neutral Tweets tweets.add("This site is giving away Free Microsoft Points #XBOX LIVE http://t.co/ZR1ythfqJ4"); tweets.add( "How To Save The World: 1. Open Microsoft Word. 2. In a size 12-36 font, type \"The World\". 3. Click save."); tweets.add( "Microsoft Special Deals for Education: Microsoft special deals for Students, faculty and staff: http://t.co/Hf0b2ixPZa"); tweets.add( "Microsoft is about to take Windows XP off life support On April 8, Windows XP's life is coming to an end. On that d http://t.co/kcSf4uIqW4"); tweets.add("Microsoft open sources its internet servers http://t.co/oLNTlVjE6Y"); tweets.add( "The Apple Macintosh computer turns 30 - ... http://t.co/CAfq09Jgn7 #CarlIcahn #IsaacsonIt #SteveJobs #WalterIsaacson"); tweets.add( "News Update| Samsung opens 60 dedicated stores in Europe with Carphone Warehouse http://t.co/1voh4yPMpN"); tweets.add("I posted a new photo to Facebook http://t.co/fI40hwklUj"); tweets.add( "Brand New Men's ADIDAS VIGOR TR 3 Athletic Running shoes. Size: 11.5 http://t.co/oPuFoXLpeI"); tweets.add("I just ran 2.58 mi with Nike+. http://t.co/pYLkhBxH4Y #nikeplus"); tweets.add("Why is facebook still a thing"); //Negative Tweets tweets.add("Thank God for microsoft programs....."); tweets.add( "RT @verge: UK government once again threatens to ditch Microsoft Office http://t.co/vhvybI1GwI"); tweets.add("Apple charge far too much for very poor phone cases"); tweets.add("Here's Why Everyone Is Worried About Apple's iPhone Sales http://t.co/Eq3oPt76AG"); tweets.add("Is Apple Ready to Disrupt Another Industry? http://t.co/07gedlN0cs via @zite"); tweets.add( "Tim Cook Officially Admits iPhone 5c Didnt Meet Expectations http://t.co/OdzGZOmdv7 #iPhone #Apple"); tweets.add("@MushIsAJedi @HeyItsAmine i dont rlly like samsung that much"); tweets.add("twitter facebook die shit"); tweets.add( "I am thinking of leaving Facebook for a while... To much spying going on.. I am sick and tired of thinking about... http:/)/t.co/ULydkDEube"); tweets.add("RT @OfficialSheIdon: RIP Facebook, too many of our parents joined."); StopWordRemoval swr = new StopWordRemoval("resources/stopwords.txt"); for (String t : tweets) { t = swr.processText(t); processedTweets.add(t); } for (int i = 0; i < 28; i++) { if (i != 4) { ArrayList<Integer> results = ClassifyTweet.classifyTweets(processedTweets, i); int correctCount = 0; int positiveCorrect = 0; int neutralCorrect = 0; int negativeCorrect = 0; int falsePosNeu = 0; int falsePosNeg = 0; int falseNeuPos = 0; int falseNeuNeg = 0; int falseNegNeu = 0; int falseNegPos = 0; for (int j = 0; j < 30; j++) { int pred = results.get(j); if (j >= 0 && j < 10) { if (pred == 1) { correctCount++; positiveCorrect++; } else if (pred == 0) { falsePosNeu++; } else if (pred == -1) { falsePosNeg++; } } else if (j >= 10 && j < 20) { if (pred == 0) { correctCount++; neutralCorrect++; } else if (pred == 1) { falseNeuPos++; } else if (pred == -1) { falseNeuNeg++; } } else if (j >= 20 && j < 30) { if (pred == -1) { correctCount++; negativeCorrect++; } else if (pred == 0) { falseNegNeu++; } else if (pred == 1) { falseNegPos++; } } } System.out.println("Correct Predictions: " + correctCount + " / 30"); System.out.println("Correct Positive: " + positiveCorrect + " / 10"); System.out.println("Correct Neutral: " + neutralCorrect + " / 10"); System.out.println("Correct Negative: " + negativeCorrect + " / 10"); System.out.println("False Positive as Neutral: " + falsePosNeu); System.out.println("False Positive as Negative: " + falsePosNeg); System.out.println("False Neutral as Positive: " + falseNeuPos); System.out.println("False Neutral as Negative: " + falseNeuNeg); System.out.println("False Negative as Positive: " + falseNegPos); System.out.println("False Negative as Neutral: " + falseNegNeu); } } exit(); case 5: exit(); } } }