Example usage for com.google.common.collect Lists newArrayList

List of usage examples for com.google.common.collect Lists newArrayList

Introduction

In this page you can find the example usage for com.google.common.collect Lists newArrayList.

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayList(Iterator<? extends E> elements) 

Source Link

Document

Creates a mutable ArrayList instance containing the given elements; a very thin shortcut for creating an empty list and then calling Iterators#addAll .

Usage

From source file:OpioidePrescriberClassification.Driver.java

public static void main(String args[]) throws Exception {
    List<Opioides> calls = Lists.newArrayList(new Parser("/input1/try.csv"));
    double heldOutPercentage = 0.10;
    //        for (int run = 0; run < 20; run++) 
    {/*w  ww .  j  a va 2s . c o  m*/
        //            Random random = RandomUtils.getRandom();
        Collections.shuffle(calls);
        int cutoff = (int) (heldOutPercentage * calls.size());
        List<Opioides> test = calls.subList(0, cutoff);
        List<Opioides> train = calls.subList(cutoff, calls.size());

        OnlineLogisticRegression lr = new OnlineLogisticRegression(NUM_CATEGORIES, Opioides.FEATURES, new L1())
                .learningRate(1).alpha(1).lambda(0.000001).stepOffset(10000).decayExponent(0.2);

        //            for (int pass = 0; pass < 2 ; pass++)
        {
            System.err.println("pass");
            for (Opioides observation : train) {
                lr.train(observation.getTarget(), observation.asVector());
            }
            //                if (pass % 2 == 0) 
            {
                Auc eval = new Auc(0.5);
                for (Opioides testCall : test) {
                    eval.add(testCall.getTarget(), lr.classifyScalar(testCall.asVector()));
                }
                System.out.printf("%d, %.4f, %.4f\n", 1, lr.currentLearningRate(), eval.auc());
            }
        }
    }
}

From source file:io.fd.honeycomb.tutorial.Main.java

public static void main(String[] args) {
    final List<Module> sampleModules = Lists.newArrayList(io.fd.honeycomb.infra.distro.Main.BASE_MODULES);

    sampleModules.add(new io.fd.honeycomb.tutorial.Module());
    sampleModules.add(new SampleInterfaceModule());

    io.fd.honeycomb.infra.distro.Main.init(sampleModules);
}

From source file:youtube1.Main.java

/**
 * @param args the command line arguments
 *//*from   w  ww  .j a  va 2 s  . c  o m*/
public static void main(String[] args) {
    List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube");
    try {
        // Authorize the request.
        Credential credential = Auth.authorize(scopes, "playlistupdates");

        youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential)
                .setApplicationName("youtube-cmdline-playlistupdates-sample").build();

        // Create a new, private playlist in the authorized user's channel.
        String playlistId = insertPlaylist();

        // If a valid playlist was created, add a video to that playlist.
        insertPlaylistItem(playlistId, VIDEO_ID);

    } catch (GoogleJsonResponseException e) {
        System.err.println(
                "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("IOException: " + e.getMessage());
        e.printStackTrace();
    } catch (Throwable t) {
        System.err.println("Throwable: " + t.getMessage());
        t.printStackTrace();
    }
}

From source file:org.apache.metron.enrichment.stellar.DocumentationGenerator.java

public static void main(String... argv) {
    List<StellarFunctionInfo> functions = Lists
            .newArrayList(SingletonFunctionResolver.getInstance().getFunctionInfo());
    Collections.sort(functions, (o1, o2) -> o1.getName().compareTo(o2.getName()));
    for (StellarFunctionInfo info : functions) {
        System.out.println("### `" + info.getName() + "`");
        System.out.println("  * Description: " + info.getDescription());
        System.out.println("  * Input:");
        for (String param : info.getParams()) {
            System.out.println("    * " + param);
        }/*from   ww  w. j  a  v a  2  s . com*/
        System.out.println("  * Returns: " + info.getReturns());
        System.out.println("");
    }
}

From source file:io.apiman.cli.Cli.java

public static void main(String... args) {
    new Cli().run(Lists.newArrayList(args));
}

From source file:com.palantir.atlasdb.clis.RegenerateCodeForSchemas.java

