⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nettaskentry.java

📁 jooneDTE的源码
💻 JAVA
字号:
/* * This object is used to trasport through the JavaSpace the net that must be trained. * There it will be taken from a Worker object that will call its execute() method */package org.joone.dte;import java.io.Serializable;import java.util.logging.Logger;import net.jini.space.JavaSpace;import org.tiling.computefarm.Task;import org.joone.net.*;import org.joone.log.*;import org.joone.engine.*;public class NetTaskEntry implements NeuralNetListener, Task, NeuralValidationListener {    /**     * Logger     * */    private static final ILogger log = LoggerFactory.getLogger(NetTaskEntry.class);        private NeuralNet nnet;    private transient boolean ready=false;    private transient double trainingRMSE=0;    private transient double validationRMSE=0;        private static final long serialVersionUID = -9011879162360410556L;        public NetTaskEntry(final NeuralNet net) {        this.nnet = net;    }        public Serializable execute(JavaSpace space) {        log.debug("Executing Task...");        if (nnet != null) {            /* First of all, registers itself as neural net's listner,             * so it can receive all the training events.             */            nnet.getMonitor().addNeuralNetListener(this);            // Runs the neural network's training cycles            nnet.start();            nnet.getMonitor().Go();            ready = false;            // Waits for the end of the training cycles            synchronized(this) {                try {                    while (!ready)                        wait();                } catch (InterruptedException ie) {                    log.warn( "InterruptedException thrown while waiting. Message is : " + ie.getMessage(),                    ie );                    return null;                }            }            if (nnet.getMonitor().getValidationPatterns() > 0) {                // Creates a copy of the neural network                nnet.getMonitor().setExporting(true);                NeuralNet newNet = nnet.cloneNet();                nnet.getMonitor().setExporting(false);                                // Cleans the old listeners                // This is a fundamental action to avoid that the validating net                // calls the cicleTerminated method of this class                newNet.removeAllListeners();                NeuralNetValidator valid = new NeuralNetValidator(newNet);                valid.addValidationListener(this);                ready = false;                valid.start();                log.debug("Validating...");                // Waits for the end of the validation phase                synchronized(this) {                    try {                        while (!ready)                            wait();                    } catch (InterruptedException ie) {                        log.warn( "InterruptedException thrown while waiting. Message is : " + ie.getMessage(),                        ie );                        return null;                    }                }            }            NeuralNetAttributes attr = nnet.getDescriptor();            attr.setTrainingError(trainingRMSE);            attr.setValidationError(validationRMSE);            log.debug("Done.");            return nnet;        }        else            throw new RuntimeException("Can't work: the neural net is null");    }        public void cicleTerminated(NeuralNetEvent e) { }        public void netStopped(NeuralNetEvent e) {        synchronized(this) {            ready = true;            // Notifies the waiting threads            notifyAll();        }    }        public void netStarted(NeuralNetEvent e) {    }        public void errorChanged(NeuralNetEvent e) {        Monitor mon = (Monitor)e.getSource();        trainingRMSE = mon.getGlobalError();    }        public void netStoppedError(NeuralNetEvent e, String error) {        log.error("Error while training: "+error);    }        public void netValidated(org.joone.net.NeuralValidationEvent neuralValidationEvent) {        NeuralNet nn = (NeuralNet)neuralValidationEvent.getSource();        validationRMSE = nn.getMonitor().getGlobalError();        synchronized (this) {            ready = true;            notifyAll();        }    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -