Example usage for weka.classifiers.functions.neural NeuralNode NeuralNode

List of usage examples for weka.classifiers.functions.neural NeuralNode NeuralNode

Introduction

In this page you can find the example usage for weka.classifiers.functions.neural NeuralNode NeuralNode.

Prototype

public NeuralNode(String id, Random r, NeuralMethod m) 

Source Link

Usage

From source file:CJWeka.java

License:Open Source License

/**
 * This creates the required output units.
 *///from w  ww  . j a  va 2 s . c o  m
private void setupOutputs() throws Exception {

    m_outputs = new NeuralEnd[m_numClasses];
    for (int noa = 0; noa < m_numClasses; noa++) {
        if (m_numeric) {
            m_outputs[noa] = new NeuralEnd(m_instances.classAttribute().name());
        } else {
            m_outputs[noa] = new NeuralEnd(
                    m_instances.classAttribute().name() + m_instances.classAttribute().value(noa));
        }

        m_outputs[noa].setLink(false, true, noa);
        NeuralNode temp = new NeuralNode("o" + m_nextId, m_random, m_sigmoidUnit);
        m_nextId++;
        addNode(temp);
        NeuralConnection.connect(temp, m_outputs[noa]);
    }

}

From source file:CJWeka.java

License:Open Source License

/**
 * Call this function to automatically generate the hidden units
 *///  w w  w . j av  a 2 s .c  o  m
private void setupHiddenLayer() {
    for (int nob = 0; nob < m_hiddenLayers; nob++) {
        NeuralNode temp = new NeuralNode("h" + m_nextId, m_random, m_sigmoidUnit);
        m_nextId++;
        addNode(temp);
    }

    for (int noa = 0; noa < m_numAttributes + m_hiddenLayers; noa++) {
        for (int nob = m_numClasses; nob < m_numClasses + m_hiddenLayers; nob++) {
            NeuralConnection.connect(m_inputs[noa], m_neuralNodes[nob]);
        }
    }
    for (int noa = m_numClasses; noa < m_neuralNodes.length; noa++) {
        for (int nob = 0; nob < m_numClasses; nob++) {
            NeuralConnection.connect(m_neuralNodes[noa], m_neuralNodes[nob]);
        }
    }

}

From source file:classifiers.mlp.MultilayerPerceptronCustom.java

License:Open Source License

/**
 * This creates the required output units.
 *///from w  ww. ja  v a 2  s .co m
private void setupOutputs() throws Exception {

    m_outputs = new NeuralEnd[m_numClasses];
    for (int noa = 0; noa < m_numClasses; noa++) {
        if (m_numeric) {
            m_outputs[noa] = new NeuralEnd(m_instances.classAttribute().name());
        } else {
            m_outputs[noa] = new NeuralEnd(m_instances.classAttribute().value(noa));
        }

        m_outputs[noa].setX(.9);
        m_outputs[noa].setY((noa + 1.0) / (m_numClasses + 1));
        m_outputs[noa].setLink(false, noa);
        NeuralNode temp = new NeuralNode(String.valueOf(m_nextId), m_random, m_sigmoidUnit);
        m_nextId++;
        temp.setX(.75);
        temp.setY((noa + 1.0) / (m_numClasses + 1));
        addNode(temp);
        NeuralConnection.connect(temp, m_outputs[noa]);
    }

}

From source file:classifiers.mlp.MultilayerPerceptronCustom.java

License:Open Source License

/**
 * Call this function to automatically generate the hidden units
 *//*from  w  w w  .  j a  va2s.c om*/
