当前位置: 首页>>代码示例>>Java>>正文


Java BasicNetwork类代码示例

本文整理汇总了Java中org.encog.neural.networks.BasicNetwork的典型用法代码示例。如果您正苦于以下问题:Java BasicNetwork类的具体用法?Java BasicNetwork怎么用?Java BasicNetwork使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BasicNetwork类属于org.encog.neural.networks包,在下文中一共展示了BasicNetwork类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createNeuralNetwork

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
private BasicNetwork createNeuralNetwork() {
  BasicNetwork network = new BasicNetwork();

  // input layer
  network.addLayer(new BasicLayer(null, true, inputLayerSize));

  // hidden layer
  network.addLayer(new BasicLayer(new ActivationSigmoid(), true, inputLayerSize / 6));
  network.addLayer(new BasicLayer(new ActivationSigmoid(), true, inputLayerSize / 6 / 4));

  // output layer
  network.addLayer(new BasicLayer(new ActivationSigmoid(), false, outputLayerSize));

  network.getStructure().finalizeStructure();
  network.reset();

  return network;
}
 
开发者ID:RusZ,项目名称:TextClassifier,代码行数:19,代码来源:Classifier.java

示例2: trainAndStore

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
@Test
public void trainAndStore() {
    BasicMLDataSet dataSet = getData();

    // Create network
    BasicNetwork network = getNetwork();

    // Train
    System.out.println("Training network...");
    Train train = new ResilientPropagation(network, dataSet);
    for (int i = 0; i < TRAIN_ITERATIONS; i++) {
        train.iteration();
    }
    System.out.println("Training finished, error: " + train.getError());

    // Save to file
    System.out.println("Saving to file...");
    saveToFile(network);
    System.out.println("Done");
}
 
开发者ID:Ignotus,项目名称:torcsnet,代码行数:21,代码来源:EncogMLPTrainingTest.java

示例3: testNewNetwork

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
/**
 * Test to see if the respective method creates a new basic neural network
 * and correctly assigns all three layer sizes.
 */
@Test
public void testNewNetwork() {
	/*
	 * Create ANN with random layer sizes. Layer sizes are rarely going to
	 * be larger than 10 neurons each.
	 */
	int inputSize = Util.PRNG.nextInt(10);
	int hiddenSize = Util.PRNG.nextInt(10);
	int outputSize = Util.PRNG.nextInt(10);
	BasicNetwork net = Util.newNetwork(inputSize, hiddenSize, outputSize);

	/*
	 * All layers should have their sizes assigned correctly.
	 */
	assertEquals(inputSize, net.getInputCount());
	assertEquals(hiddenSize, net.getLayerNeuronCount(1));
	assertEquals(outputSize, net.getOutputCount());
}
 
开发者ID:VelbazhdSoftwareLLC,项目名称:Complica4,代码行数:23,代码来源:UtilTest.java

示例4: initWeights

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
private NNParams initWeights(MasterContext<NNParams, NNParams> context) {
    int inputs = NumberFormatUtils.getInt(context.getProps().getProperty(NNConstants.GUAGUA_NN_INPUT_NODES),
            NNConstants.GUAGUA_NN_DEFAULT_INPUT_NODES);
    int hiddens = NumberFormatUtils.getInt(context.getProps().getProperty(NNConstants.GUAGUA_NN_HIDDEN_NODES),
            NNConstants.GUAGUA_NN_DEFAULT_HIDDEN_NODES);
    int outputs = NumberFormatUtils.getInt(context.getProps().getProperty(NNConstants.GUAGUA_NN_OUTPUT_NODES),
            NNConstants.GUAGUA_NN_DEFAULT_OUTPUT_NODES);
    this.learningRate = NumberFormatUtils.getDouble(context.getProps().getProperty(
            NNConstants.GUAGUA_NN_LEARNING_RATE, NNConstants.GUAGUA_NN_DEFAULT_LEARNING_RATE));

    BasicNetwork network = NNUtils.generateNetwork(inputs, hiddens, outputs);

    NNParams params = new NNParams();
    params.setTrainError(0);
    params.setTestError(0);
    // prevent null point
    params.setGradients(new double[0]);
    params.setWeights(network.getFlat().getWeights());
    return params;
}
 
开发者ID:ShifuML,项目名称:guagua,代码行数:21,代码来源:NNMaster.java

