List of usage examples for java.util Arrays copyOfRange
public static boolean[] copyOfRange(boolean[] original, int from, int to)
From source file:net.geoprism.JavascriptFileWriter.java
public static void main(String[] args) { String destination = args[0]; String[] packages = Arrays.copyOfRange(args, 1, args.length); new JavascriptFileWriter(destination, packages).write(); }
From source file:examples.cnn.ImagesClassification.java
public static void main(String[] args) { SparkConf conf = new SparkConf(); conf.setAppName("Images CNN Classification"); conf.setMaster(String.format("local[%d]", NUM_CORES)); conf.set(SparkDl4jMultiLayer.AVERAGE_EACH_ITERATION, String.valueOf(true)); try (JavaSparkContext sc = new JavaSparkContext(conf)) { JavaRDD<String> raw = sc.textFile("data/images-data-rgb.csv"); String first = raw.first(); JavaPairRDD<String, String> labelData = raw.filter(f -> f.equals(first) == false).mapToPair(r -> { String[] tab = r.split(";"); return new Tuple2<>(tab[0], tab[1]); });/* ww w . ja va 2 s. c om*/ Map<String, Long> labels = labelData.map(t -> t._1).distinct().zipWithIndex() .mapToPair(t -> new Tuple2<>(t._1, t._2)).collectAsMap(); log.info("Number of labels {}", labels.size()); labels.forEach((a, b) -> log.info("{}: {}", a, b)); NetworkTrainer trainer = new NetworkTrainer.Builder().model(ModelLibrary.net1) .networkToSparkNetwork(net -> new SparkDl4jMultiLayer(sc, net)).numLabels(labels.size()) .cores(NUM_CORES).build(); JavaRDD<Tuple2<INDArray, double[]>> labelsWithData = labelData.map(t -> { INDArray label = FeatureUtil.toOutcomeVector(labels.get(t._1).intValue(), labels.size()); double[] arr = Arrays.stream(t._2.split(" ")).map(normalize1).mapToDouble(Double::doubleValue) .toArray(); return new Tuple2<>(label, arr); }); JavaRDD<Tuple2<INDArray, double[]>>[] splited = labelsWithData.randomSplit(new double[] { .8, .2 }, seed); JavaRDD<DataSet> testDataset = splited[1].map(t -> { INDArray features = Nd4j.create(t._2, new int[] { 1, t._2.length }); return new DataSet(features, t._1); }).cache(); log.info("Number of test images {}", testDataset.count()); JavaRDD<DataSet> plain = splited[0].map(t -> { INDArray features = Nd4j.create(t._2, new int[] { 1, t._2.length }); return new DataSet(features, t._1); }); /* * JavaRDD<DataSet> flipped = splited[0].randomSplit(new double[] { .5, .5 }, seed)[0]. */ JavaRDD<DataSet> flipped = splited[0].map(t -> { double[] arr = t._2; int idx = 0; double[] farr = new double[arr.length]; for (int i = 0; i < arr.length; i += trainer.width) { double[] temp = Arrays.copyOfRange(arr, i, i + trainer.width); ArrayUtils.reverse(temp); for (int j = 0; j < trainer.height; ++j) { farr[idx++] = temp[j]; } } INDArray features = Nd4j.create(farr, new int[] { 1, farr.length }); return new DataSet(features, t._1); }); JavaRDD<DataSet> trainDataset = plain.union(flipped).cache(); log.info("Number of train images {}", trainDataset.count()); trainer.train(trainDataset, testDataset); } }
From source file:examples.cnn.cifar.Cifar10Classification.java
public static void main(String[] args) { CifarReader.downloadAndExtract();/*from w w w . j a v a2 s. c o m*/ int numLabels = 10; SparkConf conf = new SparkConf(); conf.setMaster(String.format("local[%d]", NUM_CORES)); conf.setAppName("Cifar-10 CNN Classification"); conf.set(SparkDl4jMultiLayer.AVERAGE_EACH_ITERATION, String.valueOf(true)); try (JavaSparkContext sc = new JavaSparkContext(conf)) { NetworkTrainer trainer = new NetworkTrainer.Builder().model(ModelLibrary.net2) .networkToSparkNetwork(net -> new SparkDl4jMultiLayer(sc, net)).numLabels(numLabels) .cores(NUM_CORES).build(); JavaPairRDD<String, PortableDataStream> files = sc.binaryFiles("data/cifar-10-batches-bin"); JavaRDD<double[]> imagesTrain = files .filter(f -> ArrayUtils.contains(CifarReader.TRAIN_DATA_FILES, extractFileName.apply(f._1))) .flatMap(f -> CifarReader.rawDouble(f._2.open())); JavaRDD<double[]> imagesTest = files .filter(f -> CifarReader.TEST_DATA_FILE.equals(extractFileName.apply(f._1))) .flatMap(f -> CifarReader.rawDouble(f._2.open())); JavaRDD<DataSet> testDataset = imagesTest.map(i -> { INDArray label = FeatureUtil.toOutcomeVector(Double.valueOf(i[0]).intValue(), numLabels); double[] arr = Arrays.stream(ArrayUtils.remove(i, 0)).boxed().map(normalize2) .mapToDouble(Double::doubleValue).toArray(); INDArray features = Nd4j.create(arr, new int[] { 1, arr.length }); return new DataSet(features, label); }).cache(); log.info("Number of test images {}", testDataset.count()); JavaPairRDD<INDArray, double[]> labelsWithDataTrain = imagesTrain.mapToPair(i -> { INDArray label = FeatureUtil.toOutcomeVector(Double.valueOf(i[0]).intValue(), numLabels); double[] arr = Arrays.stream(ArrayUtils.remove(i, 0)).boxed().map(normalize2) .mapToDouble(Double::doubleValue).toArray(); return new Tuple2<>(label, arr); }); JavaRDD<DataSet> flipped = labelsWithDataTrain.map(t -> { double[] arr = t._2; int idx = 0; double[] farr = new double[arr.length]; for (int i = 0; i < arr.length; i += trainer.getWidth()) { double[] temp = Arrays.copyOfRange(arr, i, i + trainer.getWidth()); ArrayUtils.reverse(temp); for (int j = 0; j < trainer.getHeight(); ++j) { farr[idx++] = temp[j]; } } INDArray features = Nd4j.create(farr, new int[] { 1, farr.length }); return new DataSet(features, t._1); }); JavaRDD<DataSet> trainDataset = labelsWithDataTrain.map(t -> { INDArray features = Nd4j.create(t._2, new int[] { 1, t._2.length }); return new DataSet(features, t._1); }).union(flipped).cache(); log.info("Number of train images {}", trainDataset.count()); trainer.train(trainDataset, testDataset); } }
From source file:backtype.storm.command.gray_upgrade.java
public static void main(String[] args) throws Exception { if (args == null || args.length < 1) { System.out.println("Invalid parameter"); usage();/*from ww w .j ava2 s. c o m*/ return; } String topologyName = args[0]; String[] str2 = Arrays.copyOfRange(args, 1, args.length); CommandLineParser parser = new GnuParser(); Options r = buildGeneralOptions(new Options()); CommandLine commandLine = parser.parse(r, str2, true); int workerNum = 0; String component = null; List<String> workers = null; if (commandLine.hasOption("n")) { workerNum = Integer.valueOf(commandLine.getOptionValue("n")); } if (commandLine.hasOption("p")) { component = commandLine.getOptionValue("p"); } if (commandLine.hasOption("w")) { String w = commandLine.getOptionValue("w"); if (!StringUtils.isBlank(w)) { workers = Lists.newArrayList(); String[] parts = w.split(","); for (String part : parts) { if (part.split(":").length == 2) { workers.add(part.trim()); } } } } upgradeTopology(topologyName, component, workers, workerNum); }
From source file:com.yahoo.pulsar.admin.cli.PulsarAdminTool.java
public static void main(String[] args) throws Exception { String configFile = args[0];/*from ww w . j a v a 2s. c o m*/ Properties properties = new Properties(); if (configFile != null) { FileInputStream fis = null; try { fis = new FileInputStream(configFile); properties.load(fis); } finally { if (fis != null) fis.close(); } } PulsarAdminTool tool = new PulsarAdminTool(properties); if (tool.run(Arrays.copyOfRange(args, 1, args.length))) { System.exit(0); } else { System.exit(1); } }
From source file:net.orpiske.ssps.sdm.main.Main.java
public static void main(String[] args) { int ret = 0;/*ww w .j a va 2s .co m*/ if (args.length == 0) { help(1); } String first = args[0]; String[] newArgs = Arrays.copyOfRange(args, 1, args.length); try { initLogger(); } catch (FileNotFoundException e) { e.printStackTrace(); System.exit(-1); } logger.debug("Initializing configuration"); initConfig(); if (first.equals("help")) { help(1); } logger.debug("Initializing user directory"); initUserSdmDirectory(); logger.debug("Initializing database"); initDatabase(); logger.debug("Initializing proxy settings"); initProxy(); logger.debug("Initializing groovy classpath"); initGroovyClasspath(); if (first.equals("install")) { Installer installer = new Installer(newArgs); ret = installer.run(); System.exit(ret); } if (first.equals("add-repository")) { AddRepository addRepository = new AddRepository(newArgs); ret = addRepository.run(); System.exit(ret); } if (first.equals("uninstall")) { Uninstall uninstall = new Uninstall(newArgs); ret = uninstall.run(); System.exit(ret); } if (first.equals("update")) { Update update = new Update(newArgs); ret = update.run(); System.exit(ret); } if (first.equals("upgrade")) { Upgrade upgrade = new Upgrade(newArgs); ret = upgrade.run(); System.exit(ret); } if (first.equals("search")) { Search search = new Search(newArgs); ret = search.run(); System.exit(ret); } if (first.equals("--version")) { System.out.println("Simple Software Provisioning System: sdm " + Constants.VERSION); System.exit(ret); } help(1); }
From source file:com.google.testing.pogen.PageObjectGenerator.java
@SuppressWarnings("static-access") public static void main(String[] args) { if (args.length == 0) { printUsage(System.out);/*from ww w . j ava 2 s.c o m*/ return; } String commandName = args[0]; // @formatter:off Options options = new Options() .addOption(OptionBuilder.withDescription( "Attribute name to be assigned in tagas containing template variables (default is 'id').") .hasArg().withLongOpt("attr").create('a')) .addOption(OptionBuilder.withDescription("Print help for this command.").withLongOpt("help") .create('h')) .addOption(OptionBuilder.withDescription("Print processed files verbosely.").withLongOpt("verbose") .create('v')); // @formatter:on String helpMessage = null; if (commandName.equals(GENERATE_COMMAND)) { // @formatter:off options.addOption(OptionBuilder.withDescription("Package name of generating skeleton test code.") .hasArg().isRequired().withLongOpt("package").create('p')) .addOption(OptionBuilder.withDescription("Output directory of generating skeleton test code.") .hasArg().isRequired().withLongOpt("out").create('o')) .addOption(OptionBuilder.withDescription( "Root input directory of html template files for analyzing the suffixes of the package name.") .hasArg().isRequired().withLongOpt("in").create('i')) .addOption(OptionBuilder.withDescription("Regex for finding html template files.").hasArg() .withLongOpt("regex").create('e')) .addOption(OptionBuilder.withDescription("Option for finding html template files recursively.") .withLongOpt("recursive").create('r')); // @formatter:on helpMessage = "java PageObjectGenerator generate -o <test_out_dir> -p <package_name> -i <root_directory> " + " [OPTIONS] <template_file1> <template_file2> ...\n" + "e.g. java PageObjectGenerator generate -a class -o PageObjectGeneratorTest/src/test/java/com/google/testing/pogen/pages" + " -i PageObjectGeneratorTest/src/main/resources -p com.google.testing.pogen.pages -e (.*)\\.html -v"; } else if (commandName.equals(MEASURE_COMMAND)) { helpMessage = "java PageObjectGenerator measure [OPTIONS] <template_file1> <template_file2> ..."; } else if (commandName.equals(LIST_COMMAND)) { helpMessage = "java PageObjectGenerator list <template_file1> <template_file2> ..."; } else { System.err.format("'%s' is not a PageObjectGenerator command.", commandName); printUsage(System.err); System.exit(-1); } BasicParser cmdParser = new BasicParser(); HelpFormatter f = new HelpFormatter(); try { CommandLine cl = cmdParser.parse(options, Arrays.copyOfRange(args, 1, args.length)); if (cl.hasOption('h')) { f.printHelp(helpMessage, options); return; } Command command = null; String[] templatePaths = cl.getArgs(); String attributeName = cl.getOptionValue('a'); attributeName = attributeName != null ? attributeName : "id"; if (commandName.equals(GENERATE_COMMAND)) { String rootDirectoryPath = cl.getOptionValue('i'); String templateFilePattern = cl.getOptionValue('e'); boolean isRecusive = cl.hasOption('r'); command = new GenerateCommand(templatePaths, cl.getOptionValue('o'), cl.getOptionValue('p'), attributeName, cl.hasOption('v'), rootDirectoryPath, templateFilePattern, isRecusive); } else if (commandName.equals(MEASURE_COMMAND)) { command = new MeasureCommand(templatePaths, attributeName, cl.hasOption('v')); } else if (commandName.equals(LIST_COMMAND)) { command = new ListCommand(templatePaths, attributeName); } try { command.execute(); return; } catch (FileProcessException e) { System.err.println(e.getMessage()); } catch (IOException e) { System.err.println("Errors occur in processing files."); System.err.println(e.getMessage()); } } catch (ParseException e) { System.err.println("Errors occur in parsing the command arguments."); System.err.println(e.getMessage()); f.printHelp(helpMessage, options); } System.exit(-1); }
From source file:com.jkoolcloud.tnt4j.streams.StreamsDaemon.java
/** * Main entry point for running as a system service. * * @param args/*from w w w. ja v a2s . co m*/ * command-line arguments. Supported arguments: * <table summary="TNT4J-Streams daemon command line arguments"> * <tr> * <td> </td> * <td> command_name</td> * <td>(mandatory) service handling command name: {@code start} or {@code stop}</td> * </tr> * <tr> * <td> </td> * <td> stream command-line arguments</td> * <td>(optional) list of streams configuration supported command-line arguments</td> * </tr> * </table> * * @see com.jkoolcloud.tnt4j.streams.StreamsAgent#main(String...) */ public static void main(String... args) { LOGGER.log(OpLevel.INFO, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "StreamsDaemon.start.main"), StreamsAgent.pkgVersion(), System.getProperty("java.version")); try { String cmd = START_COMMAND; if (args.length > 0) { LOGGER.log(OpLevel.INFO, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "StreamsDaemon.processing.args"), Arrays.toString(args)); StreamsAgent.processArgs(Arrays.copyOfRange(args, 1, args.length)); cmd = args[0]; } if (START_COMMAND.equalsIgnoreCase(cmd)) { instance.start(); } else { instance.stop(); } } catch (Exception e) { LOGGER.log(OpLevel.FATAL, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "StreamsDaemon.fatal.error"), e); } }
From source file:backtype.storm.command.update_topology.java
/** * @param args/*from w w w . ja va 2 s.co m*/ */ public static void main(String[] args) { if (args == null || args.length < 3) { System.out.println("Invalid parameter"); usage(); return; } String topologyName = args[0]; try { String[] str2 = Arrays.copyOfRange(args, 1, args.length); CommandLineParser parser = new GnuParser(); Options r = buildGeneralOptions(new Options()); CommandLine commandLine = parser.parse(r, str2, true); String pathConf = null; String pathJar = null; if (commandLine.hasOption("conf")) { pathConf = (commandLine.getOptionValues("conf"))[0]; } if (commandLine.hasOption("jar")) { pathJar = (commandLine.getOptionValues("jar"))[0]; } if (pathConf != null || pathJar != null) updateTopology(topologyName, pathJar, pathConf); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ikanow.aleph2.data_import_manager.harvest.modules.LocalHarvestTestModule.java
/** Entry point * @param args - config_file source_key harvest_tech_id * @throws Exception // w ww. j ava2s. c o m */ public static void main(final String[] args) { try { if (args.length < 3) { System.out.println("CLI: config_file source_key harvest_tech_jar_path"); System.exit(-1); } System.out.println("Running with command line: " + Arrays.toString(args)); Config config = ConfigFactory.parseFile(new File(args[0])); LocalHarvestTestModule app = ModuleUtils.initializeApplication(Arrays.asList(), Optional.of(config), Either.left(LocalHarvestTestModule.class)); app.start(args[1], args[2], Arrays.copyOfRange(args, 3, args.length)); } catch (Exception e) { try { System.out.println("Got all the way to main"); e.printStackTrace(); } catch (Exception e2) { // the exception failed! System.out.println(ErrorUtils.getLongForm("Got all the way to main: {0}", e)); } } }