Java Code Examples for gnu.trove.list.TIntList#toArray()

The following examples show how to use gnu.trove.list.TIntList#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: SortedNeighborhoodBlocking.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected int[] getMixedSortedEntities(String[] sortedTerms) {
    int datasetLimit = entityProfilesD1.size();
    final TIntList sortedEntityIds = new TIntArrayList();

    for (String blockingKey : sortedTerms) {
        final TIntList sortedIds = new TIntArrayList();
        final TIntList d1EntityIds = invertedIndexD1.get(blockingKey);
        if (d1EntityIds != null) {
            sortedIds.addAll(d1EntityIds);
        }

        final TIntList d2EntityIds = invertedIndexD2.get(blockingKey);
        if (d2EntityIds != null) {
            for (TIntIterator iterator = d2EntityIds.iterator(); iterator.hasNext();) {
                sortedIds.add(datasetLimit + iterator.next());
            }
        }

        sortedIds.shuffle(random);
        sortedEntityIds.addAll(sortedIds);
    }

    return sortedEntityIds.toArray();
}
 
Example 2
Source File: DateEncoder.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Returns an array containing the sub-field bucket indices for
 * each sub-field of the inputData. To get the associated field names for each of
 * the buckets, call getScalarNames().
 * @param  	input 	The data from the source. This is typically a object with members.
 *
 * @return 	array of bucket indices
 */
public int[] getBucketIndices(DateTime input) {

    TDoubleList scalars = getScalars(input);

    TIntList l = new TIntArrayList();
    List<EncoderTuple> encoders = getEncoders(this);
    if(encoders != null && encoders.size() > 0) {
        int i = 0;
        for(EncoderTuple t : encoders) {
            l.addAll(t.getEncoder().getBucketIndices(scalars.get(i)));
            ++i;
        }
    }else{
        throw new IllegalStateException("Should be implemented in base classes that are not " +
                "containers for other encoders");
    }
    return l.toArray();
}
 
Example 3
Source File: SortedNeighborhoodBlocking.java    From JedAIToolkit with Apache License 2.0 5 votes vote down vote up
protected int[] getSortedEntities(String[] sortedTerms) {
    final TIntList sortedEntityIds = new TIntArrayList();

    for (String blockingKey : sortedTerms) {
        final TIntList sortedIds = invertedIndexD1.get(blockingKey);
        sortedIds.shuffle(random);
        sortedEntityIds.addAll(sortedIds);
    }

    return sortedEntityIds.toArray();
}
 
Example 4
Source File: Encoder.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns an array containing the sub-field bucket indices for
    * each sub-field of the inputData. To get the associated field names for each of
    * the buckets, call getScalarNames().
 * @param  	input 	The data from the source. This is typically a object with members.
 *
 * @return 	array of bucket indices
 */
public int[] getBucketIndices(String input) {
	TIntList l = new TIntArrayList();
	Map<EncoderTuple, List<EncoderTuple>> encoders = getEncoders();
	if(encoders != null && encoders.size() > 0) {
		for(EncoderTuple t : encoders.keySet()) {
			l.addAll(t.getEncoder().getBucketIndices(input));
		}
	}else{
		throw new IllegalStateException("Should be implemented in base classes that are not " +
			"containers for other encoders");
	}
	return l.toArray();
}
 
Example 5
Source File: Encoder.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns an array containing the sub-field bucket indices for
    * each sub-field of the inputData. To get the associated field names for each of
    * the buckets, call getScalarNames().
 * @param  	input 	The data from the source. This is typically a object with members.
 *
 * @return 	array of bucket indices
 */
public int[] getBucketIndices(double input) {
	TIntList l = new TIntArrayList();
	Map<EncoderTuple, List<EncoderTuple>> encoders = getEncoders();
	if(encoders != null && encoders.size() > 0) {
		for(EncoderTuple t : encoders.keySet()) {
			l.addAll(t.getEncoder().getBucketIndices(input));
		}
	}else{
		throw new IllegalStateException("Should be implemented in base classes that are not " +
			"containers for other encoders");
	}
	return l.toArray();
}
 
Example 6
Source File: AbstractSparseBinaryMatrix.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a sorted array of occupied indexes.
 * @return  a sorted array of occupied indexes.
 */
@Override
public int[] getSparseIndices() {
    TIntList indexes = new TIntArrayList();
    for (int i = 0; i <= getMaxIndex(); i ++) {
        if (get(i) > 0) {
            indexes.add(i);
        }
    }
    
    return indexes.toArray();
}
 
