org.neuroph.util.TransferFunctionType Java Examples

The following examples show how to use org.neuroph.util.TransferFunctionType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MomentumBackPropagationTest.java    From NeurophFramework with Apache License 2.0 7 votes vote down vote up
@Test
public void testXorMSE() {
    MultiLayerPerceptron myMlPerceptron = new MultiLayerPerceptron(TransferFunctionType.SIGMOID, 2, 3, 1);
    myMlPerceptron.randomizeWeights(new WeightsRandomizer(new Random(123)));

    myMlPerceptron.setLearningRule(instance);
    myMlPerceptron.learn(xorDataSet);

    MeanSquaredError mse = new MeanSquaredError();
    for (DataSetRow testSetRow : xorDataSet.getRows()) {
        myMlPerceptron.setInput(testSetRow.getInput());
        myMlPerceptron.calculate();
        double[] networkOutput = myMlPerceptron.getOutput();
        mse.addPatternError(networkOutput, testSetRow.getDesiredOutput());
    }
    assertTrue(mse.getTotalError() < maxError);
}
 
Example #2
Source File: BackPropagationTest.java    From NeurophFramework with Apache License 2.0 7 votes vote down vote up
@Test
public void testXorMSE() {
    MultiLayerPerceptron myMlPerceptron = new MultiLayerPerceptron(TransferFunctionType.SIGMOID, 2, 3, 1);
    myMlPerceptron.randomizeWeights(new WeightsRandomizer(new Random(123)));

    myMlPerceptron.setLearningRule(instance);
    myMlPerceptron.learn(xorDataSet);

    MeanSquaredError mse = new MeanSquaredError();
    for (DataSetRow testSetRow : xorDataSet.getRows()) {
        myMlPerceptron.setInput(testSetRow.getInput());
        myMlPerceptron.calculate();
        double[] networkOutput = myMlPerceptron.getOutput();
        mse.addPatternError(networkOutput, testSetRow.getDesiredOutput());
    }
    assertTrue(mse.getTotalError() < maxError);
}
 
Example #3
Source File: RunExample.java    From NeurophFramework with Apache License 2.0 7 votes vote down vote up
public static void main(String[] args) {
    AutoTrainer trainer = new AutoTrainer()
            .setMaxError(0.01, 0.03,0.01) // isto ranhe?
            .setMaxIterations(20000)
            .setTransferFunction(TransferFunctionType.TANH)
            .setHiddenNeurons(new Range(10, 20), 2)    // kako dodati jos slojeva neurona?
            .setLearningRate(new Range(0.3, 0.6), 0.3)
            .repeat(3)
            .setTrainTestSplit(70);

    DataSet dataSet = DataSet.createFromFile(FILEPATH, 4, 3, "\t", true);
    trainer.train(dataSet);
    List<TrainingResult> results = trainer.getResults();

    
    
    
    try {
        Util.saveToCSV(trainer, results);
    } catch (FileNotFoundException ex) {
        System.out.println("Error writing csv file");
    }

    System.out.println("Main done!");
}
 
Example #4
Source File: IrisFlowers.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void run() throws InterruptedException, ExecutionException {
    System.out.println("Creating training set...");
    // get path to training set
    String dataSetFile = "data_sets/iris_data_normalised.txt";
    int inputsCount = 4;
    int outputsCount = 3;

    // create training set from file
    DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, ",");
 //   dataSet.setColumnNames(new String[]{"sepal.length", "sepal.width", "petal.length", "petal.width",  "setosa", "versicolor", "virginica"});
    dataSet.setColumnNames(new String[]{"setosa", "versicolor", "virginica"});
    dataSet.shuffle();

    System.out.println("Creating neural network...");
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(TransferFunctionType.TANH, inputsCount, 5, outputsCount);

    String[] classLabels = new String[]{"setosa", "versicolor", "virginica"};
    neuralNet.setOutputLabels(classLabels);

    KFoldCrossValidation crossVal = new KFoldCrossValidation(neuralNet, dataSet, 5);
    EvaluationResult totalResult= crossVal.run();
    List<FoldResult> cflist= crossVal.getResultsByFolds();

}
 
