Search in sources :

Example 1 with RunModelResultMessage

use of ml.shifu.shifu.message.RunModelResultMessage in project shifu by ShifuML.

the class ScoreModelWorker method handleMsg.

/*
     * (non-Javadoc)
     * 
     * @see akka.actor.UntypedActor#onReceive(java.lang.Object)
     */
@Override
public void handleMsg(Object message) throws IOException {
    if (message instanceof RunModelResultMessage) {
        log.debug("Received model score data for evaluation");
        RunModelResultMessage msg = (RunModelResultMessage) message;
        if (!resultMap.containsKey(msg.getStreamId())) {
            receivedStreamCnt++;
            resultMap.put(msg.getStreamId(), new StreamBulletin(msg.getStreamId()));
        }
        resultMap.get(msg.getStreamId()).receiveMsge(msg.getMsgId(), msg.isLastMsg());
        List<CaseScoreResult> caseScoreResultList = msg.getScoreResultList();
        StringBuilder buf = new StringBuilder();
        for (CaseScoreResult csResult : caseScoreResultList) {
            buf.setLength(0);
            Map<String, String> rawDataMap = CommonUtils.convertDataIntoMap(csResult.getInputData(), evalConfig.getDataSet().getDataDelimiter(), header);
            // get the tag
            String tag = CommonUtils.trimTag(rawDataMap.get(modelConfig.getTargetColumnName(evalConfig)));
            buf.append(tag);
            // append weight column value
            if (StringUtils.isNotBlank(evalConfig.getDataSet().getWeightColumnName())) {
                String metric = rawDataMap.get(evalConfig.getDataSet().getWeightColumnName());
                buf.append("|" + StringUtils.trimToEmpty(metric));
            } else {
                buf.append("|" + "1.0");
            }
            if (CollectionUtils.isNotEmpty(csResult.getScores())) {
                addModelScoreData(buf, csResult);
            }
            Map<String, CaseScoreResult> subModelScores = csResult.getSubModelScores();
            if (MapUtils.isNotEmpty(subModelScores)) {
                Iterator<Map.Entry<String, CaseScoreResult>> iterator = subModelScores.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, CaseScoreResult> entry = iterator.next();
                    CaseScoreResult subCs = entry.getValue();
                    addModelScoreData(buf, subCs);
                }
            }
            // append meta data
            List<String> metaColumns = evalConfig.getAllMetaColumns(modelConfig);
            if (CollectionUtils.isNotEmpty(metaColumns)) {
                for (String columnName : metaColumns) {
                    String value = rawDataMap.get(columnName);
                    buf.append("|" + StringUtils.trimToEmpty(value));
                }
            }
            scoreWriter.write(buf.toString() + "\n");
        }
        if (receivedStreamCnt == msg.getTotalStreamCnt() && hasAllMessageResult(resultMap)) {
            log.info("Finish running scoring, the score file - {} is stored in {}.", new PathFinder(modelConfig).getEvalScorePath(evalConfig).toString(), evalConfig.getDataSet().getSource().name());
            scoreWriter.close();
            // only one message will be sent
            nextActorRef.tell(new EvalResultMessage(1), this.getSelf());
        }
    } else {
        unhandled(message);
    }
}
Also used : PathFinder(ml.shifu.shifu.fs.PathFinder) CaseScoreResult(ml.shifu.shifu.container.CaseScoreResult) EvalResultMessage(ml.shifu.shifu.message.EvalResultMessage) Entry(java.util.Map.Entry) RunModelResultMessage(ml.shifu.shifu.message.RunModelResultMessage)

Example 2 with RunModelResultMessage

use of ml.shifu.shifu.message.RunModelResultMessage in project shifu by ShifuML.

the class DataPrepareWorker method handleMsg.

/*
     * (non-Javadoc)
     * 
     * @see akka.actor.UntypedActor#onReceive(java.lang.Object)
     */
