Example usage for org.apache.mahout.math.random MultiNormal MultiNormal

List of usage examples for org.apache.mahout.math.random MultiNormal MultiNormal

Introduction

In this page you can find the example usage for org.apache.mahout.math.random MultiNormal MultiNormal.

Prototype

public MultiNormal(double radius, Vector mean) 

Source Link

Usage

From source file:zx.soft.mahout.knn.search.AbstractSearchTest.java

License:Apache License

@Test
public void testNearMatch() {
    List<MatrixSlice> queries = Lists.newArrayList(Iterables.limit(testData(), 100));
    Searcher s = getSearch(20);//from w w  w .  j a va2s .c  om
    s.addAllMatrixSlicesAsWeightedVectors(testData());

    MultiNormal noise = new MultiNormal(0.01, new DenseVector(20));
    for (MatrixSlice slice : queries) {
        Vector query = slice.vector();
        final Vector epsilon = noise.sample();
        //         List<WeightedThing<Vector>> r0 = s.search(query, 2);
        query = query.plus(epsilon);
        List<WeightedThing<Vector>> r = s.search(query, 2);
        r = s.search(query, 2);
        assertEquals("Distance has to be small", epsilon.norm(2), r.get(0).getWeight(), 1e-5);
        assertEquals("Answer must be substantially the same as query", epsilon.norm(2),
                r.get(0).getValue().minus(query).norm(2), 1e-5);
        assertTrue("Wrong answer must be further away", r.get(1).getWeight() > r.get(0).getWeight());
    }
}