📄 neuralnet.java
字号:
Layer ly = this.getInputLayer(); if (ly != null) ly.setBias(p1); } public void removeInputSynapse(InputPatternListener p1) { Layer ly = this.getInputLayer(); if (ly != null) ly.removeInputSynapse(p1); } public void setLayerName(String p1) { NetName = p1; } public boolean addInputSynapse(InputPatternListener p1) { Layer ly = this.getInputLayer(); if (ly != null) return ly.addInputSynapse(p1); else return false; } public void setAllOutputs(Vector p1) { Layer ly = this.getOutputLayer(); if (ly != null) ly.setAllOutputs(p1); } public void setMonitor(Monitor p1) { mon = p1; for (int i=0; i < layers.size(); ++i) { Layer ly = (Layer)layers.elementAt(i); ly.setMonitor(mon); } setScriptingEnabled(isScriptingEnabled()); if (getTeacher() != null) getTeacher().setMonitor(p1); } public Monitor getMonitor() { return mon; } public void removeAllInputs() { Layer ly = this.getInputLayer(); if (ly != null) ly.removeAllInputs(); } public NeuralLayer copyInto(NeuralLayer p1) { return null; } public void addLayer(Layer layer) { this.addLayer(layer, HIDDEN_LAYER); } public void addLayer(Layer layer, int tier) { if (!layers.contains(layer)) { layer.setMonitor(mon); layers.addElement(layer); } if (tier == INPUT_LAYER) setInputLayer(layer); if (tier == OUTPUT_LAYER) setOutputLayer(layer); } public void removeLayer(Layer layer) { if (layers.contains(layer)) { layers.removeElement(layer); // Remove the synapses NeuralNetMatrix matrix = new NeuralNetMatrix(this); Synapse[][] conn = matrix.getConnectionMatrix(); removeSynapses(matrix.getLayerInd(layer), conn); if (layer == inputLayer) setInputLayer(null); else if (layer == outputLayer) setOutputLayer(null); } } private void removeSynapses(int ind, Synapse[][] conn) { if (ind >= 0) { // Removes input synapses for (int i=0; i < conn.length; ++i) { if (conn[i][ind] != null) { ConnectionHelper.disconnect(layers.get(i), layers.get(ind)); } } // Removes output synapses for (int i=0; i < conn[0].length; ++i) { if (conn[ind][i] != null) { ConnectionHelper.disconnect(layers.get(ind), layers.get(i)); } } } } /** * Resets all the StreamInputLayer of the net */ public void resetInput() { Layer ly = null; int i; for (i=0; i < layers.size(); ++i) { ly = (Layer)layers.elementAt(i); Vector inputs = ly.getAllInputs(); if (inputs != null) for (int x=0; x < inputs.size(); ++x) { InputPatternListener syn = (InputPatternListener)inputs.elementAt(x); if (syn instanceof StreamInputSynapse) ((StreamInputSynapse)syn).resetInput(); // if (syn instanceof InputSwitchSynapse) // ((InputSwitchSynapse)syn).resetInput(); } } if (getTeacher() != null) getTeacher().resetInput(); } public void addNeuralNetListener(NeuralNetListener listener) { if (getListeners().contains(listener)) return; listeners.addElement(listener); if (getMonitor() != null) getMonitor().addNeuralNetListener(listener); } public Vector getListeners() { if (listeners == null) listeners = new Vector(); return listeners; } public void removeNeuralNetListener(NeuralNetListener listener) { getListeners().removeElement(listener); if (getMonitor() != null) getMonitor().removeNeuralNetListener(listener); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); /* Since the listeners' vector in the Monitor object is transient, * we must fill it from the NeuralNet.listeners vector */ Vector lst = getListeners(); if (getMonitor() != null) for (int i=0; i < lst.size(); ++i) { getMonitor().addNeuralNetListener((NeuralNetListener)lst.elementAt(i)); } // Restores the exported variables jNet and jMon setMacroPlugin(macroPlugin); } /** * Method to get the version. * @return A string containing the version of joone's engine in the format xx.yy.zz */ public static String getVersion() { return MAJOR_RELEASE + "." + MINOR_RELEASE + "." + BUILD + SUFFIX; } /** * Method to get the numeric version. * @return an integer containing the joone's engine version */ public static Integer getNumericVersion() { return new Integer(MAJOR_RELEASE * 1000000 + MINOR_RELEASE * 1000 + BUILD); } public Layer getLayer(String layerName) { Layer ly = null; for (int i=0; i < layers.size(); ++i) { ly = (Layer)layers.elementAt(i); if (ly.getLayerName().compareToIgnoreCase(layerName) == 0) return ly; } return null; } public Vector getLayers() { return this.layers; } /** Permits to initialize a neural network with a Vector * containing layers. * */ public void setLayers(Vector newlayers) { this.layers = newlayers; } /** Permits to initialize a neural network with an * ArrayList containing layers. Added for Spring. * */ public void setLayersList(ArrayList list) { this.setLayers(new Vector(list)); } /** Sets the Teacher for this NeuralNet object * @param TeachingSynapse - the new teacher. It can be null to make unsupervised this neural network */ public void setTeacher(ComparingElement ts) { if (getMonitor() != null) if (ts != null) getMonitor().setSupervised(true); else getMonitor().setSupervised(false); teacher = ts; } public ComparingElement getTeacher() { return teacher; } public void setListeners(Vector listeners) { //addNeuralNetListener(listeners); } public void setInputLayer(Layer newLayer) { inputLayer = newLayer; } public void setOutputLayer(Layer newLayer) { outputLayer = newLayer; } public NeuralNetAttributes getDescriptor() { if (descriptor == null) { descriptor = new NeuralNetAttributes(); descriptor.setNeuralNetName(this.getLayerName()); } return descriptor; } public void setDescriptor(NeuralNetAttributes newdescriptor) { this.descriptor = newdescriptor; } /** * Returns true if the network is running * @return boolean */ public boolean isRunning() { if (getMonitor().isSingleThreadMode()) { if ((getSingleThread() != null) && getSingleThread().isAlive()) { return true; } } else { Layer ly = null; for (int i=0; i < layers.size(); ++i) { ly = (Layer)layers.elementAt(i); if (ly.isRunning()) { return true; } } if ((teacher != null) && (teacher.getTheLinearLayer().isRunning())) { return true; } } return false; } /** * Creates a copy of the contained neural network * * @return the cloned NeuralNet */ public NeuralNet cloneNet() { NeuralNet newnet = null; try { ByteArrayOutputStream f = new ByteArrayOutputStream(); ObjectOutput s = new ObjectOutputStream(f); s.writeObject(this); s.flush(); ByteArrayInputStream fi = new ByteArrayInputStream(f.toByteArray()); ObjectInput oi = new ObjectInputStream(fi); newnet = (NeuralNet)oi.readObject(); } catch (Exception ioe) { log.warn( "IOException while cloning the Net. Message is : " + ioe.getMessage(), ioe ); } return newnet; } public void removeAllListeners() { listeners = null; if (getMonitor() != null) getMonitor().removeAllListeners(); } /** Enable/disable the scripting engine for the net. * If disabled, all the event-driven macros will be not run * @param enabled true to enable the scripting, otherwise false */ public void setScriptingEnabled(boolean enabled) { scriptingEnabled = enabled; if (enabled) { NeuralNetListener listener = getMacroPlugin(); if (listener == null) log.info("MacroPlugin not set: Impossible to enable the scripting"); else this.addNeuralNetListener(getMacroPlugin()); } else { if (macroPlugin != null) this.removeNeuralNetListener(macroPlugin); } } /** Gets if the scripting engine is enabled * @return true if enabled */ public boolean isScriptingEnabled() { return scriptingEnabled; } /** Getter for property macroPlugin. * @return Value of property macroPlugin. */ public MacroInterface getMacroPlugin() { return macroPlugin; } /** Setter for property macroPlugin. * @param macroPlugin New value of property macroPlugin. */ public void setMacroPlugin(MacroInterface macroPlugin) { if(macroPlugin != null) { // Unregister the old listener this.removeNeuralNetListener(this.macroPlugin); // Should we register the new listener? if(scriptingEnabled) { this.addNeuralNetListener(macroPlugin); } } this.macroPlugin = macroPlugin; if (macroPlugin != null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -