Ejemplo n.º 1
0
  /** tests {@link ToVectorAndPrefReducer} */
  @Test
  public void testToVectorAndPrefReducer() throws Exception {
    Reducer<VarIntWritable, VectorOrPrefWritable, VarIntWritable, VectorAndPrefsWritable>.Context
        context = EasyMock.createMock(Reducer.Context.class);

    context.write(
        EasyMock.eq(new VarIntWritable(1)),
        vectorAndPrefsWritableMatches(
            Arrays.asList(123L, 456L),
            Arrays.asList(1.0f, 2.0f),
            MathHelper.elem(3, 0.5),
            MathHelper.elem(7, 0.8)));

    EasyMock.replay(context);

    Vector similarityColumn = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    similarityColumn.set(3, 0.5);
    similarityColumn.set(7, 0.8);

    VectorOrPrefWritable itemPref1 = new VectorOrPrefWritable(123L, 1.0f);
    VectorOrPrefWritable itemPref2 = new VectorOrPrefWritable(456L, 2.0f);
    VectorOrPrefWritable similarities = new VectorOrPrefWritable(similarityColumn);

    new ToVectorAndPrefReducer()
        .reduce(new VarIntWritable(1), Arrays.asList(itemPref1, itemPref2, similarities), context);

    EasyMock.verify(context);
  }
Ejemplo n.º 2
0
  /** tests {@link ToUserVectorReducer} using boolean data */
  @Test
  public void testToUserVectorReducerWithBooleanData() throws Exception {
    Reducer<VarLongWritable, VarLongWritable, VarLongWritable, VectorWritable>.Context context =
        EasyMock.createMock(Reducer.Context.class);

    context.write(
        EasyMock.eq(new VarLongWritable(12L)),
        MathHelper.vectorMatches(
            MathHelper.elem(TasteHadoopUtils.idToIndex(34L), 1.0),
            MathHelper.elem(TasteHadoopUtils.idToIndex(56L), 1.0)));

    EasyMock.replay(context);

    new ToUserVectorReducer()
        .reduce(
            new VarLongWritable(12L),
            Arrays.asList(new VarLongWritable(34L), new VarLongWritable(56L)),
            context);

    EasyMock.verify(context);
  }
Ejemplo n.º 3
0
  /** tests {@link SimilarityMatrixRowWrapperMapper} */
  @Test
  public void testSimilarityMatrixRowWrapperMapper() throws Exception {
    Mapper<IntWritable, VectorWritable, VarIntWritable, VectorOrPrefWritable>.Context context =
        EasyMock.createMock(Mapper.Context.class);

    context.write(
        EasyMock.eq(new VarIntWritable(12)),
        vectorOfVectorOrPrefWritableMatches(MathHelper.elem(34, 0.5), MathHelper.elem(56, 0.7)));

    EasyMock.replay(context);

    RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    vector.set(12, 1.0);
    vector.set(34, 0.5);
    vector.set(56, 0.7);

    new SimilarityMatrixRowWrapperMapper()
        .map(new IntWritable(12), new VectorWritable(vector), context);

    EasyMock.verify(context);
  }
Ejemplo n.º 4
0
  /** tests {@link ToUserVectorReducer} */
  @Test
  public void testToUserVectorReducer() throws Exception {
    Reducer<VarLongWritable, VarLongWritable, VarLongWritable, VectorWritable>.Context context =
        EasyMock.createMock(Reducer.Context.class);

    context.write(
        EasyMock.eq(new VarLongWritable(12L)),
        MathHelper.vectorMatches(
            MathHelper.elem(TasteHadoopUtils.idToIndex(34L), 1.0),
            MathHelper.elem(TasteHadoopUtils.idToIndex(56L), 2.0)));

    EasyMock.replay(context);

    Collection<VarLongWritable> varLongWritables = new LinkedList<VarLongWritable>();
    varLongWritables.add(new EntityPrefWritable(34L, 1.0f));
    varLongWritables.add(new EntityPrefWritable(56L, 2.0f));

    new ToUserVectorReducer().reduce(new VarLongWritable(12L), varLongWritables, context);

    EasyMock.verify(context);
  }