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);
}
}
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);
}
}
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);
}
}
Aggregations