mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r654943 [9/9] - in /lucene/mahout/trunk/core: ./ lib/ src/main/examples/org/ src/main/examples/org/apache/ src/main/examples/org/apache/mahout/ src/main/examples/org/apache/mahout/cf/ src/main/examples/org/apache/mahout/cf/taste/ src/main/e...
Date Fri, 09 May 2008 21:35:17 GMT
Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/TreeClusteringRecommenderTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/TreeClusteringRecommenderTest.java?rev=654943&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/TreeClusteringRecommenderTest.java
(added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/TreeClusteringRecommenderTest.java
Fri May  9 14:35:12 2008
@@ -0,0 +1,123 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.cf.taste.impl.recommender;
+
+import org.apache.mahout.cf.taste.correlation.UserCorrelation;
+import org.apache.mahout.cf.taste.impl.correlation.PearsonCorrelation;
+import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
+import org.apache.mahout.cf.taste.impl.model.GenericItem;
+import org.apache.mahout.cf.taste.impl.TasteTestCase;
+import org.apache.mahout.cf.taste.model.DataModel;
+import org.apache.mahout.cf.taste.model.Item;
+import org.apache.mahout.cf.taste.model.User;
+import org.apache.mahout.cf.taste.recommender.RecommendedItem;
+import org.apache.mahout.cf.taste.recommender.Recommender;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <p>Tests {@link TreeClusteringRecommender}.</p>
+ */
+public final class TreeClusteringRecommenderTest extends TasteTestCase {
+
+  public void testNoRecommendations() throws Exception {
+    List<User> users = new ArrayList<User>(3);
+    users.add(getUser("test1", 0.1));
+    users.add(getUser("test2", 0.2, 0.6));
+    users.add(getUser("test3", 0.4, 0.9));
+    DataModel dataModel = new GenericDataModel(users);
+    UserCorrelation correlation = new PearsonCorrelation(dataModel);
+    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
+    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
+    List<RecommendedItem> recommended = recommender.recommend("test1", 1);
+    assertNotNull(recommended);
+    assertEquals(0, recommended.size());
+  }
+
+  public void testHowMany() throws Exception {
+    List<User> users = new ArrayList<User>(3);
+    users.add(getUser("test1", 0.1, 0.2));
+    users.add(getUser("test2", 0.2, 0.3, 0.3, 0.6));
+    users.add(getUser("test3", 0.4, 0.4, 0.5, 0.9));
+    users.add(getUser("test4", 0.1, 0.4, 0.5, 0.8, 0.9, 1.0));
+    users.add(getUser("test5", 0.2, 0.3, 0.6, 0.7, 0.1, 0.2));
+    DataModel dataModel = new GenericDataModel(users);
+    UserCorrelation correlation = new PearsonCorrelation(dataModel);
+    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
+    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
+    List<RecommendedItem> fewRecommended = recommender.recommend("test1", 2);
+    List<RecommendedItem> moreRecommended = recommender.recommend("test1", 4);
+    for (int i = 0; i < fewRecommended.size(); i++) {
+      assertEquals(fewRecommended.get(i).getItem(), moreRecommended.get(i).getItem());
+    }
+  }
+
+  public void testRescorer() throws Exception {
+    List<User> users = new ArrayList<User>(3);
+    users.add(getUser("test1", 0.1, 0.2));
+    users.add(getUser("test2", 0.2, 0.3, 0.3, 0.6));
+    users.add(getUser("test3", 0.4, 0.4, 0.5, 0.9));
+    DataModel dataModel = new GenericDataModel(users);
+    UserCorrelation correlation = new PearsonCorrelation(dataModel);
+    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
+    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
+    List<RecommendedItem> originalRecommended = recommender.recommend("test1", 2);
+    List<RecommendedItem> rescoredRecommended =
+            recommender.recommend("test1", 2, new ReversingRescorer<Item>());
+    assertNotNull(originalRecommended);
+    assertNotNull(rescoredRecommended);
+    assertEquals(2, originalRecommended.size());
+    assertEquals(2, rescoredRecommended.size());
+    assertEquals(originalRecommended.get(0).getItem(), rescoredRecommended.get(1).getItem());
+    assertEquals(originalRecommended.get(1).getItem(), rescoredRecommended.get(0).getItem());
+  }
+
+  public void testEstimatePref() throws Exception {
+    List<User> users = new ArrayList<User>(4);
+    users.add(getUser("test1", 0.1, 0.3));
+    users.add(getUser("test2", 0.2, 0.3, 0.3));
+    users.add(getUser("test3", 0.4, 0.3, 0.5));
+    users.add(getUser("test4", 0.7, 0.3, 0.8, 0.9));
+    DataModel dataModel = new GenericDataModel(users);
+    UserCorrelation correlation = new PearsonCorrelation(dataModel);
+    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
+    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
+    assertEquals(0.9, recommender.estimatePreference("test3", "3"));
+  }
+
+  public void testBestRating() throws Exception {
+    List<User> users = new ArrayList<User>(4);
+    users.add(getUser("test1", 0.1, 0.3));
+    users.add(getUser("test2", 0.2, 0.3, 0.3));
+    users.add(getUser("test3", 0.4, 0.3, 0.5));
+    users.add(getUser("test4", 0.7, 0.3, 0.8));
+    DataModel dataModel = new GenericDataModel(users);
+    UserCorrelation correlation = new PearsonCorrelation(dataModel);
+    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
+    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
+    List<RecommendedItem> recommended = recommender.recommend("test1", 1);
+    assertNotNull(recommended);
+    assertEquals(1, recommended.size());
+    RecommendedItem firstRecommended = recommended.get(0);
+    // item one should be recommended because it has a greater rating/score
+    assertEquals(new GenericItem<String>("2"), firstRecommended.getItem());
+    assertEquals(0.3, firstRecommended.getValue(), EPSILON);
+  }
+
+}

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommenderTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommenderTest.java?rev=654943&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommenderTest.java
(added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommenderTest.java
Fri May  9 14:35:12 2008
@@ -0,0 +1,118 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.cf.taste.impl.recommender.slopeone;
+
+import org.apache.mahout.cf.taste.common.TasteException;
+import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
+import org.apache.mahout.cf.taste.impl.model.GenericItem;
+import org.apache.mahout.cf.taste.impl.recommender.ReversingRescorer;
+import org.apache.mahout.cf.taste.impl.TasteTestCase;
+import org.apache.mahout.cf.taste.model.DataModel;
+import org.apache.mahout.cf.taste.model.Item;
+import org.apache.mahout.cf.taste.model.User;
+import org.apache.mahout.cf.taste.recommender.RecommendedItem;
+import org.apache.mahout.cf.taste.recommender.Recommender;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <p>Tests {@link SlopeOneRecommender}.</p>
+ */
+public final class SlopeOneRecommenderTest extends TasteTestCase {
+
+  public void testRecommender() throws Exception {
+    Recommender recommender = buildRecommender();
+    List<RecommendedItem> recommended = recommender.recommend("test1", 1);
+    assertNotNull(recommended);
+    assertEquals(1, recommended.size());
+    RecommendedItem firstRecommended = recommended.get(0);
+    assertEquals(new GenericItem<String>("2"), firstRecommended.getItem());
+    assertEquals(0.34803885284992736, firstRecommended.getValue(), EPSILON);
+  }
+
+  public void testHowMany() throws Exception {
+    List<User> users = new ArrayList<User>(3);
+    users.add(getUser("test1", 0.1, 0.2));
+    users.add(getUser("test2", 0.2, 0.3, 0.3, 0.6));
+    users.add(getUser("test3", 0.4, 0.4, 0.5, 0.9));
+    users.add(getUser("test4", 0.1, 0.4, 0.5, 0.8, 0.9, 1.0));
+    users.add(getUser("test5", 0.2, 0.3, 0.6, 0.7, 0.1, 0.2));
+    DataModel dataModel = new GenericDataModel(users);
+    Recommender recommender = new SlopeOneRecommender(dataModel);
+    List<RecommendedItem> fewRecommended = recommender.recommend("test1", 2);
+    List<RecommendedItem> moreRecommended = recommender.recommend("test1", 4);
+    for (int i = 0; i < fewRecommended.size(); i++) {
+      assertEquals(fewRecommended.get(i).getItem(), moreRecommended.get(i).getItem());
+    }
+  }
+
+  public void testRescorer() throws Exception {
+    List<User> users = new ArrayList<User>(3);
+    users.add(getUser("test1", 0.1, 0.2));
+    users.add(getUser("test2", 0.2, 0.3, 0.3, 0.6));
+    users.add(getUser("test3", 0.4, 0.4, 0.5, 0.9));
+    DataModel dataModel = new GenericDataModel(users);
+    Recommender recommender = new SlopeOneRecommender(dataModel);
+    List<RecommendedItem> originalRecommended = recommender.recommend("test1", 2);
+    List<RecommendedItem> rescoredRecommended =
+            recommender.recommend("test1", 2, new ReversingRescorer<Item>());
+    assertNotNull(originalRecommended);
+    assertNotNull(rescoredRecommended);
+    assertEquals(2, originalRecommended.size());
+    assertEquals(2, rescoredRecommended.size());
+    assertEquals(originalRecommended.get(0).getItem(), rescoredRecommended.get(1).getItem());
+    assertEquals(originalRecommended.get(1).getItem(), rescoredRecommended.get(0).getItem());
+  }
+
+  public void testEstimatePref() throws Exception {
+    Recommender recommender = buildRecommender();
+    assertEquals(0.34803885284992736, recommender.estimatePreference("test1", "2"), EPSILON);
+  }
+
+  public void testBestRating() throws Exception {
+    List<User> users = new ArrayList<User>(3);
+    users.add(getUser("test1", 0.0, 0.3));
+    users.add(getUser("test2", 0.2, 0.3, 0.3));
+    users.add(getUser("test3", 0.4, 0.3, 0.5));
+    DataModel dataModel = new GenericDataModel(users);
+    Recommender recommender = new SlopeOneRecommender(dataModel);
+    List<RecommendedItem> recommended = recommender.recommend("test1", 1);
+    assertNotNull(recommended);
+    assertEquals(1, recommended.size());
+    RecommendedItem firstRecommended = recommended.get(0);
+    // item one should be recommended because it has a greater rating/score
+    assertEquals(new GenericItem<String>("2"), firstRecommended.getItem());
+    assertEquals(0.2400938676203033, firstRecommended.getValue(), EPSILON);
+  }
+
+  public void testDiffStdevBehavior() throws Exception {
+    List<User> users = new ArrayList<User>(3);
+    users.add(getUser("test1", 0.1, 0.2));
+    users.add(getUser("test2", 0.2, 0.3, 0.6));
+    DataModel dataModel = new GenericDataModel(users);
+    Recommender recommender = new SlopeOneRecommender(dataModel);
+    assertEquals(0.5, recommender.estimatePreference("test1", "2"), EPSILON);
+  }
+
+  private static Recommender buildRecommender() throws TasteException {
+    DataModel dataModel = new GenericDataModel(getMockUsers());
+    return new SlopeOneRecommender(dataModel);
+  }
+
+}

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/CaseAmplificationTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/CaseAmplificationTest.java?rev=654943&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/CaseAmplificationTest.java
(added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/CaseAmplificationTest.java
Fri May  9 14:35:12 2008
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.cf.taste.impl.transforms;
+
+/**
+ * <p>Tests {@link CaseAmplification}.</p>
+ */
+public final class CaseAmplificationTest extends TransformTestCase {
+
+  public void testOneValue() {
+    assertEquals(2.0, new CaseAmplification(0.5).transformCorrelation(null, null, 4.0), EPSILON);
+    assertEquals(-2.0, new CaseAmplification(0.5).transformCorrelation(null, null, -4.0),
EPSILON);
+  }
+
+  public void testRefresh() {
+    // Make sure this doesn't throw an exception
+    new CaseAmplification(1.0).refresh();
+  }
+
+}

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/InverseUserFrequencyTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/InverseUserFrequencyTest.java?rev=654943&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/InverseUserFrequencyTest.java
(added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/InverseUserFrequencyTest.java
Fri May  9 14:35:12 2008
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.cf.taste.impl.transforms;
+
+import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
+import org.apache.mahout.cf.taste.model.Preference;
+import org.apache.mahout.cf.taste.model.User;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <p>Tests {@link InverseUserFrequency}.</p>
+ */
+public final class InverseUserFrequencyTest extends TransformTestCase {
+
+  public void testIUF() {
+    List<User> users = new ArrayList<User>(5);
+    users.add(getUser("test1", 0.1));
+    users.add(getUser("test2", 0.2, 0.3));
+    users.add(getUser("test3", 0.4, 0.5, 0.6));
+    users.add(getUser("test4", 0.7, 0.8, 0.9, 1.0));
+    users.add(getUser("test5", 1.0, 1.0, 1.0, 1.0, 1.0));
+    GenericDataModel dummy = new GenericDataModel(users);
+    InverseUserFrequency iuf = new InverseUserFrequency(dummy, 10.0);
+
+    User user = dummy.getUser("test5");
+    for (int i = 0; i < 5; i++) {
+      Preference pref = user.getPreferenceFor(String.valueOf(i));
+      assertNotNull(pref);
+      assertEquals(Math.log(5.0 / (double) (5 - i)) / Math.log(iuf.getLogBase()),
+                   iuf.getTransformedValue(pref),
+                   EPSILON);
+    }
+
+    // Make sure this doesn't throw an exception
+    iuf.refresh();
+  }
+
+}

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/TransformTestCase.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/TransformTestCase.java?rev=654943&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/TransformTestCase.java
(added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/TransformTestCase.java
Fri May  9 14:35:12 2008
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.cf.taste.impl.transforms;
+
+import org.apache.mahout.cf.taste.impl.TasteTestCase;
+import org.apache.mahout.cf.taste.model.Preference;
+import org.apache.mahout.cf.taste.model.User;
+
+abstract class TransformTestCase extends TasteTestCase {
+
+  static void assertPrefsEquals(User user, double... expected) {
+    int i = 0;
+    for (Preference pref : user.getPreferences()) {
+      assertEquals(expected[i], pref.getValue());
+      i++;
+    }
+    assertEquals(expected.length, i);
+  }
+}

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/ZScoreTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/ZScoreTest.java?rev=654943&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/ZScoreTest.java
(added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/ZScoreTest.java
Fri May  9 14:35:12 2008
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.cf.taste.impl.transforms;
+
+import org.apache.mahout.cf.taste.model.User;
+import org.apache.mahout.cf.taste.transforms.PreferenceTransform2;
+
+/**
+ * <p>Tests {@link ZScore}.</p>
+ */
+public final class ZScoreTest extends TransformTestCase {
+
+  public void testOnePref() throws Exception {
+    User user = getUser("test", 1.0);
+    PreferenceTransform2 zScore = new ZScore();
+    assertEquals(0.0, zScore.getTransformedValue(user.getPreferenceFor("0")), EPSILON);
+  }
+
+  public void testAllSame() throws Exception {
+    User user = getUser("test", 1.0, 1.0, 1.0);
+    PreferenceTransform2 zScore = new ZScore();
+    assertEquals(0.0, zScore.getTransformedValue(user.getPreferenceFor("0")), EPSILON);
+    assertEquals(0.0, zScore.getTransformedValue(user.getPreferenceFor("1")), EPSILON);
+    assertEquals(0.0, zScore.getTransformedValue(user.getPreferenceFor("2")), EPSILON);
+  }
+
+  public void testStdev() throws Exception {
+    User user = getUser("test", -1.0, -2.0);
+    PreferenceTransform2 zScore = new ZScore();
+    assertEquals(0.707107, zScore.getTransformedValue(user.getPreferenceFor("0")), EPSILON);
+    assertEquals(-0.707107, zScore.getTransformedValue(user.getPreferenceFor("1")), EPSILON);
+  }
+
+  public void testExample() throws Exception {
+    User user = getUser("test", 5.0, 7.0, 9.0);
+    PreferenceTransform2 zScore = new ZScore();
+    assertEquals(-1.0, zScore.getTransformedValue(user.getPreferenceFor("0")), EPSILON);
+    assertEquals(0.0, zScore.getTransformedValue(user.getPreferenceFor("1")), EPSILON);
+    assertEquals(1.0, zScore.getTransformedValue(user.getPreferenceFor("2")), EPSILON);
+  }
+
+  public void testRefresh() {
+    // Make sure this doesn't throw an exception
+    new ZScore().refresh();
+  }
+
+}

Added: lucene/mahout/trunk/core/taste-build.properties
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/taste-build.properties?rev=654943&view=auto
==============================================================================
--- lucene/mahout/trunk/core/taste-build.properties (added)
+++ lucene/mahout/trunk/core/taste-build.properties Fri May  9 14:35:12 2008
@@ -0,0 +1,23 @@
+# Temporarily, this ex-Taste build file is separate. Next step is to integrate it.
+
+version=2.0
+
+junit.jar=lib/junit-3.8.2.jar
+ejb.jar=lib/ejb-2_1-api.jar
+servlet.jar=lib/servlet-api.jar
+dbcp.jar=lib/commons-dbcp-1.2.2.jar
+pool.jar=lib/commons-pool-1.4.jar
+
+# These .jars aren't included with the distribution and must be
+# manually added
+mysql.jar=lib/mysql-connector-java-5.1.6-bin.jar
+proguard.jar=lib/proguard.jar
+# Should contains Axis2 1.3 or later .jars
+axis.jars=lib/axis/
+
+# Uncomment this line to disable JDBC tests.
+# Alternatively, add "-Dnotestjdbc=true" to your ant command
+#notestjdbc=true
+# Uncomment this line to disable load tests.
+# Alternatively, add "-Dnotestload=true" to your ant command
+#notestload=true

Added: lucene/mahout/trunk/core/taste-build.xml
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/taste-build.xml?rev=654943&view=auto
==============================================================================
--- lucene/mahout/trunk/core/taste-build.xml (added)
+++ lucene/mahout/trunk/core/taste-build.xml Fri May  9 14:35:12 2008
@@ -0,0 +1,347 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Temporarily, this ex-Taste build file is separate.
+  Next step is to integrate it. -->
+
+<project basedir="." default="build" name="mahout-taste">
+
+  <property file="taste-build.properties"/>
+  <property environment="env"/>
+  <property name="name" value="${ant.project.name}"/>
+  <property name="release-jar" value="${name}.jar"/>
+  <property name="release-ejb-jar" value="${name}-ejb.jar"/>
+  <property name="release-war" value="${name}.war"/>
+  <property name="release-zip" value="${name}-${version}.zip"/>
+
+  <target name="init">
+    <tstamp/>
+    <available file="${proguard.jar}" property="proguard.jar.present"/>
+    <available file="${mysql.jar}" property="mysql.jar.present"/>
+    <available type="dir" file="${axis.jars}" property="axis.jars.present"/>
+  </target>
+
+  <target depends="init" name="build-except-jdbc" description="Compiles all but JDBC-related
code">
+    <mkdir dir="build"/>
+    <javac source="1.5"
+           target="1.5"
+           deprecation="true"
+           destdir="build"
+           debug="true"
+           optimize="true"
+           srcdir="src/main/java">
+      <compilerarg value="-Xlint:all,-serial,-unchecked"/>
+      <classpath>
+        <pathelement location="${ejb.jar}"/>
+        <pathelement location="${servlet.jar}"/>
+      </classpath>
+      <include name="org/apache/mahout/cf/taste/**"/>
+      <exclude name="org/apache/mahout/cf/taste/impl/model/jdbc/**"/>
+      <exclude name="org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/**"/>
+    </javac>
+  </target>
+
+  <target depends="init,build-except-jdbc" name="build-jdbc" description="Compiles JDBC-related
code" if="mysql.jar.present">
+    <javac source="1.5"
+           target="1.5"
+           deprecation="true"
+           destdir="build"
+           debug="true"
+           optimize="true"
+           srcdir="src/main/java">
+      <compilerarg value="-Xlint:all,-serial,-unchecked"/>
+      <classpath>
+        <pathelement location="${dbcp.jar}"/>
+        <pathelement location="${pool.jar}"/>
+        <pathelement location="${mysql.jar}"/>
+        <pathelement location="build"/>
+      </classpath>
+      <include name="org/apache/mahout/cf/taste/impl/model/jdbc/**"/>
+      <include name="org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/**"/>
+    </javac>
+  </target>
+
+  <target depends="init,build-except-jdbc,build-jdbc" name="build" description="Compiles
all code">
+    <jar jarfile="${release-jar}">
+      <fileset dir="build">
+        <include name="org/apache/mahout/cf/taste/**"/>        
+        <exclude name="org/apache/mahout/cf/taste/web/**"/>
+        <exclude name="org/apache/mahout/cf/taste/ejb/**"/>
+        <exclude name="org/apache/mahout/cf/taste/example/**"/>
+      </fileset>
+    </jar>
+  </target>
+
+  <target depends="build" name="optimize" description="Optimizes code" if="proguard.jar.present">
+    <property name="rt.jar" value="${env.JDK_HOME}/jre/lib/rt.jar"/>
+    <fail message="Can't find JDK classes at ${rt.jar}; is JDK_HOME set?">
+      <condition>
+        <not>
+          <available type="file" file="${rt.jar}"/>
+        </not>
+      </condition>
+    </fail>
+    <move file="${release-jar}" tofile="temp.jar"/>
+    <java jar="${proguard.jar}" fork="true" failonerror="true">
+      <arg value="-injars temp.jar"/>
+      <arg value="-outjars ${release-jar}"/>
+      <arg value="-libraryjars ${env.JDK_HOME}/jre/lib/rt.jar"/>
+      <arg value="-libraryjars ${pool.jar}"/>
+      <arg value="-ignorewarnings"/>
+      <arg value="-dontshrink"/>
+      <arg value="-dontobfuscate"/>
+      <arg value="-optimizationpasses 6"/>
+      <arg value="-keep public class * { public protected *; }"/>
+      <arg value="-target 5"/>
+      <arg value="-verbose"/>
+    </java>
+    <delete file="temp.jar"/>
+  </target>
+
+  <target depends="build,optimize" name="build-ejb" description="Builds deployable EJB
component">
+    <fail unless="my-recommender.jar" message="Please set -Dmy-recommender.jar=XXX"/>
+    <fail unless="my-recommender-class" message="Please set -Dmy-recommender-class=XXX"/>
+    <property name="my-ejb-jar.xml" value="${java.io.tmpdir}/ejb-jar.xml"/>
+    <copy file="src/main/java/org/apache/mahout/cf/taste/ejb/ejb-jar.xml" tofile="${my-ejb-jar.xml}">
+      <filterset>
+        <filter token="RECOMMENDER_CLASS" value="${my-recommender-class}"/>
+      </filterset>
+    </copy>
+    <jar jarfile="${release-ejb-jar}">
+      <fileset dir="build">
+        <include name="org/apache/mahout/cf/taste/ejb/**"/>
+      </fileset>
+      <zipfileset src="${release-jar}"/>
+      <metainf file="${my-ejb-jar.xml}"/>
+    </jar>
+    <delete file="${my-ejb-jar.xml}"/>
+  </target>
+
+  <target depends="build" name="build-test" description="Builds test classes">
+    <mkdir dir="build-test"/>
+    <javac source="1.5"
+           target="1.5"
+           debug="true"
+           debuglevel="lines,vars,source"
+           deprecation="true"
+           destdir="build-test"
+           srcdir="src/test/java">
+      <compilerarg value="-Xlint:all,-serial"/>
+      <classpath>
+        <pathelement location="${junit.jar}"/>
+        <pathelement location="${mysql.jar}"/>
+        <pathelement location="${release-jar}"/>
+      </classpath>
+      <include name="org/apache/mahout/cf/taste/**"/>
+    </javac>
+  </target>
+
+  <target depends="build,optimize" name="build-server" description="Builds deployable
web-based Taste server">
+    <fail unless="my-recommender.jar" message="Please set -Dmy-recommender.jar=XXX"/>
+    <fail unless="my-recommender-class" message="Please set -Dmy-recommender-class=XXX"/>
+    <fail unless="axis.jars.present" message="Please copy all Axis Java 1.4 .jar files
from its lib directory into ${axis.jars}"/>
+    <tempfile property="my-web.xml"/>
+    <copy file="src/main/java/org/apache/mahout/cf/taste/web/web.xml" tofile="${my-web.xml}">
+      <filterset>
+        <filter token="RECOMMENDER_CLASS" value="${my-recommender-class}"/>
+      </filterset>
+    </copy>
+    <war destfile="${release-war}" webxml="${my-web.xml}">
+      <lib dir=".">
+        <include name="${release-jar}"/>
+        <include name="${my-recommender.jar}"/>
+      </lib>
+      <lib dir="${axis.jars}"/>
+      <classes dir="build">
+        <include name="org/apache/mahout/cf/taste/web/**"/>
+      </classes>
+      <fileset dir="src/main/java/org/apache/mahout/cf/taste/web">
+        <include name="RecommenderService.jws"/>
+      </fileset>
+    </war>
+    <delete file="${my-web.xml}"/>
+  </target>
+
+  <target depends="init,build" name="build-grouplens-example" description="Builds deployable
GroupLens example">
+    <property name="grouplens-location" value="src/main/examples/org/apache/mahout/cf/taste/example/grouplens"/>
+    <fail message="Please download and install the GroupLens .dat files to ${grouplens-location}">
+      <condition>
+        <not>
+          <and>
+            <available type="file" file="${grouplens-location}/ratings.dat"/>
+            <available type="file" file="${grouplens-location}/movies.dat"/>
+          </and>
+        </not>
+      </condition>
+    </fail>
+    <javac source="1.5"
+           target="1.5"
+           deprecation="true"
+           debug="true"
+           optimize="true"
+           destdir="build"
+           srcdir="src/main/examples">
+      <compilerarg value="-Xlint:all,-serial"/>
+      <classpath>
+        <pathelement location="${release-jar}"/>
+      </classpath>
+    </javac>
+    <jar jarfile="grouplens.jar">
+      <include name="${grouplens-location}/ratings.dat"/>
+      <include name="${grouplens-location}/movies.dat"/>
+      <fileset dir="build">
+        <include name="org/apache/mahout/cf/taste/example/grouplens/**"/>
+      </fileset>
+    </jar>
+    <property name="my-recommender.jar" value="grouplens.jar"/>
+    <property name="my-recommender-class" value="org.apache.mahout.cf.taste.example.grouplens.GroupLensRecommender"/>
+    <antcall target="build-server"/>
+  </target>
+
+  <target depends="build-grouplens-example" name="eval-grouplens-example"
+          description="Evaluates current GroupLens example Recommender">
+    <java classname="org.apache.mahout.cf.taste.example.grouplens.GroupLensRecommenderEvaluatorRunner"
fork="true">
+      <assertions>
+        <disable/>
+      </assertions>
+      <jvmarg line="-server"/>
+      <jvmarg line="-Xmx1024m"/>
+      <classpath>
+        <pathelement location="${release-jar}"/>
+        <pathelement location="grouplens.jar"/>
+      </classpath>
+    </java>
+  </target>
+
+  <target depends="build,optimize,build-test" name="test-quick" description="Runs quick
unit tests">
+    <junit printsummary="on" haltonfailure="on" haltonerror="on" fork="on">
+      <formatter type="plain" usefile="false"/>
+      <classpath>
+        <pathelement location="${junit.jar}"/>
+        <pathelement location="${release-jar}"/>
+        <pathelement location="build-test"/>
+      </classpath>
+      <assertions>
+        <enable/>
+      </assertions>
+      <batchtest>
+        <fileset dir="src/test/java">
+          <include name="org/apache/mahout/cf/taste/**/*Test.java"/>
+          <exclude name="org/apache/mahout/cf/taste/impl/model/jdbc/*.java"/>
+          <exclude name="org/apache/mahout/cf/taste/impl/LoadTest.java"/>
+        </fileset>
+      </batchtest>
+    </junit>
+  </target>
+
+  <target depends="test-quick,test-jdbc,test-load" name="test" description="Runs all unit
tests"/>
+
+  <target depends="build,optimize,build-test" name="test-jdbc" unless="notestjdbc" description="Runs
JDBC unit tests">
+    <junit printsummary="on" haltonfailure="on" haltonerror="on" fork="on">
+      <formatter type="plain" usefile="false"/>
+      <classpath>
+        <pathelement location="${junit.jar}"/>
+        <pathelement location="${mysql.jar}"/>
+        <pathelement location="${release-jar}"/>
+        <pathelement location="build-test"/>
+      </classpath>
+      <assertions>
+        <enable/>
+      </assertions>
+      <batchtest>
+        <fileset dir="src/test/java">
+          <include name="org/apache/mahout/cf/taste/impl/model/jdbc/*Test.java"/>
+        </fileset>
+      </batchtest>
+    </junit>
+  </target>
+
+  <target depends="build,optimize,build-test" name="test-load" unless="notestload" description="Runs
load tests">
+    <junit printsummary="on" haltonfailure="on" haltonerror="on" fork="on">
+      <formatter type="plain" usefile="false"/>
+      <classpath>
+        <pathelement location="${junit.jar}"/>
+        <pathelement location="${release-jar}"/>
+        <pathelement location="build-test"/>
+      </classpath>
+      <assertions>
+        <disable/>
+      </assertions>
+      <jvmarg value="-server"/>
+      <jvmarg value="-Xmx512m"/>
+      <batchtest>
+        <fileset dir="src/test/java">
+          <include name="org/apache/mahout/cf/taste/impl/LoadTest.java"/>
+        </fileset>
+      </batchtest>
+    </junit>
+  </target>
+
+  <target depends="init" name="javadoc" description="Builds javadoc documentation">
+    <mkdir dir="docs/javadoc"/>
+    <javadoc destdir="docs/javadoc">
+      <fileset dir="src/main/java">
+        <include name="**/*.java"/>
+      </fileset>
+      <classpath>
+        <pathelement location="${ejb.jar}"/>
+        <pathelement location="${servlet.jar}"/>
+        <pathelement location="${dbcp.jar}"/>
+        <pathelement location="${pool.jar}"/>
+        <pathelement location="${mysql.jar}"/>
+      </classpath>
+    </javadoc>
+  </target>
+
+  <target depends="clean,test,build-grouplens-example,javadoc" name="release"
+          description="Builds a release package">
+    <zip destfile="${release-zip}" basedir=".">
+      <include name="${release-jar}"/>
+      <include name="src/main/java/org/apache/mahout/cf/taste/**"/>
+      <include name="src/main/examples/org/apache/mahout/cf/taste/**"/>
+      <include name="src/test/java/org/apache/mahout/cf/taste/**"/>
+      <!-- Make sure GroupLens data is not redistributed -->
+      <exclude name="src/**/*.dat"/>
+      <include name="docs/**"/>
+      <include name="lib/**"/>
+      <exclude name="lib/mysql*"/>
+      <exclude name="lib/proguard*"/>
+      <include name="build.xml"/>
+      <include name="build.properties"/>
+      <include name="CHANGES"/>
+      <include name="LICENSE"/>
+    </zip>
+  </target>
+
+  <target depends="init" name="clean" description="Deletes build products">
+    <delete dir="build"/>
+    <delete dir="build-test"/>
+    <delete dir="docs/javadoc"/>
+    <delete dir="target"/>
+    <delete file="${release-jar}"/>
+    <delete file="${release-zip}"/>
+    <delete file="${release-war}"/>
+    <delete>
+      <fileset dir=".">
+        <include name="mahout*.jar"/>
+      </fileset>
+    </delete>
+  </target>
+
+</project>



Mime
View raw message