List of usage examples for java.lang Double toString
public static String toString(double d)
From source file:main.RankerOCR.java
/** * Command line interface for RankerOCR. * <p>/*from w w w .j a va 2 s . c o m*/ * <b>Command line input:</b> * <ul> * usage: java -jar Ranker-OCR [options] * </ul> * <b>Options list:</b> * <ul> * <li>-gui Launch a graphical user interface</li> * <li>-help Show the help</li> * <li>-indoc1 [arg] Set the file name of the original document</li> * <li>-indoc2 [arg] Set the file name of the document to compare</li> * <li>-ranker [arg] Set the ranker used for the comparison</li> * <li>-outdoc [arg] Set the document where write the results</li> * <li>-separator [arg] Set the delimiter char use in the CSV out file</li> * </ul> * <b>Return values are if error:</b> * <ul> * <li>(-1) The precision parameter is not a number.</li> * <li>(-2) The precision parameter is lower than 0.</li> * <li>(-3) The precision parameter is greater than 10.</li> * <li>(-11) The ranker name is wrong</li> * <li>(-21) The separator char is empty</li> * <li>(-22) The separator is not a char</li> * <li>(-31) File name doesn't exist</li> * <li>(-32) File name is not a file</li> * <li>(-33) Error when access to documents files</li> * <li>(-34) Output file can not be write</li> * <li>(-35) Output file can not be created</li> * <li>(-41) Error when parsing parameters</li> * <li>(-100) Internal error when creating the ranker. Please report a * bug</li> * <li>(-101) Internal error when get the ranker list. Please report a * bug.</li> * <li>(-102) Error when access to help file. Please report a bug.</li> * </ul> * <p> * @param args Argument array which can have the values from options list */ public static void main(String[] args) { //Parse command line CommandLineParser parser = new GnuParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { showHelp(hf, options); } else if (cmd.hasOption("gui")) { display.DispalyRankerOCR.main(new String[] {}); } else if (cmd.hasOption("indoc1") && cmd.hasOption("indoc2") && cmd.hasOption("outdoc")) { //<editor-fold defaultstate="collapsed" desc="Rank documents"> //Prepare parameter Class ranker = evalRanker(cmd.getOptionValue("ranker", "SimpleRanker")); char separator = evalSeparator(cmd.getOptionValue("separator", "\t")); File f1 = evalInputFile(cmd.getOptionValue("indoc1", "")); File f2 = evalInputFile(cmd.getOptionValue("indoc2", "")); File f3 = evalOutputFile(cmd.getOptionValue("outdoc", ""), separator); //Read file String s1 = readInputDocText(f1); String s2 = readInputDocText(f2); //Compare file double percent = rankDocuments(s1, s2, ranker); //Write result String[] s = { Double.toString(percent), ranker.getSimpleName(), f1.getName(), f2.getName(), f1.getParent(), f2.getParent(), new Date().toString() }; writeOutpuDocCsv(f3, separator, s); //</editor-fold> } else { printFormated("java -jar Ranker-OCR [options] please type " + "-help for more info"); } } catch (ParseException ex) { printFormated(ex.getLocalizedMessage()); System.exit(-41); } }
From source file:eu.amidst.core.inference.MPEInferenceExperiments.java
/** * The class constructor./*from ww w . ja v a2s. co m*/ * @param args Array of options: "filename variable a b N useVMP" if variable is continuous or "filename variable w N useVMP" for discrete */ public static void main(String[] args) throws Exception { int seedNetwork = 61236719 + 123; int numberOfGaussians = 20; int numberOfMultinomials = numberOfGaussians; BayesianNetworkGenerator.setSeed(seedNetwork); BayesianNetworkGenerator.setNumberOfGaussianVars(numberOfGaussians); BayesianNetworkGenerator.setNumberOfMultinomialVars(numberOfMultinomials, 2); BayesianNetworkGenerator.setNumberOfLinks((int) 1.3 * (numberOfGaussians + numberOfMultinomials)); BayesianNetwork bn = BayesianNetworkGenerator.generateBayesianNetwork(); int seed = seedNetwork + 231591; //if (Main.VERBOSE) System.out.println(bn.getDAG()); if (Main.VERBOSE) System.out.println(bn.toString()); MPEInference mpeInference = new MPEInference(); mpeInference.setModel(bn); mpeInference.setParallelMode(true); if (Main.VERBOSE) System.out.println("CausalOrder: " + Arrays.toString(Utils.getTopologicalOrder(mpeInference.getOriginalModel().getDAG()).stream() .map(Variable::getName).toArray())); List<Variable> modelVariables = Utils.getTopologicalOrder(bn.getDAG()); if (Main.VERBOSE) System.out.println(); // Including evidence: //double observedVariablesRate = 0.00; //Assignment evidence = randomEvidence(seed, observedVariablesRate, bn); //mpeInference.setEvidence(evidence); int parallelSamples = 100; int samplingMethodSize = 10000; mpeInference.setSampleSize(parallelSamples); /*********************************************** * SIMULATED ANNEALING ************************************************/ // MPE INFERENCE WITH SIMULATED ANNEALING, ALL VARIABLES if (Main.VERBOSE) System.out.println(); long timeStart = System.nanoTime(); mpeInference.runInference(MPEInference.SearchAlgorithm.SA_GLOBAL); Assignment mpeEstimate = mpeInference.getEstimate(); if (Main.VERBOSE) System.out.println("MPE estimate (SA.All): " + mpeEstimate.outputString(modelVariables)); //toString(modelVariables) if (Main.VERBOSE) System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate()) + ", logProb: " + mpeInference.getLogProbabilityOfEstimate()); long timeStop = System.nanoTime(); double execTime = (double) (timeStop - timeStart) / 1000000000.0; if (Main.VERBOSE) System.out.println("computed in: " + Double.toString(execTime) + " seconds"); //if (Main.VERBOSE) System.out.println(.toString(mapInference.getOriginalModel().getStaticVariables().iterator().)); if (Main.VERBOSE) System.out.println(); // MPE INFERENCE WITH SIMULATED ANNEALING, SOME VARIABLES AT EACH TIME timeStart = System.nanoTime(); mpeInference.runInference(MPEInference.SearchAlgorithm.SA_LOCAL); mpeEstimate = mpeInference.getEstimate(); if (Main.VERBOSE) System.out.println("MPE estimate (SA.Some): " + mpeEstimate.outputString(modelVariables)); //toString(modelVariables) if (Main.VERBOSE) System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate()) + ", logProb: " + mpeInference.getLogProbabilityOfEstimate()); timeStop = System.nanoTime(); execTime = (double) (timeStop - timeStart) / 1000000000.0; if (Main.VERBOSE) System.out.println("computed in: " + Double.toString(execTime) + " seconds"); //if (Main.VERBOSE) System.out.println(.toString(mapInference.getOriginalModel().getStaticVariables().iterator().)); if (Main.VERBOSE) System.out.println(); /*********************************************** * HILL CLIMBING ************************************************/ // MPE INFERENCE WITH HILL CLIMBING, ALL VARIABLES timeStart = System.nanoTime(); mpeInference.runInference(MPEInference.SearchAlgorithm.HC_GLOBAL); mpeEstimate = mpeInference.getEstimate(); //modelVariables = mpeInference.getOriginalModel().getVariables().getListOfVariables(); if (Main.VERBOSE) System.out.println("MPE estimate (HC.All): " + mpeEstimate.outputString(modelVariables)); if (Main.VERBOSE) System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate()) + ", logProb: " + mpeInference.getLogProbabilityOfEstimate()); timeStop = System.nanoTime(); execTime = (double) (timeStop - timeStart) / 1000000000.0; if (Main.VERBOSE) System.out.println("computed in: " + Double.toString(execTime) + " seconds"); if (Main.VERBOSE) System.out.println(); // MPE INFERENCE WITH HILL CLIMBING, ONE VARIABLE AT EACH TIME timeStart = System.nanoTime(); mpeInference.runInference(MPEInference.SearchAlgorithm.HC_LOCAL); mpeEstimate = mpeInference.getEstimate(); if (Main.VERBOSE) System.out.println("MPE estimate (HC.Some): " + mpeEstimate.outputString(modelVariables)); //toString(modelVariables) if (Main.VERBOSE) System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate()) + ", logProb: " + mpeInference.getLogProbabilityOfEstimate()); timeStop = System.nanoTime(); execTime = (double) (timeStop - timeStart) / 1000000000.0; if (Main.VERBOSE) System.out.println("computed in: " + Double.toString(execTime) + " seconds"); if (Main.VERBOSE) System.out.println(); /*********************************************** * SAMPLING AND DETERMINISTIC ************************************************/ // MPE INFERENCE WITH SIMULATION AND PICKING MAX mpeInference.setSampleSize(samplingMethodSize); timeStart = System.nanoTime(); mpeInference.runInference(MPEInference.SearchAlgorithm.SAMPLING); mpeEstimate = mpeInference.getEstimate(); //modelVariables = mpeInference.getOriginalModel().getVariables().getListOfVariables(); if (Main.VERBOSE) System.out.println("MPE estimate (SAMPLING): " + mpeEstimate.outputString(modelVariables)); if (Main.VERBOSE) System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate()) + ", logProb: " + mpeInference.getLogProbabilityOfEstimate()); timeStop = System.nanoTime(); execTime = (double) (timeStop - timeStart) / 1000000000.0; if (Main.VERBOSE) System.out.println("computed in: " + Double.toString(execTime) + " seconds"); if (Main.VERBOSE) System.out.println(); if (bn.getNumberOfVars() <= 50) { // MPE INFERENCE, DETERMINISTIC timeStart = System.nanoTime(); mpeInference.runInference(MPEInference.SearchAlgorithm.EXHAUSTIVE); mpeEstimate = mpeInference.getEstimate(); //modelVariables = mpeInference.getOriginalModel().getVariables().getListOfVariables(); if (Main.VERBOSE) System.out.println("MPE estimate (DETERM.): " + mpeEstimate.outputString(modelVariables)); if (Main.VERBOSE) System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate()) + ", logProb: " + mpeInference.getLogProbabilityOfEstimate()); timeStop = System.nanoTime(); execTime = (double) (timeStop - timeStart) / 1000000000.0; if (Main.VERBOSE) System.out.println("computed in: " + Double.toString(execTime) + " seconds"); if (Main.VERBOSE) System.out.println(); } }
From source file:de.codesourcery.geoip.Main.java
public static void main(String[] args) throws Exception { final IGeoLocator<StringSubject> locator = createGeoLocator(); final JFrame frame = new JFrame("GeoIP"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { try { locator.dispose();// w w w .j ava 2 s . c om } catch (Exception e1) { e1.printStackTrace(); } }; }); final MapImage image = MapImage.getRobinsonWorldMap(); // MapImage.getMillerWorldMap(); final MapCanvas canvas = new MapCanvas(image); for (GeoLocation<StringSubject> loc : locator.locate(getSpammers())) { if (loc.hasValidCoordinates()) { canvas.addCoordinate(PointRenderer.createPoint(loc, Color.YELLOW)); } } // canvas.addCoordinate( PointRenderer.createPoint( ZERO , Color.YELLOW ) ); // canvas.addCoordinate( PointRenderer.createPoint( WELLINGTON , Color.RED ) ); // canvas.addCoordinate( PointRenderer.createPoint( MELBOURNE , Color.RED ) ); // canvas.addCoordinate( PointRenderer.createPoint( HAMBURG , Color.RED ) ); final double heightToWidth = image.height() / (double) image.width(); // preserve aspect ratio of map canvas.setPreferredSize(new Dimension(640, (int) Math.round(640 * heightToWidth))); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); panel.add(new JLabel("Scale-X")); final JTextField scaleX = new JTextField(Double.toString(image.getScaleX())); scaleX.setColumns(5); final JTextField scaleY = new JTextField(Double.toString(image.getScaleY())); scaleY.setColumns(5); final ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double x = Double.parseDouble(scaleX.getText()); double y = Double.parseDouble(scaleY.getText()); image.setScale(x, y); canvas.repaint(); } }; scaleX.addActionListener(listener); scaleY.addActionListener(listener); panel.add(new JLabel("Scale-X")); panel.add(scaleX); panel.add(new JLabel("Scale-Y")); panel.add(scaleY); final JTextField ipAddress = new JTextField("www.kickstarter.com"); ipAddress.setColumns(20); final ActionListener ipListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final String destinationIP = ipAddress.getText(); if (StringUtils.isBlank(destinationIP)) { return; } /* * Perform traceroute. */ final List<String> hops; try { if (TracePath.isPathTracingAvailable()) { hops = TracePath.trace(destinationIP); } else { System.err.println("tracepath not available."); if (TracePath.isValidAddress(destinationIP)) { hops = new ArrayList<>(); hops.add(destinationIP); } else { System.err.println(destinationIP + " is no valid IP"); return; } } } catch (Exception ex) { System.err.println("Failed to trace " + destinationIP); ex.printStackTrace(); return; } System.out.println("Trace contains " + hops.size() + " IPs"); /* * Gather locations. */ final List<StringSubject> subjects = new ArrayList<>(); for (String ip : hops) { subjects.add(new StringSubject(ip)); } final List<GeoLocation<StringSubject>> locations; try { long time = -System.currentTimeMillis(); locations = locator.locate(subjects); time += System.currentTimeMillis(); System.out.println("Locating hops for " + destinationIP + " returned " + locations.size() + " valid locations ( time: " + time + " ms)"); System.out.flush(); } catch (Exception e2) { e2.printStackTrace(); return; } /* * Weed-out invalid/unknown locations. */ { GeoLocation<StringSubject> previous = null; for (Iterator<GeoLocation<StringSubject>> it = locations.iterator(); it.hasNext();) { final GeoLocation<StringSubject> location = it.next(); if (!location.hasValidCoordinates() || (previous != null && previous.coordinate().equals(location.coordinate()))) { it.remove(); System.err.println("Ignoring invalid/duplicate location for " + location); } else { previous = location; } } } /* * Populate chart. */ System.out.println("Adding " + locations.size() + " hops to chart"); System.out.flush(); canvas.removeAllCoordinates(); if (locations.size() == 1) { canvas.addCoordinate( PointRenderer.createPoint(locations.get(0), getLabel(locations.get(0)), Color.BLACK)); } else if (locations.size() > 1) { GeoLocation<StringSubject> previous = locations.get(0); MapPoint previousPoint = PointRenderer.createPoint(previous, getLabel(previous), Color.BLACK); final int len = locations.size(); for (int i = 1; i < len; i++) { final GeoLocation<StringSubject> current = locations.get(i); // final MapPoint currentPoint = PointRenderer.createPoint( current , getLabel( current ) , Color.BLACK ); final MapPoint currentPoint = PointRenderer.createPoint(current, Color.BLACK); // canvas.addCoordinate( LineRenderer.createLine( previousPoint , currentPoint , Color.RED ) ); canvas.addCoordinate(CurvedLineRenderer.createLine(previousPoint, currentPoint, Color.RED)); previous = locations.get(i); previousPoint = currentPoint; } } System.out.println("Finished adding"); System.out.flush(); canvas.repaint(); } }; ipAddress.addActionListener(ipListener); panel.add(new JLabel("IP")); panel.add(ipAddress); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(panel, BorderLayout.NORTH); frame.getContentPane().add(canvas, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:eu.amidst.core.inference.ImportanceSamplingExperiments.java
/** * The class constructor.//ww w .ja v a2 s . co m * @param args Array of options: "filename variable a b N useVMP" if variable is continuous or "filename variable w N useVMP" for discrete */ public static void main(String[] args) throws Exception { //if (Main.VERBOSE) System.out.println("CONTINUOUS VARIABLE"); boolean discrete = false; String filename = ""; //Filename with the Bayesian Network String varname = ""; // Variable of interest in the BN double a = 0; // Lower endpoint of the interval double b = 0; // Upper endpoint of the interval int N = 0; // Sample size boolean useVMP = false; // Boolean indicating whether use VMP or not // FOR A CONTINUOUS VARIABLE OF INTEREST if (args.length == 6) { filename = args[0]; //Filename with the Bayesian Network varname = args[1]; // Variable of interest in the BN String aa = args[2]; // Lower endpoint of the interval String bb = args[3]; // Upper endpoint of the interval String NN = args[4]; // Sample size String useVMParg = args[5]; // Boolean indicating whether use VMP or not try { a = Double.parseDouble(aa); b = Double.parseDouble(bb); N = Integer.parseInt(NN); useVMP = Boolean.parseBoolean(useVMParg); } catch (NumberFormatException e) { if (Main.VERBOSE) System.out.println(e.toString()); } } // FOR A DISCRETE VARIABLE OF INTEREST else if (args.length == 5) { //if (Main.VERBOSE) System.out.println("DISCRETE VARIABLE"); discrete = true; if (Main.VERBOSE) System.out.println("Not available yet"); System.exit(1); } else if (args.length == 0) { filename = "networks/simulated/Bayesian10Vars15Links.bn"; //Filename with the Bayesian Network //filename="networks/Bayesian2Vars1Link.bn"; varname = "GaussianVar1"; // Variable of interest in the BN a = 0; // Lower endpoint of the interval b = 1; // Upper endpoint of the interval N = 10000; // Sample size useVMP = false; // Boolean indicating whether use VMP or not } else { if (Main.VERBOSE) System.out.println("Invalid number of arguments. See comments in main"); System.exit(1); } BayesianNetwork bn; VMP vmp = new VMP(); ImportanceSampling importanceSampling = new ImportanceSampling(); try { bn = BayesianNetworkLoader.loadFromFile(filename); if (Main.VERBOSE) System.out.println(bn.toString()); Variable varInterest = bn.getVariables().getVariableByName(varname); vmp.setModel(bn); vmp.runInference(); importanceSampling.setModel(bn); //importanceSampling.setSamplingModel(vmp.getSamplingModel()); importanceSampling.setSamplingModel(bn); importanceSampling.setParallelMode(true); importanceSampling.setKeepDataOnMemory(true); importanceSampling.setSampleSize(N); // Including evidence: Assignment assignment = randomEvidence(1823716125, 0.05, bn, varInterest); importanceSampling.setEvidence(assignment); //importanceSampling.setSamplingModel(vmp.getSamplingModel()); //importanceSampling.runInference(vmp); //if (Main.VERBOSE) System.out.println("Posterior of " + varInterest.getName() + " (IS w. Evidence VMP) :" + importanceSampling.getPosterior(varInterest).toString()); //importanceSampling.setSamplingModel(bn); importanceSampling.runInference(); if (Main.VERBOSE) System.out.println("Posterior of " + varInterest.getName() + " (IS w. Evidence) :" + importanceSampling.getPosterior(varInterest).toString()); if (Main.VERBOSE) System.out.println("Posterior of " + varInterest.getName() + " (VMP) :" + vmp.getPosterior(varInterest).toString()); if (Main.VERBOSE) System.out.println(); if (Main.VERBOSE) System.out.println("Variable of interest: " + varInterest.getName()); if (Main.VERBOSE) System.out.println(); a = 1.5; // Lower endpoint of the interval b = 10000; // Upper endpoint of the interval final double finalA = a; final double finalB = b; double result = importanceSampling.getExpectedValue(varInterest, v -> (finalA < v && v < finalB) ? 1.0 : 0.0); if (Main.VERBOSE) System.out.println("Query: P(" + Double.toString(a) + " < " + varInterest.getName() + " < " + Double.toString(b) + ")"); if (Main.VERBOSE) System.out.println("Probability result: " + result); /* if (Main.VERBOSE) System.out.println(); varname = "DiscreteVar2"; if (Main.VERBOSE) System.out.println(); Variable discreteVarInterest = bn.getVariables().getVariableByName(varname); if (Main.VERBOSE) System.out.println("Variable of interest: " + discreteVarInterest.getName()); importanceSampling.runInference(); int w=1; // Value of interest double result2 = importanceSampling.runQuery(discreteVarInterest, w); if (Main.VERBOSE) System.out.println("Query: P(" + discreteVarInterest.getName() + " = " + Integer.toString(w) + ")"); if (Main.VERBOSE) System.out.println("Probability result: " + result2);*/ } catch (Exception e) { if (Main.VERBOSE) System.out.println("Error loading Bayesian Network from file"); if (Main.VERBOSE) System.out.println(e.toString()); } }
From source file:com.jug.MotherMachine.java
/** * PROJECT MAIN/*w ww . j a v a 2s . c om*/ * ============ * * @param args * muh! */ public static void main(final String[] args) { try { final MotherMachine main = new MotherMachine(); guiFrame = new JFrame("Interactive MotherMachine"); main.initMainWindow(guiFrame); props = main.loadParams(); BGREM_TEMPLATE_XMIN = Integer .parseInt(props.getProperty("BGREM_TEMPLATE_XMIN", Integer.toString(BGREM_TEMPLATE_XMIN))); BGREM_TEMPLATE_XMAX = Integer .parseInt(props.getProperty("BGREM_TEMPLATE_XMAX", Integer.toString(BGREM_TEMPLATE_XMAX))); BGREM_X_OFFSET = Integer .parseInt(props.getProperty("BGREM_X_OFFSET", Integer.toString(BGREM_X_OFFSET))); GL_OFFSET_BOTTOM = Integer .parseInt(props.getProperty("GL_OFFSET_BOTTOM", Integer.toString(GL_OFFSET_BOTTOM))); GL_OFFSET_TOP = Integer.parseInt(props.getProperty("GL_OFFSET_TOP", Integer.toString(GL_OFFSET_TOP))); GL_OFFSET_LATERAL = Integer .parseInt(props.getProperty("GL_OFFSET_LATERAL", Integer.toString(GL_OFFSET_LATERAL))); MIN_CELL_LENGTH = Integer .parseInt(props.getProperty("MIN_CELL_LENGTH", Integer.toString(MIN_CELL_LENGTH))); MIN_GAP_CONTRAST = Double .parseDouble(props.getProperty("MIN_GAP_CONTRAST", Double.toString(MIN_GAP_CONTRAST))); SIGMA_PRE_SEGMENTATION_X = Double.parseDouble( props.getProperty("SIGMA_PRE_SEGMENTATION_X", Double.toString(SIGMA_PRE_SEGMENTATION_X))); SIGMA_PRE_SEGMENTATION_Y = Double.parseDouble( props.getProperty("SIGMA_PRE_SEGMENTATION_Y", Double.toString(SIGMA_PRE_SEGMENTATION_Y))); SIGMA_GL_DETECTION_X = Double .parseDouble(props.getProperty("SIGMA_GL_DETECTION_X", Double.toString(SIGMA_GL_DETECTION_X))); SIGMA_GL_DETECTION_Y = Double .parseDouble(props.getProperty("SIGMA_GL_DETECTION_Y", Double.toString(SIGMA_GL_DETECTION_Y))); DEFAULT_PATH = props.getProperty("DEFAULT_PATH", DEFAULT_PATH); GUI_POS_X = Integer.parseInt(props.getProperty("GUI_POS_X", Integer.toString(DEFAULT_GUI_POS_X))); GUI_POS_Y = Integer.parseInt(props.getProperty("GUI_POS_Y", Integer.toString(DEFAULT_GUI_POS_X))); GUI_WIDTH = Integer.parseInt(props.getProperty("GUI_WIDTH", Integer.toString(GUI_WIDTH))); GUI_HEIGHT = Integer.parseInt(props.getProperty("GUI_HEIGHT", Integer.toString(GUI_HEIGHT))); GUI_CONSOLE_WIDTH = Integer .parseInt(props.getProperty("GUI_CONSOLE_WIDTH", Integer.toString(GUI_CONSOLE_WIDTH))); // Iterate over all currently attached monitors and check if sceen position is actually possible, // otherwise fall back to the DEFAULT values and ignore the ones coming from the properties-file. boolean pos_ok = false; final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice[] gs = ge.getScreenDevices(); for (int i = 0; i < gs.length; i++) { final DisplayMode dm = gs[i].getDisplayMode(); if (gs[i].getDefaultConfiguration().getBounds() .contains(new java.awt.Point(GUI_POS_X, GUI_POS_Y))) { pos_ok = true; } } // None of the screens contained the top-left window coordinates --> fall back onto default values... if (!pos_ok) { GUI_POS_X = DEFAULT_GUI_POS_X; GUI_POS_Y = DEFAULT_GUI_POS_Y; } String path = props.getProperty("import_path", System.getProperty("user.home")); final File fPath = main.showStartupDialog(guiFrame, path); path = fPath.getAbsolutePath(); props.setProperty("import_path", fPath.getAbsolutePath()); // Setting up console window and window snapper... main.initConsoleWindow(); main.showConsoleWindow(); final JFrameSnapper snapper = new JFrameSnapper(); snapper.addFrame(main.frameConsoleWindow); snapper.addFrame(guiFrame); // --------------------------------------------------- main.processDataFromFolder(path); // --------------------------------------------------- System.out.print("Build and show GUI..."); // show loaded and annotated data ImageJFunctions.show(main.imgRaw, "Rotated & cropped raw data"); ImageJFunctions.show(main.imgTemp, "Temporary"); ImageJFunctions.show(main.imgAnnotated, "Annotated ARGB data"); final MotherMachineGui gui = new MotherMachineGui(new MotherMachineModel(main)); gui.setVisible(true); main.ij = new ImageJ(); guiFrame.add(gui); guiFrame.setSize(GUI_WIDTH, GUI_HEIGHT); guiFrame.setLocation(GUI_POS_X, GUI_POS_Y); guiFrame.setVisible(true); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { snapper.snapFrames(main.frameConsoleWindow, guiFrame, JFrameSnapper.EAST); } }); System.out.println(" done!"); } catch (final UnsatisfiedLinkError ulr) { JOptionPane.showMessageDialog(MotherMachine.guiFrame, "Could initialize Gurobi.\n" + "You might not have installed Gurobi properly or you miss a valid license.\n" + "Please visit 'www.gurobi.com' for further information.\n\n" + ulr.getMessage(), "Gurobi Error?", JOptionPane.ERROR_MESSAGE); } }
From source file:com.bah.applefox.main.Ingest.java
public static void main(String[] args) throws Exception { if (args.length == 1 && args[0].equals("--help")) { System.out.println("Not enough arguments"); System.out.println("Arguments should be in the format <properties file> <command>"); System.out.println("Valid commands:"); System.out.println("\tpr: Calculates Page Rank"); System.out.println("\timageload: Loads Images from URLs"); System.out.println("\tload: Loads Full Text Data"); System.out.println("\tingest: Ingests URLs from given seed"); System.out.println("\tftsample: Creates a Full Text Index Sample HashMap"); System.out.println("\timagesample: Creates an Image Hash and Image Tag Sample HashMap"); }/*from w ww . j av a 2s . c o m*/ if (args.length > 2) { System.out.println("2 Arguments expected, " + args.length + " given."); } if (args.length < 2) { System.out.println("Not enough arguments"); System.out.println("Arguments should be in the format <properties file> <command>"); System.out.println("Valid commands:"); System.out.println("\tpr: Calculates Page Rank"); System.out.println("\timageload: Loads Images from URLs"); System.out.println("\tload: Loads Full Text Data"); System.out.println("\tingest: Ingests URLs from given seed"); System.out.println("\tftsample: Creates a Full Text Index Sample HashMap"); System.out.println("\timagesample: Creates an Image Hash and Image Tag Sample HashMap"); } injector = Guice.createInjector(new IngesterModule()); // The properties object to read from the configuration file Properties properties = new Properties(); try { // Load configuration file from the command line properties.load(new FileInputStream(args[0])); } catch (Exception e) { log.error("ABORT: File not found or could not read from file ->" + e.getMessage()); log.error("Enter the location of the configuration file"); System.exit(1); } // Initialize variables from configuration file // Accumulo Variables INSTANCE_NAME = properties.getProperty("INSTANCE_NAME"); ZK_SERVERS = properties.getProperty("ZK_SERVERS"); USERNAME = properties.getProperty("USERNAME"); PASSWORD = properties.getProperty("PASSWORD"); SPLIT_SIZE = properties.getProperty("SPLIT_SIZE"); NUM_ITERATIONS = Integer.parseInt(properties.getProperty("NUM_ITERATIONS")); NUM_NODES = Integer.parseInt(properties.getProperty("NUM_NODES")); // General Search Variables MAX_NGRAMS = Integer.parseInt(properties.getProperty("MAX_NGRAMS")); GENERAL_STOP = properties.getProperty("GENERAL_STOP"); // Full Text Variables FT_DATA_TABLE = properties.getProperty("FT_DATA_TABLE"); FT_SAMPLE = properties.getProperty("FT_SAMPLE"); FT_CHECKED_TABLE = properties.getProperty("FT_CHECKED_TABLE"); FT_DIVS_FILE = properties.getProperty("FT_DIVS_FILE"); FT_SPLIT_SIZE = properties.getProperty("FT_SPLIT_SIZE"); // Web Crawler Variables URL_TABLE = properties.getProperty("URL_TABLE"); SEED = properties.getProperty("SEED"); USER_AGENT = properties.getProperty("USER_AGENT"); URL_SPLIT_SIZE = properties.getProperty("URL_SPLIT_SIZE"); // Page Rank Variables PR_TABLE_PREFIX = properties.getProperty("PR_TABLE_PREFIX"); PR_URL_MAP_TABLE_PREFIX = properties.getProperty("PR_URL_MAP_TABLE_PREFIX"); PR_OUT_LINKS_COUNT_TABLE = properties.getProperty("PR_OUT_LINKS_COUNT_TABLE"); PR_FILE = properties.getProperty("PR_FILE"); PR_DAMPENING_FACTOR = Double.parseDouble(properties.getProperty("PR_DAMPENING_FACTOR")); PR_ITERATIONS = Integer.parseInt(properties.getProperty("PR_ITERATIONS")); PR_SPLIT_SIZE = properties.getProperty("PR_SPLIT_SIZE"); // Image Variables IMG_HASH_TABLE = properties.getProperty("IMG_HASH_TABLE"); IMG_CHECKED_TABLE = properties.getProperty("IMG_CHECKED_TABLE"); IMG_TAG_TABLE = properties.getProperty("IMG_TAG_TABLE"); IMG_HASH_SAMPLE_TABLE = properties.getProperty("IMG_HASH_SAMPLE_TABLE"); IMG_TAG_SAMPLE_TABLE = properties.getProperty("IMG_TAG_SAMPLE_TABLE"); IMG_SPLIT_SIZE = properties.getProperty("IMG_SPLIT_SIZE"); // Future Use: // Work Directory in HDFS WORK_DIR = properties.getProperty("WORK_DIR"); // Initialize variable from command line RUN = args[1].toLowerCase(); // Set the instance information for AccumuloUtils AccumuloUtils.setInstanceName(INSTANCE_NAME); AccumuloUtils.setInstancePassword(PASSWORD); AccumuloUtils.setUser(USERNAME); AccumuloUtils.setZooserver(ZK_SERVERS); AccumuloUtils.setSplitSize(SPLIT_SIZE); String[] temp = new String[25]; // Accumulo Variables temp[0] = INSTANCE_NAME; temp[1] = ZK_SERVERS; temp[2] = USERNAME; temp[3] = PASSWORD; // Number of Map Tasks temp[4] = Integer.toString((int) Math.ceil(1.75 * NUM_NODES * 2)); // Web Crawler Variables temp[5] = URL_TABLE; temp[6] = USER_AGENT; // Future Use temp[7] = WORK_DIR; // General Search temp[8] = GENERAL_STOP; temp[9] = Integer.toString(MAX_NGRAMS); // Full Text Variables temp[10] = FT_DATA_TABLE; temp[11] = FT_CHECKED_TABLE; // Page Rank Variables temp[12] = PR_URL_MAP_TABLE_PREFIX; temp[13] = PR_TABLE_PREFIX; temp[14] = Double.toString(PR_DAMPENING_FACTOR); temp[15] = PR_OUT_LINKS_COUNT_TABLE; temp[16] = PR_FILE; // Image Variables temp[17] = IMG_HASH_TABLE; temp[18] = IMG_CHECKED_TABLE; temp[19] = IMG_TAG_TABLE; temp[20] = FT_DIVS_FILE; // Table Split Sizes temp[21] = FT_SPLIT_SIZE; temp[22] = IMG_SPLIT_SIZE; temp[23] = URL_SPLIT_SIZE; temp[24] = PR_SPLIT_SIZE; if (RUN.equals("pr")) { // Run PR_ITERATIONS number of iterations for page ranking PageRank.createPageRank(temp, PR_ITERATIONS, URL_SPLIT_SIZE); } else if (RUN.equals("imageload")) { // Load image index AccumuloUtils.setSplitSize(URL_SPLIT_SIZE); ToolRunner.run(new ImageLoader(), temp); } else if (RUN.equals("ingest")) { // Ingest System.out.println("Ingesting"); // Set table split size AccumuloUtils.setSplitSize(URL_SPLIT_SIZE); // Write the seed value to the table BatchWriter w; Value v = new Value(); v.set("0".getBytes()); Mutation m = new Mutation(SEED); m.put("0", "0", v); w = AccumuloUtils.connectBatchWrite(URL_TABLE); w.addMutation(m); for (int i = 0; i < NUM_ITERATIONS; i++) { // Run the ToolRunner for NUM_ITERATIONS iterations ToolRunner.run(CachedConfiguration.getInstance(), injector.getInstance(Ingester.class), temp); } } else if (RUN.equals("load")) { // Parse the URLs and add to the data table AccumuloUtils.setSplitSize(URL_SPLIT_SIZE); BatchWriter w = AccumuloUtils.connectBatchWrite(FT_CHECKED_TABLE); w.close(); AccumuloUtils.setSplitSize(FT_SPLIT_SIZE); w = AccumuloUtils.connectBatchWrite(FT_DATA_TABLE); w.close(); ToolRunner.run(CachedConfiguration.getInstance(), injector.getInstance(Loader.class), temp); } else if (RUN.equals("ftsample")) { // Create a sample table for full text index FTAccumuloSampler ftSampler = new FTAccumuloSampler(FT_SAMPLE, FT_DATA_TABLE, FT_CHECKED_TABLE); ftSampler.createSample(); } else if (RUN.equals("imagesample")) { // Create a sample table for images ImageAccumuloSampler imgHashSampler = new ImageAccumuloSampler(IMG_HASH_SAMPLE_TABLE, IMG_HASH_TABLE, IMG_CHECKED_TABLE); imgHashSampler.createSample(); ImageAccumuloSampler imgTagSampler = new ImageAccumuloSampler(IMG_TAG_SAMPLE_TABLE, IMG_TAG_TABLE, IMG_CHECKED_TABLE); imgTagSampler.createSample(); } else { System.out.println("Invalid argument " + RUN + "."); System.out.println("Valid Arguments:"); System.out.println("\tpr: Calculates Page Rank"); System.out.println("\timageload: Loads Images from URLs"); System.out.println("\tload: Loads Full Text Data"); System.out.println("\tingest: Ingests URLs from given seed"); System.out.println("\tftsample: Creates a Full Text Index Sample HashMap"); System.out.println("\timagesample: Creates an Image Hash and Image Tag Sample HashMap"); } }
From source file:Main.java
public static String convertDoubleToString(double f) { if (f - (int) f == 0.0) { return Double.toString(f).split("\\.")[0]; } else {/*from ww w.j a v a 2s . c o m*/ return Double.toString(f); } }
From source file:Main.java
public static double mul(double d1, double d2) { BigDecimal b1 = new BigDecimal(Double.toString(d1)); BigDecimal b2 = new BigDecimal(Double.toString(d2)); return b1.multiply(b2).doubleValue(); }
From source file:Main.java
private static String toCoordinates(double latitude, double longitude) { String coords = ""; coords += Double.toString(longitude) + ","; coords += Double.toString(latitude) + ","; coords += "0"; return coords; }
From source file:Main.java
public static Double mul(Double v1, Double v2) { BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b2 = new BigDecimal(Double.toString(v2)); double m = b1.multiply(b2).doubleValue(); return m;/*from w w w .ja va 2 s . c om*/ }