private void setupHiddenLayer() {
    StringTokenizer tok = new StringTokenizer(m_hiddenLayers, ",");
    int val = 0; //num of nodes in a layer
    int prev = 0; //used to remember the previous layer
    int num = tok.countTokens(); //number of layers
    String c;
    for (int noa = 0; noa < num; noa++) {
        //note that I am using the Double to get the value rather than the
        //Integer class, because for some reason the Double implementation can
        //handle leading white space and the integer version can't!?!
        c = tok.nextToken().trim();
        if (c.equals("a")) {
            val = (m_numAttributes + m_numClasses) / 2;
        } else if (c.equals("i")) {
            val = m_numAttributes;
        } else if (c.equals("o")) {
            val = m_numClasses;
        } else if (c.equals("t")) {
            val = m_numAttributes + m_numClasses;
        } else {
            val = Double.valueOf(c).intValue();
        }
        for (int nob = 0; nob < val; nob++) {
            NeuralNode temp = new NeuralNode(String.valueOf(m_nextId), m_random, m_sigmoidUnit);
            m_nextId++;
            temp.setX(.5 / (num) * noa + .25);
            temp.setY((nob + 1.0) / (val + 1));
            addNode(temp);
            if (noa > 0) {
                //then do connections
                for (int noc = m_neuralNodes.length - nob - 1 - prev; noc < m_neuralNodes.length - nob
                        - 1; noc++) {
                    NeuralConnection.connect(m_neuralNodes[noc], temp);
                }
            }
        }
        prev = val;
    }
    tok = new StringTokenizer(m_hiddenLayers, ",");
    c = tok.nextToken();
    if (c.equals("a")) {
        val = (m_numAttributes + m_numClasses) / 2;
    } else if (c.equals("i")) {
        val = m_numAttributes;
    } else if (c.equals("o")) {
        val = m_numClasses;
    } else if (c.equals("t")) {
        val = m_numAttributes + m_numClasses;
    } else {
        val = Double.valueOf(c).intValue();
    }

    if (val == 0) {
        for (int noa = 0; noa < m_numAttributes; noa++) {
            for (int nob = 0; nob < m_numClasses; nob++) {
                NeuralConnection.connect(m_inputs[noa], m_neuralNodes[nob]);
            }
        }
    } else {
        for (int noa = 0; noa < m_numAttributes; noa++) {
            for (int nob = m_numClasses; nob < m_numClasses + val; nob++) {
                NeuralConnection.connect(m_inputs[noa], m_neuralNodes[nob]);
            }
        }
        for (int noa = m_neuralNodes.length - prev; noa < m_neuralNodes.length; noa++) {
            for (int nob = 0; nob < m_numClasses; nob++) {
                NeuralConnection.connect(m_neuralNodes[noa], m_neuralNodes[nob]);
            }
        }
    }

}

From source file:com.ifmo.recommendersystem.metafeatures.classifierbased.internal.extractors.MultilayerPerceptron.java

License:Open Source License

/**
 * Call this function to automatically generate the hidden units
 *///ww  w .  j a v  a 2s  .  c  om
private void setupHiddenLayer() {
    StringTokenizer tok = new StringTokenizer(m_hiddenLayers, ",");
    int val = 0; // num of nodes in a layer
    int prev = 0; // used to remember the previous layer
    int num = tok.countTokens(); // number of layers
    String c;
    for (int noa = 0; noa < num; noa++) {
        // note that I am using the Double to get the value rather than the
        // Integer class, because for some reason the Double implementation can
        // handle leading white space and the integer version can't!?!
        c = tok.nextToken().trim();
        if (c.equals("a")) {
            val = (m_numAttributes + m_numClasses) / 2;
        } else if (c.equals("i")) {
            val = m_numAttributes;
        } else if (c.equals("o")) {
            val = m_numClasses;
        } else if (c.equals("t")) {
            val = m_numAttributes + m_numClasses;
        } else {
            val = Double.valueOf(c).intValue();
        }
        for (int nob = 0; nob < val; nob++) {
            NeuralNode temp = new NeuralNode(String.valueOf(m_nextId), m_random, m_sigmoidUnit);
            m_nextId++;
            temp.setX(.5 / (num) * noa + .25);
            temp.setY((nob + 1.0) / (val + 1));
            addNode(temp);
            if (noa > 0) {
                // then do connections
                for (int noc = m_neuralNodes.length - nob - 1 - prev; noc < m_neuralNodes.length - nob
                        - 1; noc++) {
                    NeuralConnection.connect(m_neuralNodes[noc], temp);
                }
            }
        }
        prev = val;
    }
    tok = new StringTokenizer(m_hiddenLayers, ",");
    c = tok.nextToken();
    if (c.equals("a")) {
        val = (m_numAttributes + m_numClasses) / 2;
    } else if (c.equals("i")) {
        val = m_numAttributes;
    } else if (c.equals("o")) {
        val = m_numClasses;
    } else if (c.equals("t")) {
        val = m_numAttributes + m_numClasses;
    } else {
        val = Double.valueOf(c).intValue();
    }

    if (val == 0) {
        for (int noa = 0; noa < m_numAttributes; noa++) {
            for (int nob = 0; nob < m_numClasses; nob++) {
                NeuralConnection.connect(m_inputs[noa], m_neuralNodes[nob]);
            }
        }
    } else {
        for (int noa = 0; noa < m_numAttributes; noa++) {
            for (int nob = m_numClasses; nob < m_numClasses + val; nob++) {
                NeuralConnection.connect(m_inputs[noa], m_neuralNodes[nob]);
            }
        }
        for (int noa = m_neuralNodes.length - prev; noa < m_neuralNodes.length; noa++) {
            for (int nob = 0; nob < m_numClasses; nob++) {
                NeuralConnection.connect(m_neuralNodes[noa], m_neuralNodes[nob]);
            }
        }
    }

}

