congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
SortedKeyIndex.tryGetIndex
Code IndexAdd Tabnine to your IDE (free)

How to use
tryGetIndex
method
in
org.lenskit.util.keys.SortedKeyIndex

Best Java code snippets using org.lenskit.util.keys.SortedKeyIndex.tryGetIndex (Showing top 20 results out of 315)

origin: lenskit/lenskit

/**
 * Get the mean rating for an item.
 * @param item The item.
 * @return The item's mean rating, or {@link Double#NaN} if the item is absent.
 */
public double getItemMean(long item) {
  int idx = itemIndex.tryGetIndex(item);
  return idx >= 0 ? itemOffsets[idx] + globalMean : Double.NaN;
}
origin: lenskit/lenskit

/**
 * Get the item's average offset from global mean.
 * @param item The item.
 * @return The item's average offset from the global mean rating, or 0 if the item is missing
 */
public double getItemOffset(long item) {
  int idx = itemIndex.tryGetIndex(item);
  return idx >= 0 ? itemOffsets[idx] : 0;
}
origin: lenskit/lenskit

double getDeviation(long item) {
  int idx = items.tryGetIndex(item);
  if (idx >= 0) {
    return deviations[idx];
  } else {
    return Double.NaN;
  }
}
origin: lenskit/lenskit

  int getCoratings(long item) {
    int idx = items.tryGetIndex(item);
    if (idx >= 0) {
      return coratings[idx];
    } else {
      return 0;
    }
  }
}
origin: lenskit/lenskit

/**
 * Query whether this set contains the specified key in its domain.
 * @param key The key.
 * @return {@code true} if the key is in the domain.
 */
@Override
public boolean containsKey(long key) {
  int idx = tryGetIndex(key);
  return idx >= lowerBound && idx < upperBound;
}
origin: lenskit/lenskit

/**
 * Get the number of ratings for the item.
 */
public int getItemRatingCount(long item) {
  int idx = itemIndex.tryGetIndex(item);
  return idx >= 0 ? itemCounts[idx] : 0;
}
origin: lenskit/lenskit

/**
 * Get the number of interactions for an item.
 * @param item The item.
 * @return The number of interactions for `item`.
 */
public int getInteractionCount(long item) {
  int idx = items.tryGetIndex(item);
  if (idx >= 0) {
    return interactionCounts[idx];
  } else {
    return 0;
  }
}
origin: lenskit/lenskit

/**
 * Get the upper bound, the first index whose key is greater than the specified key.
 *
 * @param key The key to search for.
 * @return The index of the first key greater than the specified key, or {@link #getUpperBound()} if the key
 * is the last key in the domain.
 */
public int findUpperBound(long key) {
  int index = tryGetIndex(key);
  if (index >= 0) {
    // the key is there, advance by 1
    return index + 1;
  } else {
    // the key is not there, the insertion point is > key
    return -index - 1;
  }
}
origin: lenskit/lenskit

/**
 * Get the lower bound, the first index whose key is greater than or equal to the specified key.
 * This method is paired with {@link #findUpperBound(long)}; the interval
 * {@code [findLowerBound(k),findUpperBound(k))} contains the index of {@code k}, if the key is in the
 * domain, and is empty if the key is not in the domain.
 *
 * @param key The key to search for.
 * @return The index of the first key greater than or equal to {@code key}; will be {@link #getLowerBound()} if
 * {@code key} is less than or equal to the lowest key.
 */
public int findLowerBound(long key) {
  int index = tryGetIndex(key);
  if (index >= 0) {
    // the key is there, first index is >=
    return index;
  } else {
    // the key is not there, the insertion point is > key
    return -index - 1;
  }
}
origin: lenskit/lenskit

@Override
public int getIndex(long key) {
  int idx = tryGetIndex(key);
  if (idx < 0) {
    throw new IllegalArgumentException("key " + key + " is not in the key index");
  }
  return idx;
}
origin: lenskit/lenskit

@Override
@Nonnull
public Long2DoubleMap getNeighbors(long item) {
  int idx = itemDomain.tryGetIndex(item);
  if (idx < 0) {
    return Long2DoubleMaps.EMPTY_MAP;
  } else {
    return neighborhoods.get(idx);
  }
}
origin: lenskit/lenskit

/**
 * Get a user vector normalized for score computations.
 * @param user The user ID.
 * @return The normalized user rating vector (with {@link ScoreNormalizer}).
 */
public Long2DoubleMap getUserVector(long user) {
  int idx = users.tryGetIndex(user);
  Preconditions.checkArgument(idx >= 0, "invalid user " + user);
  return vectors.get(idx);
}
origin: lenskit/lenskit

/**
 * Get a user vector normalized for similarity computations.
 *
 * @return The normalized user rating vector (with {@link SimilarityNormalizer}).
 */
public Long2DoubleMap getNormalizedUserVector(long user) {
  int idx = users.tryGetIndex(user);
  Preconditions.checkArgument(idx >= 0, "invalid user " + user);
  return normedVectors.get(idx);
}
origin: lenskit/lenskit

