Tabnine Logo
HeapSelect
Code IndexAdd Tabnine to your IDE (free)

How to use
HeapSelect
in
smile.sort

Best Java code snippets using smile.sort.HeapSelect (Showing top 11 results out of 315)

origin: com.github.haifengl/smile-core

@SuppressWarnings("unchecked")
SimpleNeighbor<T>[] neighbors = (SimpleNeighbor<T>[]) java.lang.reflect.Array.newInstance(neighbor.getClass(), k);
HeapSelect<Neighbor<T,T>> heap = new HeapSelect<>(neighbors);
for (int i = 0; i < k; i++) {
  heap.add(neighbor);
  neighbor = new SimpleNeighbor<>(null, 0, Double.MAX_VALUE);
  Neighbor<T,T> datum = heap.peek();
  if (dist < datum.distance) {
    datum.distance = dist;
    datum.key = data[i];
    datum.value = data[i];
    heap.heapify();
heap.sort();
return neighbors;
origin: com.github.haifengl/smile-core

HeapSelect<Neighbor> heap = new HeapSelect<>(neighbors);
          if (heap.peek() == null || distance < heap.peek().distance) {
            heap.add(new Neighbor(e.neuron, distance));
            hit++;
origin: com.github.haifengl/smile-core

@Override
public Neighbor<double[], E>[] knn(double[] q, int k) {
  if (k <= 0) {
    throw new IllegalArgumentException("Invalid k: " + k);
  }
  if (k > keys.length) {
    throw new IllegalArgumentException("Neighbor array length is larger than the dataset size");
  }
  Neighbor<double[], E> neighbor = new Neighbor<>(null, null, 0, Double.MAX_VALUE);
  @SuppressWarnings("unchecked")
  Neighbor<double[], E>[] neighbors = (Neighbor<double[], E>[]) java.lang.reflect.Array.newInstance(neighbor.getClass(), k);
  HeapSelect<Neighbor<double[], E>> heap = new HeapSelect<>(neighbors);
  for (int i = 0; i < k; i++) {
    heap.add(neighbor);
    neighbor = new Neighbor<>(null, null, 0, Double.MAX_VALUE);
  }
  search(q, root, heap);
  heap.sort();
  for (int i = 0; i < neighbors.length; i++) {
    neighbors[i].distance = Math.sqrt(neighbors[i].distance);
  }
  return neighbors;
}
origin: com.github.haifengl/smile-core

  Neighbor<double[], E> datum = heap.peek();
  if (distance < datum.distance) {
    datum.distance = distance;
    datum.key = keys[index[idx]];
    datum.value = data[index[idx]];
    heap.heapify();
if (heap.peek().distance >= diff * diff) {
  search(q, further, heap);
origin: com.github.haifengl/smile-math

/**
 * Sort the smallest values.
 */
public void sort() {
  if (!sorted) {
    sort(heap, Math.min(k,n));
    sorted = true;
  }
}
origin: com.github.haifengl/smile-math

/**
 * Assimilate a new value from the stream.
 */
public void add(T datum) {
  sorted = false;
  if (n < k) {
    heap[n++] = datum;
    if (n == k) {
      heapify(heap);
    }
  } else {
    n++;
    if (datum.compareTo(heap[0]) < 0) {
      heap[0] = datum;
      SortUtils.siftDown(heap, 0, k-1);
    }
  }
}
origin: com.github.haifengl/smile-core

HeapSelect<Node> heap = new HeapSelect<>(top2);
for (Node neuron : nodes) {
  neuron.dist = Math.squaredDistance(neuron.w, x);
  heap.add(neuron);
origin: com.github.haifengl/smile-math

/**
 * Returns the i-<i>th</i> smallest value seen so far. i = 0 returns the smallest
 * value seen, i = 1 the second largest, ..., i = k-1 the last position
 * tracked. Also, i must be less than the number of previous assimilated.
 */
public T get(int i) {
  if (i > Math.min(k, n) - 1) {
    throw new IllegalArgumentException("HeapSelect i is greater than the number of data received so far.");
  }
  if (i == k-1) {
    return heap[0];
  }
  
  if (!sorted) {
    sort(heap, Math.min(k,n));
    sorted = true;
  }
  return heap[k-1-i];
}
origin: com.github.haifengl/smile-core

@SuppressWarnings("unchecked")
Neighbor<double[], E>[] neighbors = (Neighbor<double[], E>[]) java.lang.reflect.Array.newInstance(neighbor.getClass(), k);
HeapSelect<Neighbor<double[], E>> heap = new HeapSelect<>(neighbors);
for (int i = 0; i < k; i++) {
  heap.add(neighbor);
  if (distance < heap.peek().distance) {
    heap.add(new Neighbor<>(key, data.get(index), index, distance));
    hit++;
heap.sort();
origin: com.github.haifengl/smile-core

HeapSelect<Neighbor<AbstractSentence, E>> heap = new HeapSelect<>(neighbors);
Neighbor<AbstractSentence, E> neighbor = new Neighbor<>(null, null, 0, Double.MAX_VALUE);
for (int i = 0; i < k; i++) {
  heap.add(neighbor);
  if (distance < heap.peek().distance) {
    heap.add(new Neighbor<>(keys.get(index), data.get(index), index, distance));
    hit++;
heap.sort();
if (hit < k) {
  Neighbor<AbstractSentence, E>[] n2 = (Neighbor<AbstractSentence, E>[])Array.newInstance(Neighbor.class, hit);
origin: com.github.haifengl/smile-core

@SuppressWarnings("unchecked")
Neighbor<double[], E>[] neighbors = (Neighbor<double[], E>[]) java.lang.reflect.Array.newInstance(neighbor.getClass(), k);
HeapSelect<Neighbor<double[], E>> heap = new HeapSelect<>(neighbors);
for (int i = 0; i < k; i++) {
  heap.add(neighbor);
  if (dist < heap.peek().distance) {
    heap.add(new Neighbor<>(key, data.get(index), index, dist));
    hit++;
heap.sort();
smile.sortHeapSelect

Javadoc

This class tracks the smallest values seen thus far in a stream of values. This implements a single-pass selection for large data sets. That is, we have a stream of input values, each of which we get to see only once. We want to be able to report at any time, say after n values, the i-th smallest value see so far.

Most used methods

  • heapify
    Place the array in max-heap order. Note that the array is not fully sorted.
  • sort
    Sorts the specified array into descending order. It is based on Shell sort, which is very efficient
  • <init>
    Constructor.
  • add
    Assimilate a new value from the stream.
  • peek
    Returns the k-th smallest value seen so far.

Popular in Java

  • Running tasks concurrently on multiple threads
  • requestLocationUpdates (LocationManager)
  • notifyDataSetChanged (ArrayAdapter)
  • getExternalFilesDir (Context)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • ImageIO (javax.imageio)
  • Notification (javax.management)
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now