@Override public SequentialAccessSparseVector vectorToTest(int size) { SequentialAccessSparseVector r = new SequentialAccessSparseVector(size); Random gen = RandomUtils.getRandom(); for (int i = 0; i < 3; i++) { r.set(gen.nextInt(r.size()), gen.nextGaussian()); } return r; }
public SequentialAccessSparseVector(Vector other) { this(other.size(), other.getNumNondefaultElements()); if (other.isSequentialAccess()) { for (Element e : other.nonZeroes()) { set(e.index(), e.get()); } } else { // If the incoming Vector to copy is random, then adding items // from the Iterator can degrade performance dramatically if // the number of elements is large as this Vector tries to stay // in order as items are added, so it's better to sort the other // Vector's elements by index and then add them to this copySortedRandomAccessSparseVector(other); } }
/** * must be synchronized, otherwise may get ArrayIndexOutOfBoundsException * @param dataPointIndex * @param featureIndex * @param featureValue */ @Override public synchronized void setFeatureValue(int dataPointIndex, int featureIndex, double featureValue) { if ((!this.hasMissingValue()) && Double.isNaN(featureValue)){ throw new IllegalArgumentException("missing value is not allowed in this data set"); } this.featureRows[dataPointIndex].set(featureIndex, featureValue); this.featureColumns[featureIndex].set(dataPointIndex, featureValue); }
protected Vector sparseItemRatingVector(final PreferenceArray prefs) { final SequentialAccessSparseVector ratings = new SequentialAccessSparseVector( Integer.MAX_VALUE, prefs.length()); for (final Preference preference : prefs) { ratings.set((int) preference.getUserID(), preference.getValue()); } return ratings; }
protected Vector sparseUserRatingVector(PreferenceArray prefs) { SequentialAccessSparseVector ratings = new SequentialAccessSparseVector(Integer.MAX_VALUE, prefs.length()); for (Preference preference : prefs) { ratings.set((int) preference.getItemID(), preference.getValue()); } return ratings; } }
protected Vector sparseItemRatingVector(PreferenceArray prefs) { SequentialAccessSparseVector ratings = new SequentialAccessSparseVector(Integer.MAX_VALUE, prefs.length()); for (Preference preference : prefs) { ratings.set((int) preference.getUserID(), preference.getValue()); } return ratings; }
protected Vector sparseUserRatingVector(final PreferenceArray prefs) { final SequentialAccessSparseVector ratings = new SequentialAccessSparseVector( Integer.MAX_VALUE, prefs.length()); for (final Preference preference : prefs) { ratings.set((int) preference.getItemID(), preference.getValue()); } return ratings; } }
protected Vector sparseItemRatingVector(PreferenceArray prefs) { SequentialAccessSparseVector ratings = new SequentialAccessSparseVector(Integer.MAX_VALUE, prefs.length()); for (Preference preference : prefs) { ratings.set(userIndex(preference.getUserID()), preference.getValue()); } return ratings; }
public SequentialAccessSparseVector(Vector other) { this(other.size(), other.getNumNondefaultElements()); if (other.isSequentialAccess()) { Iterator<Element> it = other.iterateNonZero(); Element e; while (it.hasNext() && (e = it.next()) != null) { set(e.index(), e.get()); } } else { // If the incoming Vector to copy is random, then adding items // from the Iterator can degrade performance dramatically if // the number of elements is large as this Vector tries to stay // in order as items are added, so it's better to sort the other // Vector's elements by index and then add them to this copySortedRandomAccessSparseVector(other); } }
protected Vector sparseItemRatingVector(PreferenceArray prefs) { SequentialAccessSparseVector ratings = new SequentialAccessSparseVector(Integer.MAX_VALUE, prefs.length()); for (Preference preference : prefs) { ratings.set(userIndex(preference.getUserID()), preference.getValue()); } return ratings; }
protected Vector sparseUserRatingVector(PreferenceArray prefs) { SequentialAccessSparseVector ratings = new SequentialAccessSparseVector(Integer.MAX_VALUE, prefs.length()); for (Preference preference : prefs) { ratings.set(itemIndex(preference.getItemID()), preference.getValue()); } return ratings; } }
protected Vector sparseUserRatingVector(PreferenceArray prefs) { SequentialAccessSparseVector ratings = new SequentialAccessSparseVector(Integer.MAX_VALUE, prefs.length()); for (Preference preference : prefs) { ratings.set(itemIndex(preference.getItemID()), preference.getValue()); } return ratings; } }
public SequentialAccessSparseVector(Vector other) { this(other.size(), other.getNumNondefaultElements()); if (other.isSequentialAccess()) { for (Element e : other.nonZeroes()) { set(e.index(), e.get()); } } else { // If the incoming Vector to copy is random, then adding items // from the Iterator can degrade performance dramatically if // the number of elements is large as this Vector tries to stay // in order as items are added, so it's better to sort the other // Vector's elements by index and then add them to this copySortedRandomAccessSparseVector(other); } }