/**
 * Get the rating vector for an item. Rating vectors contain normalized ratings,
 * using the applicable user-vector normalizer on the user rating vectors.
 *
 * @param item The item to query.
 * @return The rating vector for {@code item}.
 * @throws IllegalArgumentException if {@code item} is not a valid item.
 */
@Nonnull
public Long2DoubleSortedMap itemVector(long item) {
  int idx = items.tryGetIndex(item);
  Preconditions.checkArgument(idx >= 0, "unknown item");
  return itemVectors[idx];
}
origin: lenskit/lenskit

@Override
public double get(long l) {
  int idx = keys.tryGetIndex(l);
  if (idx >= 0) {
    return values[idx];
  } else {
    return defaultReturnValue();
  }
}
origin: lenskit/lenskit

@Override
public boolean contains(Object o) {
  if (o instanceof Map.Entry) {
    Map.Entry<?,?> e = (Map.Entry) o;
    long key = e instanceof Entry ? ((Entry) e).getLongKey() : (Long) e.getKey();
    int idx = keys.tryGetIndex(key);
    if (idx >= 0) {
      return e.getValue().equals(values[idx]);
    }
  }
  return false;
}
origin: lenskit/lenskit

  @SuppressWarnings("deprecation")
  private void testRatingIntegrity(SortedKeyIndex items, Long2DoubleMap[] trueRatings, ItemItemBuildContext context) {
    for (long itemId : context.getItems()) {
      assertEquals(trueRatings[items.tryGetIndex(itemId)], context.itemVector(itemId));
    }

  }
}
origin: lenskit/lenskit

  @Theory
  public void testABunch(KeyData data) {
    long[] rawKeys = data.getKeys(10);
    List<Long> keyList = new LongArrayList(rawKeys);
    SortedKeyIndex keys = SortedKeyIndex.wrap(rawKeys, rawKeys.length);
    assertThat(keys.size(), equalTo(10));
    assertThat(keys.size(), equalTo(10));

    assertThat(keys.getKeyList(), contains(keyList.toArray()));
    assertThat(keys.keySet(), contains(keyList.toArray()));

    assertThat(keys.tryGetIndex(data.getLow()), lessThan(0));
    for (int i = 0; i < 10; i++) {
      assumeThat(keys.tryGetIndex(rawKeys[i]), equalTo(i));
      assertThat(keys.tryGetIndex(data.getAfter(i)), lessThan(0));
    }
  }
}
origin: lenskit/lenskit

@Theory
public void testSingleton(KeyData data) {
  assumeThat(data, notNullValue());
  long key = data.getKey();       // key to use
  long low = data.getLow();       // unused low key
  long high = data.getAfter(1);   // unused high key
  long[] rawKeys = {key};
  SortedKeyIndex keys = SortedKeyIndex.wrap(rawKeys, 1);
  assertThat(keys.size(), equalTo(1));
  assertThat(keys.size(), equalTo(1));
  assertThat(keys.keySet(), hasSize(1));
  assertThat(keys.tryGetIndex(key), equalTo(0));
  assertThat(keys.tryGetIndex(low), lessThan(0));
  assertThat(keys.tryGetIndex(high), lessThan(0));
  assertThat(keys.getKeyList(), contains(key));
}
origin: lenskit/lenskit

@Test
public void testEmptyArray() {
  long[] rawKeys = {};
  SortedKeyIndex keys = SortedKeyIndex.wrap(rawKeys, 0);
  assertThat(keys.size(), equalTo(0));
  assertThat(keys.size(), equalTo(0));
  assertThat(keys.keySet(), hasSize(0));
  assertThat(keys.getKeyList(), hasSize(0));
  assertThat(keys.tryGetIndex(42), lessThan(0));
}
org.lenskit.util.keysSortedKeyIndextryGetIndex

Javadoc

Get the index for a key.

Popular methods of SortedKeyIndex

  • fromCollection
    Create a key set from a collection of keys.
  • size
    Get the domain size of this set.
  • getKey
    Get the key at an index.
  • keySet
    Get a view of the index as a set.
  • create
    Create a key set with some keys. All keys are initially active.
  • keyIterator
    Create an iterator over keys.
  • findLowerBound
    Get the lower bound, the first index whose key is greater than or equal to the specified key. This m
  • findUpperBound
    Get the upper bound, the first index whose key is greater than the specified key.
  • getLowerBound
    Get the lower bound of this index.
  • getUpperBound
    Get the upper bound of this index.
  • subIndex
    Create a view of a subset of this index.
  • wrap
    Wrap a key array (with a specified size) into a key set.
  • subIndex,
  • wrap,
  • containsKey,
  • fromIterator,
  • empty,
  • getKeyList

Popular in Java

  • Making http requests using okhttp
  • getContentResolver (Context)
  • addToBackStack (FragmentTransaction)
  • notifyDataSetChanged (ArrayAdapter)
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • ImageIO (javax.imageio)
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • Top 17 Free Sublime Text Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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