Você está na página 1de 2

Neural network program(JAVA)

float[][] x = DataUtils.readInputsFromFile("data/x.txt");
int[] t = DataUtils.readOutputsFromFile("data/t.txt");

NeuralNetwork neuralNetwork = new NeuralNetwork(x, t, new


INeuralNetworkCallback() {
@Override
public void success(Result result) {
float[] valueToPredict = new float[] {-0.205f, 0.780f};
System.out.println("Success percentage: " +
result.getSuccessPercentage());
System.out.println("Predicted result: " +
result.predictValue(valueToPredict));
}

@Override
public void failure(Error error) {
System.out.println("Error: " + error.getDescription());
}
});

neuralNetwork.startLearning();

Output:

Success percentage: 88.4


Predicted result: 1

This project has a example with real data that contains a list of 250 patients with two
results of a analysis as inputs and 0 or 1 (depending if the has a disease or not) as
output:

Inputs Output
------------------------ --------------------
Result 1 Result 2 Disease
----------------------- --------------------
-0.5982 0.9870 1
-0.2019 0.6210 1
0.1797 0.4518 0
-0.0982 0.5876 1
... ... ...
Using this data in neural network, this project is able to predict the output (disease
result) of a patient that isn't in the data list with a minimum percentage of success of
88%.
ALGORITHM:

This is a simple usage with default configuration:

1. First of all, load input and output data. You can read it from external text file:

float[][] x = DataUtils.readInputsFromFile("data/x.txt"); int[] t =


DataUtils.readOutputsFromFile("data/t.txt"); 2. Instantiate new NeuralNetwork and create a
new callback to receive response: java NeuralNetwork neuralNetwork = new
NeuralNetwork(x, t, new INeuralNetworkCallback() { @Override public void success(Result
result) { }
@Override
public void failure(Error error) {
}
});
```

3. Predict a value using Result entity from success response:

4. @Override
5. public void success(Result result) {
6. float[] valueToPredict = new float[] {-1.2f, 0.796f};
7. System.out.println("Predicted result: " +
result.predictValue(valueToPredict));
8. }

9. Finally, run learning of neural network:

AIM:

Simple neural network is a Java project that allow users to easily create a asynchronous
simple neural network.

This project can be used to predict a output based on a initial learning.

Features
Callback with a result entity
Number of neurons customizable
Read data from external files
Simple predictor usage

Você também pode gostar