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


Java MLDataPair类代码示例

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


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

示例1: HandWritingInputDisplay

import org.encog.ml.data.MLDataPair; //导入依赖的package包/类
public HandWritingInputDisplay(MLDataSet training) {
	this.imageValues = new double[(int) training.getRecordCount()][];
	this.numberValues = new int[(int) training.getRecordCount()];
	
	int index = 0;
	for (MLDataPair mlDataPair : training) {
		this.imageValues[index] = mlDataPair.getInputArray();
		int yIndex = 0;
		while(mlDataPair.getIdealArray()[yIndex]!=1)yIndex++;
		this.numberValues[index] = (yIndex + 1) % 10;
		index++;
	}
	
	this.currentImageIndex = 0;
	rp = new ResizeProcessor(200, 200);
	JFrame frame = DisplayUtilities.displayName(this.getCurrentImage(), "numbers");
	frame.addKeyListener(this);
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:19,代码来源:HandWritingInputDisplay.java

示例2: add

import org.encog.ml.data.MLDataPair; //导入依赖的package包/类
@Override
public void add(MLDataPair inputData) {
    long currentSize = SizeEstimator.estimate(inputData);
    if(this.byteSize + currentSize < this.maxByteSize) {
        this.byteSize += currentSize;
        this.memoryCount += 1l;
        this.memoryDataSet.add(inputData);
    } else {
        if(this.diskDataSet == null) {
            this.diskDataSet = new BufferedMLDataSet(new File(this.fileName));
            ((BufferedMLDataSet) this.diskDataSet).beginLoad(this.inputCount, this.outputCount);
        }
        this.byteSize += currentSize;
        this.diskCount += 1l;
        this.diskDataSet.add(inputData);
    }
}
 
开发者ID:ShifuML,项目名称:guagua,代码行数:18,代码来源:MemoryDiskMLDataSet.java

示例3: getError

import org.encog.ml.data.MLDataPair; //导入依赖的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

示例4: main

import org.encog.ml.data.MLDataPair; //导入依赖的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

示例5: solve

import org.encog.ml.data.MLDataPair; //导入依赖的package包/类
@Override /** {@inheritDoc} */
public double[] solve(final double[][] inputs) {
  double[] results = new double[inputs.length];
  trainingSet = new BasicMLDataSet(inputs, null);
  int i = 0;
  for (MLDataPair pair : trainingSet) {
    final MLData output = network.compute(pair.getInput());
    results[i++] = output.getData(0);
  }
  Encog.getInstance().shutdown();
  return results;
}
 
开发者ID:Saka7,项目名称:Layer-Classifier,代码行数:13,代码来源:BackPropagationNeuralNet.java

示例6: solve

import org.encog.ml.data.MLDataPair; //导入依赖的package包/类
/** {@inheritDoc} */
public double[] solve(final double[][] inputs) {
  double[] results = new double[inputs.length];
  trainingSet = new BasicMLDataSet(inputs, null);
  int i = 0;
  for (MLDataPair pair : trainingSet) {
    final MLData output = network.compute(pair.getInput());
    results[i++] = output.getData(0);
  }
  Encog.getInstance().shutdown();
  return results;
}
 
开发者ID:Saka7,项目名称:Layer-Classifier,代码行数:13,代码来源:ResilientPropagationNeuralNet.java

示例7: prepareDataCollection

import org.encog.ml.data.MLDataPair; //导入依赖的package包/类
private void prepareDataCollection() throws IOException {
	final File tmp = File.createTempFile("data", ".csv");
	final InputStream stream = HandWritingNeuralNetENCOG.class.getResourceAsStream(INPUT_LOCATION);
	final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
	String line = null;
	final PrintWriter writer = new PrintWriter(new FileWriter(tmp));
	while ((line = reader.readLine()) != null) {
		writer.println(line);
	}
	writer.close();
	reader.close();
	training = new CSVNeuralDataSet(tmp.getAbsolutePath(), 400, 10, false);
	final Iterator<MLDataPair> elementItr = this.training.iterator();
	for (; elementItr.hasNext();) {
		final MLDataPair type = elementItr.next();
		final double[] yData = type.getIdealArray();
		final double[] xData = type.getInputArray();
		int yIndex = 0;
		while (yData[yIndex] != 1)
			yIndex++;
		final int currentCount = this.examples.adjustOrPutValue(yIndex, 1, 1);
		if (currentCount < this.maxTests) {

			List<IndependentPair<double[], double[]>> numberTest = this.tests.get(yIndex);
			if (numberTest == null) {
				this.tests.put(yIndex, numberTest = new ArrayList<IndependentPair<double[], double[]>>());
			}
			numberTest.add(IndependentPair.pair(xData, yData));
			totalTests++;
		}
	}

}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:34,代码来源:HandWritingNeuralNetENCOG.java

示例8: getRecord

import org.encog.ml.data.MLDataPair; //导入依赖的package包/类
@Override
public void getRecord(long index, MLDataPair pair) {
    if(index < this.memoryCount) {
        this.memoryDataSet.getRecord(index, pair);
    } else {
        this.diskDataSet.getRecord(index - this.memoryCount, pair);
    }
}
 
开发者ID:ShifuML,项目名称:guagua,代码行数:9,代码来源:MemoryDiskMLDataSet.java

示例9: main

import org.encog.ml.data.MLDataPair; //导入依赖的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:encog,项目名称:encog-sample-java,代码行数:40,代码来源:HelloWorld.java

示例10: calculateError

import org.encog.ml.data.MLDataPair; //导入依赖的package包/类
private boolean calculateError (NeuralDataSet trainingSet){
	logger.debug("Neural Network Results:");
	double RSS = 0.0;
	double Ry = 0.0;
	double SMAPE = 0.0;
	double MAPE = 0.0;
	int no = 0;
	double all = 0.0;
	double sum = 0;
	sample = ((BasicNeuralDataSet)trainingSet).getRecordCount();
	
	for(MLDataPair pair: trainingSet ) {
	   final MLData output = bestEverNetwork.compute(pair.getInput());
	   double result = (Double.NaN == output.getData(0))? pair.getIdeal().getData(0) : output.getData(0); 
	   sum += result;
	   double difference = pair.getIdeal().getData(0) - result;
	   RSS += Math.pow(difference, 2);
	   all += Math.abs(difference);
	 
		   
	   SMAPE += calculateEachSMAPE(pair.getIdeal().getData(0), result);

	   MAPE += calculateEachMAPE(pair.getIdeal().getData(0), result);
	   Ry += Math.pow(pair.getIdeal().getData(0) - meanIdeal, 2);
	   logger.debug("Actual=" + output.getData(0) + ", Ideal=" + pair.getIdeal().getData(0));
	   no++;
	}
	this.RSS = RSS;
	//System.out.print("Ry: " + Ry + "\n");
	this.R = 1-(Ry==0? RSS : RSS/Ry);
	this.SMAPE = SMAPE/no;
	this.MAPE = MAPE/no;
	//System.out.print(no+"MSE: " + bestEverNetwork.calculateError(trainingSet) + "\n");
	return sum != 0;
}
 
开发者ID:taochen,项目名称:ssascaling,代码行数:36,代码来源:EncogFeedForwardNeuralNetwork.java

示例11: test

import org.encog.ml.data.MLDataPair; //导入依赖的package包/类
public static void test(double[][] inputValues, double[][] outputValues)
{
    NeuralDataSet trainingSet = new BasicNeuralDataSet(inputValues, outputValues);
    BasicNetwork network = new BasicNetwork();
    network.addLayer(new BasicLayer(new ActivationSigmoid(), false, 4));
    network.addLayer(new BasicLayer(new ActivationSigmoid(), false, 1000));
    network.addLayer(new BasicLayer(new ActivationLinear(), false, 1));
    network.getStructure().finalizeStructure();
    network.reset();
    final Train train = new ResilientPropagation(network, trainingSet);
    int epoch = 1;
    do
    {
        train.iteration();
        System.out.println("Epoch #" + epoch + " Error:" + train.getError());
        epoch++;
    }
    while(epoch < 10000);
    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));

    }
}
 
