use of ml.shifu.shifu.message.StatsResultMessage in project shifu by ShifuML.
the class PostTrainWorker method handleMsg.
/*
* (non-Javadoc)
*
* @see akka.actor.UntypedActor#onReceive(java.lang.Object)
*/
@Override
public void handleMsg(Object message) {
if (message instanceof ColumnScoreMessage) {
ColumnScoreMessage msg = (ColumnScoreMessage) message;
colScoreList.addAll(msg.getColScoreList());
receivedMsgCnt++;
log.debug("Received " + receivedMsgCnt + " messages, total message count is:" + msg.getTotalMsgCnt());
if (receivedMsgCnt == msg.getTotalMsgCnt()) {
// received all message, start to calculate
int columnNum = msg.getColumnNum();
ColumnConfig config = columnConfigList.get(columnNum);
Double[] binScore = new Double[config.getBinLength()];
Integer[] binCount = new Integer[config.getBinLength()];
for (int i = 0; i < binScore.length; i++) {
binScore[i] = 0.0;
binCount[i] = 0;
}
for (ColumnScoreObject colScore : colScoreList) {
int binNum = BinUtils.getBinNum(config, colScore.getColumnVal());
binScore[binNum] += Double.valueOf(colScore.getAvgScore());
binCount[binNum]++;
}
List<Integer> binAvgScore = new ArrayList<Integer>();
for (int i = 0; i < binScore.length; i++) {
binScore[i] /= binCount[i];
binAvgScore.add((int) Math.round(binScore[i]));
}
config.setBinAvgScore(binAvgScore);
nextActorRef.tell(new StatsResultMessage(config), getSelf());
}
} else {
unhandled(message);
}
}
use of ml.shifu.shifu.message.StatsResultMessage in project shifu by ShifuML.
the class CalculateStatsActor 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());
for (Scanner scanner : scanners) {
dataLoadRef.tell(new ScanStatsRawDataMessage(scanners.size(), scanner), getSelf());
}
} else if (message instanceof StatsResultMessage) {
StatsResultMessage statsRstMsg = (StatsResultMessage) message;
ColumnConfig columnConfig = statsRstMsg.getColumnConfig();
columnConfigList.set(columnConfig.getColumnNum(), columnConfig);
resultCnt++;
if (resultCnt == columnNumToActorMap.size()) {
log.info("Received " + resultCnt + " messages. Finished Calculating Stats.");
PathFinder pathFinder = new PathFinder(modelConfig);
JSONUtils.writeValue(new File(pathFinder.getColumnConfigPath()), columnConfigList);
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);
}
}
use of ml.shifu.shifu.message.StatsResultMessage in project shifu by ShifuML.
the class PostTrainActor 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 StatsResultMessage) {
StatsResultMessage statsRstMsg = (StatsResultMessage) message;
ColumnConfig columnConfig = statsRstMsg.getColumnConfig();
columnConfigList.set(columnConfig.getColumnNum(), columnConfig);
resultCnt++;
log.debug("Received " + resultCnt + " messages, expected message count is:" + expectedResultCnt);
if (resultCnt == expectedResultCnt) {
log.info("Finished post-train.");
PathFinder pathFinder = new PathFinder(modelConfig);
JSONUtils.writeValue(new File(pathFinder.getColumnConfigPath()), columnConfigList);
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);
}
}
use of ml.shifu.shifu.message.StatsResultMessage in project shifu by ShifuML.
the class StatsCalculateWorker method handleMsg.
@Override
public void handleMsg(Object message) {
if (message instanceof StatsValueObjectMessage) {
StatsValueObjectMessage statsVoMessage = (StatsValueObjectMessage) message;
voList.addAll(statsVoMessage.getVoList());
this.missing += statsVoMessage.getMissing();
this.total += statsVoMessage.getTotal();
receivedMsgCnt++;
if (receivedMsgCnt == statsVoMessage.getTotalMsgCnt()) {
ColumnConfig columnConfig = columnConfigList.get(statsVoMessage.getColumnNum());
calculateColumnStats(columnConfig, voList);
columnConfig.setMissingCnt(this.missing);
columnConfig.setTotalCount(this.total);
columnConfig.setMissingPercentage((double) missing / total);
parentActorRef.tell(new StatsResultMessage(columnConfig), this.getSelf());
}
} else {
unhandled(message);
}
}
Aggregations