Example 7
Source File: SDRClassifier.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
    * Constructor for the SDRClassifier
    * 
    * @param steps Sequence of the different steps of multi-step predictions to learn.
    * @param alpha The alpha used to adapt the weight matrix during learning. A larger alpha
    * 		  results in faster adaptation to the data.
    * @param actValueAlpha Used to track the actual value withing each bucket. A lower 
    * 		  actValueAlpha results in longer term memory.
    * @param verbosity Verbosity level, can be 0, 1, or 2.
    */
public SDRClassifier(TIntList steps, double alpha, double actValueAlpha, int verbosity) {
       this.steps = steps;
       this.alpha = alpha;
       this.actValueAlpha = actValueAlpha;
       this.verbosity = verbosity;
       actualValues.add(null);
       patternNZHistory = new Deque<Tuple>(ArrayUtils.max(steps.toArray()) + 1);
	for(int step : steps.toArray())
		weightMatrix.put(step, new FlexCompRowMatrix(maxBucketIdx + 1, maxInputIdx + 1));
}
 
Example 8
Source File: SpatialPooler.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Performs inhibition. This method calculates the necessary values needed to
 * actually perform inhibition and then delegates the task of picking the
 * active columns to helper functions.
 * 
 * @param c         the {@link Connections} matrix
 * @param overlaps  an array containing the overlap score for each  column.
 *                  The overlap score for a column is defined as the number
 *                  of synapses in a "connected state" (connected synapses)
 *                  that are connected to input bits which are turned on.
 * @param density   The fraction of columns to survive inhibition. This
 *                  value is only an intended target. Since the surviving
 *                  columns are picked in a local fashion, the exact fraction
 *                  of surviving columns is likely to vary.
 * @return  indices of the winning columns
 */
public int[] inhibitColumnsLocal(Connections c, double[] overlaps, double density) {
    double addToWinners = ArrayUtils.max(overlaps) / 1000.0d;
    if(addToWinners == 0) {
        addToWinners = 0.001;
    }
    double[] tieBrokenOverlaps = Arrays.copyOf(overlaps, overlaps.length);
    
    TIntList winners = new TIntArrayList();
    double stimulusThreshold = c.getStimulusThreshold();
    int inhibitionRadius = c.getInhibitionRadius();
    for(int i = 0;i < overlaps.length;i++) {
        int column = i;
        if(overlaps[column] >= stimulusThreshold) {
           int[] neighborhood = getColumnNeighborhood(c, column, inhibitionRadius);
           double[] neighborhoodOverlaps = ArrayUtils.sub(tieBrokenOverlaps, neighborhood);
           
           long numBigger = Arrays.stream(neighborhoodOverlaps)
               .parallel()
               .filter(d -> d > overlaps[column])
               .count();
           
           int numActive = (int)(0.5 + density * neighborhood.length);
           if(numBigger < numActive) {
               winners.add(column);
               tieBrokenOverlaps[column] += addToWinners;
           }
        }
    }

    return winners.toArray();
}
 
Example 9
Source File: AbstractSparseMatrix.java    From htm.java with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public int[] get1DIndexes() {
    TIntList results = new TIntArrayList(getMaxIndex() + 1);
    visit(getDimensions(), 0, new int[getNumDimensions()], results);
    return results.toArray();
}
 
Example 10
Source File: ArrayUtils.java    From htm.java with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * Returns an array which starts from lowerBounds (inclusive) and
 * ends at the upperBounds (exclusive).
 *
 * @param lowerBounds
 * @param upperBounds
 * @return
 */
public static int[] range(int lowerBounds, int upperBounds) {
    TIntList ints = new TIntArrayList();
    for (int i = lowerBounds; i < upperBounds; i++) {
        ints.add(i);
    }
    return ints.toArray();
}
 
Example 11
Source File: ArrayUtils.java    From htm.java with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * Returns an array which starts from lowerBounds (inclusive) and
 * ends at the upperBounds (exclusive).
 *
 * @param lowerBounds the starting value
 * @param upperBounds the maximum value (exclusive)
 * @param interval    the amount by which to increment the values
 * @return
 */
public static int[] xrange(int lowerBounds, int upperBounds, int interval) {
    TIntList ints = new TIntArrayList();
    for (int i = lowerBounds; i < upperBounds; i += interval) {
        ints.add(i);
    }
    return ints.toArray();
}