官术网_书友最值得收藏!

Engine design

The starting point of the application is the Engine. This is indicated in the engine.json file of your project shown as follows:

    {
"id": "default",
"description": "Default settings",
"engineFactory":
"org.template.recommendation.RecommendationEngine"
,
"datasource": {
"params" : {
"appName": "Recommenderapp"
}
},
"algorithms": [
----
}

The Engine class for our reference is written as follows:

    public class RecommendationEngine extends EngineFactory {
@Override
public BaseEngine<EmptyParams, Query, PredictedResult,
Set<String>> apply() {
return new Engine<>(
DataSource.class,
Preparator.class,
Collections.<String, Class<? extends
BaseAlgorithm<PreparedData,
?, Query, PredictedResult>>>singletonMap("algo",
Algorithm.class),
Serving.class
);
}
}

Key points to make a note from the preceding code are as follows:

  • An engine class extends from EngineFactory, which is provided by PredictionIO
  • The apply() interface method of the EngineFactory base class is overridden
  • The apply() method returns an instance of the engine class that has constructor parameters for the Datasource class, the Preparator class, the Singleton Map of Algorithm class, and the serving class

Let's observe the following lines of code:

    Collections.<String, Class<? extends BaseAlgorithm<PreparedData,
?, Query, PredictedResult>>>singletonMap(
"algo", Algorithm.class)

The preceding lines may be hard to interpret; class <? extends BaseAlgorithm<>> means that the type of the class is undetermined, but you are guaranteed that it extends BaseAlgorithm.

If you are familiar with Scala, the Scala code for the Engine would look as follows:

    object ECommerceRecommendationEngine extends IEngineFactory {
def apply() = {
new Engine(
classOf[DataSource],
classOf[Preparator],
Map("ecomm" -> classOf[ECommAlgorithm]),
classOf[Serving])
}
}
主站蜘蛛池模板: 浙江省| 礼泉县| 丹寨县| 石狮市| 鞍山市| 东源县| 泰州市| 肥乡县| 荥阳市| 平遥县| 含山县| 双江| 台南县| 陈巴尔虎旗| 无锡市| 广宁县| 堆龙德庆县| SHOW| 武宁县| 兖州市| 衡水市| 鄱阳县| 宝兴县| 鄱阳县| 玉龙| 蕉岭县| 湟中县| 濮阳县| 大同县| 北宁市| 筠连县| 申扎县| 眉山市| 丰宁| 普兰店市| 黔西| 朝阳市| 木兰县| 宿松县| 汉沽区| 漯河市|