mahout-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Dunning <ted.dunn...@gmail.com>
Subject Re: divide a vector (sum) by a double, error
Date Mon, 16 Jun 2014 16:20:40 GMT
Patrice,

This sounds like a classpath problem more than code error.  Are you sure
that you can run any program that use Mahout?  Do you perhaps have two
versions of Mahout floating around?

Regarding the code, this is a more compact idiom for the same thing:

    Matrix m = ...;
    Vector centroid = m.aggregateColumns(new VectorFunction() {
      @Override
      public double apply(Vector f) {
        return f.zSum() / f.size();
      }
    });

This uses a matrix as a container for vectors rather than a set of Vectors.
 If you really want to use a set, then your iteration based approach should
be fine.

In your code, you could also be much tighter.  For instance, the last three
lines could simply be:

    return sum.divide(vectors.size);

None of the stuff with the Integer or casting is necessary.



On Mon, Jun 16, 2014 at 9:01 AM, Patrice Seyed <apseyed@gmail.com> wrote:

> Hi all,
>
>
> I have attempted to write a method centroid() that
>
> 1) sums a HashSet of org.apache.mahout.math.Vector (vectors that are
> DenseVector), and
> 2) (org.apache.mahout.math.Vector.divide) divides the summed vector by
> its size, as a double.
>
> I get an error:
>
> Exception in thread "main" java.lang.IncompatibleClassChangeError:
> class org.apache.mahout.math.function.Functions$1 has interface
> org.apache.mahout.math.function.DoubleFunction as super class
>
> I've tried this with a set of DenseVector and
> SequentialAccessSparseVector with the same result.
>
> Any help appreciated, the actual method is below.
> I noticed a class Centroid in the mahout distribution, but seems to
> cover a different sense of centroid than that I'm implementing here.
>
> Thanks,
> Patrice
>
>
> public Vector centroid (HashSet<Vector> vectors){
>
> Iterator<Vector> it = vectors.iterator();
>
> Vector sum = it.next();
>
> while(it.hasNext()){
>
> Vector aVector = it.next();
>
>
> sum = sum.plus(aVector);
>
> System.out.println(sum.toString());
>
> }
>
> Integer totalVectors = vectors.size();
>
> double dlTotalVectors = totalVectors.doubleValue();
>
> return sum.divide(dlTotalVectors);
>
>
> }
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message