Search in sources :

Example 1 with EvalResultMessage

use of ml.shifu.shifu.message.EvalResultMessage 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.getScoreMetaColumns(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 EvalResultMessage

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

the class EvalModelActor method onReceive.

/* (non-Javadoc)
     * @see akka.actor.UntypedActor#onReceive(java.lang.Object)
     */
@Override
public void onReceive(Object message) throws Exception {
    if (message instanceof AkkaActorInputMessage) {
        resultCnt = 0;
        AkkaActorInputMessage msg = (AkkaActorInputMessage) message;
        List<Scanner> scanners = msg.getScanners();
        log.debug("Num of Scanners: " + scanners.size());
        int streamId = 0;
        for (Scanner scanner : scanners) {
            dataLoadRef.tell(new ScanEvalDataMessage(streamId++, scanners.size(), scanner), getSelf());
        }
    } else if (message instanceof EvalResultMessage) {
        EvalResultMessage msg = (EvalResultMessage) message;
        resultCnt++;
        if (resultCnt == msg.getTotalMsgCnt()) {
            getContext().system().shutdown();
        }
    } else if (message instanceof ExceptionMessage) {
        // since some children actors meet some exception, shutdown the system
        ExceptionMessage msg = (ExceptionMessage) message;
        getContext().system().shutdown();
        // and wrapper the exception into Return status
        addExceptionIntoCondition(msg.getException());
    } else {
        unhandled(message);
    }
}
Also used : AkkaActorInputMessage(ml.shifu.shifu.message.AkkaActorInputMessage) Scanner(java.util.Scanner) EvalResultMessage(ml.shifu.shifu.message.EvalResultMessage) ExceptionMessage(ml.shifu.shifu.message.ExceptionMessage) ScanEvalDataMessage(ml.shifu.shifu.message.ScanEvalDataMessage)

Aggregations

EvalResultMessage (ml.shifu.shifu.message.EvalResultMessage)2 Entry (java.util.Map.Entry)1 Scanner (java.util.Scanner)1 CaseScoreResult (ml.shifu.shifu.container.CaseScoreResult)1 PathFinder (ml.shifu.shifu.fs.PathFinder)1 AkkaActorInputMessage (ml.shifu.shifu.message.AkkaActorInputMessage)1 ExceptionMessage (ml.shifu.shifu.message.ExceptionMessage)1 RunModelResultMessage (ml.shifu.shifu.message.RunModelResultMessage)1 ScanEvalDataMessage (ml.shifu.shifu.message.ScanEvalDataMessage)1