@Override
public void handleMsg(Object message) {
    if (message instanceof StatsPartRawDataMessage) {
        StatsPartRawDataMessage partData = (StatsPartRawDataMessage) message;
        Map<Integer, List<ValueObject>> columnVoListMap = buildColumnVoListMap(partData.getRawDataList().size());
        DataPrepareStatsResult rt = convertRawDataIntoValueObject(partData.getRawDataList(), columnVoListMap);
        int totalMsgCnt = partData.getTotalMsgCnt();
        for (Map.Entry<Integer, List<ValueObject>> entry : columnVoListMap.entrySet()) {
            Integer columnNum = entry.getKey();
            log.info("send {} with {} value object", columnNum, entry.getValue().size());
            columnNumToActorMap.get(columnNum).tell(new StatsValueObjectMessage(totalMsgCnt, columnNum, entry.getValue(), rt.getMissingMap().containsKey(columnNum) ? rt.getMissingMap().get(columnNum) : 0, rt.getTotal()), getSelf());
        }
    } else if (message instanceof RunModelResultMessage) {
        RunModelResultMessage msg = (RunModelResultMessage) message;
        Map<Integer, List<ColumnScoreObject>> columnScoreListMap = buildColumnScoreListMap();
        convertModelResultIntoColScore(msg.getScoreResultList(), columnScoreListMap);
        int totalMsgCnt = msg.getTotalStreamCnt();
        for (Entry<Integer, List<ColumnScoreObject>> column : columnScoreListMap.entrySet()) {
            columnNumToActorMap.get(column.getKey()).tell(new ColumnScoreMessage(totalMsgCnt, column.getKey(), column.getValue()), getSelf());
        }
    } else {
        unhandled(message);
    }
}
Also used : ColumnScoreObject(ml.shifu.shifu.container.ColumnScoreObject) StatsPartRawDataMessage(ml.shifu.shifu.message.StatsPartRawDataMessage) StatsValueObjectMessage(ml.shifu.shifu.message.StatsValueObjectMessage) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List) RunModelResultMessage(ml.shifu.shifu.message.RunModelResultMessage) ColumnScoreMessage(ml.shifu.shifu.message.ColumnScoreMessage) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with RunModelResultMessage

use of ml.shifu.shifu.message.RunModelResultMessage in project shifu by ShifuML.

the class RunModelWorker method handleMsg.

/*
     * (non-Javadoc)
     * 
     * @see akka.actor.UntypedActor#onReceive(java.lang.Object)
     */
@Override
public void handleMsg(Object message) {
    if (message instanceof RunModelDataMessage) {
        RunModelDataMessage msg = (RunModelDataMessage) message;
        List<String> evalDataList = msg.getEvalDataList();
        List<CaseScoreResult> scoreDataList = new ArrayList<CaseScoreResult>(evalDataList.size());
        for (String evalData : evalDataList) {
            CaseScoreResult scoreData = calculateModelScore(evalData);
            if (scoreData != null) {
                scoreData.setInputData(evalData);
                scoreDataList.add(scoreData);
            }
        }
        nextActorRef.tell(new RunModelResultMessage(msg.getStreamId(), msg.getTotalStreamCnt(), msg.getMsgId(), msg.isLastMsg(), scoreDataList), getSelf());
    } else {
        unhandled(message);
    }
}
Also used : CaseScoreResult(ml.shifu.shifu.container.CaseScoreResult) ArrayList(java.util.ArrayList) RunModelResultMessage(ml.shifu.shifu.message.RunModelResultMessage) RunModelDataMessage(ml.shifu.shifu.message.RunModelDataMessage)

Aggregations

RunModelResultMessage (ml.shifu.shifu.message.RunModelResultMessage)3 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 CaseScoreResult (ml.shifu.shifu.container.CaseScoreResult)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ColumnScoreObject (ml.shifu.shifu.container.ColumnScoreObject)1 PathFinder (ml.shifu.shifu.fs.PathFinder)1 ColumnScoreMessage (ml.shifu.shifu.message.ColumnScoreMessage)1 EvalResultMessage (ml.shifu.shifu.message.EvalResultMessage)1 RunModelDataMessage (ml.shifu.shifu.message.RunModelDataMessage)1 StatsPartRawDataMessage (ml.shifu.shifu.message.StatsPartRawDataMessage)1 StatsValueObjectMessage (ml.shifu.shifu.message.StatsValueObjectMessage)1