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

📄 abstractconverterplugin.java

📁 一个纯java写的神经网络源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * AbstractConverterPlugIn.java * * Created on October 11, 2004, 3:52 PM */package org.joone.util;import java.util.*;import java.io.*;import org.joone.net.NetCheck;import org.joone.engine.*;import org.joone.log.*;/** * This abstract class must be extended to implement plug-ins for input or output * data pre- or post-processing. * * <!-- Note *      This class is created to remove differences and duplicated code between * the ConverterPlugIn and the OutputConverterPlugIn. * --> * * @author  Boris Jansen */public abstract class AbstractConverterPlugIn implements java.io.Serializable, PlugInListener {        /** The serial version of this object. */    private static final long serialVersionUID = 5698511686417862414L;    /** The object used when logging debug, errors, warnings and info. */    private static final ILogger log = LoggerFactory.getLogger(AbstractConverterPlugIn.class);        /** The next plugin in this series of cascading plugins. */    private AbstractConverterPlugIn nextPlugIn = null;        /** The name of this plug-in object. */    private String name;        /** This flag indicates if this plug-in is connected. Whenever a plug in is connected     * it cannot be connected / added to another input stream / plug-in. */    private boolean connected;        /** A vector of objects that are listening to this object for plug-in (data changed) events. */    protected Vector pluginListeners;        /** The Vector of input patterns which this converter must process. */    private transient Vector InputVector;        /**     * The <code>AdvancedSerieSelector</code> instructs this plug-in what serie/columns     * it should process. The format of this specification is a common separated list of     * values and ranges. E.g '1,2,5,7' will instruct the converter to convert serie 1     * and 2 and 5 and 7. A range can also be used e.g '2,4,5-8,9' will instruct the     * converter to process serie 2 and 4 and 5 and 6 and 7 and 8 and 9.  A range is specifed     * using a '-' character with the number of the serie on either side.     * <P>Note <b>NO</b> negative numbers can be used in the <code>AdvancedSerieSelector</code>.</P>     */    private String AdvancedSerieSelector = new String("");        /** The series to be converted. */    private transient int [] serieSelected;        /** Creates a new instance of AbstractConverterPlugIn */    public AbstractConverterPlugIn() {    }        /**     * Creates a new instance of AbstractConverterPlugIn     *     * @param anAdvancedSerieSelector the advanced serie selector to use.     * @see setAdvancedSerieSelector()     */    public AbstractConverterPlugIn(String anAdvancedSerieSelector) {        setAdvancedSerieSelector(anAdvancedSerieSelector);    }        /**     * Converts all the patterns contained by {@link #InputVector} and on the     * serie specifed by the call to {@link setAdvancedSerieSelector#setAdvancedSerieSelector}.     * It cascades also the conversion to the next-plugin connected in the chain.     */    public void convertPatterns() {        apply();        cascade();    }        /**     * Applies all the conversions on the patterns contained by {@link #InputVector}      * @return true if the input buffer is changed     */    protected boolean apply() {        boolean retValue = false;        if ((getInputVector() != null) && (getInputVector().size() > 0)) {            retValue = applyOnColumns() | applyOnRows();        } else {            log.warn( getName()+" : Plugin has no input data to convert." );        }        return retValue;    }        /**     * Applies the conversion on the patterns contained by {@link #InputVector} and on the     * columns specifed by the call to {@link setAdvancedSerieSelector#setAdvancedSerieSelector}.     */    protected boolean applyOnColumns() {        boolean retValue = false;        Pattern currPE = (Pattern) getInputVector().elementAt(0);        int aSize = currPE.getArray().length;                // Use Advanced Serie Selector to select the serie to convert        if ( (getAdvancedSerieSelector() != null ) && (!getAdvancedSerieSelector().equals(new String(""))) ) {            int [] mySerieSelected = getSerieSelected();            for(int i = 0; i < mySerieSelected.length; i++) {                if(mySerieSelected[i]-1 < aSize) {  // Check we don't go over array bounds.                    retValue = convert(mySerieSelected[i]-1) | retValue;                } else {                    log.warn(getName() + " : Advanced Serie Selector contains too many serie. Check the number of columns in the appropriate input synapse.");                }            }        }        return retValue;    }        /**     * Applies the conversion on the patterns contained by {@link #InputVector}      * on all the rows. Override this empty method to apply any change to the      * order of the input vector's rows.     */    protected boolean applyOnRows() {        return false;    }        /**     * Cascades the <code>convertPatterns()</code> method call to the next plug-in.     */    protected void cascade() {        if (getNextPlugIn() != null) { // Loop through other cascading plugins            AbstractConverterPlugIn myPlugIn = getNextPlugIn();            myPlugIn.setInputVector(getInputVector());            myPlugIn.convertPatterns();        }    }        /**     * Applies the conversion on the Nth serie of the buffered pattern data. The method is abstract     * and should be overridden by the implementing class. Implementing classes can obtain the     * input patterns by calling the {@link #getInputVector()} method. The result is a     * <code>Vector</code> of <code>Pattern</code> objects which this method should use by converting     * the requested serie.     *     * @param serie the serie to convert     */    protected abstract boolean convert(int serie);        /**     * Gets the double value at the specified row (point) in the specifed serie /     * column.     *     * @param point The row at which to get the pattern's double value.     * @param serie The serie or column from which to obtain the value.     * @return The value at the specified point in the input vector.     */    protected double getValuePoint(int point, int serie) {        Pattern currPE = (Pattern) getInputVector().elementAt(point);        return currPE.getArray()[serie];    }        /**     * Gets the name of this plug-in object.     *     * @return The name of this plug-in.     */    public String getName() {        return name;    }        /**     * Sets the name of this plug-in object.     *     * @param aName New name for this object.     */    public void setName(String aName) {        name = aName;    }        /**     * Getter for property connected.     * This property is true when this plugin has been     * attached either to a StreamInputSynapse or to     * another plugin.     * @return Value of property connected.     */    public boolean isConnected() {        return connected;    }        /**     * Setter for property connected.     * This property is true when this plugin has been     * attached either to a StreamInputSynapse or to     * another plugin.     * @param aConnected New value of property connected.     */    public void setConnected(boolean aConnected) {        connected = aConnected;    }        /**     * Adds an {@link PlugInListener} to this plug-in. Usually this will be the     * previous plug-in in the series of cascading plug-ins or the stream     * input/output synapse.     *     * @param aListener The listener that requires notification of events from     * this plug-in whenever data changes.     */    public synchronized void addPlugInListener(PlugInListener aListener) {        if(!getPluginListeners().contains(aListener)) {            getPluginListeners().add(aListener);        }    }        /**     * Removes a {@link PlugInListener} that was previously registered to receive     * plugin (data changed) events.     *     * @param aListener The listener that does not want to receive any events     * anymore from this plug-in.     */    public synchronized void removePlugInListener(PlugInListener aListener) {        if (getPluginListeners().contains(aListener)) {            getPluginListeners().remove(aListener);        }    }        /**     * Gets a vector of all the {@link PlugInListener}s that have been registerd     * to receive events from this plug-in.     *     * @return The vector of <code>PlugInListener</code>s listening to this     * converter plug-in object.     */

⌨️ 快捷键说明

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