本文整理汇总了Java中org.encog.ml.data.MLData.getData方法的典型用法代码示例。如果您正苦于以下问题:Java MLData.getData方法的具体用法?Java MLData.getData怎么用?Java MLData.getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.encog.ml.data.MLData
的用法示例。
在下文中一共展示了MLData.getData方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getError
import org.encog.ml.data.MLData; //导入方法依赖的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};
}
示例2: enquireNeuralNetwork
import org.encog.ml.data.MLData; //导入方法依赖的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;
}
示例3: doPredict
import org.encog.ml.data.MLData; //导入方法依赖的package包/类
@Override
protected Object doPredict(String[] line) {
NormalizationHelper helper = model.getDataset().getNormHelper();
MLData input = helper.allocateInputVector();
helper.normalizeInputVector(line, input.getData(), false);
MLData output = method.compute(input);
DataType outputType = types.get(this.output);
switch (outputType) {
case _float : return output.getData(0);
case _class: return helper.denormalizeOutputVectorToString(output)[0];
default: throw new IllegalArgumentException("Output type not yet supported "+outputType);
}
}
示例4: autonomousMoveDirection
import org.encog.ml.data.MLData; //导入方法依赖的package包/类
public Directions autonomousMoveDirection() {
updateVision();
MLData result = this.brain.compute(this.vision);
double winningOutput = Double.NEGATIVE_INFINITY;
Directions winningDirection = Directions.UP;
for (int i = 0; i < result.size(); i++) {
// determine direction
Directions direction = directionFromIndex(i);
if(getMap().get(Position.getInDirection(this.getPosition(), direction)).isPresent()) {
if(getMap().get(Position.getInDirection(this.getPosition(), direction)).get().getType().equals(TypeObject.Obstacle)) {
continue;
}
}
// evaluate if this is a "winning" direction
double thisOutput = result.getData(i);
if (thisOutput > winningOutput) {
winningOutput = thisOutput;
winningDirection = direction;
}
}
return winningDirection;
}
示例5: updatePredictions
import org.encog.ml.data.MLData; //导入方法依赖的package包/类
@Override
public void updatePredictions(SensorModel model) {
RealVector vec = sensorsToVector(model, mNorm);
MLData prediction = mNN.compute(new BasicMLData(vec.toArray()));
mPredictions = new ArrayRealVector(prediction.getData());
mNorm.denormalizeOutput(mPredictions, 0, 1);
}
示例6: solve
import org.encog.ml.data.MLData; //导入方法依赖的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;
}
示例7: solve
import org.encog.ml.data.MLData; //导入方法依赖的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;
}
示例8: calculateError
import org.encog.ml.data.MLData; //导入方法依赖的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;
}
示例9: move
import org.encog.ml.data.MLData; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public int move(Board board, int player) throws NoValidMoveException {
super.move(board, player);
int[][] state = board.getState();
/*
* State matrix should be with valid dimensions.
*/
int size = 0;
for (int i = 0; i < state.length; i++) {
size += state[i].length;
}
/*
* Encode in the input the player who is playing.
*/
size += NUMBER_OF_PLAYERS;
/*
* Check ANN input layer size.
*/
if (size != net.getInputCount()) {
throw new NoValidMoveException();
}
/*
* Scale input in the range of [0.0-1.0].
*/
double input[] = new double[size];
for (int i = 0, k = 0; i < state.length; i++) {
for (int j = 0; j < state[i].length; j++, k++) {
input[k] = (state[i][j] - min) / (max - min);
}
}
/*
* Mark the player who is playing.
*/
for (int i = input.length - NUMBER_OF_PLAYERS, p = 1; i < input.length; i++, p++) {
if (player == p) {
input[i] = 1;
} else {
input[i] = 0;
}
}
/*
* Feed the ANN input. ANN calculation.
*/
MLData data = new BasicMLData(input);
data = net.compute(data);
/*
* Obtain the ANN output.
*/
double output[] = data.getData();
/*
* Suggest move.
*/
int index = 0;
for (int i = 0; i < output.length; i++) {
if (output[i] > output[index]) {
index = i;
}
}
return index;
}