All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.basking2.sdsai.sandbox.ai.nnet.NeuralNet Maven / Gradle / Ivy

The newest version!
/* $Id: NeuralNet.java 670 2008-05-02 20:42:07Z sbaskin $ */

package com.github.basking2.sdsai.sandbox.ai.nnet;

import com.github.basking2.sdsai.sandbox.graph.GraphCopier;
import com.github.basking2.sdsai.sandbox.graph.Node;

public class NeuralNet
{
  
  protected boolean learn;
  protected IngressEdge[] input;
  protected EgressEdge[] output;
  
  /**
   * Version of input or output.
   */
  protected int version = 0;
  
  /**
   * Speed at which to "learn."
   */
  protected double eta = 10;

  /**
   * A scaler used to alter the range of eta values computed.
   */
  protected double scaler = 1;

  /**
   * This constructor takes a user-constructed neural net.  The only
   * nodes required are ingress and egress edge arrays.  All hidden
   * nodes are manipulated by recursivly operating on the egress edges.
   * The ingress edges are needed to set the input values.
   */
  public NeuralNet(IngressEdge[] i, EgressEdge[] o){
    input = i;
    output = o;
  }

  /**
   * This constructor automates the process of building a neural net.
   * The number of input and outputs is specified.  The layerSize is an
   * array of layer sizes.  An array of size 0 or null may be passed if no
   * hidden units are desired.  The boolean sc, if true, uses a 
   * ScaledHiddenNode instead of a HiddenNode for the hidden nodes.
   * The difference is that a ScaledHiddenNode has one extra edge for input.
   * The extra, scaling, edge can sometimes allow for better versatility in
   * training but may also confuse the neural net in some instances.
   * This is why the option of choices is given.  Note the neural nets with
   * scaled hidden nodes tend to have significantly longer training epoches.
   * @param innumber the number of inputs.
   * @param outnumber the number of classes or outputs.
   * @param layerSizes an array of sizes for each hidden layer from the
   * inputs to the outputs.
   * @param sc if true, ScaledHiddenNodes are used instead of HiddenNodes.
   */
  public NeuralNet(int innumber, int outnumber, int[] layerSizes, boolean sc)
  {
    input  = new IngressEdge[innumber];
    output = new EgressEdge[outnumber];
    
    if(layerSizes==null)
      layerSizes=new int[0];

    HiddenNode[] layer1 = new HiddenNode[innumber]; /* set up input */
    HiddenNode[] layer2; /* another layer used later*/

    /**** CREATE INPUT LAYER ****/
    for(int i=0;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy