Package org.apache.mahout.math.Vector

Examples of org.apache.mahout.math.Vector.Element.index()


        accumDots(j, aRow.getQuick(j), yRow);
      }
    } else {
      for (Iterator<Element> iter = aRow.iterateNonZero(); iter.hasNext();) {
        Element el = iter.next();
        accumDots(el.index(), el.get(), yRow);
      }
    }
  }

  /**
 
View Full Code Here


        accumDots(j, aRow.getQuick(j), yRowOut);
      }
    } else {
      for (Iterator<Element> iter = aRow.iterateNonZero(); iter.hasNext();) {
        Element el = iter.next();
        accumDots(el.index(), el.get(), yRowOut);
      }
    }
  }

  protected void accumDots(int aIndex, double aElement, double[] yRow) {
View Full Code Here

  public double getScoreForLabelInstance(int label, Vector instance) {
    double result = 0.0;
    Iterator<Element> it = instance.iterateNonZero();
    while (it.hasNext()) {
      Element e = it.next();
      result +=  getScoreForLabelFeature(label, e.index());
    }
    return result;
  }
 
  @Override
View Full Code Here

    int label = key.get();
    double sigmaK = labelSum.get(label);
    Iterator<Element> it = vector.iterateNonZero();
    while (it.hasNext()) {
      Element e = it.next();
      double numerator = featureSum.get(e.index()) - e.get() + alphaI;
      double denominator = totalSum - sigmaK + vocabCount;
      double weight = Math.log(numerator / denominator);
      perLabelThetaNormalizer.set(label, perLabelThetaNormalizer.get(label) + weight);
    }
  }
View Full Code Here

    int maxIndex = -1;
    double val = Integer.MIN_VALUE;
    while (it.hasNext()) {
      Element e = it.next();
      if (val <= e.get()) {
        maxIndex = e.index();
        val = e.get();
      }
    }
    return maxIndex;
  }
View Full Code Here

    Vector sample = new RandomAccessSparseVector(original.size(), sampleSize);
    Iterator<Element> sampledElements =
        new FixedSizeSamplingIterator<Vector.Element>(sampleSize, original.nonZeroes().iterator());
    while (sampledElements.hasNext()) {
      Element elem = sampledElements.next();
      sample.setQuick(elem.index(), elem.get());
    }
    return sample;
  }

  public static Vector topKElements(int k, Vector original) {
View Full Code Here

      Iterator<Vector.Element> xi = x.all().iterator();
      Iterator<Vector.Element> yi = y.all().iterator();
      OrderedIntDoubleMapping updates = new OrderedIntDoubleMapping(false);
      while (xi.hasNext() && yi.hasNext()) {
        Element xe = xi.next();
        updates.set(xe.index(), f.apply(xe.get(), yi.next().get()));
      }
      x.mergeUpdates(updates);
      return x;
    }
  }
View Full Code Here

    public Vector assign(Vector x, Vector y, DoubleDoubleFunction f) {
      Iterator<Vector.Element> xi = x.all().iterator();
      Iterator<Vector.Element> yi = y.all().iterator();
      while (xi.hasNext() && yi.hasNext()) {
        Element xe = xi.next();
        x.setQuick(xe.index(), f.apply(xe.get(), yi.next().get()));
      }
      return x;
    }
  }
View Full Code Here

    expectedIndices = Sets.newHashSet(expectedIndices);
    Iterator<Element> allIterator = vector.all().iterator();
    int index = 0;
    while (allIterator.hasNext()) {
      Element element = allIterator.next();
      assertEquals(index, element.index());
      if (expectedIndices.contains(index)) {
        assertEquals((double) index * 2, element.get(), EPSILON);
      } else {
        assertEquals(0.0, element.get(), EPSILON);
      }
View Full Code Here

      }
      index++;
    }

    for (Element element : vector.nonZeroes()) {
      index = element.index();
      assertTrue(expectedIndices.contains(index));
      assertEquals((double) index * 2, element.get(), EPSILON);
      expectedIndices.remove(index);
    }
    assertTrue(expectedIndices.isEmpty());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.