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

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])
}
}
主站蜘蛛池模板: 丰顺县| 大庆市| 长岭县| 乌拉特中旗| 仲巴县| 淮北市| 江西省| 江油市| 西宁市| 江城| 万载县| 碌曲县| 勐海县| 威宁| 前郭尔| 恭城| 梓潼县| 安阳县| 揭东县| 临沂市| 万年县| 琼海市| 达孜县| 彰武县| 水富县| 恩平市| 固安县| 揭西县| 栾城县| 内黄县| 汽车| 兖州市| 津南区| 盐亭县| 静乐县| 永康市| 中阳县| 光泽县| 石屏县| 台北市| 商都县|