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

📄 streaminputsynapse.java

📁 一个纯java写的神经网络源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * the plug in is not added, e.g. in case the plug in is already added /     * connected to another synapse.     */    public boolean addPlugIn(ConverterPlugIn aNewPlugIn) {        if(plugIn == aNewPlugIn) {            return false;        }                // The null parameter is used to detach or delete a plugin        if(aNewPlugIn == null) {            // We need to declare the next plugin, if existing,            // as not more used, so it could be used again.            if (plugIn != null) {                plugIn.setConnected(false);            }            plugIn = null;            resetInput();            return true;        }                if(aNewPlugIn.isConnected()) {            // The new plugin is already connected to another plugin,            // hence cannot be used.            return false;        }                if(plugIn == null) {            aNewPlugIn.setConnected(true);            aNewPlugIn.addPlugInListener(this);            setBuffered(true);            plugIn = aNewPlugIn;            resetInput();            return true;        } else {            return plugIn.addPlugIn(aNewPlugIn);        }    }        /**     * Removes (and disconnects) all (cascading) plug-ins.     */    public void removeAllPlugIns() {        if(plugIn != null) {            plugIn.setConnected(false);            plugIn.removeAllPlugIns();            plugIn = null;        }    }        /**     * Sets the plugin for the data preprocessing.     * @param newPlugIn the plug in to set     *     * @deprecated {@link #addPlugIn(ConverterPlugIn)}. If you want to replace     * the plug in by setting a new plug in please use     * {@link #removeAllPlugIns(ConverterPlugIn)} and {@link #addPlugIn(ConverterPlugIn)}.     */    public boolean setPlugin(ConverterPlugIn newPlugIn) {        if (newPlugIn == plugIn)            return false;        if (newPlugIn == null)            plugIn.setConnected(false);        else {            if (newPlugIn.isConnected())                return false;            newPlugIn.setConnected(true);            newPlugIn.addPlugInListener(this);            buffered = true;        }        plugIn = newPlugIn;        this.resetInput();        return true;    }        /** Gets the attached ConverterPlugin, if any     * @return neural.engine.ConverterPlugIn     */    public ConverterPlugIn getPlugIn() {        return plugIn;    }        /** Added for XML serialization     *  **** DO NOT USE ****     * Use getPlugin instead     */    public void setPlugIn(ConverterPlugIn newPlugIn) {        this.setPlugin(newPlugIn);    }        /**     * Inserire qui la descrizione del metodo.     * Data di creazione: (10/04/00 23.23.26)     * @param newStepCounter boolean     */    public void setStepCounter(boolean newStepCounter) {        StepCounter = newStepCounter;    }        protected void writeObjectBase(ObjectOutputStream out) throws IOException {        int s = 0;        if (isBuffered()) {            s = getInputVector().size();            if ((s == 0) && (tokens != null)) {                gotoFirstLine();                readAll();            }        }        if (out.getClass().getName().indexOf("xstream") != -1) {            out.defaultWriteObject();            if (isBuffered()) {                out.writeObject(InputVector);            }        } else {            out.defaultWriteObject();            if (isBuffered()) {                s = getInputVector().size();                out.writeInt(s);                for (int i = 0; i < s; ++i) {                    out.writeObject(InputVector.elementAt(i));                }            }        }    }        protected void readObjectBase(ObjectInputStream in) throws IOException, ClassNotFoundException {        in.defaultReadObject();        if (in.getClass().getName().indexOf("xstream") != -1) {            if (isBuffered()) {                InputVector = (Vector)in.readObject();            }        } else {            if (isBuffered()) {                Pattern ptn;                getInputVector().removeAllElements();                int s = in.readInt();                for (int i = 0; i < s; ++i) {                    ptn = (Pattern) in.readObject();                    InputVector.addElement(ptn);                }            }        }        if (advColumnsSel == null) {            advColumnsSel = "";        }        if (plugInListeners == null) {            plugInListeners = new ArrayList();        }    }        /** Getter for property lastCol.     * @return Value of property lastCol.     * @deprecated     */    public int getLastCol() {        return lastCol;    }        /** Setter for property lastCol.     * @param lastCol New value of property lastCol.     * @deprecated     */    public void setLastCol(int lastCol) throws IllegalArgumentException {        if (this.lastCol != lastCol) {            this.lastCol = lastCol;            cols = null;        }    }        /** Getter for property firstCol.     * @return Value of property firstCol.     * @deprecated     */    public int getFirstCol() {        return firstCol;    }        /** Setter for property firstCol.     * @param firstCol New value of property firstCol.     * @deprecated     */    public void setFirstCol(int firstCol) throws IllegalArgumentException {        if (this.firstCol != firstCol) {            this.firstCol = firstCol;            cols = null;        }    }        public String getAdvancedColumnSelector() {        return advColumnsSel;    }        public void setAdvancedColumnSelector(String newAdvColSel) {        if (advColumnsSel.compareTo(newAdvColSel) != 0) {            advColumnsSel = newAdvColSel;            this.resetInput();        }    }        public void dataChanged(PlugInEvent data) {        resetInput();    }        /** Getter for property tokens.     * @return Value of property tokens.     */    protected PatternTokenizer getTokens() throws JooneRuntimeException {        if (tokens == null)            initInputStream();        return tokens;    }        protected void setTokens(PatternTokenizer tkn) {        tokens = tkn;        if (tokens != null)            tokens.setDecimalPoint(this.getDecimalPoint());        restart();    }        protected Pattern zeroPattern() {        Pattern pat = new Pattern(new double[getOutputDimension()]);        pat.setCount(-1);        return pat;    }        // You must override this method and insert here the setting of the object tokens.    protected abstract void initInputStream() throws JooneRuntimeException;        /**     * Check that parameters are set correctly.     *     * @see Synapse     * @return validation errors.     */    public TreeSet check() {                // Get the parent's cehck messages.        TreeSet checks = super.check();                // Check that the first row is greater than 0.        if (firstRow <= 0) {            checks.add(new NetCheck(NetCheck.FATAL, "First Row parameter cannot be less than 1.", this));        }                if ( advColumnsSel == null )            if ((firstCol <= 0 || lastCol <= 0)) {            checks.add(new NetCheck(NetCheck.FATAL, "Input columns not set.", this));            } else                //                if ( advColumnsSel != null ) {                if ( advColumnsSel.trim().length() == 0 )                    checks.add(new NetCheck(NetCheck.FATAL, "Input columns not set.", this));                else {            // Check if it can be parsed here...                }        //                }        if (isBuffered()) {            if (getInputVector().size() == 0)                try {                    getTokens();                } catch (JooneRuntimeException jre) {                    checks.add(new NetCheck(NetCheck.FATAL, "Cannot initialize the input stream: "+jre.getMessage(), this));                }        }        if ( getPlugIn() != null ) {            getPlugIn().check(checks); // Should propogate down the plugins        }                return checks;    }        public Collection Inspections() {        Collection col = new ArrayList();        if (isBuffered()) {            if (getInputVector().size() == 0)                if (getTokens() != null)                    readAll();            col.add(new InputsInspection(getInputVector()));        } else {            col.add(new InputsInspection(null));        }        return col;    }        public String InspectableTitle() {        return getName();    }        /** reset the state of the input synapse     *     */    public void reset() {        super.reset();        outs = null; // This will force the call to gotoFirstLine when fwdGet is called    }        /** Getter for property maxBufSize.     * @return Value of property maxBufSize.     *     */    public int getMaxBufSize() {        return maxBufSize;    }        /** Setter for property maxBufSize.     * @param maxBufSize New value of property maxBufSize.     *     */    public void setMaxBufSize(int maxBufSize) {        this.maxBufSize = maxBufSize;    }        /**     * Getter for property inputPatterns.     * Added for XML serialization     * @return Value of property inputPatterns.     */    public Vector getInputPatterns() {        return InputVector;    }        /**     * Setter for property inputPatterns.     * Added for XML serialization     * @param inputPatterns New value of property inputPatterns.     */    public void setInputPatterns(Vector inputPatterns) {        this.InputVector = inputPatterns;    }        /* **************************************************************     * Starting from here there is all the code added in order to     * implement the new I/O framework (see the InputConnector class)     * by P. Marrone (13/09/2004)     */        private int myFirstRow = 1;    private int myLastRow = 0;    // Used to indicate if the plugin.newCycle method must be invoked    private transient boolean skipNewCycle = false;        /** This method is called by the InputConnector in order     * to get the next input pattern available for that connector     */    public synchronized Pattern fwdGet(InputConnector conn) {        if (isBuffered() && (getInputVector().size() == 0)) {            // It'll enter here only the first time, to fill the internal buffer            firstRow = myFirstRow;            lastRow = myLastRow;            startFrom = 0;            skipNewCycle = false;            readAll();        }        // Context switching        if (conn == null)            return null;        // as only one InputConnector can have stepCounter=true,        // the plugin.newCycle is called only once        skipNewCycle = !conn.isStepCounter();        firstRow = conn.getFirstRow();        lastRow = conn.getLastRow();        EOF = conn.isEOF();        currentRow = conn.getCurrentRow();        startFrom = firstRow;        Pattern retValue = fwdGet();        // Reset the context        firstRow = myFirstRow;        lastRow = myLastRow;        startFrom = 0;        return retValue;    }        /**     * Getter for property currentRow.     * @return Value of property currentRow.     */    public int getCurrentRow() {        return currentRow;    }        /**     * Adds a plug-in lsitener to this input stream.     *     * @param aListener the listener to add     */    public void addPlugInListener(PlugInListener aListener) {        if(!plugInListeners.contains(aListener)) {            plugInListeners.add(aListener);        }    }        /**     * Removes a plug-in listener from this input stream.     *     * @param aListener the listener to remove     */    public void removePlugInListener(PlugInListener aListener) {        plugInListeners.remove(aListener);    }        /**     * Gets all the plug-in listeners.     *     * @return the plug-in listeners.     */    public List getAllPlugInListeners() {        return plugInListeners;    }        /**     * Fires an event to the plug-in listeners notifying that the underlying data     * has changed.     */    protected void fireDataChanged() {        Object[] myList;        synchronized (this) {            myList = getAllPlugInListeners().toArray();        }                for (int i=0; i < myList.length; ++i) {            if (myList[i] != null) {                ((PlugInListener)myList[i]).dataChanged(new PlugInEvent(this));            }        }    }        }

⌨️ 快捷键说明

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