Update
FeatureConstruction has a logic error in classify. You're assuming that the parameter 'training' has no more than 2 elements in it.
public double classify(Dataset training, Dataset testing) {
// initial the threshold and two classes
Object[] clzz = new Object[training.classes().size()]; // <--- Init the array to the size of training
int index = 0;
for (Object o : training.classes()) {
clzz[index] = o; //<-- Now everything in training has a place to be.
index++;
}
From the stacktrace you're providing the problem initializes on line 87 of your class; however, the Exception is being thrown from line 192 of the class FeatureConstruction within the same package. It seems like there is an implied dependency between the Particle.getPosition() and Problem.fitness(position) that is not being satisfied.
I would guess that Problem extends FeatureConstruction, and that the issue is related to state management and expectations between the Problem implementation and the parent class.
I would recommend inspecting the variables in the call stack down to FeatureConstrction.classify(). Determine what the state of the Problem is as it pertains to that specific invocation, and build a JUnit test to replicate the condition. That can help to isolate the problem and accelerate testing modifications to correct.
The Junit test will assist in understanding the state of the classes, and possibly allow checks to be put in place to prevent that state. At the end of the day I expect that at least one of three things is going to be the culprit:
- FeatureConstruction has a logic issue in the classify function.
- Problem (assumed extension of FeatureConstruction) is not accounting for state of the parent class, and is missing some kind of initialization or update call to keep the parent data model in sync.
- The process that controls the dependency between the Problem and the Particle has a logic error in one case, and the setup is misconfiguring the data association.
Hope that helps.