コード例 #1
0
  /** Sets default input and output neurons for network (first layer as input, last as output) */
  public static void setDefaultIO(NeuralNetwork nnet) {
    ArrayList<Neuron> inputNeuronsList = new ArrayList<Neuron>();
    Layer firstLayer = nnet.getLayerAt(0);
    for (Neuron neuron : firstLayer.getNeurons()) {
      if (!(neuron instanceof BiasNeuron)) { // dont set input to bias
        // neurons
        inputNeuronsList.add(neuron);
      }
    }

    Neuron[] inputNeurons = new Neuron[inputNeuronsList.size()];
    inputNeurons = inputNeuronsList.toArray(inputNeurons);
    Neuron[] outputNeurons = ((Layer) nnet.getLayerAt(nnet.getLayersCount() - 1)).getNeurons();

    nnet.setInputNeurons(inputNeurons);
    nnet.setOutputNeurons(outputNeurons);
  }
  private void learnPattern(DataSetRow dataSetRow, int neighborhood) {
    neuralNetwork.setInput(dataSetRow.getInput());
    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
  }