Search in sources :

Example 1 with ColumnScoreObject

use of ml.shifu.shifu.container.ColumnScoreObject 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 2 with ColumnScoreObject

use of ml.shifu.shifu.container.ColumnScoreObject 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 = CommonUtils.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 3 with ColumnScoreObject

use of ml.shifu.shifu.container.ColumnScoreObject in project shifu by ShifuML.

the class DataPrepareWorker method convertModelResultIntoColScore.

/*
     * Convert model result data into column-based
     * 
     * @param evalDataList
     *            evaluation result list
     * @param columnScoreListMap
     *            (column-id, List<ColumnScoreObject>)
     */
private void convertModelResultIntoColScore(List<CaseScoreResult> scoreResultList, Map<Integer, List<ColumnScoreObject>> columnScoreListMap) {
    for (CaseScoreResult scoreResult : scoreResultList) {
        Map<String, String> rawDataMap = CommonUtils.convertDataIntoMap(scoreResult.getInputData(), super.modelConfig.getDataSetDelimiter(), this.trainDataHeader);
        for (ColumnConfig config : columnConfigList) {
            if (config.isFinalSelect()) {
                ColumnScoreObject columnScore = new ColumnScoreObject(config.getColumnNum(), rawDataMap.get(config.getColumnName()));
                columnScore.setScores(scoreResult.getScores());
                columnScore.setMaxScore(scoreResult.getMaxScore());
                columnScore.setMinScore(scoreResult.getMinScore());
                columnScore.setAvgScore(scoreResult.getAvgScore());
                List<ColumnScoreObject> csList = columnScoreListMap.get(config.getColumnNum());
                if (csList == null) {
                    csList = new ArrayList<ColumnScoreObject>();
                    columnScoreListMap.put(config.getColumnNum(), csList);
                }
                csList.add(columnScore);
            }
        }
    }
}
Also used : CaseScoreResult(ml.shifu.shifu.container.CaseScoreResult) ColumnScoreObject(ml.shifu.shifu.container.ColumnScoreObject) ColumnConfig(ml.shifu.shifu.container.obj.ColumnConfig)

Aggregations

ColumnScoreObject (ml.shifu.shifu.container.ColumnScoreObject)3 ArrayList (java.util.ArrayList)2 ColumnConfig (ml.shifu.shifu.container.obj.ColumnConfig)2 ColumnScoreMessage (ml.shifu.shifu.message.ColumnScoreMessage)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 CaseScoreResult (ml.shifu.shifu.container.CaseScoreResult)1 RunModelResultMessage (ml.shifu.shifu.message.RunModelResultMessage)1 StatsPartRawDataMessage (ml.shifu.shifu.message.StatsPartRawDataMessage)1 StatsResultMessage (ml.shifu.shifu.message.StatsResultMessage)1 StatsValueObjectMessage (ml.shifu.shifu.message.StatsValueObjectMessage)1