Search in sources :

Example 1 with StatsResultMessage

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);
    }
}
Also used : ColumnScoreObject(ml.shifu.shifu.container.ColumnScoreObject) ColumnConfig(ml.shifu.shifu.container.obj.ColumnConfig) StatsResultMessage(ml.shifu.shifu.message.StatsResultMessage) ArrayList(java.util.ArrayList) ColumnScoreMessage(ml.shifu.shifu.message.ColumnScoreMessage)

Example 2 with StatsResultMessage

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);
    }
}
Also used : AkkaActorInputMessage(ml.shifu.shifu.message.AkkaActorInputMessage) Scanner(java.util.Scanner) ExceptionMessage(ml.shifu.shifu.message.ExceptionMessage) ColumnConfig(ml.shifu.shifu.container.obj.ColumnConfig) StatsResultMessage(ml.shifu.shifu.message.StatsResultMessage) PathFinder(ml.shifu.shifu.fs.PathFinder) File(java.io.File) ScanStatsRawDataMessage(ml.shifu.shifu.message.ScanStatsRawDataMessage)

Example 3 with StatsResultMessage

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);
    }
}
Also used : AkkaActorInputMessage(ml.shifu.shifu.message.AkkaActorInputMessage) Scanner(java.util.Scanner) ExceptionMessage(ml.shifu.shifu.message.ExceptionMessage) ColumnConfig(ml.shifu.shifu.container.obj.ColumnConfig) StatsResultMessage(ml.shifu.shifu.message.StatsResultMessage) ScanEvalDataMessage(ml.shifu.shifu.message.ScanEvalDataMessage) PathFinder(ml.shifu.shifu.fs.PathFinder) File(java.io.File)

Example 4 with StatsResultMessage

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);
    }
}
Also used : ColumnConfig(ml.shifu.shifu.container.obj.ColumnConfig) StatsValueObjectMessage(ml.shifu.shifu.message.StatsValueObjectMessage) StatsResultMessage(ml.shifu.shifu.message.StatsResultMessage)

Aggregations

ColumnConfig (ml.shifu.shifu.container.obj.ColumnConfig)4 StatsResultMessage (ml.shifu.shifu.message.StatsResultMessage)4 File (java.io.File)2 Scanner (java.util.Scanner)2 PathFinder (ml.shifu.shifu.fs.PathFinder)2 AkkaActorInputMessage (ml.shifu.shifu.message.AkkaActorInputMessage)2 ExceptionMessage (ml.shifu.shifu.message.ExceptionMessage)2 ArrayList (java.util.ArrayList)1 ColumnScoreObject (ml.shifu.shifu.container.ColumnScoreObject)1 ColumnScoreMessage (ml.shifu.shifu.message.ColumnScoreMessage)1 ScanEvalDataMessage (ml.shifu.shifu.message.ScanEvalDataMessage)1 ScanStatsRawDataMessage (ml.shifu.shifu.message.ScanStatsRawDataMessage)1 StatsValueObjectMessage (ml.shifu.shifu.message.StatsValueObjectMessage)1