Java Code Examples for gnu.trove.set.TIntSet#toArray()
The following examples show how to use
gnu.trove.set.TIntSet#toArray() .
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: GraphConfidenceEstimator.java From ambiverse-nlu with Apache License 2.0 | 6 votes |
/** * Will return numElements integers from the input elements. If numElements * is larger than elements.size(), everything will be returned. * * @param elements Elements to choose from. * @param numElements Number of elements to choose. * @return numElement random integers from elements. */ private TIntSet getRandomElements(TIntSet elements, int numElements) { TIntList source = new TIntArrayList(elements.toArray()); TIntSet randomElements = new TIntHashSet(); for (int i = 0; i < numElements; ++i) { if (source.size() == 0) { break; } // TODO: this is not efficient, as deleting from the ArrayList // will copy ... make this more efficient when necessary. int elementPosition = random_.nextInt(source.size()); int element = source.get(elementPosition); source.remove(element); randomElements.add(element); } return randomElements; }
Example 2
Source File: SDRCategoryEncoder.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
private int[] getSortedSample(final int populationSize, final int sampleLength) { TIntSet resultSet = new TIntHashSet(); while (resultSet.size() < sampleLength) { resultSet.add(random.nextInt(populationSize)); } int[] result = resultSet.toArray(); Arrays.sort(result); return result; }
Example 3
Source File: Input.java From metanome-algorithms with Apache License 2.0 | 4 votes |
public void buildPLIs() { long time = System.currentTimeMillis(); final int COLUMN_COUNT = parsedColumns.size(); final int ROW_COUNT = getLineCount(); List<Integer> tIDs = new TupleIDProvider(ROW_COUNT).gettIDs(); // to save integers storage int[][] inputs = getInts(); for (int col = 0; col < COLUMN_COUNT; ++col) { TIntSet distincts = new TIntHashSet(); for (int line = 0; line < ROW_COUNT; ++line) { distincts.add(inputs[line][col]); } int[] distinctsArray = distincts.toArray(); // need to sort for doubles and integers if (!(parsedColumns.get(col).getType() == String.class)) { Arrays.sort(distinctsArray);// ascending is the default } TIntIntMap translator = new TIntIntHashMap(); for (int position = 0; position < distinctsArray.length; position++) { translator.put(distinctsArray[position], position); } List<Set<Integer>> setPlis = new ArrayList<>(); for (int i = 0; i < distinctsArray.length; i++) { setPlis.add(new TreeSet<Integer>()); } for (int line = 0; line < ROW_COUNT; ++line) { Integer tid = tIDs.get(line); setPlis.get(translator.get(inputs[line][col])).add(tid); } int values[] = new int[ROW_COUNT]; for (int line = 0; line < ROW_COUNT; ++line) { values[line] = inputs[line][col]; } PLI pli; if (!(parsedColumns.get(col).getType() == String.class)) { pli = new PLI(setPlis, ROW_COUNT, true, values); } else { pli = new PLI(setPlis, ROW_COUNT, false, values); } parsedColumns.get(col).setPLI(pli); } log.info("Time to build plis: " + (System.currentTimeMillis() - time)); }
Example 4
Source File: ArrayUtils.java From htm.java with GNU Affero General Public License v3.0 | 3 votes |
/** * Test whether each element of a 1-D array is also present in a second * array. * * Returns a int array whose length is the number of intersections. * * @param ar1 the array of values to find in the second array * @param ar2 the array to test for the presence of elements in the first array. * @return an array containing the intersections or an empty array if none are found. */ public static int[] in1d(int[] ar1, int[] ar2) { if(ar1 == null || ar2 == null) { return EMPTY_ARRAY; } TIntSet retVal = new TIntHashSet(ar2); retVal.retainAll(ar1); return retVal.toArray(); }