Edit: How do I calculate the output for a non traning input?

allissaid's picture

Hallo and thanks for the amazing Encog project.

In the XOR (backprop type of NN) example I can see how you calculate the outputs for the training inputs,
but how can I compute the output for an specific input? Not the training inputs,
an input that I declare once the network is trained.

Thanks very much for the patience.

allissaid

allissaid's picture

Ok I have realized that I have to create a NeuralData type of variable and use network.compute().

But here is where I am:

final NeuralData input;
input.setData(C);

where C is a double array with the pattern I want to recognize.

The compiler says:

The local variable input may not have been initialized.

Any help? Should be easy!

Thanks again.

gshank's picture

I make it a habit to initialize all variables so either:
NeuralData input = null; // and then set it later
-- OR --
double[] data = { something };
DataNormalization normalize = new DataNormalization();
NeuralData input = normalize.buildForNetworkInput(data);

allissaid's picture

The first option still doesnt work,

but so does the second one!

Thanks gshank.

By the way, do you know how to save a network in order to do not train it every time I want to execute the aplication?

Thanks again.

gshank's picture

private void save(String filename) throws FileNotFoundException, IOException {
ObjectOutputStream out = null;
try {
out = new ObjectOutputStream(new FileOutputStream(filename));
out.writeObject(network); // network is BasicNetwork class variable
}
finally {
out.close();
}
}
private void load(String filename) throws FileNotFoundException, IOException, ClassNotFoundException {
ObjectInputStream in = null;
try {
in = new ObjectInputStream(new FileInputStream(filename));
network = (BasicNetwork)in.readObject(); // network is a BasicNetwork class variable
}
finally {
in.close();
}
}

allissaid's picture

Thank you very much for the patience gshank.

I am now trying to call the save method, and I get this from the compiler:

"Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method save(String) from the type XaxraNeuronal refers to the missing type FileNotFoundException"

Can you help me?

Thanks again !

gshank's picture

you need to have import's for each of those classes. For example, you'll need:
import java.io.FileNotFoundException;
or in your case, you might want to just do:
import java.io.*;
which imports all java.io classes

allissaid's picture

Ok! I imported the io classes.

Now I can go but on the save method the compiler says:

"Exception in thread "main" java.lang.NullPointerException
at OCRBackprop.XaxraNeuronal.save(XaxraNeuronal.java:46)"

It corresponds to the "out.close();" line.

Thanks !


Copyright 2005 - 2012 by Heaton Research, Inc.. Heaton Research™ and Encog™ are trademarks of Heaton Research. Click here for copyright, license and trademark information.