Java Code Examples for it.unimi.dsi.fastutil.longs.LongOpenHashSet#size()
The following examples show how to use
it.unimi.dsi.fastutil.longs.LongOpenHashSet#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PageRank.java From GraphJet with Apache License 2.0 | 5 votes |
/** * Constructs this object for running PageRank over a directed graph. * * @param graph the directed graph * @param nodes nodes in the graph * @param maxNodeId maximum node id * @param dampingFactor damping factor * @param maxIterations maximum number of iterations to run * @param tolerance L1 norm threshold for convergence */ public PageRank(OutIndexedDirectedGraph graph, LongOpenHashSet nodes, long maxNodeId, double dampingFactor, int maxIterations, double tolerance) { if (maxNodeId > Integer.MAX_VALUE) { throw new UnsupportedOperationException("maxNodeId exceeds Integer.MAX_VALUE!"); } this.graph = graph; this.nodes = nodes; this.maxNodeId = maxNodeId; this.dampingFactor = dampingFactor; this.nodeCount = nodes.size(); this.maxIterations = maxIterations; this.tolerance = tolerance; }
Example 2
Source File: GlobalVisitStats.java From fasten with Apache License 2.0 | 4 votes |
public static Result reaches(final KnowledgeBase kb, final long startSig, final int maxRevs, final ProgressLogger pl) { final LongOpenHashSet result = new LongOpenHashSet(); final Object2ObjectOpenHashMap<String, IntOpenHashSet> product2Revs = new Object2ObjectOpenHashMap<>(); final MutableLong totRevs = new MutableLong(); // Visit queue final LongArrayFIFOQueue queue = new LongArrayFIFOQueue(); queue.enqueue(startSig); result.add(startSig); String p = kb.callGraphs.get(index(startSig)).product; IntOpenHashSet revs = new IntOpenHashSet(); revs.add(index(startSig)); product2Revs.put(p, revs); totRevs.increment(); pl.itemsName = "nodes"; pl.info = new Object() { @Override public String toString() { return "[nodes: " + result.size() + " products: " + product2Revs.size() + " revisions: " + totRevs.getValue() + "]"; } }; pl.start("Visiting reachable nodes..."); while (!queue.isEmpty()) { final long node = queue.dequeueLong(); for (final long s : kb.successors(node)) if (!result.contains(s)) { p = kb.callGraphs.get(index(s)).product; final long gid = gid(s); if (badGIDs.contains(gid)) continue; final String targetNameSpace = kb.new Node(gid, index(s)).toFastenURI().getRawNamespace(); if (targetNameSpace.startsWith("java.") || targetNameSpace.startsWith("javax.") || targetNameSpace.startsWith("jdk.")) { badGIDs.add(gid); continue; } revs = product2Revs.get(p); if (revs == null) product2Revs.put(p, revs = new IntOpenHashSet()); if (revs.contains(index(s)) || revs.size() < maxRevs) { queue.enqueue(s); result.add(s); //System.out.println(kb.new Node(gid(node), index(node)).toFastenURI() + " -> " + kb.new Node(gid(s), index(s)).toFastenURI()); if (revs.add(index(s))) totRevs.increment(); } } pl.lightUpdate(); } pl.done(); return new Result(result, product2Revs.size(), totRevs.getValue().longValue()); }
Example 3
Source File: GlobalVisitStats.java From fasten with Apache License 2.0 | 4 votes |
public static Result coreaches(final KnowledgeBase kb, final long startSig, final int maxRevs, final ProgressLogger pl) { final LongOpenHashSet result = new LongOpenHashSet(); final Object2ObjectOpenHashMap<String, IntOpenHashSet> product2Revs = new Object2ObjectOpenHashMap<>(); final MutableLong totRevs = new MutableLong(); // Visit queue final LongArrayFIFOQueue queue = new LongArrayFIFOQueue(); queue.enqueue(startSig); result.add(startSig); String p = kb.callGraphs.get(index(startSig)).product; IntOpenHashSet revs = new IntOpenHashSet(); revs.add(index(startSig)); product2Revs.put(p, revs); totRevs.increment(); pl.itemsName = "nodes"; pl.info = new Object() { @Override public String toString() { return "[nodes: " + result.size() + " products: " + product2Revs.size() + " revisions: " + totRevs.getValue() + "]"; } }; pl.start("Visiting coreachable nodes..."); while (!queue.isEmpty()) { final long node = queue.dequeueLong(); for (final long s : kb.predecessors(node)) if (!result.contains(s)) { p = kb.callGraphs.get(index(s)).product; final String targetNameSpace = kb.new Node(gid(s), index(s)).toFastenURI().getRawNamespace(); if (targetNameSpace.startsWith("java.") || targetNameSpace.startsWith("javax.") || targetNameSpace.startsWith("jdk.")) continue; revs = product2Revs.get(p); if (revs == null) product2Revs.put(p, revs = new IntOpenHashSet()); if (revs.contains(index(s)) || revs.size() < maxRevs) { queue.enqueue(s); result.add(s); //System.out.println(kb.new Node(gid(node), index(node)).toFastenURI() + " -> " + kb.new Node(gid(s), index(s)).toFastenURI()); if (revs.add(index(s))) totRevs.increment(); } } pl.lightUpdate(); } pl.done(); return new Result(result, product2Revs.size(), totRevs.getValue().longValue()); }
Example 4
Source File: PrecisionOrRecall.java From StreamingRec with Apache License 2.0 | 4 votes |
public void evaluate(Transaction transaction, LongArrayList recommendations, LongOpenHashSet userTransactions) { //if there is no ground truth, there is nothing to evaluate if (userTransactions == null || userTransactions.isEmpty()) { return; } // if the algorithm does not return any recommendations, count it as 0 if (recommendations.isEmpty()) { results.add(0); return; } // if the algorithm retrieves less than k recommendations, we calculate // the real k value for this case int realK = Math.min(k, recommendations.size()); // check duplicates LongOpenHashSet uniqueRecs = new LongOpenHashSet(); for (int i = 0; i < realK; i++) { if (!uniqueRecs.add(recommendations.getLong(i))) { throw new RuntimeException("Duplicate recommendation."); } } // calculate the precision double result = 0; // iterate over relevant items and recommendations to calculate the // intersection for (LongIterator iterator = userTransactions.iterator(); iterator.hasNext();) { long itemID = iterator.nextLong(); for (int i = 0; i < realK; i++) { if (itemID == recommendations.getLong(i)) { result++; } } } //determine the divider of the fraction (different for precision and recall) double divider; if(type == Type.Precision){ divider = realK; }else if(type == Type.Recall){ divider = userTransactions.size(); }else{ throw new RuntimeException("Neither precision nor recall defined."); } // store the precision/Recall results.add(result / divider); }
Example 5
Source File: ImmutableDictionaryTest.java From incubator-pinot with Apache License 2.0 | 4 votes |
@BeforeClass public void setUp() throws Exception { FileUtils.deleteQuietly(TEMP_DIR); IntOpenHashSet intSet = new IntOpenHashSet(); while (intSet.size() < NUM_VALUES) { intSet.add(RANDOM.nextInt()); } _intValues = intSet.toIntArray(); Arrays.sort(_intValues); LongOpenHashSet longSet = new LongOpenHashSet(); while (longSet.size() < NUM_VALUES) { longSet.add(RANDOM.nextLong()); } _longValues = longSet.toLongArray(); Arrays.sort(_longValues); FloatOpenHashSet floatSet = new FloatOpenHashSet(); while (floatSet.size() < NUM_VALUES) { floatSet.add(RANDOM.nextFloat()); } _floatValues = floatSet.toFloatArray(); Arrays.sort(_floatValues); DoubleOpenHashSet doubleSet = new DoubleOpenHashSet(); while (doubleSet.size() < NUM_VALUES) { doubleSet.add(RANDOM.nextDouble()); } _doubleValues = doubleSet.toDoubleArray(); Arrays.sort(_doubleValues); Set<String> stringSet = new HashSet<>(); while (stringSet.size() < NUM_VALUES) { stringSet.add(RandomStringUtils.random(RANDOM.nextInt(MAX_STRING_LENGTH)).replace('\0', ' ')); } _stringValues = stringSet.toArray(new String[NUM_VALUES]); Arrays.sort(_stringValues); Set<ByteArray> bytesSet = new HashSet<>(); while (bytesSet.size() < NUM_VALUES) { byte[] bytes = new byte[BYTES_LENGTH]; RANDOM.nextBytes(bytes); bytesSet.add(new ByteArray(bytes)); } _bytesValues = bytesSet.toArray(new ByteArray[NUM_VALUES]); Arrays.sort(_bytesValues); try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_intValues, new DimensionFieldSpec(INT_COLUMN_NAME, FieldSpec.DataType.INT, true), TEMP_DIR)) { dictionaryCreator.build(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_longValues, new DimensionFieldSpec(LONG_COLUMN_NAME, FieldSpec.DataType.LONG, true), TEMP_DIR)) { dictionaryCreator.build(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_floatValues, new DimensionFieldSpec(FLOAT_COLUMN_NAME, FieldSpec.DataType.FLOAT, true), TEMP_DIR)) { dictionaryCreator.build(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_doubleValues, new DimensionFieldSpec(DOUBLE_COLUMN_NAME, FieldSpec.DataType.DOUBLE, true), TEMP_DIR)) { dictionaryCreator.build(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_stringValues, new DimensionFieldSpec(STRING_COLUMN_NAME, FieldSpec.DataType.STRING, true), TEMP_DIR)) { dictionaryCreator.build(); _numBytesPerStringValue = dictionaryCreator.getNumBytesPerEntry(); } try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_bytesValues, new DimensionFieldSpec(BYTES_COLUMN_NAME, FieldSpec.DataType.BYTES, true), TEMP_DIR)) { dictionaryCreator.build(); assertEquals(dictionaryCreator.getNumBytesPerEntry(), BYTES_LENGTH); } }