Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.encog.ml.ea.opp.CompoundOperator not Serializable #241

Closed
dsmaugy opened this issue Feb 21, 2017 · 11 comments
Closed

org.encog.ml.ea.opp.CompoundOperator not Serializable #241

dsmaugy opened this issue Feb 21, 2017 · 11 comments
Labels
Milestone

Comments

@dsmaugy
Copy link

dsmaugy commented Feb 21, 2017

I'm trying to serialize my BasicEA object which implements Serializable, but I get this exception:
java.io.NotSerializableException: org.encog.ml.ea.opp.CompoundOperator
Is it safe to just go into the source and make that class serializable?

@xerx593
Copy link

xerx593 commented Feb 21, 2017 via email

@dsmaugy
Copy link
Author

dsmaugy commented Feb 21, 2017

Hmm, I did this but I kept having to serialize classes until the stack trace said that I needed to serialize Thread. Would setting the non serializable instance variables of BasicEA to transient break the BasicEA?

@dsmaugy
Copy link
Author

dsmaugy commented Feb 21, 2017

Well I tried making the ThreadPoolExecutor transient, and I'm getting a null pointer exception when the BasicEA tries to load up threads

@xerx593
Copy link

xerx593 commented Feb 21, 2017 via email

@xerx593
Copy link

xerx593 commented Feb 22, 2017 via email

@dsmaugy
Copy link
Author

dsmaugy commented Feb 22, 2017

I actually think I fixed it?

In the BasicEA class, I changed this check in the iteration() method.

if (this.actualThreadCount == -1) {
	this.preIteration();
} 

to

if (this.actualThreadCount == -1 || this.taskExecutor == null) {
	this.preIteration();
}

I didn't seem to get any errors so I guess that is working. Maybe it's a placebo, but I feel like my training runs a lot slower now. Maybe somehow I ruined multithreading?

@jeffheaton
Copy link
Owner

jeffheaton commented Feb 22, 2017 via email

@dsmaugy
Copy link
Author

dsmaugy commented Feb 22, 2017

I assume you want to save them so that you can resume training
later?

Yes, I want to be able to train for a couple of iterations, stop the training program if needed, and then resume training again with the same best genome.

I thought that just serializing the NEATPopulation would suffice, but everytime I restarted the program, the training object wouldn't train to beat the best genome of the NEATPopulation, it would act as if it was training with fresh training data.

As I was typing this, I just thought to myself, would manually setting the best genome of the train object to the best genome of the population fix this and negate the need for serialization of the training object?

@jeffheaton
Copy link
Owner

jeffheaton commented Feb 25, 2017

It is safe enough for that member variable, but to make it fully serializable a few other adjustments are needed. I am going to check in a change for that soon. Your fix might work, but I would have to try it to know for sure. I think serializing the population is the cleaner solution than serializing the trainer. But I will have a look at that.

@jeffheaton
Copy link
Owner

I was able to reproduce this issue and checked in a fix that allows you to serialize an EATrain object being used with NEAT. This is checked into the current codebase and will be in the next release. You can see a unit test that demonstrates persisting a trainer and reloading it:

https://github.com/encog/encog-java-core/blob/master/src/test/java/org/encog/persist/TestPersistNEAT.java

@jeffheaton jeffheaton added this to the Encog v3.4 milestone Sep 3, 2017
@jeffheaton jeffheaton added the Bug label Sep 3, 2017
@jeffheaton
Copy link
Owner

Fixed as of 3.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants