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

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])
}
}
主站蜘蛛池模板: 田林县| 绍兴县| 西林县| 庄浪县| 顺昌县| 开阳县| 鄂托克旗| 明溪县| 东光县| 南皮县| 凤翔县| 云阳县| 高唐县| 禄劝| 广昌县| 长寿区| 汾阳市| 武城县| 上高县| 永修县| 石狮市| 含山县| 富平县| 元江| 泽普县| 南投县| 江永县| 郧西县| 藁城市| 若尔盖县| 德化县| 琼结县| 江阴市| 永仁县| 汉寿县| 叶城县| 鲁甸县| 木兰县| 高密市| 新竹县| 浦江县|