示例5: postApplication

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
@Override
public void postApplication(MasterContext<NNParams, NNParams> context) {
    LOG.info("NNOutput starts to write model to files.");
    int inputs = NumberFormatUtils.getInt(context.getProps().getProperty(NNConstants.GUAGUA_NN_INPUT_NODES),
            NNConstants.GUAGUA_NN_DEFAULT_INPUT_NODES);
    int hiddens = NumberFormatUtils.getInt(context.getProps().getProperty(NNConstants.GUAGUA_NN_HIDDEN_NODES),
            NNConstants.GUAGUA_NN_DEFAULT_HIDDEN_NODES);
    int outputs = NumberFormatUtils.getInt(context.getProps().getProperty(NNConstants.GUAGUA_NN_OUTPUT_NODES),
            NNConstants.GUAGUA_NN_DEFAULT_OUTPUT_NODES);
    BasicNetwork network = NNUtils.generateNetwork(inputs, hiddens, outputs);

    Path out = new Path(context.getProps().getProperty(NNConstants.GUAGUA_NN_OUTPUT));
    FSDataOutputStream fos = null;
    try {
        fos = FileSystem.get(new Configuration()).create(out);
        LOG.info("Writing results to {}", out.toString());
        network.getFlat().setWeights(context.getMasterResult().getWeights());
        EncogDirectoryPersistence.saveObject(fos, network);
    } catch (IOException e) {
        LOG.error("Error in writing output.", e);
    } finally {
        IOUtils.closeStream(fos);
    }
}
 
开发者ID:ShifuML,项目名称:guagua,代码行数:25,代码来源:NNOutput.java

示例6: getError

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
private double[] getError(NeuralDataSet trainingSet, BasicNetwork network){
	double total = 0.0;
	double size = 0;
	double RSS = 0.0;
	double Ry = 0.0;
	for (MLDataPair pair : trainingSet) {

		final MLData output = network.compute(pair.getInput());
		if (Double.isNaN(output.getData(0))) {
			throw new RuntimeException("There is a NaN! may be something wrong with the data conversion");
		}
		double result = (Double.isNaN(output.getData(0)))? pair.getIdeal().getData(0) : output.getData(0); 
		//System.out.print("Result ********** " +result+"\n");
		total += calculateEachMAPE(pair.getIdeal().getData(0),
				result);

		double difference = pair.getIdeal().getData(0) - result;
		RSS += Math.pow(difference, 2);
		Ry += Math.pow(pair.getIdeal().getData(0) - meanIdeal, 2);
		size++;
	}

	return new double[]{Ry==0?RSS:RSS/Ry, 
			total/size};
}
 
开发者ID:taochen,项目名称:ssascaling,代码行数:26,代码来源:EncogFeedForwardNeuralNetwork.java