From source file:org.ssase.debt.classification.OnlineMultilayerPerceptron.java

License:Open Source License

/**
 * Call this function to automatically generate the hidden units
 *///from  w w w  .  j  a v  a2s. c om
private void setupHiddenLayer() {
    StringTokenizer tok = new StringTokenizer(m_hiddenLayers, ",");
    int val = 0; // num of nodes in a layer
    int prev = 0; // used to remember the previous layer
    int num = tok.countTokens(); // number of layers
    String c;
    for (int noa = 0; noa < num; noa++) {
        // note that I am using the Double to get the value rather than the
        // Integer class, because for some reason the Double implementation
        // can
        // handle leading white space and the integer version can't!?!
        c = tok.nextToken().trim();
        if (c.equals("a")) {
            val = (m_numAttributes + m_numClasses) / 2;
        } else if (c.equals("i")) {
            val = m_numAttributes;
        } else if (c.equals("o")) {
            val = m_numClasses;
        } else if (c.equals("t")) {
            val = m_numAttributes + m_numClasses;
        } else {
            val = Double.valueOf(c).intValue();
        }
        for (int nob = 0; nob < val; nob++) {
            NeuralNode temp = new NeuralNode(String.valueOf(m_nextId), m_random, m_sigmoidUnit);
            m_nextId++;
            temp.setX(.5 / (num) * noa + .25);
            temp.setY((nob + 1.0) / (val + 1));
            addNode(temp);
            if (noa > 0) {
                // then do connections
                for (int noc = m_neuralNodes.length - nob - 1 - prev; noc < m_neuralNodes.length - nob
                        - 1; noc++) {
                    NeuralConnection.connect(m_neuralNodes[noc], temp);
                }
            }
        }
        prev = val;
    }
    tok = new StringTokenizer(m_hiddenLayers, ",");
    c = tok.nextToken();
    if (c.equals("a")) {
        val = (m_numAttributes + m_numClasses) / 2;
    } else if (c.equals("i")) {
        val = m_numAttributes;
    } else if (c.equals("o")) {
        val = m_numClasses;
    } else if (c.equals("t")) {
        val = m_numAttributes + m_numClasses;
    } else {
        val = Double.valueOf(c).intValue();
    }

    if (val == 0) {
        for (int noa = 0; noa < m_numAttributes; noa++) {
            for (int nob = 0; nob < m_numClasses; nob++) {
                NeuralConnection.connect(m_inputs[noa], m_neuralNodes[nob]);
            }
        }
    } else {
        for (int noa = 0; noa < m_numAttributes; noa++) {
            for (int nob = m_numClasses; nob < m_numClasses + val; nob++) {
                NeuralConnection.connect(m_inputs[noa], m_neuralNodes[nob]);
            }
        }
        for (int noa = m_neuralNodes.length - prev; noa < m_neuralNodes.length; noa++) {
            for (int nob = 0; nob < m_numClasses; nob++) {
                NeuralConnection.connect(m_neuralNodes[noa], m_neuralNodes[nob]);
            }
        }
    }

}