开发者ID:santjuan,项目名称:dailyBot,代码行数:28,代码来源:NeuralNetworkAnalysis.java

示例12: value

import org.encog.ml.data.MLDataPair; //导入依赖的package包/类
@Override
public double value(double[] weights) {
	double error  = 0;
	updateReadoutWeights(weights);
	for(MLDataPair pair: trainingSet ) {
		try {
			
			reservoir.input(pair.getInput());
			double [] output = readout.getOutput().getData();
			double [] target = pair.getIdeal().getData();
			//error += compareSpikeTrains(target, output);
			error += ErrorUtility.computeLinearRegressionError(target, output);
			//logger.info("error");
		} catch (ReserviorException e) {
			//Because we are in an implemented class kill this way for now.
			logger.error(e);
			System.exit(0);
		}
		//After each time the reservoir sees a training entry reset the reservoir
		reservoir.getReservior().reset();
		readout.reset();

	}
	//error *= error;
	CMAES.this.epoch++;
	//ByteArrayOutputStream baos = new ByteArrayOutputStream();
//	PrintStream ps = new PrintStream(baos);
//	ps.printf("%2d \t %5.5f",epoch, error);
//	logger.info(baos.toString());
	logger.info(epoch + "\t" + error + "\t*" + minError);
	if (error < minError){
		minError = error;
		bestWeights = weights;
	}
	return error;
}
 
开发者ID:wil3,项目名称:lacus,代码行数:37,代码来源:CMAES.java

示例13: setData

import org.encog.ml.data.MLDataPair; //导入依赖的package包/类
public void setData(double[][] p) {
    for(int i = 0 ; i < p.length; i ++){
        double[] input  = p[i];
        
        MLDataPair pair = new BasicMLDataPair(new BasicMLData(input), new BasicMLData(input));
        
        dataset.add(pair);
    }
}
 