public static void main(String[] args) {
    List<AtlasSchema> schemas = Lists.newArrayList(SweepSchema.INSTANCE);

    for (AtlasSchema schema : schemas) {
        try {//from ww w  .j a  v a 2  s.  co m
            log.info("Attempting to generate source code for schema: " + schema.getClass().getCanonicalName());

            Path location = Paths
                    .get(schema.getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
            log.info("Generating source directory related to classes in " + location);
            if (location.toString().endsWith("jar")) {
                log.error("You need to set your classpaths to not come from jars / ivy / whatever.");
                System.exit(1);
            }

            Path sourceDirLocation = location.resolve("../src");
            if (schema.getClass().getCanonicalName().contains("Test")) {
                sourceDirLocation = location.resolve("../test-src");
            }

            if (!Files.exists(sourceDirLocation)) {
                log.info("Didn't find anything at " + sourceDirLocation + ", trying another directory...");
                sourceDirLocation = resolveIdeaSourceLocation(sourceDirLocation);
                if (!Files.exists(sourceDirLocation)) {
                    log.error("Could not find a matching source code directory for this project.");
                    continue;
                }
            }
            log.info("Placing source in: " + sourceDirLocation + "\n");
            schema.getLatestSchema().renderTables(sourceDirLocation.toFile());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.apache.mahout.classifier.sgd.pserver.AdultIncomeClassificationMain.java

public static void main(String[] args) throws Exception {
    List<AdultData> adults = Lists.newArrayList(new AdultDataParser("adult.data.txt"));

    double heldOutPercentage = 0.10;

    for (int run = 0; run < 20; run++) {
        Collections.shuffle(adults);
        int cutoff = (int) (heldOutPercentage * adults.size());
        List<AdultData> test = adults.subList(0, cutoff);
        List<AdultData> train = adults.subList(cutoff, adults.size());

        OnlineLogisticRegression lr = new OnlineLogisticRegression(NUM_CATEGORIES, AdultData.FEATURES, new L1())
                .learningRate(1).alpha(1).lambda(0.000001).stepOffset(10000).decayExponent(0.2);
        for (int pass = 0; pass < 20; pass++) {
            for (AdultData adultData : train) {
                lr.train(adultData.getTarget(), adultData.asVector());
            }//from w  w w.ja  v  a  2s  .  c  om
            if (pass % 5 == 0) {
                Auc eval = new Auc(0.5);
                for (AdultData testCall : test) {
                    eval.add(testCall.getTarget(), lr.classifyScalar(testCall.asVector()));
                }
                System.out.printf("%d, %.4f, %.4f\n", pass, lr.currentLearningRate(), eval.auc());
            }
        }
    }
}

From source file:org.ros.RosRun.java

public static void main(String[] argv) throws Exception {
    if (argv.length == 0) {
        printUsage();//from  w w  w .  j  a v  a 2s .com
        System.exit(1);
    }

    CommandLineLoader loader = new CommandLineLoader(Lists.newArrayList(argv));
    String nodeClassName = loader.getNodeClassName();
    System.out.println("Loading node class: " + loader.getNodeClassName());
    NodeConfiguration nodeConfiguration = loader.build();

    NodeMain nodeMain = null;
    try {
        nodeMain = loader.loadClass(nodeClassName);
    } catch (ClassNotFoundException e) {
        throw new RosRuntimeException("Unable to locate node: " + nodeClassName, e);
    } catch (InstantiationException e) {
        throw new RosRuntimeException("Unable to instantiate node: " + nodeClassName, e);
    } catch (IllegalAccessException e) {
        throw new RosRuntimeException("Unable to instantiate node: " + nodeClassName, e);
    }

    Preconditions.checkState(nodeMain != null);
    NodeMainExecutor nodeMainExecutor = DefaultNodeMainExecutor.newDefault();
    nodeMainExecutor.execute(nodeMain, nodeConfiguration);
}

From source file:org.apache.mahout.classifier.sgd.bankmarketing.BankMarketingClassificationMain.java

public static void main(String[] args) throws Exception {
    List<TelephoneCall> calls = Lists.newArrayList(new TelephoneCallParser("bank-full.csv"));

    double heldOutPercentage = 0.10;

    for (int run = 0; run < 20; run++) {
        Collections.shuffle(calls);
        int cutoff = (int) (heldOutPercentage * calls.size());
        List<TelephoneCall> test = calls.subList(0, cutoff);
        List<TelephoneCall> train = calls.subList(cutoff, calls.size());

        OnlineLogisticRegression lr = new OnlineLogisticRegression(NUM_CATEGORIES, TelephoneCall.FEATURES,
                new L1()).learningRate(1).alpha(1).lambda(0.000001).stepOffset(10000).decayExponent(0.2);
        for (int pass = 0; pass < 20; pass++) {
            for (TelephoneCall observation : train) {
                lr.train(observation.getTarget(), observation.asVector());
            }/*  w w  w.  j a  va 2 s .c  om*/
            if (pass % 5 == 0) {
                Auc eval = new Auc(0.5);
                for (TelephoneCall testCall : test) {
                    eval.add(testCall.getTarget(), lr.classifyScalar(testCall.asVector()));
                }
                System.out.printf("%d, %.4f, %.4f\n", pass, lr.currentLearningRate(), eval.auc());
            }
        }

    }
}

From source file:ivory.app.PreprocessGov2.java

public static void main(String[] args) throws Exception {
    Map<String, String> map = new ImmutableMap.Builder<String, String>()
            .put(PreprocessCollection.COLLECTION_NAME, "Gov2")
            .put(PreprocessCollection.DOCNO_MAPPING, Gov2DocnoMapping.class.getCanonicalName())
            .put(PreprocessCollection.INPUTFORMAT, SequenceFileInputFormat.class.getCanonicalName())
            .put(PreprocessCollection.TOKENIZER, GalagoTokenizer.class.getCanonicalName())
            .put(PreprocessCollection.MIN_DF, "10").build();

    List<String> s = Lists.newArrayList(args);
    for (Map.Entry<String, String> e : map.entrySet()) {
        s.add("-" + e.getKey());
        s.add(e.getValue());//from   w  ww. j  a v  a  2 s.  c om
    }

    ToolRunner.run(new PreprocessGov2(), s.toArray(new String[s.size()]));
}