Example #5
Source File: ART1Network.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
/**
    *
    * @param vigilance
    * @param L
    * @param neuronsInLayers
    */
   public ART1Network (double vigilance, int L, int ... neuronsInLayers) {
	// init neuron settings


	NeuronProperties neuronProperties = new NeuronProperties();
               neuronProperties.setProperty("useBias", true);
	neuronProperties.setProperty("transferFunction",
			TransferFunctionType.SIGMOID);
               neuronProperties.setProperty("inputFunction", WeightedSum.class);

               // Makes a vector, which gives as an array of numbers of neurons in each layer

	List<Integer> neuronsInLayersVector = new ArrayList<>();
	for(int i=0; i<neuronsInLayers.length; i++) {
                   neuronsInLayersVector.add(new Integer(neuronsInLayers[i]));
               }

	this.createNetwork(neuronsInLayersVector, neuronProperties, vigilance, L);
}
 
Example #6
Source File: TestMatrixMLP.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
/**
 * Create and run MLP with XOR training set
 */
public static void main(String[] args) {
    // create training set (logical XOR function)
    DataSet trainingSet = new DataSet(2, 1);
    trainingSet.add(new DataSetRow(new double[]{0, 0}, new double[]{0}));
    trainingSet.add(new DataSetRow(new double[]{0, 1}, new double[]{1}));
    trainingSet.add(new DataSetRow(new double[]{1, 0}, new double[]{1}));
    trainingSet.add(new DataSetRow(new double[]{1, 1}, new double[]{0}));

    MultiLayerPerceptron nnet = new MultiLayerPerceptron( TransferFunctionType.TANH ,2, 3, 1);
    MatrixMultiLayerPerceptron mnet = new MatrixMultiLayerPerceptron(nnet);

    System.out.println("Training network...");

    mnet.learn(trainingSet);

    System.out.println("Done training network.");
}
 
Example #7
Source File: TestTimeSeries.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void train() {
    // get the path to file with data
    String inputFileName = "C:\\timeseries\\BSW15";
    
    // create MultiLayerPerceptron neural network
    neuralNet = new MultiLayerPerceptron(TransferFunctionType.TANH, 5, 10, 1);
    MomentumBackpropagation learningRule = (MomentumBackpropagation)neuralNet.getLearningRule();
    learningRule.setLearningRate(0.2);
    learningRule.setMomentum(0.5);
    // learningRule.addObserver(this);
    learningRule.addListener(this);        
    
    // create training set from file
     trainingSet = DataSet.createFromFile(inputFileName, 5, 1, "\t", false);
    // train the network with training set
    neuralNet.learn(trainingSet);         
          
    System.out.println("Done training.");          
}
 
Example #8
Source File: SunSpots.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void run() {

		// uncomment the following line to use regular Neuroph (non-flat) processing
		//Neuroph.getInstance().setFlattenNetworks(false);
		// create neural network
		NeuralNetwork network = new MultiLayerPerceptron(TransferFunctionType.SIGMOID, WINDOW_SIZE, 10, 1);

                // normalize training data
		normalizeSunspots(0.1, 0.9);

		network.getLearningRule().addListener(this);

                // create training set
		DataSet trainingSet = generateTrainingData();
		network.learn(trainingSet);
		predict(network);

		Neuroph.getInstance().shutdown();
	}
 
Example #9
Source File: MultiLayerPerceptron.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public MultiLayerPerceptron(TransferFunctionType transferFunctionType, int... neuronsInLayers) {
    // init neuron settings
    NeuronProperties neuronProperties = new NeuronProperties();
    neuronProperties.setProperty("useBias", true);
    neuronProperties.setProperty("transferFunction", transferFunctionType);
    neuronProperties.setProperty("inputFunction", WeightedSum.class);


    List<Integer> neuronsInLayersVector = new ArrayList<>();
    for (int i = 0; i < neuronsInLayers.length; i++) {
        neuronsInLayersVector.add(Integer.valueOf(neuronsInLayers[i]));
    }

    this.createNetwork(neuronsInLayersVector, neuronProperties);
}
 
Example #10
Source File: ART1Network.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/** Creates new ART1 Network, with specified number of neurons in layers
  *   and a vigilance parameter
  *
  *  @param neuronsInLayers
  *            collection of neuron number in layers
   * @param vigilance
   * @param L
  *
  */

  public ART1Network (List<Integer> neuronsInLayers, double vigilance, int L ) {

NeuronProperties neuronProperties = new NeuronProperties();
              neuronProperties.setProperty("useBias", true);
neuronProperties.setProperty("transferFunction", TransferFunctionType.SIGMOID);
              neuronProperties.setProperty("inputFunction", new WeightedSum());

this.createNetwork(neuronsInLayers, neuronProperties, vigilance, L);
  }
 
