Package org.neuroph.core

Examples of org.neuroph.core.Layer


    // init neuron settings for this type of network
    NeuronProperties neuronProperties = new NeuronProperties();
    neuronProperties.setProperty("transferFunction", TransferFunctionType.STEP);
   
    // create input layer
    Layer inputLayer = LayerFactory.createLayer(1, neuronProperties);
    this.addLayer(inputLayer);

    // createLayer output layer
    neuronProperties.setProperty("transferFunction", TransferFunctionType.RAMP);
    Layer outputLayer = LayerFactory.createLayer(outputNeuronsCount,  neuronProperties);
    this.addLayer(outputLayer);

    // create full conectivity between input and output layer
    ConnectionFactory.fullConnect(inputLayer, outputLayer);
View Full Code Here


    // set network type
    this.setNetworkType(NeuralNetworkType.NEURO_FUZZY_REASONER);

    // createLayer input layer
    NeuronProperties neuronProperties = new NeuronProperties();
    Layer inLayer = LayerFactory.createLayer(new Integer(inputNum),
        neuronProperties);
    this.addLayer(inLayer);

    // createLayer fuzzy set layer
    neuronProperties.setProperty("transferFunction",
        TransferFunctionType.TRAPEZOID);
    Enumeration<Integer> e = inputSets.elements();
    int fuzzySetsNum = 0;
    while (e.hasMoreElements()) {
      Integer i = e.nextElement();
      fuzzySetsNum = fuzzySetsNum + i.intValue();
    }
    Layer setLayer = LayerFactory.createLayer(fuzzySetsNum,
        neuronProperties);
    this.addLayer(setLayer);

    // TODO: postavi parametre funkcija pripadnosti
    // nizove sa trning elementima iznesi van klase i prosledjuj ih kao
    // parametre
    Iterator<Neuron> ii = setLayer.getNeuronsIterator();
    Enumeration<Integer> en;// =setLayer.neurons();
    int c = 0;
    while (ii.hasNext()) {
      Neuron cell = ii.next();
      Trapezoid tf = (Trapezoid) cell.getTransferFunction();

      if (c <= 3) {
        tf.setLeftLow(pointsSets[c][0]);
        tf.setLeftHigh(pointsSets[c][1]);
        tf.setRightLow(pointsSets[c][3]);
        tf.setRightHigh(pointsSets[c][2]);
      } else {
        tf.setLeftLow(timeSets[c - 4][0]);
        tf.setLeftHigh(timeSets[c - 4][1]);
        tf.setRightLow(timeSets[c - 4][3]);
        tf.setRightHigh(timeSets[c - 4][2]);
      }
      c++;
    }

    // povezi prvi i drugi sloj
    int s = 0; // brojac celija sloja skupova (fazifikacije)
    for (int i = 0; i < inputNum; i++) { // brojac ulaznih celija
      Neuron from = inLayer.getNeuronAt(i);
      int jmax = inputSets.elementAt(i).intValue();
      for (int j = 0; j < jmax; j++) {
        Neuron to = setLayer.getNeuronAt(s);
        ConnectionFactory.createConnection(from, to, 1);
        s++;
      }
    }

    // ----------------------------------------------------------

    // createLayer rules layer
    NeuronProperties ruleNeuronProperties = new NeuronProperties(
                        WeightsFunctionType.WEIGHTED_INPUT,
                        SummingFunctionType.MIN,
                        TransferFunctionType.LINEAR);
    en = inputSets.elements();
    int fuzzyAntNum = 1;
    while (en.hasMoreElements()) {
      Integer i = en.nextElement();
      fuzzyAntNum = fuzzyAntNum * i.intValue();
    }
    Layer ruleLayer = LayerFactory.createLayer(fuzzyAntNum,
        ruleNeuronProperties);
    this.addLayer(ruleLayer);

    int scIdx = 0; // set cell index

    for (int i = 0; i < inputNum; i++) { // brojac ulaza (grupa fuzzy
                        // skupova)
      int setsNum = inputSets.elementAt(i).intValue();

      for (int si = 0; si < setsNum; si++) { // brojac celija fuzzy
                          // skupova
        if (i == 0) {
          Neuron from = setLayer.getNeuronAt(si);
          int connPerCell = fuzzyAntNum / setsNum;
          scIdx = si;

          for (int k = 0; k < connPerCell; k++) { // brojac celija
                              // hipoteza
            Neuron to = ruleLayer.getNeuronAt(si * connPerCell + k);
            ConnectionFactory.createConnection(from, to,
                new Double(1));
          } // for
        } // if
        else {
          scIdx++;
          Neuron from = setLayer.getNeuronAt(scIdx);
          int connPerCell = fuzzyAntNum / setsNum;

          for (int k = 0; k < connPerCell; k++) { // brojac celija
                              // hipoteza
            int toIdx = si + k * setsNum;
            Neuron to = ruleLayer.getNeuronAt(toIdx);
            ConnectionFactory.createConnection(from, to,
                new Double(1));
          } // for k
        } // else
      } // for si
    } // for i

    // kreiraj izlazni sloj
    neuronProperties = new NeuronProperties();
    neuronProperties.setProperty("transferFunction",
        TransferFunctionType.STEP);
    Layer outLayer = LayerFactory.createLayer(new Integer(outNum),
        neuronProperties);
    this.addLayer(outLayer);

    ConnectionFactory.fullConnect(ruleLayer, outLayer);