开发者ID:m4rkl1u,项目名称:AutoEncoder,代码行数:10,代码来源:AutoEncoder.java

示例14: load

import org.encog.ml.data.MLDataPair; //导入依赖的package包/类
@Override
public void load(GuaguaWritableAdapter<LongWritable> currentKey, GuaguaWritableAdapter<Text> currentValue,
        WorkerContext<NNParams, NNParams> workerContext) {
    ++this.count;
    if((this.count) % 100000 == 0) {
        LOG.info("Read {} records.", this.count);
    }

    // use guava to iterate only once
    double[] ideal = new double[1];
    int inputNodes = NumberFormatUtils.getInt(
            workerContext.getProps().getProperty(NNConstants.GUAGUA_NN_INPUT_NODES),
            NNConstants.GUAGUA_NN_DEFAULT_INPUT_NODES);
    double[] inputs = new double[inputNodes];

    int i = 0;
    for(String input: Splitter.on(NNConstants.NN_DEFAULT_COLUMN_SEPARATOR).split(
            currentValue.getWritable().toString())) {
        if(i == 0) {
            ideal[i++] = NumberFormatUtils.getDouble(input, 0.0d);
        } else {
            int inputsIndex = (i++) - 1;
            if(inputsIndex >= inputNodes) {
                break;
            }
            inputs[inputsIndex] = NumberFormatUtils.getDouble(input, 0.0d);
        }
    }

    if(i < (inputNodes + 1)) {
        throw new GuaguaRuntimeException(String.format(
                "Not enough data columns, input nodes setting:%s, data column:%s", inputNodes, i));
    }

    int scale = NumberFormatUtils.getInt(workerContext.getProps().getProperty(NNConstants.NN_RECORD_SCALE), 1);
    for(int j = 0; j < scale; j++) {
        double[] tmpInputs = j == 0 ? inputs : new double[inputs.length];
        double[] tmpIdeal = j == 0 ? ideal : new double[ideal.length];
        System.arraycopy(inputs, 0, tmpInputs, 0, inputs.length);
        MLDataPair pair = new BasicMLDataPair(new BasicMLData(tmpInputs), new BasicMLData(tmpIdeal));
        double r = Math.random();
        if(r >= 0.5d) {
            this.trainingData.add(pair);
        } else {
            this.testingData.add(pair);
        }
    }
}
 
开发者ID:ShifuML,项目名称:guagua,代码行数:49,代码来源:NNWorker.java

示例15: train

import org.encog.ml.data.MLDataPair; //导入依赖的package包/类
public void train(final ArrayList<DataPoint> dataHistory) {
	if (isTraining()) {
		throw new IllegalStateException();
	}

	setTrainerThread(new Thread() {
		public void run() {
			// Clean and normalize the data history
			ArrayList<DataPoint> cleanedDataHistory = cleanDataHistory(dataHistory);
			ArrayList<DataPoint> normalizedDataHistory = normalizeDataHistory(cleanedDataHistory);

			// Create a new neural network and data set
			BasicNetwork neuralNetwork = EncogUtility.simpleFeedForward(2, getHiddenLayerNeurons(0),
					getHiddenLayerNeurons(1), 5, true);
			MLDataSet dataSet = new BasicMLDataSet();

			// Add all points of the data history to the data set
			for (DataPoint dataPoint : normalizedDataHistory) {
				MLData input = new BasicMLData(2);
				input.setData(0, dataPoint.getX());
				input.setData(1, dataPoint.getY());

				// If getButton() is 0, the output will be 0, 0, 0, 0
				// If getButton() is 2, the output will be 0, 1, 0, 0
				// If getButton() is 4, the output will be 0, 0, 0, 1
				MLData ideal = new BasicMLData(5);
				for (int i = 0; i <= 4; i++) {
					ideal.setData(i, (dataPoint.getButton() == i) ? 1 : 0);
				}

				MLDataPair pair = new BasicMLDataPair(input, ideal);
				dataSet.add(pair);
			}

			// Create a training method
			MLTrain trainingMethod = new ResilientPropagation((ContainsFlat) neuralNetwork, dataSet);
			long startTime = System.currentTimeMillis();
			int timeLeft = getMaxTrainingTime();
			int iteration = 0;

			// Train the network using multiple iterations on the training method
			do {
				trainingMethod.iteration();
				timeLeft = (int) ((startTime + getMaxTrainingTime()) - System.currentTimeMillis());
				iteration++;

				sendNeuralNetworkIteration(iteration, trainingMethod.getError(), timeLeft);
			} while (trainingMethod.getError() > getMaxTrainingError() && timeLeft > 0
					&& !trainingMethod.isTrainingDone());
			trainingMethod.finishTraining();

			// Return the neural network to all listeners
			sendNeuralNetworkTrainerResult(neuralNetwork);
		}
	});
	getTrainerThread().start();
}
 
开发者ID:bsmulders,项目名称:StepManiaSolver,代码行数:58,代码来源:NeuralNetworkTrainer.java


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