Search in sources :

Example 1 with TrainInstanceMessage

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

the class TrainDataPrepWorker method handleMsg.

/*
     * (non-Javadoc)
     * 
     * @see akka.actor.UntypedActor#onReceive(java.lang.Object)
     */
@Override
public void handleMsg(Object message) throws IOException {
    if (message instanceof TrainPartDataMessage) {
        log.debug("Received value object list for training model.");
        TrainPartDataMessage msg = (TrainPartDataMessage) message;
        for (MLDataPair mlDataPir : msg.getMlDataPairList()) {
            if (modelConfig.isTrainOnDisk() && !initialized) {
                int inputSize = mlDataPir.getInput().size();
                int idealSize = mlDataPir.getIdeal().size();
                ((BufferedMLDataSet) masterDataSet).beginLoad(inputSize, idealSize);
                initialized = true;
            }
            masterDataSet.add(mlDataPir);
        }
        receivedMsgCnt++;
        log.debug("Expected " + msg.getTotalMsgCnt() + " messages, received " + receivedMsgCnt + " message(s).");
        if (receivedMsgCnt == msg.getTotalMsgCnt()) {
            if (modelConfig.isTrainOnDisk() && initialized) {
                ((BufferedMLDataSet) masterDataSet).endLoad();
            }
            for (AbstractTrainer trainer : trainers) {
                // if the trainOnDisk is true, setting the "D" option
                if (modelConfig.isTrainOnDisk()) {
                    trainer.setTrainingOption("D");
                }
                trainer.setDataSet(masterDataSet);
                nextActorRef.tell(new TrainInstanceMessage(trainer), this.getSelf());
            }
            if (modelConfig.isTrainOnDisk() && initialized) {
                masterDataSet.close();
                masterDataSet = null;
            }
        }
    } else if (message instanceof StatsPartRawDataMessage) {
        StatsPartRawDataMessage msg = (StatsPartRawDataMessage) message;
        receivedMsgCnt++;
        log.debug("Expected " + msg.getTotalMsgCnt() + " messages, received " + receivedMsgCnt + " message(s).");
        if (receivedMsgCnt == msg.getTotalMsgCnt()) {
            for (AbstractTrainer trainer : trainers) {
                // ((DecisionTreeTrainer)trainer).setDataSet(rawInstanceList);
                nextActorRef.tell(new TrainInstanceMessage(trainer), this.getSelf());
            }
        }
    } else {
        unhandled(message);
    }
}
Also used : MLDataPair(org.encog.ml.data.MLDataPair) TrainInstanceMessage(ml.shifu.shifu.message.TrainInstanceMessage) StatsPartRawDataMessage(ml.shifu.shifu.message.StatsPartRawDataMessage) TrainPartDataMessage(ml.shifu.shifu.message.TrainPartDataMessage) AbstractTrainer(ml.shifu.shifu.core.AbstractTrainer) BufferedMLDataSet(org.encog.ml.data.buffer.BufferedMLDataSet)

Example 2 with TrainInstanceMessage

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

the class TrainModelWorker method handleMsg.

/* (non-Javadoc)
     * @see akka.actor.UntypedActor#onReceive(java.lang.Object)
     */
@Override
public void handleMsg(Object message) throws IOException {
    if (message instanceof TrainInstanceMessage) {
        log.info("Received train data for model training");
        TrainInstanceMessage msg = (TrainInstanceMessage) message;
        msg.getTrainer().train();
        nextActorRef.tell(new TrainResultMessage(), getSelf());
    } else {
        unhandled(message);
    }
}
Also used : TrainInstanceMessage(ml.shifu.shifu.message.TrainInstanceMessage) TrainResultMessage(ml.shifu.shifu.message.TrainResultMessage)

Aggregations

TrainInstanceMessage (ml.shifu.shifu.message.TrainInstanceMessage)2 AbstractTrainer (ml.shifu.shifu.core.AbstractTrainer)1 StatsPartRawDataMessage (ml.shifu.shifu.message.StatsPartRawDataMessage)1 TrainPartDataMessage (ml.shifu.shifu.message.TrainPartDataMessage)1 TrainResultMessage (ml.shifu.shifu.message.TrainResultMessage)1 MLDataPair (org.encog.ml.data.MLDataPair)1 BufferedMLDataSet (org.encog.ml.data.buffer.BufferedMLDataSet)1