List of usage examples for java.util HashSet size
public int size()
From source file:ch.unil.genescore.pathway.GeneSetLibrary.java
License:asdf
protected double[] getSetChisq(GeneSet set) { HashSet<Gene> gSet = set.getGenes(); double[] ret = new double[gSet.size()]; // Sum the chi2 stats int i = 0;/*from w w w . ja v a 2 s . c o m*/ for (Gene g : gSet) { ret[i] = g.getChi2Stat(); i++; } return ret; }
From source file:com.hellblazer.slp.anubis.EndToEndTest.java
public void testSmoke() throws Exception { String memberIdKey = "test.member.id"; ServiceURL url = new ServiceURL("service:http://foo.bar/drink-me"); List<Listener> listeners = new ArrayList<Listener>(); for (ApplicationContext context : memberContexts) { Listener listener = new Listener(context, memberContexts.size()); listeners.add(listener);// ww w. j a va 2 s.com listener.register(getQuery("*")); } for (ApplicationContext context : memberContexts) { HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put(memberIdKey, context.getBean(Identity.class).id); context.getBean(ServiceScope.class).register(url, properties); } for (Listener listener : listeners) { assertTrue(String.format("Listener: %s did not receive all events", listener), listener.await(60, TimeUnit.SECONDS)); } for (Listener listener : listeners) { assertEquals(listeners.size(), listener.events.size()); HashSet<Integer> sent = new HashSet<Integer>(); for (ServiceEvent event : listener.events) { assertEquals(EventType.REGISTERED, event.getType()); assertEquals(url, event.getReference().getUrl()); sent.add((Integer) event.getReference().getProperties().get(memberIdKey)); assertEquals(event.getReference().getProperties().get(AnubisScope.MEMBER_IDENTITY), event.getReference().getProperties().get(memberIdKey)); } assertEquals(listeners.size(), sent.size()); } }
From source file:com.qwazr.cluster.manager.ClusterManager.java
private ClusterManager(ExecutorService executor, String publicAddress, Set<String> myGroups) throws IOException, URISyntaxException { myAddress = ClusterNode.toAddress(publicAddress); if (logger.isInfoEnabled()) logger.info("Server: " + myAddress + " Groups: " + ArrayUtils.prettyPrint(myGroups)); this.myGroups = myGroups; this.executor = executor; // Load the configuration String masters_env = System.getenv("QWAZR_MASTERS"); // No configuration file ? Okay, we are a simple node if (StringUtils.isEmpty(masters_env)) { clusterMasterArray = null;//from w w w . ja v a 2 s . c om clusterNodeMap = null; clusterClient = null; checkTimeMap = null; lastTimeCheck = null; isMaster = false; isCluster = false; if (logger.isInfoEnabled()) logger.info("No QWAZR_MASTERS environment variable. This node is not part of a cluster."); return; } // Store the last time a master checked the node checkTimeMap = new ConcurrentHashMap<>(); lastTimeCheck = new AtomicLong(); // Build the master list and check if I am a master boolean isMaster = false; HashSet<String> masterSet = new HashSet<>(); int i = 0; String[] masters = StringUtils.split(masters_env, ','); for (String master : masters) { String masterAddress = ClusterNode.toAddress(master.trim()); logger.info("Add a master: " + masterAddress); masterSet.add(masterAddress); if (masterAddress == myAddress) { isMaster = true; if (logger.isInfoEnabled()) logger.info("I am a master!"); } } isCluster = true; clusterMasterArray = masterSet.toArray(new String[masterSet.size()]); clusterClient = new ClusterMultiClient(executor, clusterMasterArray, 60000); this.isMaster = isMaster; if (!isMaster) { clusterNodeMap = null; return; } // We load the cluster node map clusterNodeMap = new ClusterNodeMap(); }
From source file:ch.unil.genescore.pathway.GeneSetLibrary.java
License:asdf
protected void computeHypGeomPvalue(GeneSet set) { ArrayList<Double> quantiles = Pascal.set.hypGeomQuantiles_; double[] pvals = new double[quantiles.size()]; if (set.getGenes().size() == 0) { for (int i = 0; i < quantiles.size(); i++) { pvals[i] = 1;/*w ww . j ava2 s.c o m*/ } set.setHypGeomPvalues(pvals); return; } for (int j = 0; j < quantiles.size(); j++) { double[] valAr = new double[genesForSimulation_.size()]; for (int i = 0; i < genesForSimulation_.size(); i++) { valAr[i] = genesForSimulation_.get(i).getChi2Stat(); } Arrays.sort(valAr); int n = (int) Math.floor(valAr.length * quantiles.get(j)); double cutoffVal = valAr[n]; int setSize = valAr.length - n - 1; HashSet<Gene> pathwayGenes = set.getGenes(); if (pathwayGenes.size() == 0) return; int q = 0; for (Gene g : pathwayGenes) { if (g.getChi2Stat() > cutoffVal) q += 1; } HypergeometricDistribution myHypgeom = new HypergeometricDistribution(valAr.length, setSize, pathwayGenes.size()); double pval = 1 - myHypgeom.cumulativeProbability((q - 1)); pvals[j] = pval; } set.setHypGeomPvalues(pvals); }
From source file:ch.unil.genescore.pathway.GeneSetLibrary.java
License:asdf
public void computeApproxPathwayCorrelationLowerBound() { DenseMatrix corMat = new DenseMatrix(geneSets_.size(), geneSets_.size()); for (int i = 0; i < geneSets_.size(); i++) { HashSet<Gene> leftSet = geneSets_.get(i).genes_; double leftSize = leftSet.size(); for (int j = 0; j < geneSets_.size(); j++) { HashSet<Gene> rightSet = geneSets_.get(j).genes_; double rightSize = rightSet.size(); HashSet<Gene> copyLeftSet = new HashSet<Gene>(leftSet); copyLeftSet.retainAll(rightSet); double count = copyLeftSet.size(); double corr = count / Math.sqrt(leftSize * rightSize); //double corr = count; corMat.set(i, j, corr);//from w w w .j a va2 s . com } } pathwayCorMat_ = corMat; }
From source file:maui.main.MauiTopicExtractor.java
/** * Builds the model from the files/*from w ww. j av a2 s. c o m*/ */ public void extractKeyphrases(HashSet<String> fileNames) throws Exception { // Check whether there is actually any data if (fileNames.size() == 0) { throw new Exception("Couldn't find any data in " + inputDirectoryName); } mauiFilter.setVocabularyName(vocabularyName); mauiFilter.setVocabularyFormat(vocabularyFormat); mauiFilter.setDocumentLanguage(documentLanguage); mauiFilter.setStemmer(stemmer); mauiFilter.setStopwords(stopwords); if (wikipedia != null) { mauiFilter.setWikipedia(wikipedia); } else if (wikipediaServer.equals("localhost") && wikipediaDatabase.equals("database")) { mauiFilter.setWikipedia(wikipedia); } else { mauiFilter.setWikipedia(wikipediaServer, wikipediaDatabase, cacheWikipediaData, wikipediaDataDirectory); } if (!vocabularyName.equals("none") && !vocabularyName.equals("wikipedia")) { loadThesaurus(stemmer, stopwords, vocabularyDirectory); mauiFilter.setVocabulary(vocabulary); } FastVector atts = new FastVector(3); atts.addElement(new Attribute("filename", (FastVector) null)); atts.addElement(new Attribute("doc", (FastVector) null)); atts.addElement(new Attribute("keyphrases", (FastVector) null)); Instances data = new Instances("keyphrase_training_data", atts, 0); System.err.println("-- Extracting keyphrases... "); Vector<Double> correctStatistics = new Vector<Double>(); Vector<Double> precisionStatistics = new Vector<Double>(); Vector<Double> recallStatistics = new Vector<Double>(); for (String fileName : fileNames) { double[] newInst = new double[3]; newInst[0] = (double) data.attribute(0).addStringValue(fileName); ; File documentTextFile = new File(inputDirectoryName + "/" + fileName + ".txt"); File documentTopicsFile = new File(inputDirectoryName + "/" + fileName + ".key"); try { String documentText; if (!documentEncoding.equals("default")) { documentText = FileUtils.readFileToString(documentTextFile, documentEncoding); } else { documentText = FileUtils.readFileToString(documentTextFile); } // Adding the text of the document to the instance newInst[1] = (double) data.attribute(1).addStringValue(documentText); } catch (Exception e) { System.err.println("Problem with reading " + documentTextFile); e.printStackTrace(); newInst[1] = Instance.missingValue(); } try { String documentTopics; if (!documentEncoding.equals("default")) { documentTopics = FileUtils.readFileToString(documentTopicsFile, documentEncoding); } else { documentTopics = FileUtils.readFileToString(documentTopicsFile); } // Adding the topics to the file newInst[2] = (double) data.attribute(2).addStringValue(documentTopics); } catch (Exception e) { if (debugMode) { System.err.println("No existing topics for " + documentTextFile); } newInst[2] = Instance.missingValue(); } data.add(new Instance(1.0, newInst)); mauiFilter.input(data.instance(0)); data = data.stringFreeStructure(); if (debugMode) { System.err.println("-- Processing document: " + fileName); } Instance[] topRankedInstances = new Instance[topicsPerDocument]; Instance inst; // Iterating over all extracted keyphrases (inst) while ((inst = mauiFilter.output()) != null) { int index = (int) inst.value(mauiFilter.getRankIndex()) - 1; if (index < topicsPerDocument) { topRankedInstances[index] = inst; } } if (debugMode) { System.err.println("-- Keyphrases and feature values:"); } FileOutputStream out = null; PrintWriter printer = null; if (!documentTopicsFile.exists()) { out = new FileOutputStream(documentTopicsFile); if (!documentEncoding.equals("default")) { printer = new PrintWriter(new OutputStreamWriter(out, documentEncoding)); } else { printer = new PrintWriter(out); } } double numExtracted = 0, numCorrect = 0; wikipedia = mauiFilter.getWikipedia(); HashMap<Article, Integer> topics = null; if (printGraph) { topics = new HashMap<Article, Integer>(); } int p = 0; String root = ""; for (int i = 0; i < topicsPerDocument; i++) { if (topRankedInstances[i] != null) { if (!topRankedInstances[i].isMissing(topRankedInstances[i].numAttributes() - 1)) { numExtracted += 1.0; } if ((int) topRankedInstances[i].value(topRankedInstances[i].numAttributes() - 1) == 1) { numCorrect += 1.0; } if (printer != null) { String topic = topRankedInstances[i].stringValue(mauiFilter.getOutputFormIndex()); printer.print(topic); if (printGraph) { Article article = wikipedia.getArticleByTitle(topic); if (article == null) { article = wikipedia.getMostLikelyArticle(topic, new CaseFolder()); } if (article != null) { if (root == "") { root = article.getTitle(); } topics.put(article, new Integer(p)); } else { if (debugMode) { System.err.println( "Couldn't find article for " + topic + " in " + documentTopicsFile); } } p++; } if (additionalInfo) { printer.print("\t"); printer.print(topRankedInstances[i].stringValue(mauiFilter.getNormalizedFormIndex())); printer.print("\t"); printer.print(Utils.doubleToString( topRankedInstances[i].value(mauiFilter.getProbabilityIndex()), 4)); } printer.println(); } if (debugMode) { System.err.println(topRankedInstances[i]); } } } if (printGraph) { String graphFile = documentTopicsFile.getAbsolutePath().replace(".key", ".gv"); computeGraph(topics, root, graphFile); } if (numExtracted > 0) { if (debugMode) { System.err.println("-- " + numCorrect + " correct"); } double totalCorrect = mauiFilter.getTotalCorrect(); correctStatistics.addElement(new Double(numCorrect)); precisionStatistics.addElement(new Double(numCorrect / numExtracted)); recallStatistics.addElement(new Double(numCorrect / totalCorrect)); } if (printer != null) { printer.flush(); printer.close(); out.close(); } } if (correctStatistics.size() != 0) { double[] st = new double[correctStatistics.size()]; for (int i = 0; i < correctStatistics.size(); i++) { st[i] = correctStatistics.elementAt(i).doubleValue(); } double avg = Utils.mean(st); double stdDev = Math.sqrt(Utils.variance(st)); if (correctStatistics.size() == 1) { System.err.println("\n-- Evaluation results based on 1 document:"); } else { System.err.println("\n-- Evaluation results based on " + correctStatistics.size() + " documents:"); } System.err.println("Avg. number of correct keyphrases per document: " + Utils.doubleToString(avg, 2) + " +/- " + Utils.doubleToString(stdDev, 2)); st = new double[precisionStatistics.size()]; for (int i = 0; i < precisionStatistics.size(); i++) { st[i] = precisionStatistics.elementAt(i).doubleValue(); } double avgPrecision = Utils.mean(st); double stdDevPrecision = Math.sqrt(Utils.variance(st)); System.err.println("Precision: " + Utils.doubleToString(avgPrecision * 100, 2) + " +/- " + Utils.doubleToString(stdDevPrecision * 100, 2)); st = new double[recallStatistics.size()]; for (int i = 0; i < recallStatistics.size(); i++) { st[i] = recallStatistics.elementAt(i).doubleValue(); } double avgRecall = Utils.mean(st); double stdDevRecall = Math.sqrt(Utils.variance(st)); System.err.println("Recall: " + Utils.doubleToString(avgRecall * 100, 2) + " +/- " + Utils.doubleToString(stdDevRecall * 100, 2)); double fMeasure = 2 * avgRecall * avgPrecision / (avgRecall + avgPrecision); System.err.println("F-Measure: " + Utils.doubleToString(fMeasure * 100, 2)); System.err.println(""); } mauiFilter.batchFinished(); }
From source file:io.pravega.service.server.containers.StreamSegmentMapperTests.java
/** * Tests the ability of the StreamSegmentMapper to generate/return the Id of an existing StreamSegment, as well as * retrieving existing attributes.//w ww . j a v a 2 s. co m */ @Test public void testGetOrAssignStreamSegmentId() { final int segmentCount = 10; final int transactionsPerSegment = 5; @Cleanup TestContext context = new TestContext(); HashSet<String> storageSegments = new HashSet<>(); for (int i = 0; i < segmentCount; i++) { String segmentName = getName(i); storageSegments.add(segmentName); setAttributes(segmentName, storageSegments.size() % ATTRIBUTE_COUNT, context); for (int j = 0; j < transactionsPerSegment; j++) { // There is a small chance of a name conflict here, but we don't care. As long as we get at least one // Transaction per segment, we should be fine. String transactionName = StreamSegmentNameUtils.getTransactionNameFromId(segmentName, UUID.randomUUID()); storageSegments.add(transactionName); setAttributes(transactionName, storageSegments.size() % ATTRIBUTE_COUNT, context); } } // We setup all necessary handlers, except the one for create. We do not need to create new Segments here. setupOperationLog(context); Predicate<String> isSealed = segmentName -> segmentName.hashCode() % 2 == 0; Function<String, Long> getInitialLength = segmentName -> (long) Math.abs(segmentName.hashCode()); setupStorageGetHandler(context, storageSegments, segmentName -> new StreamSegmentInformation(segmentName, getInitialLength.apply(segmentName), isSealed.test(segmentName), false, new ImmutableDate())); // First, map all the parents (stand-alone segments). for (String name : storageSegments) { if (StreamSegmentNameUtils.getParentStreamSegmentName(name) == null) { long id = context.mapper.getOrAssignStreamSegmentId(name, TIMEOUT).join(); Assert.assertNotEquals("No id was assigned for StreamSegment " + name, ContainerMetadata.NO_STREAM_SEGMENT_ID, id); SegmentMetadata sm = context.metadata.getStreamSegmentMetadata(id); Assert.assertNotNull("No metadata was created for StreamSegment " + name, sm); long expectedLength = getInitialLength.apply(name); boolean expectedSeal = isSealed.test(name); Assert.assertEquals("Metadata does not have the expected length for StreamSegment " + name, expectedLength, sm.getDurableLogLength()); Assert.assertEquals( "Metadata does not have the expected value for isSealed for StreamSegment " + name, expectedSeal, sm.isSealed()); val segmentState = context.stateStore.get(name, TIMEOUT).join(); Map<UUID, Long> expectedAttributes = segmentState == null ? null : segmentState.getAttributes(); SegmentMetadataComparer.assertSameAttributes( "Unexpected attributes in metadata for StreamSegment " + name, expectedAttributes, sm); } } // Now, map all the Transactions. for (String name : storageSegments) { String parentName = StreamSegmentNameUtils.getParentStreamSegmentName(name); if (parentName != null) { long id = context.mapper.getOrAssignStreamSegmentId(name, TIMEOUT).join(); Assert.assertNotEquals("No id was assigned for Transaction " + name, ContainerMetadata.NO_STREAM_SEGMENT_ID, id); SegmentMetadata sm = context.metadata.getStreamSegmentMetadata(id); Assert.assertNotNull("No metadata was created for Transaction " + name, sm); long expectedLength = getInitialLength.apply(name); boolean expectedSeal = isSealed.test(name); Assert.assertEquals("Metadata does not have the expected length for Transaction " + name, expectedLength, sm.getDurableLogLength()); Assert.assertEquals( "Metadata does not have the expected value for isSealed for Transaction " + name, expectedSeal, sm.isSealed()); val segmentState = context.stateStore.get(name, TIMEOUT).join(); Map<UUID, Long> expectedAttributes = segmentState == null ? null : segmentState.getAttributes(); SegmentMetadataComparer.assertSameAttributes( "Unexpected attributes in metadata for Transaction " + name, expectedAttributes, sm); // Check parenthood. Assert.assertNotEquals("No parent defined in metadata for Transaction " + name, ContainerMetadata.NO_STREAM_SEGMENT_ID, sm.getParentId()); long parentId = context.metadata.getStreamSegmentId(parentName, false); Assert.assertEquals("Unexpected parent defined in metadata for Transaction " + name, parentId, sm.getParentId()); } } }
From source file:org.hyperic.hq.authz.server.session.ResourceGroupManagerImpl.java
/** * Get the resource groups with the specified ids * @param ids the resource group ids/* ww w . j a v a 2 s.c o m*/ * @param pc Paging information for the request * */ @Transactional(readOnly = true) public PageList<ResourceGroupValue> getResourceGroupsById(AuthzSubject whoami, Integer[] ids, PageControl pc) throws PermissionException { if (ids.length == 0) { return new PageList<ResourceGroupValue>(); } PageControl allPc = new PageControl(); // get all roles, sorted but not paged allPc.setSortattribute(pc.getSortattribute()); allPc.setSortorder(pc.getSortorder()); Collection<ResourceGroup> all = getAllResourceGroups(whoami, false); // build an index of ids HashSet<Integer> index = new HashSet<Integer>(); index.addAll(Arrays.asList(ids)); int numToFind = index.size(); // find the requested roles List<ResourceGroup> groups = new ArrayList<ResourceGroup>(numToFind); Iterator<ResourceGroup> i = all.iterator(); while (i.hasNext() && (groups.size() < numToFind)) { ResourceGroup g = i.next(); if (index.contains(g.getId())) { groups.add(g); } } // TODO: G PageList<ResourceGroupValue> plist = _groupPager.seek(groups, pc.getPagenum(), pc.getPagesize()); plist.setTotalSize(groups.size()); return plist; }
From source file:org.apache.sysml.hops.codegen.opt.ReachabilityGraph.java
private ArrayList<Pair<CutSet, Double>> evaluateCutSets(ArrayList<ArrayList<NodeLink>> candCS, ArrayList<ArrayList<NodeLink>> remain) { ArrayList<Pair<CutSet, Double>> cutSets = new ArrayList<>(); for (ArrayList<NodeLink> cand : candCS) { HashSet<NodeLink> probe = new HashSet<>(cand); //determine subproblems for cutset candidates HashSet<NodeLink> part1 = new HashSet<>(); rCollectInputs(_root, probe, part1); HashSet<NodeLink> part2 = new HashSet<>(); for (NodeLink rNode : cand) rCollectInputs(rNode, probe, part2); //select, score and create cutsets if (!CollectionUtils.containsAny(part1, part2) && !part1.isEmpty() && !part2.isEmpty()) { //score cutsets (smaller is better) double base = UtilFunctions.pow(2, _matPoints.size()); double numComb = UtilFunctions.pow(2, cand.size()); double score = (numComb - 1) / numComb * base + 1 / numComb * UtilFunctions.pow(2, part1.size()) + 1 / numComb * UtilFunctions.pow(2, part2.size()); //construct cutset cutSets.add(Pair.of(new CutSet(cand.stream().map(p -> p._p).toArray(InterestingPoint[]::new), part1.stream().map(p -> p._p).toArray(InterestingPoint[]::new), part2.stream().map(p -> p._p).toArray(InterestingPoint[]::new)), score)); } else {//from w ww.j a va2s. c om remain.add(cand); } } return cutSets; }