List of usage examples for java.util ArrayList get
public E get(int index)
From source file:mmllabvsdextractfeature.MMllabVSDExtractFeature.java
/** * @param args the command line arguments *///from w w w . j a va 2s .c o m public static void main(String[] args) throws IOException { // TODO code application logic here MMllabVSDExtractFeature hello = new MMllabVSDExtractFeature(); FileStructer metdata = new FileStructer(); //Utility utilityClassIni = new Utility(); FrameStructer frameStructer = new FrameStructer(); /* Flow : 1. Read metdata file 2. Untar folder: -1 Shot content 25 frame -1 folder 50 shot Process with 1 shot: - Resize All image 1 shot --> delete orginal. - Extract feature 25 frame - Pooling Max and aveg. - Delete Image, feature - zip file Feature 3. Delete File. */ // Load metadata File String dir = "/media/data1"; String metadataFileDir = "/media/data1/metdata/devel2011-new.lst"; ArrayList<FileStructer> listFileFromMetadata = metdata.readMetadata(metadataFileDir); // String test = utilityClass.readTextFile("C:\\Users\\tiendv\\Downloads\\VSD_devel2011_1.shot_1.RKF_1.Frame_1.txt"); // ArrayList <String> testFeatureSave = utilityClass.SplitUsingTokenizerWithLineArrayList(test, " "); // utilityClass.writeToFile("C:\\Users\\tiendv\\Downloads\\VSD_devel2011_1.shot_1.txt", testFeatureSave); // System.out.println(test); for (int i = 0; i < listFileFromMetadata.size(); i++) { Utility utilityClass = new Utility(); //Un zip file String folderName = listFileFromMetadata.get(i).getWholeFolderName(); String nameZipFile = dir + "/" + folderName + "/" + listFileFromMetadata.get(i).getNameZipFileName() + ".tar"; nameZipFile = nameZipFile.replaceAll("\\s", ""); String outPutFolder = dir + "/" + folderName + "/" + listFileFromMetadata.get(i).getNameZipFileName(); outPutFolder = outPutFolder.replaceAll("\\s", ""); utilityClass.unTarFolder(UNTARSHFILE, nameZipFile, outPutFolder + "_"); // Resize all image in folder has been unzip utilityClass.createFolder(CREADFOLDER, outPutFolder); utilityClass.resizeWholeFolder(outPutFolder + "_", outPutFolder, resizeWidth, resizeHeight); utilityClass.deleteWholeFolder(DELETEFOLDER, outPutFolder + "_"); // Read all file from Folder has been unzip ArrayList<FrameStructer> allFrameInZipFolder = new ArrayList<>(); allFrameInZipFolder = frameStructer.getListFileInZipFolder(outPutFolder); System.out.println(allFrameInZipFolder.size()); // sort with shot ID Collections.sort(allFrameInZipFolder, FrameStructer.frameIDNo); // Loop with 1 shot int indexFrame = 0; for (int n = 0; n < allFrameInZipFolder.size() / 25; n++) { // Process with 1 ArrayList<String> nameAllFrameOneShot = new ArrayList<>(); String shotAndFolderName = new String(); for (; indexFrame < Math.min((n + 1) * 25, allFrameInZipFolder.size()); indexFrame++) { String imageForExtract = outPutFolder + "/" + allFrameInZipFolder.get(indexFrame).toFullName() + ".jpg"; shotAndFolderName = allFrameInZipFolder.get(indexFrame).shotName(); String resultNameAfterExtract = outPutFolder + "/" + allFrameInZipFolder.get(indexFrame).toFullName() + ".txt"; nameAllFrameOneShot.add(resultNameAfterExtract); // extract and Delete image file --> ouput image'feature utilityClass.excuteFeatureExtractionAnImage(EXTRACTFEATUREANDDELETESOURCEIMAGESHFILE, "0", CUDAOVERFEATPATH, imageForExtract, resultNameAfterExtract); } // Pooling // DenseMatrix64F resultMaTrixFeatureOneShot = utilityClass.buidEJMLMatrixFeatureOneShot(nameAllFrameOneShot); // utilityClass.savePoolingFeatureOneShotWithEJMLFromMatrix(resultMaTrixFeatureOneShot,outPutFolder,shotAndFolderName); utilityClass.buidPoolingFileWithOutMatrixFeatureOneShot(nameAllFrameOneShot, outPutFolder, shotAndFolderName); // Save A file for (int frameCount = 0; frameCount < nameAllFrameOneShot.size(); frameCount++) { // Delete feature extract file utilityClass.deletefile(DELETEFILE, nameAllFrameOneShot.get(frameCount)); } // Release one shot data nameAllFrameOneShot.clear(); System.out.print("The end of one's shot" + "\n" + n); } // Delete zip file utilityClass.deletefile(DELETEFILE, nameZipFile); // Zip Whole Folder /** * Extract 1 shot * Resize 25 frame with the same shotid --> delete orgra. * Extract 25 frame --> feature file --->delete * */ } }
From source file:edu.oregonstate.eecs.mcplan.domains.toy.SavingProblem.java
public static void main(final String[] argv) throws NumberFormatException, IOException { final RandomGenerator rng = new MersenneTwister(42); final int T = 30; // final int price_min = -8; // final int price_max = 4; // final int invest_period = 6; // final int loan_period = 4; final int price_min = -4; final int price_max = 4; final int maturity_period = 3; final int invest_period = 4; final int loan_period = 4; final Parameters params = new Parameters(T, price_min, price_max, maturity_period, invest_period, loan_period);//from w ww . j a v a 2 s . co m final Actions actions = new Actions(params); final FsssModel model = new FsssModel(rng, params); State s = model.initialState(); while (!s.isTerminal()) { System.out.println(s); System.out.println("R(s): " + model.reward(s)); actions.setState(s, 0); final ArrayList<Action> action_list = Fn.takeAll(actions); for (int i = 0; i < action_list.size(); ++i) { System.out.println(i + ": " + action_list.get(i)); } System.out.print(">>> "); final BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); final int choice = Integer.parseInt(cin.readLine()); final Action a = action_list.get(choice); System.out.println("R(s, a): " + model.reward(s, a)); s = model.sampleTransition(s, a); } // Estimate the value of a "good" policy. // Note: The "good" policy is to Invest when you can, and Sell if the // price is >= 2. This is not necessarily optimal because: // 1. You should Borrow once the episode will end before the loan must be repaid // 2. For some values of invest_period, you should pass on a low price // early in the period to try to get a better one later. // final int Ngames = 10000; // double V = 0; // int Ninvest = 0; // for( int i = 0; i < Ngames; ++i ) { // State s = model.initialState(); // double Vi = model.reward( s ); // while( !s.isTerminal() ) { // final Action a; // // // "Good" policy // if( s.investment == 0 ) { // a = new InvestAction(); // Ninvest += 1; // } // else if( s.investment > 0 && s.price >= 2 ) { // if( s.invest_t < (params.invest_period - 1) || s.price > 2 ) { // a = new SellAction(); // } // else { // a = new SaveAction(); // } //// a = new SellAction(); // } // else { // a = new SaveAction(); // } // // // "Borrow" policy //// if( s.loan == 0 ) { //// a = new BorrowAction(); //// } //// else { //// a = new SaveAction(); //// } // // final double ra = model.reward( s, a ); // s = model.sampleTransition( s, a ); // Vi += ra + model.reward( s ); // } // V += Vi; // } // // final double Vavg = V / Ngames; // final double Navg = (Ninvest / ((double) Ngames)); // System.out.println( "Avg. value: " + Vavg ); // System.out.println( "Avg. Invest actions: " + Navg ); // System.out.println( "V(Invest) ~= " + ( 1 + (Vavg - params.T)/Navg ) ); }
From source file:com.oltpbenchmark.multitenancy.MuTeBench.java
/** * @param args/*from w ww . j a v a 2 s . c o m*/ * @throws Exception */ public static void main(String[] args) throws Exception { String duration = null; String scenarioFile = null; // ------------------------------------------------------------------- // INITIALIZE LOGGING // ------------------------------------------------------------------- String log4jPath = System.getProperty("log4j.configuration"); if (log4jPath != null) { org.apache.log4j.PropertyConfigurator.configure(log4jPath); } else { throw new RuntimeException("Missing log4j.properties file"); } // ------------------------------------------------------------------- // PARSE COMMAND LINE PARAMETERS // ------------------------------------------------------------------- CommandLineParser parser = new PosixParser(); XMLConfiguration pluginConfig = null; try { pluginConfig = new XMLConfiguration("config/plugin.xml"); } catch (ConfigurationException e1) { LOG.info("Plugin configuration file config/plugin.xml is missing"); e1.printStackTrace(); } pluginConfig.setExpressionEngine(new XPathExpressionEngine()); Options options = new Options(); options.addOption("s", "scenario", true, "[required] Workload scenario file"); options.addOption("a", "analysis-buckets", true, "sampling buckets for result aggregation"); options.addOption("r", "runtime", true, "maximum runtime (no events will be started after finishing runtime)"); options.addOption("v", "verbose", false, "Display Messages"); options.addOption("g", "gui", false, "Show controlling GUI"); options.addOption("h", "help", false, "Print this help"); options.addOption("o", "output", true, "Output file (default System.out)"); options.addOption("b", "baseline", true, "Output files of previous baseline run"); options.addOption(null, "histograms", false, "Print txn histograms"); options.addOption("d", "dialects-export", true, "Export benchmark SQL to a dialects file"); // parse the command line arguments CommandLine argsLine = parser.parse(options, args); if (argsLine.hasOption("h")) { printUsage(options); return; } else if (!argsLine.hasOption("scenario")) { INIT_LOG.fatal("Missing scenario description file"); System.exit(-1); } else scenarioFile = argsLine.getOptionValue("scenario"); if (argsLine.hasOption("r")) duration = argsLine.getOptionValue("r"); if (argsLine.hasOption("runtime")) duration = argsLine.getOptionValue("runtime"); // ------------------------------------------------------------------- // CREATE TENANT SCHEDULE // ------------------------------------------------------------------- INIT_LOG.info("Create schedule"); Schedule schedule = new Schedule(duration, scenarioFile); HashMap<Integer, ScheduleEvents> tenantEvents = schedule.getTenantEvents(); ArrayList<Integer> tenantList = schedule.getTenantList(); List<BenchmarkModule> benchList = new ArrayList<BenchmarkModule>(); for (int tenInd = 0; tenInd < tenantList.size(); tenInd++) { int tenantID = tenantList.get(tenInd); for (int tenEvent = 0; tenEvent < tenantEvents.get(tenantID).size(); tenEvent++) { BenchmarkSettings benchmarkSettings = (BenchmarkSettings) tenantEvents.get(tenantID) .getBenchmarkSettings(tenEvent); // update benchmark Settings benchmarkSettings.setTenantID(tenantID); // ------------------------------------------------------------------- // GET PLUGIN LIST // ------------------------------------------------------------------- String plugins = benchmarkSettings.getBenchmark(); String[] pluginList = plugins.split(","); String configFile = benchmarkSettings.getConfigFile(); XMLConfiguration xmlConfig = new XMLConfiguration(configFile); xmlConfig.setExpressionEngine(new XPathExpressionEngine()); int lastTxnId = 0; for (String plugin : pluginList) { // ---------------------------------------------------------------- // WORKLOAD CONFIGURATION // ---------------------------------------------------------------- String pluginTest = ""; pluginTest = "[@bench='" + plugin + "']"; WorkloadConfiguration wrkld = new WorkloadConfiguration(); wrkld.setTenantId(tenantID); wrkld.setBenchmarkName(setTenantIDinString(plugin, tenantID)); wrkld.setXmlConfig(xmlConfig); wrkld.setDBType(DatabaseType.get(setTenantIDinString(xmlConfig.getString("dbtype"), tenantID))); wrkld.setDBDriver(setTenantIDinString(xmlConfig.getString("driver"), tenantID)); wrkld.setDBConnection(setTenantIDinString(xmlConfig.getString("DBUrl"), tenantID)); wrkld.setDBName(setTenantIDinString(xmlConfig.getString("DBName"), tenantID)); wrkld.setDBUsername(setTenantIDinString(xmlConfig.getString("username"), tenantID)); wrkld.setDBPassword(setTenantIDinString(xmlConfig.getString("password"), tenantID)); String terminalString = setTenantIDinString(xmlConfig.getString("terminals[not(@bench)]", "0"), tenantID); int terminals = Integer.parseInt(xmlConfig.getString("terminals" + pluginTest, terminalString)); wrkld.setTerminals(terminals); int taSize = Integer.parseInt(xmlConfig.getString("taSize", "1")); if (taSize < 0) INIT_LOG.fatal("taSize must not be negative!"); wrkld.setTaSize(taSize); wrkld.setProprietaryTaSyntax(xmlConfig.getBoolean("proprietaryTaSyntax", false)); wrkld.setIsolationMode(setTenantIDinString( xmlConfig.getString("isolation", "TRANSACTION_SERIALIZABLE"), tenantID)); wrkld.setScaleFactor(Double .parseDouble(setTenantIDinString(xmlConfig.getString("scalefactor", "1.0"), tenantID))); wrkld.setRecordAbortMessages(xmlConfig.getBoolean("recordabortmessages", false)); int size = xmlConfig.configurationsAt("/works/work").size(); for (int i = 1; i < size + 1; i++) { SubnodeConfiguration work = xmlConfig.configurationAt("works/work[" + i + "]"); List<String> weight_strings; // use a workaround if there multiple workloads or // single // attributed workload if (pluginList.length > 1 || work.containsKey("weights[@bench]")) { weight_strings = get_weights(plugin, work); } else { weight_strings = work.getList("weights[not(@bench)]"); } int rate = 1; boolean rateLimited = true; boolean disabled = false; // can be "disabled", "unlimited" or a number String rate_string; rate_string = setTenantIDinString(work.getString("rate[not(@bench)]", ""), tenantID); rate_string = setTenantIDinString(work.getString("rate" + pluginTest, rate_string), tenantID); if (rate_string.equals(RATE_DISABLED)) { disabled = true; } else if (rate_string.equals(RATE_UNLIMITED)) { rateLimited = false; } else if (rate_string.isEmpty()) { LOG.fatal(String.format( "Tenant " + tenantID + ": Please specify the rate for phase %d and workload %s", i, plugin)); System.exit(-1); } else { try { rate = Integer.parseInt(rate_string); if (rate < 1) { LOG.fatal("Tenant " + tenantID + ": Rate limit must be at least 1. Use unlimited or disabled values instead."); System.exit(-1); } } catch (NumberFormatException e) { LOG.fatal(String.format( "Tenant " + tenantID + ": Rate string must be '%s', '%s' or a number", RATE_DISABLED, RATE_UNLIMITED)); System.exit(-1); } } Phase.Arrival arrival = Phase.Arrival.REGULAR; String arrive = setTenantIDinString(work.getString("@arrival", "regular"), tenantID); if (arrive.toUpperCase().equals("POISSON")) arrival = Phase.Arrival.POISSON; int activeTerminals; activeTerminals = Integer.parseInt(setTenantIDinString( work.getString("active_terminals[not(@bench)]", String.valueOf(terminals)), tenantID)); activeTerminals = Integer.parseInt(setTenantIDinString( work.getString("active_terminals" + pluginTest, String.valueOf(activeTerminals)), tenantID)); if (activeTerminals > terminals) { LOG.fatal("Tenant " + tenantID + ": Configuration error in work " + i + ": number of active terminals" + "" + "is bigger than the total number of terminals"); System.exit(-1); } wrkld.addWork(Integer.parseInt(setTenantIDinString(work.getString("/time"), tenantID)), rate, weight_strings, rateLimited, disabled, activeTerminals, arrival); } // FOR int numTxnTypes = xmlConfig .configurationsAt("transactiontypes" + pluginTest + "/transactiontype").size(); if (numTxnTypes == 0 && pluginList.length == 1) { // if it is a single workload run, <transactiontypes /> // w/o attribute is used pluginTest = "[not(@bench)]"; numTxnTypes = xmlConfig .configurationsAt("transactiontypes" + pluginTest + "/transactiontype").size(); } wrkld.setNumTxnTypes(numTxnTypes); // CHECKING INPUT PHASES int j = 0; for (Phase p : wrkld.getAllPhases()) { j++; if (p.getWeightCount() != wrkld.getNumTxnTypes()) { LOG.fatal(String.format("Tenant " + tenantID + ": Configuration files is inconsistent, phase %d contains %d weights but you defined %d transaction types", j, p.getWeightCount(), wrkld.getNumTxnTypes())); System.exit(-1); } } // FOR // Generate the dialect map wrkld.init(); assert (wrkld.getNumTxnTypes() >= 0); assert (xmlConfig != null); // ---------------------------------------------------------------- // BENCHMARK MODULE // ---------------------------------------------------------------- String classname = pluginConfig.getString("/plugin[@name='" + plugin + "']"); if (classname == null) { throw new ParseException("Plugin " + plugin + " is undefined in config/plugin.xml"); } BenchmarkModule bench = ClassUtil.newInstance(classname, new Object[] { wrkld }, new Class<?>[] { WorkloadConfiguration.class }); assert (benchList.get(0) != null); Map<String, Object> initDebug = new ListOrderedMap<String, Object>(); initDebug.put("Benchmark", String.format("%s {%s}", plugin.toUpperCase(), classname)); initDebug.put("Configuration", configFile); initDebug.put("Type", wrkld.getDBType()); initDebug.put("Driver", wrkld.getDBDriver()); initDebug.put("URL", wrkld.getDBConnection()); initDebug.put("Isolation", setTenantIDinString( xmlConfig.getString("isolation", "TRANSACTION_SERIALIZABLE [DEFAULT]"), tenantID)); initDebug.put("Scale Factor", wrkld.getScaleFactor()); INIT_LOG.info(SINGLE_LINE + "\n\n" + StringUtil.formatMaps(initDebug)); INIT_LOG.info(SINGLE_LINE); // Load TransactionTypes List<TransactionType> ttypes = new ArrayList<TransactionType>(); // Always add an INVALID type for Carlo ttypes.add(TransactionType.INVALID); int txnIdOffset = lastTxnId; for (int i = 1; i < wrkld.getNumTxnTypes() + 1; i++) { String key = "transactiontypes" + pluginTest + "/transactiontype[" + i + "]"; String txnName = setTenantIDinString(xmlConfig.getString(key + "/name"), tenantID); int txnId = i + 1; if (xmlConfig.containsKey(key + "/id")) { txnId = Integer .parseInt(setTenantIDinString(xmlConfig.getString(key + "/id"), tenantID)); } ttypes.add(bench.initTransactionType(txnName, txnId + txnIdOffset)); lastTxnId = i; } // FOR TransactionTypes tt = new TransactionTypes(ttypes); wrkld.setTransTypes(tt); if (benchmarkSettings.getBenchmarkSlaFile() != null) wrkld.setSlaFromFile(benchmarkSettings.getBenchmarkSlaFile()); LOG.debug("Tenant " + tenantID + ": Using the following transaction types: " + tt); bench.setTenantOffset(tenantEvents.get(tenantID).getTime(tenEvent)); bench.setTenantID(tenantID); bench.setBenchmarkSettings(benchmarkSettings); benchList.add(bench); } } } // create result collector ResultCollector rCollector = new ResultCollector(tenantList); // execute benchmarks in parallel ArrayList<Thread> benchThreads = new ArrayList<Thread>(); for (BenchmarkModule benchmark : benchList) { BenchmarkExecutor benchThread = new BenchmarkExecutor(benchmark, argsLine); Thread t = new Thread(benchThread); t.start(); benchThreads.add(t); benchmark.getWorkloadConfiguration().setrCollector(rCollector); } // waiting for completion of all benchmarks for (Thread t : benchThreads) { t.join(); } // print statistics int analysisBuckets = -1; if (argsLine.hasOption("analysis-buckets")) analysisBuckets = Integer.parseInt(argsLine.getOptionValue("analysis-buckets")); String output = null; if (argsLine.hasOption("o")) output = argsLine.getOptionValue("o"); String baseline = null; if (argsLine.hasOption("b")) baseline = argsLine.getOptionValue("b"); rCollector.printStatistics(output, analysisBuckets, argsLine.hasOption("histograms"), baseline); // create GUI if (argsLine.hasOption("g") && (!rCollector.getAllResults().isEmpty())) { try { Gui gui = new Gui(Integer.parseInt(argsLine.getOptionValue("analysis-buckets", "10")), rCollector, output); } catch (Exception e) { e.printStackTrace(); } } }
From source file:Anaphora_Resolution.ParseAllXMLDocuments.java
public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException, TransformerException { // File dataFolder = new File("DataToPort"); // File[] documents; String grammar = "grammar/englishPCFG.ser.gz"; String[] options = { "-maxLength", "100", "-retainTmpSubcategories" }; //LexicalizedParser lp = new LexicalizedParser(grammar, options); LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"); //// www. j a v a 2 s . co m // if (dataFolder.isDirectory()) { // documents = dataFolder.listFiles(); // } else { // documents = new File[] {dataFolder}; // } // int currfile = 0; // int totfiles = documents.length; // for (File paper : documents) { // currfile++; // if (paper.getName().equals(".DS_Store")||paper.getName().equals(".xml")) { // currfile--; // totfiles--; // continue; // } // System.out.println("Working on "+paper.getName()+" (file "+currfile+" out of "+totfiles+")."); // // DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); // This is for XML // DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // Document doc = docBuilder.parse(paper.getAbsolutePath()); // // NodeList textlist = doc.getElementsByTagName("text"); // for(int i=0; i < textlist.getLength(); i++) { // Node currentnode = textlist.item(i); // String wholetext = textlist.item(i).getTextContent(); String wholetext = "How about other changes for example the ways of doing the work and \n" + "\n" + "Iwould say security has , there 's more pressure put on people now than there used to be because obviously , especially after Locherbie , they tightened up on security and there 's a lot more pressure now especially from the ETR and stuff like that \n" + "People do n't feel valued any more , they feel I do n't know I think they feel that nobody cares about them really anyway \n"; //System.out.println(wholetext); //Iterable<List<? extends HasWord>> sentences; ArrayList<Tree> parseTrees = new ArrayList<Tree>(); String asd = ""; int j = 0; StringReader stringreader = new StringReader(wholetext); DocumentPreprocessor dp = new DocumentPreprocessor(stringreader); @SuppressWarnings("rawtypes") ArrayList<List> sentences = preprocess(dp); for (List sentence : sentences) { parseTrees.add(lp.apply(sentence)); // Parsing a new sentence and adding it to the parsed tree ArrayList<Tree> PronounsList = findPronouns(parseTrees.get(j)); // Locating all pronouns to resolve in the sentence Tree corefedTree; for (Tree pronounTree : PronounsList) { parseTrees.set(parseTrees.size() - 1, HobbsResolve(pronounTree, parseTrees)); // Resolving the coref and modifying the tree for each pronoun } StringWriter strwr = new StringWriter(); PrintWriter prwr = new PrintWriter(strwr); TreePrint tp = new TreePrint("penn"); tp.printTree(parseTrees.get(j), prwr); prwr.flush(); asd += strwr.toString(); j++; } String armando = ""; for (Tree sentence : parseTrees) { for (Tree leaf : Trees.leaves(sentence)) armando += leaf + " "; } System.out.println(wholetext); System.out.println(); System.out.println("......"); System.out.println(armando); System.out.println("All done."); // currentnode.setTextContent(asd); // } // TransformerFactory transformerFactory = TransformerFactory.newInstance(); // Transformer transformer = transformerFactory.newTransformer(); // DOMSource source = new DOMSource(doc); // StreamResult result = new StreamResult(paper); // transformer.transform(source, result); // // System.out.println("Done"); // } }
From source file:ch.epfl.lsir.xin.test.MostPopularTest.java
/** * @param args//from w ww . j av a2s .c o m */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub PrintWriter logger = new PrintWriter(".//results//MostPopular"); PropertiesConfiguration config = new PropertiesConfiguration(); config.setFile(new File(".//conf//MostPopular.properties")); try { config.load(); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } logger.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " Read rating data..."); DataLoaderFile loader = new DataLoaderFile(".//data//MoveLens100k.txt"); loader.readSimple(); DataSetNumeric dataset = loader.getDataset(); System.out.println("Number of ratings: " + dataset.getRatings().size() + " Number of users: " + dataset.getUserIDs().size() + " Number of items: " + dataset.getItemIDs().size()); logger.println("Number of ratings: " + dataset.getRatings().size() + ", Number of users: " + dataset.getUserIDs().size() + ", Number of items: " + dataset.getItemIDs().size()); logger.flush(); TrainTestSplitter splitter = new TrainTestSplitter(dataset); splitter.splitFraction(config.getDouble("TRAIN_FRACTION")); ArrayList<NumericRating> trainRatings = splitter.getTrain(); ArrayList<NumericRating> testRatings = splitter.getTest(); HashMap<String, Integer> userIDIndexMapping = new HashMap<String, Integer>(); HashMap<String, Integer> itemIDIndexMapping = new HashMap<String, Integer>(); //create rating matrix for (int i = 0; i < dataset.getUserIDs().size(); i++) { userIDIndexMapping.put(dataset.getUserIDs().get(i), i); } for (int i = 0; i < dataset.getItemIDs().size(); i++) { itemIDIndexMapping.put(dataset.getItemIDs().get(i), i); } RatingMatrix trainRatingMatrix = new RatingMatrix(dataset.getUserIDs().size(), dataset.getItemIDs().size()); for (int i = 0; i < trainRatings.size(); i++) { trainRatingMatrix.set(userIDIndexMapping.get(trainRatings.get(i).getUserID()), itemIDIndexMapping.get(trainRatings.get(i).getItemID()), trainRatings.get(i).getValue()); } RatingMatrix testRatingMatrix = new RatingMatrix(dataset.getUserIDs().size(), dataset.getItemIDs().size()); for (int i = 0; i < testRatings.size(); i++) { //only consider 5-star rating in the test set // if( testRatings.get(i).getValue() < 5 ) // continue; testRatingMatrix.set(userIDIndexMapping.get(testRatings.get(i).getUserID()), itemIDIndexMapping.get(testRatings.get(i).getItemID()), testRatings.get(i).getValue()); } System.out.println("Training: " + trainRatingMatrix.getTotalRatingNumber() + " vs Test: " + testRatingMatrix.getTotalRatingNumber()); logger.println("Initialize a most popular based recommendation model."); MostPopular algo = new MostPopular(trainRatingMatrix); algo.setLogger(logger); algo.build(); algo.saveModel(".//localModels//" + config.getString("NAME")); logger.println("Save the model."); logger.flush(); HashMap<Integer, ArrayList<ResultUnit>> results = new HashMap<Integer, ArrayList<ResultUnit>>(); for (int i = 0; i < testRatingMatrix.getRow(); i++) { ArrayList<ResultUnit> rec = algo.getRecommendationList(i); if (rec == null) continue; int total = testRatingMatrix.getUserRatingNumber(i); if (total == 0)//this user is ignored continue; results.put(i, rec); } RankResultGenerator generator = new RankResultGenerator(results, algo.getTopN(), testRatingMatrix, trainRatingMatrix); System.out.println("Precision@N: " + generator.getPrecisionN()); System.out.println("Recall@N: " + generator.getRecallN()); System.out.println("MAP@N: " + generator.getMAPN()); System.out.println("MRR@N: " + generator.getMRRN()); System.out.println("NDCG@N: " + generator.getNDCGN()); System.out.println("AUC@N: " + generator.getAUC()); logger.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "\n" + "Precision@N: " + generator.getPrecisionN() + "\n" + "Recall@N: " + generator.getRecallN() + "\n" + "MAP@N: " + generator.getMAPN() + "\n" + "MRR@N: " + generator.getMRRN() + "\n" + "NDCG@N: " + generator.getNDCGN() + "\n" + "AUC@N: " + generator.getAUC()); logger.flush(); logger.close(); }
From source file:edu.oregonstate.eecs.mcplan.domains.toy.CliffWorld.java
public static void main(final String[] argv) throws NumberFormatException, IOException { final RandomGenerator rng = new MersenneTwister(42); final int L = 7; final int W = 4; final int F = 5; final State s = new State(rng, L, W, F); final Simulator sim = new Simulator(s, rng); final Actions actions = new Actions(rng); while (!sim.state().isTerminal()) { System.out.println(s);//w w w. jav a 2 s . c o m actions.setState(sim.state(), sim.t()); final ArrayList<Action> action_list = Fn.takeAll(actions); for (int i = 0; i < action_list.size(); ++i) { System.out.println(i + ": " + action_list.get(i)); } System.out.print(">>> "); final BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); final int choice = Integer.parseInt(cin.readLine()); final Action a = action_list.get(choice); sim.takeAction(new JointAction<Action>(a)); System.out.println("Reward: " + Arrays.toString(sim.reward())); } }
From source file:gamlss.algorithm.Gamlss.java
/** * Main method.//from ww w . j ava 2 s. com * @param args - command-line arguments */ public static void main(final String[] args) { //String fileName = "Data/dataReduced.csv"; String fileName = "Data/oil.csv"; // String fileName = "Data/sp.csv"; //String fileName = "Data/dataReduced.csv"; CSVFileReader readData = new CSVFileReader(fileName); readData.readFile(); ArrayList<String> data = readData.storeValues; ArrayRealVector y = new ArrayRealVector(data.size()); BlockRealMatrix muX = new BlockRealMatrix(data.size(), 1); BlockRealMatrix sigmaX = new BlockRealMatrix(data.size(), 1); BlockRealMatrix nuX = new BlockRealMatrix(data.size(), 1); BlockRealMatrix tauX = new BlockRealMatrix(data.size(), 1); ArrayRealVector w = new ArrayRealVector(data.size()); BlockRealMatrix muS = new BlockRealMatrix(data.size(), 1); BlockRealMatrix sigmaS = new BlockRealMatrix(data.size(), 1); BlockRealMatrix nuS = new BlockRealMatrix(data.size(), 1); BlockRealMatrix tauS = new BlockRealMatrix(data.size(), 1); for (int i = 0; i < data.size(); i++) { String[] line = data.get(i).split(","); y.setEntry(i, Double.parseDouble(line[0])); muX.setEntry(i, 0, Double.parseDouble(line[1])); muS.setEntry(i, 0, Double.parseDouble(line[1])); sigmaX.setEntry(i, 0, Double.parseDouble(line[1])); sigmaS.setEntry(i, 0, Double.parseDouble(line[1])); nuX.setEntry(i, 0, Double.parseDouble(line[1])); nuS.setEntry(i, 0, Double.parseDouble(line[1])); tauX.setEntry(i, 0, Double.parseDouble(line[1])); tauS.setEntry(i, 0, Double.parseDouble(line[1])); } Hashtable<Integer, BlockRealMatrix> designMatrices = new Hashtable<Integer, BlockRealMatrix>(); designMatrices.put(DistributionSettings.MU, muX); designMatrices.put(DistributionSettings.SIGMA, sigmaX); designMatrices.put(DistributionSettings.NU, nuX); designMatrices.put(DistributionSettings.TAU, tauX); HashMap<Integer, BlockRealMatrix> smoothMatrices = new HashMap<Integer, BlockRealMatrix>(); smoothMatrices.put(DistributionSettings.MU, muS); smoothMatrices.put(DistributionSettings.SIGMA, sigmaS); smoothMatrices.put(DistributionSettings.NU, nuS); smoothMatrices.put(DistributionSettings.TAU, tauS); //smoothMatrices.put(DistributionSettings.MU, null); //smoothMatrices.put(DistributionSettings.SIGMA, null); //smoothMatrices.put(DistributionSettings.NU, null); //smoothMatrices.put(DistributionSettings.TAU, null); DistributionSettings.DISTR = DistributionSettings.SST; Controls.GLOB_DEVIANCE_TOL = 5500; Controls.INTER = 50;//only for the PB smoother Controls.SMOOTHER = Controls.PB; //or PB Controls.IS_SVD = true; Controls.BIG_DATA = true; Controls.JAVA_OPTIMIZATION = false; Controls.GAMLSS_NUM_CYCLES = 50; //Gamlss gamlss = new Gamlss(y, designMatrices, null); Gamlss gamlss = new Gamlss(y, designMatrices, null); //Gamlss gamlss = new Gamlss(y, null, smoothMatrices); gamlss.saveFittedDistributionParameters("Data/oilresults.csv"); }
From source file:edu.oregonstate.eecs.mcplan.ml.InformationTheoreticMetricLearner.java
/** * @param args//from ww w .ja v a2 s .co m */ public static void main(final String[] args) { final RandomGenerator rng = new MersenneTwister(42); final int d = 2; final double u = 5.0; final double ell = 7.0; final double gamma = 1.0; final ArrayList<RealVector> X = new ArrayList<RealVector>(); final RealMatrix A0 = MatrixUtils.createRealIdentityMatrix(d); for (final int w : new int[] { 0, 5 }) { for (final int h : new int[] { 0, 50 }) { for (int x = -1; x <= 1; ++x) { for (int y = -1; y <= 1; ++y) { X.add(new ArrayRealVector(new double[] { x + w, y + h })); } } } } final ArrayList<int[]> S = new ArrayList<int[]>(); S.add(new int[] { 4, 12 }); // Must link diagonally S.add(new int[] { 21, 31 }); final ArrayList<double[]> Sd = new ArrayList<double[]>(); for (final int[] s : S) { final double[] a = X.get(s[0]).subtract(X.get(s[1])).toArray(); Sd.add(a); } final ArrayList<int[]> D = new ArrayList<int[]>(); D.add(new int[] { 5, 23 }); D.add(new int[] { 13, 32 }); // Cannot link vertically final ArrayList<double[]> Dd = new ArrayList<double[]>(); for (final int[] dd : D) { final double[] a = X.get(dd[0]).subtract(X.get(dd[1])).toArray(); Dd.add(a); } final InformationTheoreticMetricLearner itml = new InformationTheoreticMetricLearner(Sd, Dd, u, ell, A0, gamma, rng); itml.run(); final RealMatrix A = itml.A(); System.out.println(A0.toString()); for (final int[] c : S) { final RealVector diff = X.get(c[0]).subtract(X.get(c[1])); System.out.println(diff.dotProduct(A0.operate(diff))); } for (final int[] c : D) { final RealVector diff = X.get(c[0]).subtract(X.get(c[1])); System.out.println(diff.dotProduct(A0.operate(diff))); } System.out.println(A.toString()); for (final int[] c : S) { final RealVector diff = X.get(c[0]).subtract(X.get(c[1])); System.out.println(diff.dotProduct(A.operate(diff))); } for (final int[] c : D) { final RealVector diff = X.get(c[0]).subtract(X.get(c[1])); System.out.println(diff.dotProduct(A.operate(diff))); } // int i = 0; // for( final int w : new int[] { 0, 5 } ) { // for( final int h : new int[] { 0, 5 } ) { // for( int x = -1; x <= 1; ++x ) { // for( int y = -1; y <= 1; ++y ) { // System.out.println( itml.A().operate( X.get( i++ ) ) ); // } // } // } // } }
From source file:HannonHillSecret.HannonHillSecret.java
/** * @param args the command line arguments *///from w ww .j a v a2s .c o m public static void main(String[] args) { // This is a placeholder for the provided value of N final int N = 55; int currentNum = 0; int x = 0; int sizePrimes; boolean isAdditive = true; ArrayList<Integer> primeNumbers = new ArrayList<>(); currentNum = Primes.nextPrime(currentNum); //Add all prime numbers less than or equal to N while (currentNum <= N) { primeNumbers.add(currentNum); currentNum = Primes.nextPrime(currentNum++); } sizePrimes = primeNumbers.size(); // If there are only two prime numbers in the arraylist, it means it is empty or there // is only one. if (sizePrimes < 2) { System.out.println("Cannot test if Secret is additive since there " + "are not two or more prime numbers less than N!"); } else // Testing for additive property is possible { outerloop: // Assuming the additive test only requires pair combinations, go through // all possible pairs until all pass or one fails while (x < sizePrimes && isAdditive) { for (int y = x + 1; y <= sizePrimes; y++) { isAdditive = isSecretAdditive(primeNumbers.get(x), primeNumbers.get(x)); //Failed additive test for a combination of prime numbers, // so break the while loop and return false if (!isAdditive) { break outerloop; } } x++; } if (isAdditive) { System.out.println("Secret is additive!"); } else { System.out.println("Secret is NOT additive!"); } } }
From source file:mlbench.pagerank.PagerankNaive.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void main(String[] args) throws IOException, InterruptedException { try {//from w w w.j a va 2 s .c o m parseArgs(args); HashMap<String, String> conf = new HashMap<String, String>(); initConf(conf); MPI_D.Init(args, MPI_D.Mode.Common, conf); JobConf jobConf = new JobConf(confPath); if (MPI_D.COMM_BIPARTITE_O != null) { // O communicator int rank = MPI_D.Comm_rank(MPI_D.COMM_BIPARTITE_O); int size = MPI_D.Comm_size(MPI_D.COMM_BIPARTITE_O); if (rank == 0) { LOG.info(PagerankNaive.class.getSimpleName() + " O start."); } FileSplit[] inputs1 = DataMPIUtil.HDFSDataLocalLocator.getTaskInputs(MPI_D.COMM_BIPARTITE_O, jobConf, edgeDir, rank); FileSplit[] inputs2 = DataMPIUtil.HDFSDataLocalLocator.getTaskInputs(MPI_D.COMM_BIPARTITE_O, jobConf, vecDir, rank); FileSplit[] inputs = (FileSplit[]) ArrayUtils.addAll(inputs2, inputs1); for (int i = 0; i < inputs.length; i++) { FileSplit fsplit = inputs[i]; LineRecordReader kvrr = new LineRecordReader(jobConf, fsplit); LongWritable key = kvrr.createKey(); Text value = kvrr.createValue(); { IntWritable k = new IntWritable(); Text v = new Text(); while (kvrr.next(key, value)) { String line_text = value.toString(); // ignore comments in edge file if (line_text.startsWith("#")) continue; final String[] line = line_text.split("\t"); if (line.length < 2) continue; // vector : ROWID VALUE('vNNNN') if (line[1].charAt(0) == 'v') { k.set(Integer.parseInt(line[0])); v.set(line[1]); MPI_D.Send(k, v); } else { /* * In other matrix-vector multiplication, we * output (dst, src) here However, In PageRank, * the matrix-vector computation formula is M^T * * v. Therefore, we output (src,dst) here. */ int src_id = Integer.parseInt(line[0]); int dst_id = Integer.parseInt(line[1]); k.set(src_id); v.set(line[1]); MPI_D.Send(k, v); if (make_symmetric == 1) { k.set(dst_id); v.set(line[0]); MPI_D.Send(k, v); } } } } } } else if (MPI_D.COMM_BIPARTITE_A != null) { // A communicator int rank = MPI_D.Comm_rank(MPI_D.COMM_BIPARTITE_A); if (rank == 0) { LOG.info(PagerankNaive.class.getSimpleName() + " A start."); } HadoopWriter<IntWritable, Text> outrw = HadoopIOUtil.getNewWriter(jobConf, outDir, IntWritable.class, Text.class, TextOutputFormat.class, null, rank, MPI_D.COMM_BIPARTITE_A); IntWritable oldKey = null; int i; double cur_rank = 0; ArrayList<Integer> dst_nodes_list = new ArrayList<Integer>(); Object[] keyValue = MPI_D.Recv(); while (keyValue != null) { IntWritable key = (IntWritable) keyValue[0]; Text value = (Text) keyValue[1]; if (oldKey == null) { oldKey = key; } // A new key arrives if (!key.equals(oldKey)) { outrw.write(oldKey, new Text("s" + cur_rank)); int outdeg = dst_nodes_list.size(); if (outdeg > 0) { cur_rank = cur_rank / (double) outdeg; } for (i = 0; i < outdeg; i++) { outrw.write(new IntWritable(dst_nodes_list.get(i)), new Text("v" + cur_rank)); } oldKey = key; cur_rank = 0; dst_nodes_list = new ArrayList<Integer>(); } // common record String line_text = value.toString(); final String[] line = line_text.split("\t"); if (line.length == 1) { if (line_text.charAt(0) == 'v') { // vector : VALUE cur_rank = Double.parseDouble(line_text.substring(1)); } else { // edge : ROWID dst_nodes_list.add(Integer.parseInt(line[0])); } } keyValue = MPI_D.Recv(); } // write the left part if (cur_rank != 0) { outrw.write(oldKey, new Text("s" + cur_rank)); int outdeg = dst_nodes_list.size(); if (outdeg > 0) { cur_rank = cur_rank / (double) outdeg; } for (i = 0; i < outdeg; i++) { outrw.write(new IntWritable(dst_nodes_list.get(i)), new Text("v" + cur_rank)); } } outrw.close(); } MPI_D.Finalize(); } catch (MPI_D_Exception e) { e.printStackTrace(); } }