Example #11
Source File: MultiLayerPerceptron.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public MultiLayerPerceptron(List<Integer> neuronsInLayers, TransferFunctionType transferFunctionType) {
    // init neuron settings
    NeuronProperties neuronProperties = new NeuronProperties();
    neuronProperties.setProperty("useBias", true);
    neuronProperties.setProperty("transferFunction", transferFunctionType);

    this.createNetwork(neuronsInLayers, neuronProperties);
}
 
Example #12
Source File: MomentumBackPropagationTest.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Test
public void testXorMaxError() {
    MultiLayerPerceptron myMlPerceptron = new MultiLayerPerceptron(TransferFunctionType.SIGMOID, 2, 3, 1);
    myMlPerceptron.randomizeWeights(new WeightsRandomizer(new Random(123)));

    myMlPerceptron.setLearningRule(instance);
    myMlPerceptron.learn(xorDataSet);

    assertTrue(instance.getTotalNetworkError() < maxError);
}
 
Example #13
Source File: BackPropagationTest.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Test
public void testXorMaxError() {
    MultiLayerPerceptron myMlPerceptron = new MultiLayerPerceptron(TransferFunctionType.SIGMOID, 2, 3, 1);
    myMlPerceptron.randomizeWeights(new WeightsRandomizer(new Random(123)));

    myMlPerceptron.setLearningRule(instance);
    myMlPerceptron.learn(xorDataSet);

    assertTrue(instance.getTotalNetworkError() < maxError);
}
 
Example #14
Source File: SgnTest.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Test of getProperties method, of class Sgn.
 */
@Test
public void testGetProperties() {
	Properties expResult = new Properties();
	expResult.setProperty("transferFunction", TransferFunctionType.SGN.toString());
	Properties result = instance.getProperties();
	assertEquals(expResult, result);

}
 
Example #15
Source File: BackpropBenchmarksExample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {

        BackPropBenchmarks bpb = new BackPropBenchmarks();
        bpb.setNoOfRepetitions(3);
        
        MultiLayerPerceptron mlp = new MultiLayerPerceptron(TransferFunctionType.SIGMOID, 4, 7, 3);
        
        DataSet trainingSet = DataSet.createFromFile("iris_data_normalised.txt", 4, 3, ",");

        TrainingSettingsGenerator generator = new TrainingSettingsGenerator();
      
        Properties prop = new Properties();
        prop.setProperty(BackpropagationSettings.MIN_LEARNING_RATE, "0.1");
        prop.setProperty(BackpropagationSettings.MAX_LEARNING_RATE, "0.4");
        prop.setProperty(BackpropagationSettings.LEARNING_RATE_STEP, "0.5");
        prop.setProperty(BackpropagationSettings.MIN_HIDDEN_NEURONS, "9");
        prop.setProperty(BackpropagationSettings.MAX_HIDDEN_NEURONS, "10");
        prop.setProperty(BackpropagationSettings.HIDDEN_NEURONS_STEP, "1");
        prop.setProperty(BackpropagationSettings.MOMENTUM, "0.5");
        prop.setProperty(BackpropagationSettings.MAX_ERROR, "0.1");
        prop.setProperty(BackpropagationSettings.MAX_ITERATIONS, "10000");
        prop.setProperty(BackpropagationSettings.BATCH_MODE, "true");
      
        generator.setSettings(prop);

        List<TrainingSettings> settingsCollection = generator.generateSettings();
        List<Class<? extends AbstractTraining>> trainingTypeCollection = new ArrayList<>();
        trainingTypeCollection.add(BackpropagationTraining.class);
        trainingTypeCollection.add(MomentumTraining.class);
        
        bpb.startBenchmark(trainingTypeCollection, settingsCollection, trainingSet, mlp);
        bpb.saveResults("C:\\Users\\Mladen\\Desktop\\test123");
      
    }
 
Example #16
Source File: AbstractTraining.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Create instance of training with new neural network
 *
 * @param dataset
 * @param settings
 */
public AbstractTraining(DataSet dataset, TrainingSettings settings) {
    this.dataset = dataset;
    this.settings = settings;
    this.stats = new TrainingStatistics();
    this.neuralNet = new MultiLayerPerceptron(TransferFunctionType.SIGMOID, dataset.getInputSize(), settings.getHiddenNeurons(), dataset.getOutputSize());
}
 