View Full Code Here

    // set network type
    this.setNetworkType(NeuralNetworkType.NEURO_FUZZY_REASONER);

    // CREATE INPUT LAYER
    NeuronProperties neuronProperties = new NeuronProperties();
    Layer inLayer = LayerFactory.createLayer(new Integer(inputNum),
        neuronProperties);
    this.addLayer(inLayer);

    // CREATE FUZZY SET LAYER
    neuronProperties.setProperty("transferFunction",
        TransferFunctionType.TRAPEZOID);
    Enumeration<Integer> e = inputSets.elements();
    int fuzzySetsNum = 0;
    while (e.hasMoreElements()) {
      Integer i = e.nextElement();
      fuzzySetsNum = fuzzySetsNum + i.intValue();
    }
    Layer setLayer = LayerFactory.createLayer(new Integer(fuzzySetsNum),
        neuronProperties);
    this.addLayer(setLayer);

    // TODO: postavi parametre funkcija pripadnosti
    // nizove sa trning elementima iznesi van klase i prosledjuj ih kao
    // parametre
    Iterator<Neuron> ii = setLayer.getNeuronsIterator();
    Enumeration<Integer> en;// =setLayer.neurons();
    int c = 0;
    while (ii.hasNext()) {
      Neuron cell = ii.next();
      Trapezoid tf = (Trapezoid) cell.getTransferFunction();
      /*
       * if (c<=3) { tf.setLeftLow(pointsSets[c][0]);
       * tf.setLeftHigh(pointsSets[c][1]); tf.setRightLow(pointsSets[c][3]);
       * tf.setRightHigh(pointsSets[c][2]); } else { tf.setLeftLow(timeSets[c-4][0]);
       * tf.setLeftHigh(timeSets[c-4][1]); tf.setRightLow(timeSets[c-4][3]);
       * tf.setRightHigh(timeSets[c-4][2]); } c++;
       */
    }

    // createLayer connections between input and fuzzy set getLayersIterator
    int s = 0; // brojac celija sloja skupova (fazifikacije)
    for (int i = 0; i < inputNum; i++) { // brojac ulaznih celija
      Neuron from = inLayer.getNeuronAt(i);
      int jmax = inputSets.elementAt(i).intValue();
      for (int j = 0; j < jmax; j++) {
        Neuron to = setLayer.getNeuronAt(s);
        ConnectionFactory.createConnection(from, to, new Double(1));
        s++;
      }
    }

    // ----------------------------------------------------------

    // kreiraj sloj pravila
    neuronProperties
        .setProperty("summingFunction", SummingFunctionType.MIN);
    neuronProperties.setProperty("transferFunction",
        TransferFunctionType.LINEAR);
    en = inputSets.elements();
    int fuzzyAntNum = 1;
    while (en.hasMoreElements()) {
      Integer i = en.nextElement();
      fuzzyAntNum = fuzzyAntNum * i.intValue();
    }
    Layer ruleLayer = LayerFactory.createLayer(new Integer(fuzzyAntNum),
        neuronProperties);
    this.addLayer(ruleLayer);

    // povezi set i rule layer

    int scIdx = 0; // set cell index

    for (int i = 0; i < inputNum; i++) { // brojac ulaza (grupa fuzzy
                        // skupova)
      int setsNum = inputSets.elementAt(i).intValue();

      for (int si = 0; si < setsNum; si++) { // brojac celija fuzzy
                          // skupova
        if (i == 0) {
          Neuron from = setLayer.getNeuronAt(si);
          int connPerCell = fuzzyAntNum / setsNum;
          scIdx = si;

          for (int k = 0; k < connPerCell; k++) { // brojac celija
                              // hipoteza
            Neuron to = ruleLayer.getNeuronAt(si * connPerCell + k);
            ConnectionFactory.createConnection(from, to,
                new Double(1));
          } // for
        } // if
        else {
          scIdx++;
          Neuron from = setLayer.getNeuronAt(scIdx);
          int connPerCell = fuzzyAntNum / setsNum;

          for (int k = 0; k < connPerCell; k++) { // brojac celija
                              // hipoteza
            int toIdx = si + k * setsNum;
            Neuron to = ruleLayer.getNeuronAt(toIdx);
            ConnectionFactory.createConnection(from, to,
                new Double(1));
          } // for k
        } // else
      } // for si
    } // for i

    // set input and output cells for this network
    neuronProperties = new NeuronProperties();
    neuronProperties.setProperty("transferFunction",
        TransferFunctionType.STEP);
    Layer outLayer = LayerFactory.createLayer(new Integer(outNum),
        neuronProperties);
    this.addLayer(outLayer);

    ConnectionFactory.fullConnect(ruleLayer, outLayer);

