You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@predictionio.apache.org by ch...@apache.org on 2017/09/28 15:55:06 UTC
[25/57] [abbrv] incubator-predictionio git commit: [PIO-107] Removal
of examples under examples/experimental.
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/DataSource.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/DataSource.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/DataSource.java
deleted file mode 100644
index f8c5907..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/DataSource.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial1;
-
-import org.apache.predictionio.controller.java.LJavaDataSource;
-import scala.Tuple2;
-import scala.Tuple3;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.lang.Iterable;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Scanner;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class DataSource extends LJavaDataSource<
- DataSourceParams, Object, TrainingData, Query, Object> {
-
- final static Logger logger = LoggerFactory.getLogger(DataSource.class);
-
- DataSourceParams params;
-
- public DataSource(DataSourceParams params) {
- this.params = params;
- }
-
- @Override
- public Iterable<Tuple3<Object, TrainingData, Iterable<Tuple2<Query, Object>>>> read() {
-
- File ratingFile = new File(params.filePath);
- Scanner sc = null;
-
- try {
- sc = new Scanner(ratingFile);
- } catch (FileNotFoundException e) {
- logger.error("Caught FileNotFoundException " + e.getMessage());
- System.exit(1);
- }
-
- List<TrainingData.Rating> ratings = new ArrayList<TrainingData.Rating>();
-
- while (sc.hasNext()) {
- String line = sc.nextLine();
- String[] tokens = line.split("[\t,]");
- try {
- TrainingData.Rating rating = new TrainingData.Rating(
- Integer.parseInt(tokens[0]),
- Integer.parseInt(tokens[1]),
- Float.parseFloat(tokens[2]));
- ratings.add(rating);
- } catch (Exception e) {
- logger.error("Can't parse rating file. Caught Exception: " + e.getMessage());
- System.exit(1);
- }
- }
-
- List<Tuple3<Object, TrainingData, Iterable<Tuple2<Query, Object>>>> data =
- new ArrayList<Tuple3<Object, TrainingData, Iterable<Tuple2<Query, Object>>>>();
-
- data.add(new Tuple3<Object, TrainingData, Iterable<Tuple2<Query, Object>>>(
- null,
- new TrainingData(ratings),
- new ArrayList<Tuple2<Query, Object>>()
- ));
-
- return data;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/DataSourceParams.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/DataSourceParams.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/DataSourceParams.java
deleted file mode 100644
index aae78c6..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/DataSourceParams.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial1;
-
-import org.apache.predictionio.controller.java.JavaParams;
-
-public class DataSourceParams implements JavaParams {
- public String filePath; // file path
-
- public DataSourceParams(String path) {
- this.filePath = path;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/EngineFactory.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/EngineFactory.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/EngineFactory.java
deleted file mode 100644
index 66bcee9..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/EngineFactory.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial1;
-
-import org.apache.predictionio.controller.java.IJavaEngineFactory;
-import org.apache.predictionio.controller.java.JavaSimpleEngine;
-import org.apache.predictionio.controller.java.JavaSimpleEngineBuilder;
-
-public class EngineFactory implements IJavaEngineFactory {
- public JavaSimpleEngine<TrainingData, Object, Query, Float, Object> apply() {
- return new JavaSimpleEngineBuilder<
- TrainingData, Object, Query, Float, Object> ()
- .dataSourceClass(DataSource.class)
- .preparatorClass() // Use default Preparator
- .addAlgorithmClass("MyRecommendationAlgo", Algorithm.class)
- .servingClass() // Use default Serving
- .build();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/Model.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/Model.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/Model.java
deleted file mode 100644
index 0d4a2ab..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/Model.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial1;
-
-import java.io.Serializable;
-import java.util.Map;
-import org.apache.commons.math3.linear.RealVector;
-
-public class Model implements Serializable {
- public Map<Integer, RealVector> itemSimilarity;
- public Map<Integer, RealVector> userHistory;
-
- public Model(Map<Integer, RealVector> itemSimilarity,
- Map<Integer, RealVector> userHistory) {
- this.itemSimilarity = itemSimilarity;
- this.userHistory = userHistory;
- }
-
- @Override
- public String toString() {
- String s;
- if ((itemSimilarity.size() > 20) || (userHistory.size() > 20)) {
- s = "Model: [itemSimilarity.size=" + itemSimilarity.size() + "]\n"
- +"[userHistory.size=" + userHistory.size() + "]";
- } else {
- s = "Model: [itemSimilarity: " + itemSimilarity.toString() + "]\n"
- +"[userHistory: " + userHistory.toString() + "]";
- }
- return s;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/Query.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/Query.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/Query.java
deleted file mode 100644
index b17e5a0..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/Query.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial1;
-
-import java.io.Serializable;
-
-public class Query implements Serializable {
- public int uid; // user ID
- public int iid; // item ID
-
- public Query(int uid, int iid) {
- this.uid = uid;
- this.iid = iid;
- }
-
- @Override
- public String toString() {
- return "(" + uid + "," + iid + ")";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/TrainingData.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/TrainingData.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/TrainingData.java
deleted file mode 100644
index a4cb567..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/TrainingData.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial1;
-
-import java.io.Serializable;
-import java.util.List;
-
-public class TrainingData implements Serializable {
- public List<Rating> ratings;
-
- public TrainingData(List<Rating> ratings) {
- this.ratings = ratings;
- }
-
- @Override
- public String toString() {
- String s;
- if (ratings.size() > 20)
- s = "TrainingData.size=" + ratings.size();
- else
- s = ratings.toString();
- return s;
- }
-
- public static class Rating implements Serializable {
- public int uid; // user ID
- public int iid; // item ID
- public float rating;
-
- public Rating(int uid, int iid, float rating) {
- this.uid = uid;
- this.iid = iid;
- this.rating = rating;
- }
-
- @Override
- public String toString() {
- return "(" + uid + "," + iid + "," + rating + ")";
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/engine.json
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/engine.json b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/engine.json
deleted file mode 100644
index 12c3927..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/engine.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "id": "org.apache.predictionio.examples.java.recommendations.tutorial1.EngineFactory",
- "version": "0.9.1",
- "name": "Simple Recommendations Engine",
- "engineFactory": "org.apache.predictionio.examples.java.recommendations.tutorial1.EngineFactory"
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/params/algorithms.json
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/params/algorithms.json b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/params/algorithms.json
deleted file mode 100644
index 0f9715e..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/params/algorithms.json
+++ /dev/null
@@ -1,5 +0,0 @@
-[
- { "name": "MyRecommendationAlgo",
- "params" : { "threshold" : 0.2 }
- }
-]
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/params/datasource.json
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/params/datasource.json b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/params/datasource.json
deleted file mode 100644
index bf00f87..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial1/params/datasource.json
+++ /dev/null
@@ -1 +0,0 @@
-{ "filePath" : "data/ml-100k/u.data" }
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial2/Runner1.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial2/Runner1.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial2/Runner1.java
deleted file mode 100644
index 71b694a..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial2/Runner1.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial2;
-
-import org.apache.predictionio.examples.java.recommendations.tutorial1.TrainingData;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.Query;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.DataSource;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.DataSourceParams;
-
-import org.apache.predictionio.controller.java.EmptyParams;
-import org.apache.predictionio.controller.java.IJavaEngineFactory;
-import org.apache.predictionio.controller.java.JavaSimpleEngine;
-import org.apache.predictionio.controller.java.JavaSimpleEngineBuilder;
-import org.apache.predictionio.controller.java.JavaEngineParams;
-import org.apache.predictionio.controller.java.JavaEngineParamsBuilder;
-import org.apache.predictionio.controller.java.JavaWorkflow;
-import org.apache.predictionio.controller.java.WorkflowParamsBuilder;
-import java.util.HashMap;
-
-public class Runner1 {
-
- // During development, one can build a semi-engine, only add the first few layers. In this
- // particular example, we only add until dataSource layer
- private static class HalfBakedEngineFactory implements IJavaEngineFactory {
- public JavaSimpleEngine<TrainingData, Object, Query, Float, Object> apply() {
- return new JavaSimpleEngineBuilder<
- TrainingData, Object, Query, Float, Object> ()
- .dataSourceClass(DataSource.class)
- .build();
- }
- }
-
- public static void runComponents(String filePath) {
- JavaEngineParams engineParams = new JavaEngineParamsBuilder()
- .dataSourceParams(new DataSourceParams(filePath))
- .build();
-
- JavaWorkflow.runEngine(
- (new HalfBakedEngineFactory()).apply(),
- engineParams,
- null,
- new EmptyParams(),
- new WorkflowParamsBuilder().batch("MyEngine").verbose(3).build()
- );
- }
-
- public static void main(String[] args) {
- if (args.length == 0) {
- System.out.println("Error: Please specify the file path as argument");
- System.exit(1);
- }
- runComponents(args[0]);
- System.exit(0); // clean shutdown is needed for spark
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial2/Runner2.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial2/Runner2.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial2/Runner2.java
deleted file mode 100644
index 1d82ad1..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial2/Runner2.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial2;
-
-import org.apache.predictionio.examples.java.recommendations.tutorial1.TrainingData;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.Query;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.DataSource;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.DataSourceParams;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.Algorithm;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.AlgoParams;
-
-import org.apache.predictionio.controller.java.EmptyParams;
-import org.apache.predictionio.controller.java.IJavaEngineFactory;
-import org.apache.predictionio.controller.java.JavaSimpleEngine;
-import org.apache.predictionio.controller.java.JavaSimpleEngineBuilder;
-import org.apache.predictionio.controller.java.JavaEngineParams;
-import org.apache.predictionio.controller.java.JavaEngineParamsBuilder;
-import org.apache.predictionio.controller.java.JavaWorkflow;
-import org.apache.predictionio.controller.java.WorkflowParamsBuilder;
-
-import java.util.HashMap;
-
-import org.apache.predictionio.controller.IdentityPreparator;
-
-public class Runner2 {
-
- // During development, one can build a semi-engine, only add the first few layers. In this
- // particular example, we only add until dataSource layer
- private static class HalfBakedEngineFactory implements IJavaEngineFactory {
- public JavaSimpleEngine<TrainingData, Object, Query, Float, Object> apply() {
- return new JavaSimpleEngineBuilder<
- TrainingData, Object, Query, Float, Object> ()
- .dataSourceClass(DataSource.class)
- .preparatorClass() // Use default Preparator
- .addAlgorithmClass("MyRecommendationAlgo", Algorithm.class) // Add Algorithm
- .build();
- }
- }
-
- public static void runComponents(String filePath) {
- JavaEngineParams engineParams = new JavaEngineParamsBuilder()
- .dataSourceParams(new DataSourceParams(filePath))
- .addAlgorithmParams("MyRecommendationAlgo", new AlgoParams(0.2)) // Add Algorithm Params
- .build();
-
- JavaWorkflow.runEngine(
- (new HalfBakedEngineFactory()).apply(),
- engineParams,
- null,
- new EmptyParams(),
- new WorkflowParamsBuilder().batch("MyEngine").verbose(3).build()
- );
- }
-
- public static void main(String[] args) {
- if (args.length == 0) {
- System.out.println("Error: Please specify the file path as argument");
- System.exit(1);
- }
- runComponents(args[0]);
- System.exit(0); // clean shutdown is needed for spark
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/DataSource.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/DataSource.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/DataSource.java
deleted file mode 100644
index 1ee125d..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/DataSource.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial3;
-
-import org.apache.predictionio.examples.java.recommendations.tutorial1.TrainingData;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.Query;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.DataSourceParams;
-
-import org.apache.predictionio.controller.java.LJavaDataSource;
-import scala.Tuple2;
-import scala.Tuple3;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.lang.Iterable;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Scanner;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Random;
-import java.util.Collections;
-
-public class DataSource extends LJavaDataSource<
- DataSourceParams, Object, TrainingData, Query, Float> {
-
- final static Logger logger = LoggerFactory.getLogger(DataSource.class);
-
- DataSourceParams params;
-
- public DataSource(DataSourceParams params) {
- this.params = params;
- }
-
- @Override
- public Iterable<Tuple3<Object, TrainingData, Iterable<Tuple2<Query, Float>>>> read() {
-
- File ratingFile = new File(params.filePath);
- Scanner sc = null;
-
- try {
- sc = new Scanner(ratingFile);
- } catch (FileNotFoundException e) {
- logger.error("Caught FileNotFoundException " + e.getMessage());
- System.exit(1);
- }
-
- List<TrainingData.Rating> ratings = new ArrayList<TrainingData.Rating>();
-
- while (sc.hasNext()) {
- String line = sc.nextLine();
- String[] tokens = line.split("[\t,]");
- try {
- TrainingData.Rating rating = new TrainingData.Rating(
- Integer.parseInt(tokens[0]),
- Integer.parseInt(tokens[1]),
- Float.parseFloat(tokens[2]));
- ratings.add(rating);
- } catch (Exception e) {
- logger.error("Can't parse rating file. Caught Exception: " + e.getMessage());
- System.exit(1);
- }
- }
-
- int size = ratings.size();
- float trainingPercentage = 0.8f;
- float testPercentage = 1 - trainingPercentage;
- int iterations = 3;
-
- // cap by original size
- int trainingEndIndex = Math.min(size,
- (int) (ratings.size() * trainingPercentage));
- int testEndIndex = Math.min(size,
- trainingEndIndex + (int) (ratings.size() * testPercentage));
- // trainingEndIndex + 10);
-
- Random rand = new Random(0); // seed
-
- List<Tuple3<Object, TrainingData, Iterable<Tuple2<Query, Float>>>> data = new
- ArrayList<Tuple3<Object, TrainingData, Iterable<Tuple2<Query, Float>>>>();
-
- for (int i = 0; i < iterations; i++) {
- Collections.shuffle(ratings, new Random(rand.nextInt()));
-
- // create a new ArrayList because subList() returns view and not serialzable
- List<TrainingData.Rating> trainingRatings =
- new ArrayList<TrainingData.Rating>(ratings.subList(0, trainingEndIndex));
- List<TrainingData.Rating> testRatings = ratings.subList(trainingEndIndex, testEndIndex);
- TrainingData td = new TrainingData(trainingRatings);
- List<Tuple2<Query, Float>> qaList = prepareValidation(testRatings);
-
- data.add(new Tuple3<Object, TrainingData, Iterable<Tuple2<Query, Float>>>(
- null, td, qaList));
- }
-
- return data;
- }
-
- private List<Tuple2<Query, Float>> prepareValidation(List<TrainingData.Rating> testRatings) {
- List<Tuple2<Query, Float>> validationList = new ArrayList<Tuple2<Query, Float>>();
-
- for (TrainingData.Rating r : testRatings) {
- validationList.add(new Tuple2<Query, Float>(
- new Query(r.uid, r.iid),
- r.rating));
- }
-
- return validationList;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/EngineFactory.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/EngineFactory.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/EngineFactory.java
deleted file mode 100644
index 67c2afc..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/EngineFactory.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial3;
-
-import org.apache.predictionio.examples.java.recommendations.tutorial1.Algorithm;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.TrainingData;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.Query;
-
-import org.apache.predictionio.controller.java.IJavaEngineFactory;
-import org.apache.predictionio.controller.java.JavaSimpleEngine;
-import org.apache.predictionio.controller.java.JavaSimpleEngineBuilder;
-
-public class EngineFactory implements IJavaEngineFactory {
- public JavaSimpleEngine<TrainingData, Object, Query, Float, Float> apply() {
- return new JavaSimpleEngineBuilder<
- TrainingData, Object, Query, Float, Float> ()
- .dataSourceClass(DataSource.class)
- .preparatorClass() // Use default Preparator
- .addAlgorithmClass("MyRecommendationAlgo", Algorithm.class)
- .servingClass() // Use default Serving
- .build();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/Evaluator.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/Evaluator.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/Evaluator.java
deleted file mode 100644
index a5c712d..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/Evaluator.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial3;
-
-import org.apache.predictionio.examples.java.recommendations.tutorial1.Query;
-import org.apache.predictionio.controller.java.JavaEvaluator;
-import org.apache.predictionio.controller.java.EmptyParams;
-
-import scala.Tuple2;
-import java.util.Arrays;
-import org.apache.commons.collections.IteratorUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/** Root mean square error */
-public class Evaluator
- extends JavaEvaluator<EmptyParams, Object, Query, Float, Float,
- Double, Double, String> {
-
- final static Logger logger = LoggerFactory.getLogger(Evaluator.class);
-
- @Override
- public Double evaluateUnit(Query query, Float predicted, Float actual) {
- logger.info("Q: " + query.toString() + " P: " + predicted + " A: " + actual);
- // return squared error
- double error;
- if (predicted.isNaN())
- error = -actual;
- else
- error = predicted - actual;
- return (error * error);
- }
-
- @Override
- public Double evaluateSet(Object dataParams, Iterable<Double> metricUnits) {
- double sum = 0.0;
- int count = 0;
- for (double squareError : metricUnits) {
- sum += squareError;
- count += 1;
- }
- return Math.sqrt(sum / count);
- }
-
- @Override
- public String evaluateAll(
- Iterable<Tuple2<Object, Double>> input) {
- return Arrays.toString(IteratorUtils.toArray(input.iterator()));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/Runner3.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/Runner3.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/Runner3.java
deleted file mode 100644
index dbd5baa..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial3/Runner3.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial3;
-
-import org.apache.predictionio.examples.java.recommendations.tutorial1.DataSourceParams;
-import org.apache.predictionio.examples.java.recommendations.tutorial1.AlgoParams;
-
-import org.apache.predictionio.controller.java.EmptyParams;
-import org.apache.predictionio.controller.java.IJavaEngineFactory;
-import org.apache.predictionio.controller.java.JavaSimpleEngine;
-import org.apache.predictionio.controller.java.JavaSimpleEngineBuilder;
-import org.apache.predictionio.controller.java.JavaEngineParams;
-import org.apache.predictionio.controller.java.JavaEngineParamsBuilder;
-import org.apache.predictionio.controller.java.JavaWorkflow;
-import org.apache.predictionio.controller.java.WorkflowParamsBuilder;
-
-import java.util.HashMap;
-
-public class Runner3 {
-
- public static void runEvaluation(String filePath) {
- JavaEngineParams engineParams = new JavaEngineParamsBuilder()
- .dataSourceParams(new DataSourceParams(filePath))
- .addAlgorithmParams("MyRecommendationAlgo", new AlgoParams(0.2))
- .build();
-
- JavaWorkflow.runEngine(
- (new EngineFactory()).apply(),
- engineParams,
- Evaluator.class,
- new EmptyParams(),
- new WorkflowParamsBuilder().batch("MyEngine").verbose(3).build()
- );
- }
-
- public static void main(String[] args) {
- if (args.length == 0) {
- System.out.println("Error: Please specify the file path as argument");
- System.exit(1);
- }
- runEvaluation(args[0]);
- System.exit(0); // clean shutdown is needed for spark
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/CollaborativeFilteringAlgorithm.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/CollaborativeFilteringAlgorithm.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/CollaborativeFilteringAlgorithm.java
deleted file mode 100644
index 70e5eb2..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/CollaborativeFilteringAlgorithm.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import org.apache.predictionio.controller.java.LJavaAlgorithm;
-import org.apache.commons.math3.linear.RealVector;
-import org.apache.commons.math3.linear.ArrayRealVector;
-import org.apache.commons.math3.linear.OpenMapRealVector;
-import scala.Tuple2;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Queue;
-import java.util.PriorityQueue;
-import java.util.Comparator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class CollaborativeFilteringAlgorithm extends
- LJavaAlgorithm<CollaborativeFilteringAlgorithmParams, PreparedData, CollaborativeFilteringModel,
- Query, Float> {
-
- final static Logger logger = LoggerFactory.getLogger(CollaborativeFilteringAlgorithm.class);
-
- CollaborativeFilteringAlgorithmParams params;
-
- public CollaborativeFilteringAlgorithm(CollaborativeFilteringAlgorithmParams params) {
- this.params = params;
- }
-
- @Override
- public CollaborativeFilteringModel train(PreparedData data) {
- // pre-process
- Map<Integer, Map<Integer, Float>> itemMap = new HashMap<Integer, Map<Integer, Float>>();
- Map<Integer, Integer> userIndexMap = new HashMap<Integer, Integer>();
- Map<Integer, Integer> itemIndexMap = new HashMap<Integer, Integer>();
-
- int itemIndex = 0;
- int userIndex = 0;
- for (TrainingData.Rating r : data.ratings) {
- Map<Integer, Float> userRating = itemMap.get(r.iid);
- if (userRating == null) {
- // new item
- userRating = new HashMap<Integer, Float>();
- itemMap.put(r.iid, userRating);
- itemIndexMap.put(r.iid, itemIndex);
- itemIndex += 1; // increment item index for next item
- }
- userRating.put(r.uid, r.rating);
-
- // update user index
- Integer u = userIndexMap.get(r.uid);
- if (u == null) {
- // new user
- userIndexMap.put(r.uid, userIndex);
- userIndex += 1;
- }
- }
-
- int numOfItems = itemIndexMap.size();
- int numOfUsers = userIndexMap.size();
-
- Map<Integer, RealVector> itemVectors = new HashMap<Integer, RealVector>();
- Map<Integer, RealVector> userHistory = new HashMap<Integer, RealVector>();
-
- for (Map.Entry<Integer, Map<Integer, Float>> entry : itemMap.entrySet()) {
- Integer itemID = entry.getKey();
- Integer iindex = itemIndexMap.get(itemID);
- Map<Integer, Float> userRatingMap = entry.getValue();
- RealVector item = new ArrayRealVector(numOfUsers); // dimension is numOfUsers
- for (Map.Entry<Integer, Float> r : userRatingMap.entrySet()) {
- Integer userID = r.getKey();
- Float rating = r.getValue();
- Integer uindex = userIndexMap.get(userID);
- item.setEntry(uindex, rating);
- // update user History
- RealVector user = userHistory.get(userID);
- if (user == null) {
- user = new OpenMapRealVector(numOfItems);
- userHistory.put(userID, user);
- }
- user.setEntry(iindex, rating);
- }
- itemVectors.put(itemID, item);
- }
-
- // calculate sim
-
- Map<Integer, RealVector> itemSimilarity = new HashMap<Integer, RealVector>();
- List<Integer> item1List = new ArrayList<Integer>(itemIndexMap.keySet());
- List<Integer> item2List = new ArrayList<Integer>(item1List);
-
- int numSimilarItems = 100;
- Comparator<IndexAndScore> comparator = new IndexAndScoreComparator();
- Map<Integer, Queue<IndexAndScore>> topItemSimilarity =
- new HashMap<Integer, Queue<IndexAndScore>>();
-
- for (Integer itemID1 : item1List) {
- item2List.remove(0);
- Integer index1 = itemIndexMap.get(itemID1);
- for (Integer itemID2: item2List) {
- RealVector vector1 = itemVectors.get(itemID1);
- RealVector vector2 = itemVectors.get(itemID2);
- double score = vector1.cosine(vector2);
- if (score > params.threshold) {
- Integer index2 = itemIndexMap.get(itemID2);
- setTopItemSimilarity(topItemSimilarity, itemID1, index2, score, numSimilarItems,
- comparator);
- setTopItemSimilarity(topItemSimilarity, itemID2, index1, score, numSimilarItems,
- comparator);
- }
- }
- }
-
- for (Map.Entry<Integer, Queue<IndexAndScore>> entry : topItemSimilarity.entrySet()) {
- Iterator<IndexAndScore> it = entry.getValue().iterator();
- RealVector vector = new OpenMapRealVector(numOfItems);
- while (it.hasNext()) {
- IndexAndScore d = it.next();
- vector.setEntry(d.index, d.score);
- }
- itemSimilarity.put(entry.getKey(), vector);
- }
-
- return new CollaborativeFilteringModel(itemSimilarity, userHistory);
- }
-
- private class IndexAndScore {
- int index;
- double score;
- public IndexAndScore(int index, double score) {
- this.index = index;
- this.score = score;
- }
- }
-
- private class IndexAndScoreComparator implements Comparator<IndexAndScore> {
- @Override
- public int compare(IndexAndScore o1, IndexAndScore o2) {
- int r = 0;
- if (o1.score < o2.score)
- r = -1;
- else if (o1.score > o2.score)
- r = 1;
- return r;
- }
- }
-
- private void setTopItemSimilarity(Map<Integer, Queue<IndexAndScore>> topItemSimilarity,
- Integer itemID1, Integer index2, double score, int capacity,
- Comparator<IndexAndScore> comparator) {
- Queue<IndexAndScore> queue = topItemSimilarity.get(itemID1);
- if (queue == null) {
- queue = new PriorityQueue<IndexAndScore>(capacity, comparator);
- topItemSimilarity.put(itemID1, queue);
- }
- IndexAndScore entry = new IndexAndScore(index2, score);
- if (queue.size() < capacity)
- queue.add(entry);
- else if (comparator.compare(queue.peek(), entry) < 0) {
- queue.poll();
- queue.add(entry);
- }
- }
-
- @Override
- public Float predict(CollaborativeFilteringModel model, Query query) {
- RealVector itemVector = model.itemSimilarity.get(query.iid);
- RealVector userVector = model.userHistory.get(query.uid);
- if (itemVector == null) {
- // cold start item, can't be handled by this algo, return hard code value.
- return Float.NaN;
- } else if (userVector == null) {
- // new user, can't be handled by this algo, return hard code value.
- return Float.NaN;
- } else {
- //logger.info("(" + query.uid + "," + query.iid + ")");
- //logger.info(itemVector.toString());
- //logger.info(userVector.toString());
- double accum = 0.0;
- double accumSim = 0.0;
- for (int i = 0; i < itemVector.getDimension(); i++) {
- double weight = itemVector.getEntry(i);
- double rating = userVector.getEntry(i);
- if ((weight != 0) && (rating != 0)) {
- accum += weight * rating;
- accumSim += Math.abs(weight);
- }
- }
-
- if (accumSim == 0.0) {
- return Float.NaN;
- } else {
- return (float) (accum / accumSim);
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/CollaborativeFilteringAlgorithmParams.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/CollaborativeFilteringAlgorithmParams.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/CollaborativeFilteringAlgorithmParams.java
deleted file mode 100644
index 1a43426..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/CollaborativeFilteringAlgorithmParams.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import org.apache.predictionio.controller.java.JavaParams;
-
-public class CollaborativeFilteringAlgorithmParams implements JavaParams {
- public double threshold;
-
- public CollaborativeFilteringAlgorithmParams(double threshold) {
- this.threshold = threshold;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/CollaborativeFilteringModel.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/CollaborativeFilteringModel.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/CollaborativeFilteringModel.java
deleted file mode 100644
index 9836a24..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/CollaborativeFilteringModel.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import java.io.Serializable;
-import java.util.Map;
-import org.apache.commons.math3.linear.RealVector;
-
-public class CollaborativeFilteringModel implements Serializable {
- public Map<Integer, RealVector> itemSimilarity;
- public Map<Integer, RealVector> userHistory;
-
- public CollaborativeFilteringModel(Map<Integer, RealVector> itemSimilarity,
- Map<Integer, RealVector> userHistory) {
- this.itemSimilarity = itemSimilarity;
- this.userHistory = userHistory;
- }
-
- @Override
- public String toString() {
- String s;
- if ((itemSimilarity.size() > 20) || (userHistory.size() > 20)) {
- s = "Model: [itemSimilarity.size=" + itemSimilarity.size() + "]\n"
- +"[userHistory.size=" + userHistory.size() + "]";
- } else {
- s = "Model: [itemSimilarity: " + itemSimilarity.toString() + "]\n"
- +"[userHistory: " + userHistory.toString() + "]";
- }
- return s;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/DataSource.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/DataSource.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/DataSource.java
deleted file mode 100644
index 3944e7e..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/DataSource.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import java.util.Arrays;
-import org.apache.predictionio.controller.java.LJavaDataSource;
-import org.apache.predictionio.controller.java.EmptyParams;
-import scala.Tuple2;
-import scala.Tuple3;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.lang.Iterable;
-import java.util.List;
-import java.util.Map;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Scanner;
-import java.util.HashMap;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import java.io.FileReader;
-import java.io.BufferedReader;
-
-
-public class DataSource extends LJavaDataSource<
- DataSourceParams, EmptyParams, TrainingData, Query, Object> {
-
- final static Logger logger = LoggerFactory.getLogger(DataSource.class);
-
- DataSourceParams params;
-
- public static class FakeData {
- // User -1 is a action movie lover. He should have high ratings for Item -2 ("Cold Action
- // Movie"). Notice that Item -2 is new, hence have no rating. Feature-based algorithm should be
- // able to return a high rating using user profile.
- public static final List<String> itemData = Arrays.asList(
- "-1|Action Movie (2046)|01-Jan-2046||http://i.dont.exist/|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0",
- "-2|Cold Action Movie II(2047)|01-Jan-2047||http://i.dont.exist/|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0",
- "-3|Documentary (1997)|01-July-1997||http://no.pun.intended/|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0|0|0");
- public static final List<String> userData = Arrays.asList(
- "-1|30|M|action_lover|94087",
- "-2|30|M|documentary_lover|94087",
- "-3|30|M|cold|94087");
- public static final List<String> ratingData = Arrays.asList(
- "-1,-1,5,881250949",
- "-2,-3,5,881250949",
- "-2,1,5,881250949");
- }
-
- public DataSource(DataSourceParams params) {
- this.params = params;
- }
-
- public List<String[]> readFile(String filepath, String delimiter) {
- return readFile(filepath, delimiter, new ArrayList<String>());
- }
-
- public List<String[]> readFile(String filepath, String delimiter, List<String> fakeData) {
- List<String[]> tokensList = new ArrayList<String[]>();
- try {
- List<String> lines = new ArrayList<String>();
- lines.addAll(fakeData);
-
- BufferedReader in = new BufferedReader(new FileReader(filepath));
-
- while (in.ready()) {
- String s = in.readLine();
- lines.add(s);
- }
- in.close();
-
- for (String line: lines) {
- String[] tokens = line.split(delimiter);
- tokensList.add(tokens);
- }
-
- } catch (FileNotFoundException e) {
- logger.error("Caught FileNotFoundException " + e.getMessage());
- System.exit(1);
- } catch (Exception e) {
- logger.error("Can't parse file. Caught Exception: " + e.getMessage()
- + "Trace: " + Arrays.toString(e.getStackTrace()));
- System.exit(1);
- }
-
- return tokensList;
- }
-
- public List<TrainingData.Rating> getRatings() {
- List<TrainingData.Rating> ratings = new ArrayList<TrainingData.Rating>();
-
- List<String[]> tokensList = readFile(params.dir + "u.data", "[\t,]",
- (params.addFakeData) ? FakeData.ratingData : new ArrayList<String>());
-
- for (String[] tokens: tokensList) {
- TrainingData.Rating rating = new TrainingData.Rating(
- Integer.parseInt(tokens[0]),
- Integer.parseInt(tokens[1]),
- Float.parseFloat(tokens[2]));
- ratings.add(rating);
- }
-
- return ratings;
- }
-
- public List<String> getGenres() {
- List<String> genres = new ArrayList<String>();
- for (String[] tokens: readFile(params.dir + "u.genre", "[\t,]")) {
- if (!tokens[0].equals("")) {
- genres.add(tokens[0]);
- }
- }
- return genres;
- }
-
- public Map<Integer, String[]> getItemInfo() {
- List<String[]> tokensList = readFile(params.dir + "u.item", "[\\|]",
- (params.addFakeData) ? FakeData.itemData : new ArrayList<String>());
-
-
- Map<Integer, String[]> itemInfo = new HashMap <> ();
- for (String[] tokens : tokensList) {
- itemInfo.put(Integer.parseInt(tokens[0]), tokens);
- }
-
- return itemInfo;
- }
-
- public Map<Integer, String[]> getUserInfo() {
- List<String[]> tokensList = readFile(params.dir + "u.user", "[\\|]",
- (params.addFakeData) ? FakeData.userData : new ArrayList<String>());
-
- Map<Integer, String[]> userInfo = new HashMap <> ();
- for (String[] tokens : tokensList) {
- userInfo.put(Integer.parseInt(tokens[0]), tokens);
- }
- return userInfo;
- }
-
- @Override
- public Iterable<Tuple3<EmptyParams, TrainingData, Iterable<Tuple2<Query, Object>>>> read() {
- List<Tuple3<EmptyParams, TrainingData, Iterable<Tuple2<Query, Object>>>> data =
- new ArrayList<Tuple3<EmptyParams, TrainingData, Iterable<Tuple2<Query, Object>>>>();
-
- data.add(new Tuple3<EmptyParams, TrainingData, Iterable<Tuple2<Query, Object>>>(
- new EmptyParams(),
- new TrainingData(getRatings(), getGenres(), getItemInfo(), getUserInfo()),
- new ArrayList<Tuple2<Query, Object>>()
- ));
-
- return data;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/DataSourceParams.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/DataSourceParams.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/DataSourceParams.java
deleted file mode 100644
index 46ad0ec..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/DataSourceParams.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import org.apache.predictionio.controller.java.JavaParams;
-
-public class DataSourceParams implements JavaParams {
- public String dir;
- public boolean addFakeData;
-
- public DataSourceParams(String dir, boolean addFakeData) {
- this.dir = dir;
- this.addFakeData = addFakeData;
- }
-
- public DataSourceParams(String dir) {
- this(dir, false);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/EngineFactory.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/EngineFactory.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/EngineFactory.java
deleted file mode 100644
index 8861a4c..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/EngineFactory.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import org.apache.predictionio.controller.java.EmptyParams;
-import org.apache.predictionio.controller.java.IJavaEngineFactory;
-import org.apache.predictionio.controller.java.JavaEngine;
-import org.apache.predictionio.controller.java.JavaEngineBuilder;
-
-public class EngineFactory implements IJavaEngineFactory {
- public JavaEngine<TrainingData, EmptyParams, PreparedData, Query, Float, Object> apply() {
- return new JavaEngineBuilder<
- TrainingData, EmptyParams, PreparedData, Query, Float, Object> ()
- .dataSourceClass(DataSource.class)
- .preparatorClass(Preparator.class)
- .addAlgorithmClass("featurebased", FeatureBasedAlgorithm.class)
- .addAlgorithmClass("collaborative", CollaborativeFilteringAlgorithm.class)
- .servingClass(Serving.class)
- .build();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/FeatureBasedAlgorithm.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/FeatureBasedAlgorithm.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/FeatureBasedAlgorithm.java
deleted file mode 100644
index 89f59f2..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/FeatureBasedAlgorithm.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import org.apache.predictionio.controller.java.LJavaAlgorithm;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.util.Map;
-import java.util.HashMap;
-import org.apache.commons.math3.linear.RealVector;
-import org.apache.commons.math3.linear.ArrayRealVector;
-
-public class FeatureBasedAlgorithm
- extends LJavaAlgorithm<
- FeatureBasedAlgorithmParams, PreparedData, FeatureBasedModel, Query, Float> {
- public final FeatureBasedAlgorithmParams params;
- final static Logger logger = LoggerFactory.getLogger(FeatureBasedAlgorithm.class);
-
- public FeatureBasedAlgorithm(FeatureBasedAlgorithmParams params) {
- this.params = params;
- }
-
- public FeatureBasedModel train(PreparedData data) {
- Map<Integer, RealVector> userFeatures = new HashMap<Integer, RealVector>();
- Map<Integer, Integer> userActions = new HashMap<Integer, Integer>();
-
- for (Integer uid : data.userInfo.keySet()) {
- userFeatures.put(uid, new ArrayRealVector(data.featureCount));
- userActions.put(uid, 0);
- }
-
- for (TrainingData.Rating rating : data.ratings) {
- final int uid = rating.uid;
- final int iid = rating.iid;
- final double rate = rating.rating;
-
- // Skip features outside the range.
- if (!(params.min <= rate && rate <= params.max)) continue;
-
- final double actualRate = (rate - params.drift) * params.scale;
- final RealVector userFeature = userFeatures.get(uid);
- final RealVector itemFeature = data.itemFeatures.get(iid);
- userFeature.combineToSelf(1, actualRate, itemFeature);
-
- userActions.put(uid, userActions.get(uid) + 1);
- }
-
- // Normalize userFeatures by l-inf-norm
- for (Integer uid : userFeatures.keySet()) {
- final RealVector feature = userFeatures.get(uid);
- feature.mapDivideToSelf(feature.getLInfNorm());
- }
-
- // Normalize itemFeatures by weight
- Map<Integer, RealVector> itemFeatures = new HashMap<Integer, RealVector>();
- for (Integer iid : data.itemFeatures.keySet()) {
- final RealVector feature = data.itemFeatures.get(iid);
- final RealVector normalizedFeature = feature.mapDivide(feature.getL1Norm());
- itemFeatures.put(iid, normalizedFeature);
- }
-
- return new FeatureBasedModel(userFeatures, userActions, itemFeatures);
- }
-
- public Float predict(FeatureBasedModel model, Query query) {
- final int uid = query.uid;
- final int iid = query.iid;
-
- if (!model.userFeatures.containsKey(uid)) {
- return Float.NaN;
- }
-
- if (!model.itemFeatures.containsKey(iid)) {
- return Float.NaN;
- }
-
- final RealVector userFeature = model.userFeatures.get(uid);
- final RealVector itemFeature = model.itemFeatures.get(iid);
-
- return new Float(userFeature.dotProduct(itemFeature));
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/FeatureBasedAlgorithmParams.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/FeatureBasedAlgorithmParams.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/FeatureBasedAlgorithmParams.java
deleted file mode 100644
index ae03fad..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/FeatureBasedAlgorithmParams.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import org.apache.predictionio.controller.java.JavaParams;
-
-// actual score = (rating - drift) / scale if min <= rating <= max
-// if rating is outside [min, max], that scoring will not be used.
-public class FeatureBasedAlgorithmParams implements JavaParams {
- public final double min;
- public final double max;
- public final double drift;
- public final double scale;
-
- public FeatureBasedAlgorithmParams(double min, double max, double drift, double scale) {
- this.min = min;
- this.max = max;
- this.drift = drift;
- this.scale = scale;
- }
-
- public FeatureBasedAlgorithmParams(double min, double max) {
- this(min, max, 0.0, 1.0);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/FeatureBasedModel.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/FeatureBasedModel.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/FeatureBasedModel.java
deleted file mode 100644
index 5b50c5a..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/FeatureBasedModel.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import java.io.Serializable;
-import java.util.Map;
-import org.apache.commons.math3.linear.RealVector;
-
-public class FeatureBasedModel implements Serializable {
- // Feature value is always between -1 and 1.
- public final Map<Integer, RealVector> userFeatures;
- public final Map<Integer, Integer> userActions;
- public final Map<Integer, RealVector> itemFeatures;
-
- public FeatureBasedModel(
- Map<Integer, RealVector> userFeatures,
- Map<Integer, Integer> userActions,
- Map<Integer, RealVector> itemFeatures) {
- this.userFeatures = userFeatures;
- this.userActions = userActions;
- this.itemFeatures = itemFeatures;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Preparator.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Preparator.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Preparator.java
deleted file mode 100644
index 3902371..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Preparator.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import org.apache.predictionio.controller.java.LJavaPreparator;
-import org.apache.predictionio.controller.java.EmptyParams;
-
-import java.util.Arrays;
-import java.util.Map;
-import java.util.HashMap;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.commons.math3.linear.ArrayRealVector;
-import org.apache.commons.math3.linear.RealVector;
-
-public class Preparator extends LJavaPreparator<EmptyParams, TrainingData, PreparedData> {
-
- final static Logger logger = LoggerFactory.getLogger(Preparator.class);
- final int indexOffset = 5;
-
- public Preparator() {}
-
- public PreparedData prepare(TrainingData trainingData) {
- Map<Integer, RealVector> itemFeatures = new HashMap<Integer, RealVector>();
-
- int featureSize = trainingData.genres.size();
-
- for (Integer iid: trainingData.itemInfo.keySet()) {
- String[] info = trainingData.itemInfo.get(iid);
-
- RealVector features = new ArrayRealVector(featureSize);
- for (int i = 0; i < featureSize; i++) {
- features.setEntry(i, Double.parseDouble(info[i + indexOffset]));
- }
- itemFeatures.put(iid, features);
- }
-
- return new PreparedData(trainingData, itemFeatures, featureSize);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/PreparedData.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/PreparedData.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/PreparedData.java
deleted file mode 100644
index b07d86d..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/PreparedData.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import java.util.Map;
-import org.apache.commons.math3.linear.RealVector;
-
-public class PreparedData extends TrainingData {
- public final Map<Integer, RealVector> itemFeatures;
- public final int featureCount;
-
- public PreparedData(TrainingData data, Map<Integer, RealVector> itemFeatures, int featureCount) {
- super(data);
- this.itemFeatures = itemFeatures;
- this.featureCount = featureCount;
- }
-
- @Override
- public String toString() {
- return super.toString() + " itemFeatures.size=" + itemFeatures.size()
- + " featureCount=" + featureCount;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Query.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Query.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Query.java
deleted file mode 100644
index 302de0c..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Query.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import java.io.Serializable;
-
-public class Query implements Serializable {
- public int uid; // user ID
- public int iid; // item ID
-
- public Query(int uid, int iid) {
- this.uid = uid;
- this.iid = iid;
- }
-
- @Override
- public String toString() {
- return "(" + uid + "," + iid + ")";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Runner4a.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Runner4a.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Runner4a.java
deleted file mode 100644
index a52fe76..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Runner4a.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import org.apache.predictionio.controller.java.EmptyParams;
-import org.apache.predictionio.controller.java.IJavaEngineFactory;
-import org.apache.predictionio.controller.java.JavaEngine;
-import org.apache.predictionio.controller.java.JavaEngineBuilder;
-import org.apache.predictionio.controller.java.JavaEngineParams;
-import org.apache.predictionio.controller.java.JavaEngineParamsBuilder;
-import org.apache.predictionio.controller.java.JavaWorkflow;
-import org.apache.predictionio.controller.java.WorkflowParamsBuilder;
-
-import java.util.HashMap;
-
-import org.apache.predictionio.controller.IdentityPreparator;
-
-public class Runner4a {
-
- private static class HalfBakedEngineFactory implements IJavaEngineFactory {
- public JavaEngine<TrainingData, EmptyParams, TrainingData, Query, Float, Object> apply() {
- return new JavaEngineBuilder<
- TrainingData, EmptyParams, TrainingData, Query, Float, Object> ()
- .dataSourceClass(DataSource.class)
- .build();
- }
- }
-
- public static void main(String[] args) {
- if (args.length == 0) {
- System.out.println("Error: Please specify the file directory as argument");
- System.exit(1);
- }
-
- JavaEngineParams engineParams = new JavaEngineParamsBuilder()
- .dataSourceParams(new DataSourceParams(args[0], true))
- .build();
-
- JavaWorkflow.runEngine(
- (new HalfBakedEngineFactory()).apply(),
- engineParams,
- new WorkflowParamsBuilder().batch("Recommendation.tutorial4.Runner4a").verbose(3).build()
- );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Runner4b.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Runner4b.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Runner4b.java
deleted file mode 100644
index 6964946..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Runner4b.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import org.apache.predictionio.controller.java.EmptyParams;
-import org.apache.predictionio.controller.java.IJavaEngineFactory;
-import org.apache.predictionio.controller.java.JavaEngine;
-import org.apache.predictionio.controller.java.JavaEngineBuilder;
-import org.apache.predictionio.controller.java.JavaEngineParams;
-import org.apache.predictionio.controller.java.JavaEngineParamsBuilder;
-import org.apache.predictionio.controller.java.JavaWorkflow;
-import org.apache.predictionio.controller.java.WorkflowParamsBuilder;
-
-import java.util.HashMap;
-
-import org.apache.predictionio.controller.IdentityPreparator;
-
-public class Runner4b {
-
- private static class HalfBakedEngineFactory implements IJavaEngineFactory {
- public JavaEngine<TrainingData, EmptyParams, PreparedData, Query, Float, Object> apply() {
- return new JavaEngineBuilder<
- TrainingData, EmptyParams, PreparedData, Query, Float, Object> ()
- .dataSourceClass(DataSource.class)
- .preparatorClass(Preparator.class)
- .build();
- }
- }
-
- public static void main(String[] args) {
- if (args.length == 0) {
- System.out.println("Error: Please specify the file directory as argument");
- System.exit(1);
- }
-
- JavaEngineParams engineParams = new JavaEngineParamsBuilder()
- .dataSourceParams(new DataSourceParams(args[0], true))
- .build();
-
- JavaWorkflow.runEngine(
- (new HalfBakedEngineFactory()).apply(),
- engineParams,
- new WorkflowParamsBuilder().batch("Recommendation.tutorial4.Runner4b").verbose(3).build()
- );
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/dec9f84c/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Runner4c.java
----------------------------------------------------------------------
diff --git a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Runner4c.java b/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Runner4c.java
deleted file mode 100644
index 681bd5f..0000000
--- a/examples/experimental/java-local-tutorial/src/main/java/recommendations/tutorial4/Runner4c.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.predictionio.examples.java.recommendations.tutorial4;
-
-import org.apache.predictionio.controller.java.EmptyParams;
-import org.apache.predictionio.controller.java.IJavaEngineFactory;
-import org.apache.predictionio.controller.java.JavaEngine;
-import org.apache.predictionio.controller.java.JavaEngineBuilder;
-import org.apache.predictionio.controller.java.JavaEngineParams;
-import org.apache.predictionio.controller.java.JavaEngineParamsBuilder;
-import org.apache.predictionio.controller.java.LJavaFirstServing;
-import org.apache.predictionio.controller.java.JavaWorkflow;
-import org.apache.predictionio.controller.java.WorkflowParamsBuilder;
-
-import java.util.HashMap;
-
-import org.apache.predictionio.controller.IdentityPreparator;
-
-public class Runner4c {
- public static void main(String[] args) {
- if (args.length == 0) {
- System.out.println("Error: Please specify the file directory as argument");
- System.exit(1);
- }
-
- JavaEngineParams engineParams = new JavaEngineParamsBuilder()
- .dataSourceParams(new DataSourceParams(args[0], true))
- // 1 -> -1., 2 -> -.5, 3 -> 0., 4 -> .5, 5 -> 1.
- .addAlgorithmParams("featurebased", new FeatureBasedAlgorithmParams(1.0, 5.0, 3.0, 0.5))
- .build();
-
- JavaWorkflow.runEngine(
- (new SingleEngineFactory()).apply(),
- engineParams,
- new WorkflowParamsBuilder().batch("Recommendation.tutorial4.Runner4c").verbose(3).build()
- );
- }
-}
-
-