示例7: SimpleNeuralNetVisualizer

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
public SimpleNeuralNetVisualizer(BasicNetwork neuralNet, String[] attributeNames) {
	this.neuralNet = neuralNet;
	this.attributeNames = attributeNames;
	addMouseListener(this);
       
       // calculate maximal absolute weight
       this.maxAbsoluteWeight = Double.NEGATIVE_INFINITY;
       List<Layer> layers = this.neuralNet.getLayers();
       Iterator i = layers.iterator();
       while (i.hasNext()) {
           Layer layer = (Layer)i.next();
           if (layer.hasMatrix()) {
           	Matrix matrix = layer.getMatrix();
       		int rows = matrix.getRows();
       		int cols = matrix.getCols();
       		for (int c = 0; c < cols; c++) {
       			for (int r = 0; r < rows; r++) {
       				double weight = matrix.get(r, c);
       				this.maxAbsoluteWeight = Math.max(this.maxAbsoluteWeight, Math.abs(weight));
       			}
       		}
           }
       }
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:25,代码来源:SimpleNeuralNetVisualizer.java

示例8: Perceptron

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
public Perceptron(int in, int out){
	this.numberOutputs = out;
	this.numberInputs = in;
	//this.network = new BasicNetwork();
	//In
	/*network.addLayer(new BasicLayer(null,false,in));
	network.addLayer(new BasicLayer(new ActivationLinear(),false,out));
	network.getStructure().finalizeStructure();
	network.reset();
	*/
	ADALINEPattern pattern = new ADALINEPattern();
	pattern.setInputNeurons(in);
	pattern.setOutputNeurons(out);
	this.network = (BasicNetwork)pattern.generate();
	
	

}
 
开发者ID:wil3,项目名称:lacus,代码行数:19,代码来源:Perceptron.java

示例9: enquireNeuralNetwork

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
public int enquireNeuralNetwork(final BasicNetwork neuralNetwork, DataPoint dataPoint) {
	MLData input = new BasicMLData(2);
	input.setData(0, dataPoint.getX());
	input.setData(1, dataPoint.getY());
	MLData output = neuralNetwork.compute(input);

	// Check to see which button has the highest output
	double buttons[] = output.getData();
	int buttonIndex = -1;
	for (int i = 0; i < buttons.length; i++) {
		if (buttons[i] > 0 && (buttonIndex == -1 || buttons[i] > buttons[buttonIndex])) {
			buttonIndex = i;
		}
	}

	return buttonIndex;
}
 
开发者ID:bsmulders,项目名称:StepManiaSolver,代码行数:18,代码来源:NeuralNetworkBasher.java

示例10: main

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
/**
 * The main method.
 * @param args No arguments are used.
 */
public static void main(final String args[]) {

    // create a neural network, without using a factory
    BasicNetwork network = new BasicNetwork();
    network.addLayer(new BasicLayer(null,true,2));
    network.addLayer(new BasicLayer(new ActivationSigmoid(),true,3));
    network.addLayer(new BasicLayer(new ActivationSigmoid(),false,1));
    network.getStructure().finalizeStructure();
    network.reset();

    // create training data
    MLDataSet trainingSet = new BasicMLDataSet(XOR_INPUT, XOR_IDEAL);

    // train the neural network
    final ResilientPropagation train = new ResilientPropagation(network, trainingSet);

    int epoch = 1;

    do {
        train.iteration();
        System.out.println("Epoch #" + epoch + " Error:" + train.getError());
        epoch++;
    } while(train.getError() > 0.01);
    train.finishTraining();

    // test the neural network
    System.out.println("Neural Network Results:");
    for(MLDataPair pair: trainingSet ) {
        final MLData output = network.compute(pair.getInput());
        System.out.println(pair.getInput().getData(0) + "," + pair.getInput().getData(1)
                + ", actual=" + output.getData(0) + ",ideal=" + pair.getIdeal().getData(0));
    }

    Encog.getInstance().shutdown();
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-ml-procedures,代码行数:40,代码来源:XORHelloWorld.java

示例11: Classifier

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
public Classifier(File trainedNetwork, Characteristic characteristic, List<VocabularyWord> vocabulary, NGramStrategy nGramStrategy) {
  if (characteristic == null ||
      characteristic.getName().equals("") ||
      characteristic.getPossibleValues() == null ||
      characteristic.getPossibleValues().size() == 0 ||
      vocabulary == null ||
      vocabulary.size() == 0 ||
      nGramStrategy == null) {
    throw new IllegalArgumentException();
  }

  this.characteristic = characteristic;
  this.vocabulary = vocabulary;
  this.inputLayerSize = vocabulary.size();
  this.outputLayerSize = characteristic.getPossibleValues().size();
  this.nGramStrategy = nGramStrategy;

  if (trainedNetwork == null) {
    this.network = createNeuralNetwork();
  } else {
    // load neural network from file
    try {
      this.network = (BasicNetwork) loadObject(trainedNetwork);
    } catch (PersistError e) {
      throw new IllegalArgumentException();
    }
  }
}
 
开发者ID:RusZ,项目名称:TextClassifier,代码行数:29,代码来源:Classifier.java

示例12: NeuralAgent

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
public NeuralAgent(NeuralAgent neuralAgent, BasicNetwork brain, EnvironmentMap map) {
    this.brain = neuralAgent.brain;
    this.setMap(map);
    if (neuralAgent.getAlgorithm() != null) {
        setAlgorithm(neuralAgent.getAlgorithm().clone());
    }
    setPosition(neuralAgent.getPosition().getX(), neuralAgent.getPosition().getY());
    this.vision = new BasicNeuralData(NeuralConstants.VISION_POINTS);
}
 
开发者ID:AdrianBZG,项目名称:IEMLS,代码行数:10,代码来源:NeuralAgent.java

示例13: generateAgent

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
public static NeuralAgent generateAgent(EnvironmentMap map)
{
    BasicNetwork network = new BasicNetwork();
    network.addLayer(new BasicLayer(NeuralConstants.INPUT_NEURON_COUNT));
    network.addLayer(new BasicLayer(60));
    network.addLayer(new BasicLayer(30));
    network.addLayer(new BasicLayer(NeuralConstants.OUTPUT_NEURON_COUNT));
    network.getStructure().finalizeStructure();
    network.reset();

    NeuralAgent agent = new NeuralAgent(network, map);
    return agent;
}
 
开发者ID:AdrianBZG,项目名称:IEMLS,代码行数:14,代码来源:NeuralAgentFactory.java

示例14: runMLPRace

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
private void runMLPRace(String mlpFile) {
    PersistBasicNetwork persistence = new PersistBasicNetwork();
    try {
        FileInputStream fis = new FileInputStream(mlpFile);
        BasicNetwork nn = (BasicNetwork)persistence.read(fis);
        runRace(new EvolvedController(nn));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Ignotus,项目名称:torcsnet,代码行数:11,代码来源:EvolutionaryDriverAlgorithm.java

示例15: saveToFile

import org.encog.neural.networks.BasicNetwork; //导入依赖的package包/类
private void saveToFile(BasicNetwork network) {
    PersistBasicNetwork ps = new PersistBasicNetwork();
    try {
        FileOutputStream os = new FileOutputStream(Configuration.ENCOG_TRAINED_FILE);
        ps.save(os, network);
        os.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Ignotus,项目名称:torcsnet,代码行数:11,代码来源:EncogMLPTrainingTest.java


注:本文中的org.encog.neural.networks.BasicNetwork类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。