Package org.apache.mahout.math

Examples of org.apache.mahout.math.Vector.maxValue()


    assertEquals(123, v1.norm(1), 0);

    Vector v2 = new DenseVector(20);
    enc.setProbes(2);
    enc.addToVector((byte[]) null, 123, v2);
    assertEquals(123, v2.maxValue(), 0);
    assertEquals(2 * 123, v2.norm(1), 0);

    // v1 has one probe, v2 has two.  The first probe in v2 should be in the same
    // place as the only probe in v1
    v1 = v2.minus(v1);
View Full Code Here


        t.set(2, "lots of text for testing");

        pv = PigVector.fromBytes(ev.exec(t));
        Vector v3 = pv.assign(v1, Functions.MINUS);
        assertEquals(10, v3.zSum(), 0);
        assertEquals(1, v3.maxValue(), 1);

        EncodeVector ev2 = new EncodeVector("100", "x+y", "x:numeric, not:text, y:text");
        t.set(2, "");
        pv = PigVector.fromBytes(ev2.exec(t));
        Vector v4 = pv;
View Full Code Here

        t.set(2, "");
        pv = PigVector.fromBytes(ev2.exec(t));
        Vector v4 = pv;
        assertEquals(3.1, v1.get(10), 0);
        assertEquals(3.1, v4.zSum(), 0);
        assertEquals(3.1, v4.maxValue(), 1);
    }

    @Test
    public void testBadIndex() throws IOException {
        EncodeVector ev2 = new EncodeVector("100", "x+y", "x:numeric, not:text, y:text");
View Full Code Here

    Vector v1 = new DenseVector(200);
    enc.addInteractionToVector("a","1.0",1.0, v1);
    int k = enc.getProbes();
    // should set k distinct locations to 1
    assertEquals((float) k, v1.norm(1), 0);
    assertEquals(1.0, v1.maxValue(), 0);

    // adding same interaction again should increment weights
    enc.addInteractionToVector("a","1.0",1.0,v1);
    assertEquals((float) k*2, v1.norm(1), 0);
    assertEquals(2.0, v1.maxValue(), 0);
View Full Code Here

    assertEquals(1.0, v1.maxValue(), 0);

    // adding same interaction again should increment weights
    enc.addInteractionToVector("a","1.0",1.0,v1);
    assertEquals((float) k*2, v1.norm(1), 0);
    assertEquals(2.0, v1.maxValue(), 0);

    Vector v2 = new DenseVector(20000);
    enc.addInteractionToVector("a","1.0",1.0,v2);
    wv.addToVector("a", v2);
    cv.addToVector("1.0", v2);
View Full Code Here

    Vector v1 = new DenseVector(200);
    enc.addInteractionToVector("a","0.9",0.5, v1);
    int k = enc.getProbes();
    // should set k distinct locations to 0.9*0.5
    assertEquals((float) k*0.5*0.9, v1.norm(1), 0);
    assertEquals(0.5*0.9, v1.maxValue(), 0);
  }

  @Test
  public void testAddToVectorWithTextValueEncoder() {
    WordValueEncoder wv = new StaticWordValueEncoder("word");
View Full Code Here

    Vector v1 = new DenseVector(200);
    enc.addToVector("test1 and more", v1);
    enc.flush(1, v1);
    // should set 6 distinct locations to 1
    assertEquals(6.0, v1.norm(1), 0);
    assertEquals(1.0, v1.maxValue(), 0);

    // now some fancy weighting
    StaticWordValueEncoder w = new StaticWordValueEncoder("text");
    w.setDictionary(ImmutableMap.<String, Double>of("word1", 3.0, "word2", 1.5));
    enc.setWordEncoder(w);
View Full Code Here

    enc.flush(1, v1);

    //should be the same as text test above, since we are splitting on whitespace
    // should set 6 distinct locations to 1
    assertEquals(6.0, v1.norm(1), 0);
    assertEquals(1.0, v1.maxValue(), 0);

    v1 = new DenseVector(200);
    enc.addToVector("", v1);
    enc.flush(1, v1);
    assertEquals(0.0, v1.norm(1), 0);
View Full Code Here

    v1 = new DenseVector(200);
    enc.addToVector("", v1);
    enc.flush(1, v1);
    assertEquals(0.0, v1.norm(1), 0);
    assertEquals(0.0, v1.maxValue(), 0);

    v1 = new DenseVector(200);
    StringBuilder builder = new StringBuilder(5000);
    for (int i = 0; i < 1000; i++) {//lucene's internal buffer length request is 4096, so let's make sure we can handle larger size
      builder.append("token_").append(i).append(' ');
View Full Code Here

    }
    enc.addToVector(builder.toString(), v1);
    enc.flush(1, v1);
    //System.out.println(v1);
    assertEquals(2000.0, v1.norm(1), 0);
    assertEquals(19.0, v1.maxValue(), 0);
  }
}
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.