Example #17
Source File: TestBinaryClass.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        DataSet trainingSet = new DataSet(2, 1);
        trainingSet.add(new DataSetRow(new double[]{0, 0}, new double[]{0}));
        trainingSet.add(new DataSetRow(new double[]{0, 1}, new double[]{1}));
        trainingSet.add(new DataSetRow(new double[]{1, 0}, new double[]{1}));
        trainingSet.add(new DataSetRow(new double[]{1, 1}, new double[]{0}));

        MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(TransferFunctionType.TANH, 2, 3, 1);
        neuralNet.learn(trainingSet);

        Evaluation.runFullEvaluation(neuralNet, trainingSet);
    }
 
Example #18
Source File: XorResilientPropagationSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Runs this sample
 */
public  void run() {

    // create training set (logical XOR function)
    DataSet trainingSet = new DataSet(2, 1);
    trainingSet.add(new DataSetRow(new double[]{0, 0}, new double[]{0}));
    trainingSet.add(new DataSetRow(new double[]{0, 1}, new double[]{1}));
    trainingSet.add(new DataSetRow(new double[]{1, 0}, new double[]{1}));
    trainingSet.add(new DataSetRow(new double[]{1, 1}, new double[]{0}));

    // create multi layer perceptron
    MultiLayerPerceptron myMlPerceptron = new MultiLayerPerceptron(TransferFunctionType.SIGMOID, 2, 3, 1);
    // set ResilientPropagation learning rule
    myMlPerceptron.setLearningRule(new ResilientPropagation());
    LearningRule learningRule = myMlPerceptron.getLearningRule();
    learningRule.addListener(this);

    // learn the training set
    System.out.println("Training neural network...");
    myMlPerceptron.learn(trainingSet);

    int iterations = ((SupervisedLearning)myMlPerceptron.getLearningRule()).getCurrentIteration();
    System.out.println("Learned in "+iterations+" iterations");

    // test perceptron
    System.out.println("Testing trained neural network");
    testNeuralNetwork(myMlPerceptron, trainingSet);

}
 
Example #19
Source File: ImageRecognitionHelper.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
        * Creates and returns new neural network for image recognition.
 * Assumes that all of the FractionRgbData objects in the given map have identical
 * length arrays in them so that the input layer of the neural network can be
 * created here.
 *
        * @param label neural network label
        * @param samplingResolution sampling resolution (image size)
 * @param imageLabels image labels
        * @param layersNeuronsCount neuron counts in hidden layers
 * @param transferFunctionType type of transfer function to use for neurons in network
        * @param colorMode color mode
    * @return
 */
public static NeuralNetwork createNewNeuralNetwork(String label, Dimension samplingResolution, ColorMode colorMode, List<String> imageLabels,  List<Integer> layersNeuronsCount, TransferFunctionType transferFunctionType) {

               int numberOfInputNeurons;
               if ((colorMode == ColorMode.COLOR_RGB) || (colorMode == ColorMode.COLOR_HSL) ){ // for full color rgb or hsl
                   numberOfInputNeurons = 3 * samplingResolution.getWidth() * samplingResolution.getHeight();
               } else { // for black n white network
                   numberOfInputNeurons = samplingResolution.getWidth() * samplingResolution.getHeight();
               }

               int numberOfOuputNeurons = imageLabels.size();

	layersNeuronsCount.add(0, numberOfInputNeurons);
	layersNeuronsCount.add(numberOfOuputNeurons);

	System.out.println("Neuron layer size counts vector = " + layersNeuronsCount);

	NeuralNetwork neuralNetwork = new MultiLayerPerceptron(layersNeuronsCount, transferFunctionType);

	neuralNetwork.setLabel(label);
	PluginBase imageRecognitionPlugin = new ImageRecognitionPlugin(samplingResolution, colorMode);
	neuralNetwork.addPlugin(imageRecognitionPlugin);

	assignLabelsToOutputNeurons(neuralNetwork, imageLabels);
               neuralNetwork.setLearningRule(new MomentumBackpropagation());

           return neuralNetwork;
}
 