View Full Code Here

    // set network type code
    this.setNetworkType(NeuralNetworkType.RBF_NETWORK);

    // create input layer
    Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, TransferFunctionType.LINEAR);
    this.addLayer(inputLayer);

    // create rbf layer
    Layer rbfLayer = LayerFactory.createLayer(rbfNeuronsCount, rbfNeuronProperties);
    this.addLayer(rbfLayer);

    // create output layer
    Layer outputLayer = LayerFactory.createLayer(outputNeuronsCount, TransferFunctionType.LINEAR);
    this.addLayer(outputLayer);

    // create full conectivity between input and rbf layer
    ConnectionFactory.fullConnect(inputLayer, rbfLayer);
    // create full conectivity between rbf and output layer
View Full Code Here

    // set network type code
    this.setNetworkType(NeuralNetworkType.UNSUPERVISED_HEBBIAN_NET);

    // createLayer input layer
    Layer inputLayer = LayerFactory.createLayer(inputNeuronsNum,
      neuronProperties);
    this.addLayer(inputLayer);

    // createLayer output layer
    Layer outputLayer = LayerFactory.createLayer(outputNeuronsNum,
      neuronProperties);
    this.addLayer(outputLayer);

    // createLayer full conectivity between input and output layer
    ConnectionFactory.fullConnect(inputLayer, outputLayer);
View Full Code Here

   *            training set to learn
   */
  public void learn(TrainingSet trainingSet) {
    int M = trainingSet.size();
    int N = neuralNetwork.getLayerAt(0).getNeuronsCount();
    Layer hopfieldLayer = neuralNetwork.getLayerAt(0);

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (j == i)
          continue;
        Neuron ni = hopfieldLayer.getNeuronAt(i);
        Neuron nj = hopfieldLayer.getNeuronAt(j);
        Connection cij = nj.getConnectionFrom(ni);
        Connection cji = ni.getConnectionFrom(nj);
        double w = 0;
        for (int k = 0; k < M; k++) {
          TrainingElement trainingElement = trainingSet.elementAt(k);
View Full Code Here

     * buffers to update all weights in network. It is executed after each epoch if learning is in batch mode.
     */
    protected void batchModeWeightsUpdate() {
        // iterate layers from output to input
        for (int i = neuralNetwork.getLayersCount() - 1; i > 0; i--) {
            Layer layer = neuralNetwork.getLayers().get(i);
            // iterate neurons at each layer
            for (Neuron neuron : layer.getNeurons()) {
                // iterate connections/weights for each neuron
                for (Connection connection : neuron.getInputConnections()) {
                    // for each connection weight apply accumulated weight change
                    Weight weight = connection.getWeight();
                    // get deltaWeightSum
View Full Code Here

     * This method initializes training data buffers in all network weights.
     * It can be overridden to create bigger training data buffer for each weight.
     */
    protected void initTrainingDataBuffer() {
        for (int i = neuralNetwork.getLayersCount() - 1; i > 0; i--) {
            Layer layer = neuralNetwork.getLayers().get(i);
            for (Neuron neuron : layer.getNeurons()) {
                for (Connection connection : neuron.getInputConnections()) {
                    Weight weight = connection.getWeight();
                    weight.initTrainingDataBuffer(this.trainingDataBufferSize);
                }
            }
View Full Code Here

   */
  protected void adjustHiddenLayers() {
    int layerNum = this.neuralNetwork.getLayersCount();

    for (int i = layerNum - 2; i > 0; i--) {
      Layer layer = neuralNetwork.getLayerAt(i);
     
      for(Neuron neuron : layer.getNeurons()) { 
        double delta = this.calculateDelta(neuron);
        neuron.setError(delta);
        this.updateNeuronWeights(neuron);
      } // for
    } // for
View Full Code Here

    neuralNetwork.calculate();
    Neuron winner = getClosest();
    if (winner.getOutput() == 0)
      return; // ako je vec istrenirana jedna celija, izadji

    Layer mapLayer = neuralNetwork.getLayerAt(1);
    int winnerIdx = mapLayer.indexOf(winner);
    adjustCellWeights(winner, 0);

    int cellNum = mapLayer.getNeuronsCount();
    for (int p = 0; p < cellNum; p++) {
      if (p == winnerIdx)
        continue;
      if (isNeighbor(winnerIdx, p, neighborhood)) {
        Neuron cell = mapLayer.getNeuronAt(p);
        adjustCellWeights(cell, 1);
      } // if
    } // for

  }
View Full Code Here

TOP

Related Classes of org.neuroph.core.Layer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.