Encog 1.0 for Java serialization

gc's picture

hello!
how to serialize BasicNetwork object?
i have tried:
WRITING:
FileOutputStream out;
try {
out = new FileOutputStream("neuron_reka.ocr");
ObjectOutputStream s = new ObjectOutputStream(out);
s.writeObject(network);
s.flush();
} catch (FileNotFoundException e) { e.printStackTrace();
} catch (IOException e) { e.printStackTrace(); }
READING:
try {
inn = new FileInputStream("neuron_reka.ocr");
ObjectInputStream s = new ObjectInputStream(inn);
network = (BasicNetwork)s.readObject();
} catch (FileNotFoundException e) { e.printStackTrace();
} catch (IOException e) { e.printStackTrace();
} catch (ClassNotFoundException e) { e.printStackTrace(); }
but it don't work :-P
maybe someone did it and could share the secret of easy-BasicNetwork-serialization?

jeffheaton's picture

However, there is a bug with Encog 1.0 where serialization does not work. I normally use EncogPersistedCollection and just store it to an Encog XML file.

However, if you want to use serialization, that has been fixed with Encog 1.1. Encog 1.1 is probably about a week from release. If you would like to grab a copy now, you can get it from this URL.

http://www.heatonresearch.com/dload/encog-core.jar

Jeff

liboh's picture

I'm using the code above with Encog 1.1 and I get this exception in the line: network = (BasicNetwork)s.readObject();


java.lang.ClassCastException: cannot assign instance of org.encog.neural.networks.layers.FeedforwardLayer to field org.encog.neural.networks.layers.BasicLayer.next of type java.util.List in instance of org.encog.neural.networks.layers.FeedforwardLayer

Why is that happening?

jeffheaton's picture

See my reply in the other forum.


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