Example #20
Source File: RGBImageRecognitionTrainingSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    
    // path to image directory
    String imageDir ="/home/zoran/Downloads/MihailoHSLTest/trening";
    
    // image names - used for output neuron labels
    List<String> imageLabels = new ArrayList();
    imageLabels.add("bird");                                                   
    imageLabels.add("cat");
    imageLabels.add("dog");
            

    // create dataset
    Map<String,FractionRgbData> map = ImageRecognitionHelper.getFractionRgbDataForDirectory (new File(imageDir), new Dimension(20, 20));
    DataSet dataSet = ImageRecognitionHelper.createRGBTrainingSet(imageLabels, map);

    // create neural network
    List <Integer> hiddenLayers = new ArrayList<>();
    hiddenLayers.add(12);
    NeuralNetwork nnet = ImageRecognitionHelper.createNewNeuralNetwork("someNetworkName", new Dimension(20,20), ColorMode.COLOR_RGB, imageLabels, hiddenLayers, TransferFunctionType.SIGMOID);

    // set learning rule parameters
    MomentumBackpropagation mb = (MomentumBackpropagation)nnet.getLearningRule();
    mb.setLearningRate(0.2);
    mb.setMaxError(0.9);
    mb.setMomentum(1);
  
    // traiin network
    System.out.println("NNet start learning...");
    nnet.learn(dataSet);
    System.out.println("NNet learned");                
    
}
 
Example #21
Source File: HSLImageRecognitionTrainingSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public static void main (String [] args) throws IOException {
    
    // path to image directory
    String imageDir ="/home/zoran/Downloads/MihailoHSLTest/trening";
    
    // image names - used for output neuron labels
    List<String> imageLabels = new ArrayList();
    imageLabels.add("bird");                                                   
    imageLabels.add("cat");
    imageLabels.add("dog");
            

    // create dataset
    Map<String,FractionHSLData> map = ImageRecognitionHelper.getFractionHSLDataForDirectory (new File(imageDir), new Dimension(20, 20));
    DataSet dataSet = ImageRecognitionHelper.createHSLTrainingSet(imageLabels, map);

    // create neural network
    List <Integer> hiddenLayers = new ArrayList<>();
    hiddenLayers.add(12);
    NeuralNetwork nnet = ImageRecognitionHelper.createNewNeuralNetwork("someNetworkName", new Dimension(20,20), ColorMode.COLOR_HSL, imageLabels, hiddenLayers, TransferFunctionType.SIGMOID);

    // set learning rule parameters
    MomentumBackpropagation mb = (MomentumBackpropagation)nnet.getLearningRule();
    mb.setLearningRate(0.2);
    mb.setMaxError(0.9);
    mb.setMomentum(1);
  
    // traiin network
    System.out.println("NNet start learning...");
    nnet.learn(dataSet);
    System.out.println("NNet learned");        
}
 
Example #22
Source File: MLPNetworkMaker.java    From FakeImageDetection with GNU General Public License v3.0 5 votes vote down vote up
public MLPNetworkMaker(String networkLabel, Dimension samplingDimension, ColorMode mode, List<String> outputNeuronLabels, List<Integer> neuronCounts, TransferFunctionType type, String saveLocation) {
    this.networkLabel = networkLabel;
    this.samplingDimension = samplingDimension;
    this.mode = mode;
    this.outputNeuronLabels = outputNeuronLabels;
    this.neuronCounts = neuronCounts;
    this.type = type;
    this.saveLocation = saveLocation;
}
 
Example #23
Source File: MultiLayerPerceptron.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public MultiLayerPerceptron(int... neuronsInLayers) {
    // init neuron settings
    NeuronProperties neuronProperties = new NeuronProperties();
    neuronProperties.setProperty("useBias", true);
    neuronProperties.setProperty("transferFunction", TransferFunctionType.SIGMOID);
    neuronProperties.setProperty("inputFunction", WeightedSum.class);

    List<Integer> neuronsInLayersVector = new ArrayList<>();
    for (int i = 0; i < neuronsInLayers.length; i++) {
        neuronsInLayersVector.add(Integer.valueOf(neuronsInLayers[i]));
    }

    this.createNetwork(neuronsInLayersVector, neuronProperties);
}
 
