List of usage examples for com.google.common.collect HashBasedTable create
public static <R, C, V> HashBasedTable<R, C, V> create()
From source file:com.urey.flume.source.taildir.ReliableTaildirEventReader.java
/** * Create a ReliableTaildirEventReader to watch the given directory. *//*from w w w . j ava2 s . c om*/ private ReliableTaildirEventReader(Map<String, String> filePaths, Table<String, String, String> headerTable, String positionFilePath, boolean skipToEnd, boolean addByteOffset, boolean recursiveDirectorySearch, boolean annotateYarnApplicationId, boolean annotateYarnContainerId, boolean annotateFileName, String fileNameHeader) throws IOException { // Sanity checks Preconditions.checkNotNull(filePaths); Preconditions.checkNotNull(positionFilePath); if (logger.isDebugEnabled()) { logger.debug("Initializing {} with directory={}, metaDir={}", new Object[] { ReliableTaildirEventReader.class.getSimpleName(), filePaths }); } Table<String, File, Pattern> tailFileTable = HashBasedTable.create(); for (Entry<String, String> e : filePaths.entrySet()) { File f = new File(e.getValue()); File parentDir = f.getParentFile(); Preconditions.checkState(parentDir.exists(), "Directory does not exist: " + parentDir.getAbsolutePath()); Pattern fileNamePattern = Pattern.compile(f.getName()); tailFileTable.put(e.getKey(), parentDir, fileNamePattern); } logger.info("tailFileTable: " + tailFileTable.toString()); logger.info("headerTable: " + headerTable.toString()); this.tailFileTable = tailFileTable; this.headerTable = headerTable; this.addByteOffset = addByteOffset; this.recursiveDirectorySearch = recursiveDirectorySearch; this.annotateYarnApplicationId = annotateYarnApplicationId; this.annotateYarnContainerId = annotateYarnContainerId; this.annotateFileName = annotateFileName; this.fileNameHeader = fileNameHeader; updateTailFiles(skipToEnd); logger.info("Updating position from position file: " + positionFilePath); loadPositionFile(positionFilePath); }
From source file:mtsar.processors.answer.KOSAggregator.java
@Override @Nonnull/* www . j av a2 s .co m*/ public Map<Integer, AnswerAggregation> aggregate(@Nonnull Collection<Task> tasks) { requireNonNull(stage, "the stage provider should not provide null"); checkArgument(tasks.stream().allMatch(SINGLE_BINARY_TYPE), "tasks should be of the type single and have only two possible answers"); if (tasks.isEmpty()) return Collections.emptyMap(); final List<Answer> answers = answerDAO.listForStage(stage.getId()); if (answers.isEmpty()) return Collections.emptyMap(); final Map<Integer, Task> taskMap = taskDAO.listForStage(stage.getId()).stream().filter(SINGLE_BINARY_TYPE) .collect(Collectors.toMap(Task::getId, Function.identity())); final Map<Integer, BiMap<String, Short>> answerIndex = taskMap.values().stream() .collect(Collectors.toMap(Task::getId, task -> { final BiMap<String, Short> map = HashBiMap.create(2); map.put(task.getAnswers().get(0), (short) -1); map.put(task.getAnswers().get(1), (short) +1); return map; })); /* rows are tasks IDs, columns are worker IDs, values are answers */ final Table<Integer, Integer, Short> graph = HashBasedTable.create(); for (final Answer answer : answers) { if (!answer.getType().equalsIgnoreCase(AnswerDAO.ANSWER_TYPE_ANSWER)) continue; graph.put(answer.getTaskId(), answer.getWorkerId(), answerIndex.get(answer.getTaskId()).get(answer.getAnswers().get(0))); } final Map<Integer, Double> estimations = converge(graph, getKMax()); return estimations.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, estimation -> { final String answer = answerIndex.get(estimation.getKey()).inverse() .get(estimation.getValue() < 0 ? (short) -1 : (short) +1); return new AnswerAggregation.Builder().setTask(taskMap.get(estimation.getKey())).addAnswers(answer) .build(); })); }
From source file:es.upm.dit.xsdinferencer.statistics.ComplexTypeStatisticsEntry.java
/** * Default constructor/*from w ww . j ava 2s.com*/ * @param inputDocumentsCount how many input documents are there */ public ComplexTypeStatisticsEntry(int inputDocumentsCount) { this.inputDocumentsCount = inputDocumentsCount; this.elementInfo = new HashMap<SchemaElement, BasicStatisticsEntry>(); this.subpatternsInfo = new HashMap<List<SchemaElement>, Integer>(); this.attributeOccurrencesInfo = new HashMap<SchemaAttribute, BasicStatisticsEntry>(); this.valuesInfo = HashBasedTable.create(); this.lastAllValuesTablesHash = valuesInfo.hashCode(); }
From source file:com.rackspacecloud.blueflood.io.astyanax.AEnumIO.java
/** * Read the metrics_preaggregated_{granularity} for specific locators. Organize * the data as a table of locator, timestamp, and enum object * * @param locators/*from ww w . j av a2 s . c o m*/ * @param columnFamily * @return */ @Override public Table<Locator, Long, BluefloodEnumRollup> getEnumRollupsForLocators(List<Locator> locators, String columnFamily, Range range) { AstyanaxReader reader = AstyanaxReader.getInstance(); Map<Locator, ColumnList<Long>> locatorToColumnList = reader.getColumnsFromDB(locators, CassandraModel.getColumnFamily(columnFamily), range); Table<Locator, Long, BluefloodEnumRollup> locatorHashRollup = HashBasedTable.create(); for (Map.Entry<Locator, ColumnList<Long>> entry : locatorToColumnList.entrySet()) { ColumnList<Long> columnList = entry.getValue(); for (Column<Long> column : columnList) { locatorHashRollup.put(entry.getKey(), column.getName(), column.getValue(Serializers.enumRollupInstance)); } } return locatorHashRollup; }
From source file:org.apache.sentry.provider.db.generic.UpdatableCache.java
/** * Build cache replica with latest values * * @return cache replica with latest values *//*from ww w . j a v a2 s . c o m*/ private Table<String, String, Set<String>> loadFromRemote() throws Exception { Table<String, String, Set<String>> tempCache = HashBasedTable.create(); String requestor; requestor = UserGroupInformation.getLoginUser().getShortUserName(); final SentryGenericServiceClient client = getClient(); final Set<TSentryRole> tSentryRoles = client.listAllRoles(requestor, componentType); for (TSentryRole tSentryRole : tSentryRoles) { final String roleName = tSentryRole.getRoleName(); final Set<TSentryPrivilege> tSentryPrivileges = client.listPrivilegesByRoleName(requestor, roleName, componentType, serviceName); for (String group : tSentryRole.getGroups()) { Set<String> currentPrivileges = tempCache.get(group, roleName); if (currentPrivileges == null) { currentPrivileges = new HashSet<>(); tempCache.put(group, roleName, currentPrivileges); } for (TSentryPrivilege tSentryPrivilege : tSentryPrivileges) { currentPrivileges.add(tSentryPrivilegeConverter.toString(tSentryPrivilege)); } } } return tempCache; }
From source file:de.uni_potsdam.hpi.asg.logictool.synthesis.model.EspressoTable.java
public static EspressoTable importFromFile(File file) { List<String> lines = FileHelper.getInstance().readFile(file); if (lines == null) { logger.error("Could not read-in results from espresso"); return null; }/*w ww . java 2 s .c o m*/ String[] inputs = null; String[] outputs = null; Table<EspressoTerm, String, EspressoValue> table = HashBasedTable.create(); Matcher m = null; for (String str : lines) { m = tablePattern.matcher(str); if (m.matches()) { if (outputs != null && inputs != null) { EspressoTerm t = new EspressoTerm(m.group(1), inputs); int i = 0; for (String out : outputs) { switch (m.group(2).charAt(i)) { case '0': table.put(t, out, EspressoValue.zero); break; case '1': table.put(t, out, EspressoValue.one); break; case '-': table.put(t, out, EspressoValue.dontcare); break; default: System.err.println("Unknown char in table: " + m.group(2).charAt(i)); } i++; } } else { System.err.println("No in/outputs"); return null; } continue; } m = inputsPattern.matcher(str); if (m.matches()) { continue; } m = outputsPattern.matcher(str); if (m.matches()) { continue; } m = inputNamePattern.matcher(str); if (m.matches()) { inputs = m.group(1).split(" "); continue; } m = outputNamePattern.matcher(str); if (m.matches()) { outputs = m.group(1).split(" "); continue; } m = tableEntriesPattern.matcher(str); if (m.matches()) { continue; } m = endPattern.matcher(str); if (m.matches()) { break; } System.err.println("No match: " + str); } return new EspressoTable(inputs, table); }
From source file:net.librec.recommender.cf.rating.GPLSARecommender.java
@Override protected void setup() throws LibrecException { super.setup(); numTopics = conf.getInt("rec.topic.number", 10); // Initialize users' conditional probabilities userTopicProbs = new DenseMatrix(numUsers, numTopics); for (int u = 0; u < numUsers; u++) { double[] probs = Randoms.randProbs(numTopics); for (int z = 0; z < numTopics; z++) { userTopicProbs.set(u, z, probs[z]); }//from ww w . jav a2s. c om } double mean = trainMatrix.mean(); double sd = Stats.sd(trainMatrix.getData(), mean); userMu = new DenseVector(numUsers); userSigma = new DenseVector(numUsers); smoothWeight = conf.getInt("rec.recommender.smoothWeight"); for (int u = 0; u < numUsers; u++) { SparseVector userRow = trainMatrix.row(u); int numRatings = userRow.size(); if (numRatings < 1) { continue; } // Compute mu_u double mu_u = (userRow.sum() + smoothWeight * mean) / (numRatings + smoothWeight); userMu.set(u, mu_u); // Compute sigma_u double sum = 0; for (VectorEntry ve : userRow) { sum += Math.pow(ve.get() - mu_u, 2); } sum += smoothWeight * Math.pow(sd, 2); double sigma_u = Math.sqrt(sum / (numRatings + smoothWeight)); userSigma.set(u, sigma_u); } // Initialize Q Q = HashBasedTable.create(); for (MatrixEntry trainMatrixEntry : trainMatrix) { int userIdx = trainMatrixEntry.row(); int itemIdx = trainMatrixEntry.column(); double rating = trainMatrixEntry.get(); double r = (rating - userMu.get(userIdx)) / userSigma.get(userIdx); trainMatrix.set(userIdx, itemIdx, r); Q.put(userIdx, itemIdx, new HashMap<Integer, Double>()); } // Initialize Mu, Sigma topicItemMu = new DenseMatrix(numItems, numTopics); topicItemSigma = new DenseMatrix(numItems, numTopics); for (int i = 0; i < numItems; i++) { SparseVector itemColumn = trainMatrix.column(i); int numRatings = itemColumn.size(); if (numRatings < 1) { continue; } double mu_i = itemColumn.mean(); double sum = 0; for (VectorEntry ve : itemColumn) { sum += Math.pow(ve.get() - mu_i, 2); } double sd_i = Math.sqrt(sum / numRatings); for (int z = 0; z < numTopics; z++) { topicItemMu.set(i, z, mu_i + smallValue * Randoms.uniform()); topicItemSigma.set(i, z, sd_i + smallValue * Randoms.uniform()); } } }
From source file:net.librec.recommender.cf.rating.URPRecommender.java
@Override protected void setup() throws LibrecException { super.setup(); numTopics = conf.getInt("rec.pgm.number", 10); numRatingLevels = trainMatrix.getValueSet().size(); // cumulative parameters userTopicSumProbs = new DenseMatrix(numUsers, numTopics); topicItemRatingSumProbs = new double[numTopics][numItems][numRatingLevels]; // initialize count variables userTopicNum = new DenseMatrix(numUsers, numTopics); userNum = new DenseVector(numUsers); topicItemRatingNum = new int[numTopics][numItems][numRatingLevels]; topicItemNum = new DenseMatrix(numTopics, numItems); alpha = new DenseVector(numTopics); double initAlpha = conf.getDouble("rec.pgm.bucm.alpha", 1.0 / numTopics); alpha.setAll(initAlpha);//from www . j a v a2s .c o m beta = new DenseVector(numRatingLevels); double initBeta = conf.getDouble("rec.pgm.bucm.beta", 1.0 / numTopics); beta.setAll(initBeta); // initialize topics topics = HashBasedTable.create(); for (MatrixEntry me : trainMatrix) { int u = me.row(); int i = me.column(); double rui = me.get(); int r = ratingScale.indexOf(rui); // rating level 0 ~ numLevels int t = (int) (Randoms.uniform() * numTopics); // 0 ~ k-1 // Assign a topic t to pair (u, i) topics.put(u, i, t); // number of pairs (u, t) in (u, i, t) userTopicNum.add(u, t, 1); // total number of items of user u userNum.add(u, 1); // number of pairs (t, i, r) topicItemRatingNum[t][i][r]++; // total number of words assigned to topic t topicItemNum.add(t, i, 1); } }
From source file:rapture.sheet.memory.InMemorySheet.java
public void setCell(int dim, int row, int col, String val) { Table<Integer, Integer, RaptureSheetCell> table = dimToData.get(dim); if (table == null) { table = HashBasedTable.create(); dimToData.put(dim, table);/*from w ww.j av a 2 s. c o m*/ } setCell(table, row, col, val); }
From source file:co.cask.cdap.internal.app.AbstractInMemoryProgramRunner.java
protected Table<String, Integer, ProgramController> startPrograms(Program program, RunId runId, ProgramOptions options, ProgramRunnerFactory.Type type, int numInstances) { Table<String, Integer, ProgramController> components = HashBasedTable.create(); try {// w w w .j av a2 s. c o m startComponent(program, program.getName(), numInstances, runId, options, components, type); } catch (Throwable t) { LOG.error("Failed to start all program instances", t); try { // Need to stop all started components Futures.successfulAsList(Iterables.transform(components.values(), new Function<ProgramController, ListenableFuture<?>>() { @Override public ListenableFuture<?> apply(ProgramController controller) { return controller.stop(); } })).get(); throw Throwables.propagate(t); } catch (Exception e) { LOG.error("Failed to stop all program instances upon startup failure.", e); throw Throwables.propagate(e); } } return components; }