Example #24
Source File: UnsupervisedHebbianNetwork.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
	 * Creates an instance of Unsuervised Hebian net with specified number
	 * of neurons in input layer and output layer, and transfer function
	 * 
	 * @param inputNeuronsNum
	 *            number of neurons in input layer
	 * @param outputNeuronsNum
	 *            number of neurons in output layer
	 * @param transferFunctionType
	 *            transfer function type
	 */
	private void createNetwork(int inputNeuronsNum, int outputNeuronsNum,
		TransferFunctionType transferFunctionType) {

		// init neuron properties
		NeuronProperties neuronProperties = new NeuronProperties();
//		neuronProperties.setProperty("bias", new Double(-Math
//				.abs(Math.random() - 0.5))); // Hebbian network cann not work
		// without bias
		neuronProperties.setProperty("transferFunction", transferFunctionType);
		neuronProperties.setProperty("transferFunction.slope", new Double(1));

		// 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);

		// set input and output cells for this network
		NeuralNetworkFactory.setDefaultIO(this);

		// set appropriate learning rule for this network
		this.setLearningRule(new UnsupervisedHebbianLearning());
	//this.setLearningRule(new OjaLearning(this));
	}
 
Example #25
Source File: Adaline.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
	 * Creates adaline network architecture with specified number of input neurons
	 *
	 * @param inputNeuronsCount
         *              number of neurons in input layer
	 */
	private void createNetwork(int inputNeuronsCount) {
		// set network type code
		this.setNetworkType(NeuralNetworkType.ADALINE);

                // create input layer neuron settings for this network
		NeuronProperties inNeuronProperties = new NeuronProperties();
		inNeuronProperties.setProperty("transferFunction", TransferFunctionType.LINEAR);

		// createLayer input layer with specified number of neurons
		//Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, inNeuronProperties);
                Layer inputLayer = new InputLayer(inputNeuronsCount);
                inputLayer.addNeuron(new BiasNeuron()); // add bias neuron (always 1, and it will act as bias input for output neuron)
		this.addLayer(inputLayer);

               // create output layer neuron settings for this network
		NeuronProperties outNeuronProperties = new NeuronProperties();
		outNeuronProperties.setProperty("transferFunction", TransferFunctionType.LINEAR); // was RAMP
//		outNeuronProperties.setProperty("transferFunction.slope", new Double(1));
//		outNeuronProperties.setProperty("transferFunction.yHigh", new Double(1));
//		outNeuronProperties.setProperty("transferFunction.xHigh", new Double(1));
//		outNeuronProperties.setProperty("transferFunction.yLow", new Double(-1));
//		outNeuronProperties.setProperty("transferFunction.xLow", new Double(-1));

		// createLayer output layer (only one neuron)
		Layer outputLayer = LayerFactory.createLayer(1, outNeuronProperties);
		this.addLayer(outputLayer);

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

		// set input and output cells for network
		NeuralNetworkFactory.setDefaultIO(this);

		// set LMS learning rule for this network
		this.setLearningRule(new LMS());
	}
 
Example #26
Source File: CompetitiveNetwork.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Creates Competitive network architecture
 * 
 * @param inputNeuronsCount
 *            input neurons number
        * @param outputNeuronsCount
        *            output neurons number
 * @param neuronProperties
 *            neuron properties
 */
private void createNetwork(int inputNeuronsCount, int outputNeuronsCount) {
	// set network type
	this.setNetworkType(NeuralNetworkType.COMPETITIVE);

	// createLayer input layer
	Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, new NeuronProperties());
	this.addLayer(inputLayer);

	// createLayer properties for neurons in output layer
	NeuronProperties neuronProperties = new NeuronProperties();
	neuronProperties.setProperty("neuronType", CompetitiveNeuron.class);
	neuronProperties.setProperty("inputFunction",	WeightedSum.class);
	neuronProperties.setProperty("transferFunction",TransferFunctionType.RAMP);

	// createLayer full connectivity in competitive layer
	CompetitiveLayer competitiveLayer = new CompetitiveLayer(outputNeuronsCount, neuronProperties);

	// add competitive layer to network
	this.addLayer(competitiveLayer);

	double competitiveWeight = -(1 / (double) outputNeuronsCount);
	// createLayer full connectivity within competitive layer
	ConnectionFactory.fullConnect(competitiveLayer, competitiveWeight, 1);

	// createLayer full connectivity from input to competitive layer
	ConnectionFactory.fullConnect(inputLayer, competitiveLayer);

	// set input and output cells for this network
	NeuralNetworkFactory.setDefaultIO(this);

	this.setLearningRule(new CompetitiveLearning());
}
 
Example #27
Source File: Perceptron.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
	 * Creates perceptron architecture with specified number of neurons in input
	 * and output layer, specified transfer function
	 * 
	 * @param inputNeuronsCount
	 *            number of neurons in input layer
	 * @param outputNeuronsCount
	 *            number of neurons in output layer
	 * @param transferFunctionType
	 *            neuron transfer function type
	 */
	private void createNetwork(int inputNeuronsCount, int outputNeuronsCount, TransferFunctionType transferFunctionType) {
		// set network type
		this.setNetworkType(NeuralNetworkType.PERCEPTRON);

                Layer inputLayer = new InputLayer(inputNeuronsCount);
		this.addLayer(inputLayer);

		NeuronProperties outputNeuronProperties = new NeuronProperties();
		outputNeuronProperties.setProperty("neuronType", ThresholdNeuron.class);
		outputNeuronProperties.setProperty("thresh", new Double(Math.abs(Math.random())));
		outputNeuronProperties.setProperty("transferFunction", transferFunctionType);
		// for sigmoid and tanh transfer functions set slope propery
		outputNeuronProperties.setProperty("transferFunction.slope", new Double(1));

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

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

		// set input and output cells for this network
		NeuralNetworkFactory.setDefaultIO(this);
                
                this.setLearningRule(new BinaryDeltaRule());
		// set appropriate learning rule for this network
//		if (transferFunctionType == TransferFunctionType.STEP) {
//			this.setLearningRule(new BinaryDeltaRule(this));
//		} else if (transferFunctionType == TransferFunctionType.SIGMOID) {
//			this.setLearningRule(new SigmoidDeltaRule(this));
//		} else if (transferFunctionType == TransferFunctionType.TANH) {
//			this.setLearningRule(new SigmoidDeltaRule(this));
//		} else {
//			this.setLearningRule(new PerceptronLearning(this));
//		}
	}
 
Example #28
Source File: BAM.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance of BAM network with specified number of neurons
        * in input and output layers.
 * 
 * @param inputNeuronsCount
 *            number of neurons in input layer
 * @param outputNeuronsCount
 *            number of neurons in output layer
 */
public BAM(int inputNeuronsCount, int outputNeuronsCount) {

	// init neuron settings for BAM network
	NeuronProperties neuronProperties = new NeuronProperties();
	neuronProperties.setProperty("neuronType", InputOutputNeuron.class);
	neuronProperties.setProperty("bias", new Double(0));
	neuronProperties.setProperty("transferFunction", TransferFunctionType.STEP);
	neuronProperties.setProperty("transferFunction.yHigh", new Double(1));
	neuronProperties.setProperty("transferFunction.yLow", new Double(0));

	this.createNetwork(inputNeuronsCount, outputNeuronsCount, neuronProperties);
}
 
Example #29
Source File: SupervisedHebbianNetwork.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 *Creates an instance of Supervised Hebbian Network with specified number
 * of neurons in input layer, output layer and transfer function
 * 
 * @param inputNeuronsNum
 *            number of neurons in input layer
 * @param outputNeuronsNum
 *            number of neurons in output layer
 * @param transferFunctionType
 *            transfer function type
 */
private void createNetwork(int inputNeuronsNum, int outputNeuronsNum,
	TransferFunctionType transferFunctionType) {

	// init neuron properties
	NeuronProperties neuronProperties = new NeuronProperties();
	neuronProperties.setProperty("transferFunction", transferFunctionType);
	neuronProperties.setProperty("transferFunction.slope", new Double(1));
	neuronProperties.setProperty("transferFunction.yHigh", new Double(1));
	neuronProperties.setProperty("transferFunction.xHigh", new Double(1));		
	neuronProperties.setProperty("transferFunction.yLow", new Double(-1));
	neuronProperties.setProperty("transferFunction.xLow", new Double(-1));
	
	// set network type code
	this.setNetworkType(NeuralNetworkType.SUPERVISED_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);

	// set input and output cells for this network
	NeuralNetworkFactory.setDefaultIO(this);

	// set appropriate learning rule for this network
	this.setLearningRule(new SupervisedHebbianLearning());
}
 
Example #30
Source File: Outstar.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Creates Outstar architecture with specified number of neurons in 
 * output layer
 * 
 * @param outputNeuronsCount
 *            number of neurons in output layer
 */
private void createNetwork(int outputNeuronsCount ) {

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

	// 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);

	// set input and output cells for this network
	NeuralNetworkFactory.setDefaultIO(this);

	// set outstar learning rule for this network
	this.setLearningRule(new OutstarLearning());
}