// Create random particles for the RBF.
GenerateRandom rnd = new MersenneTwisterGenerateRandom();
RBFNetwork[] particles = new RBFNetwork[TitanicConfig.ParticleCount];
for (int i = 0; i < particles.length; i++) {
particles[i] = new RBFNetwork(TitanicConfig.InputFeatureCount, TitanicConfig.RBF_COUNT, 1);
particles[i].reset(rnd);
}
/**
* Construct a network to hold the best network.
*/
if (bestNetwork == null) {
bestNetwork = new RBFNetwork(TitanicConfig.InputFeatureCount, TitanicConfig.RBF_COUNT, 1);
}
/**
* Setup the scoring function.
*/
ScoreFunction score = new ScoreTitanic(training);
ScoreFunction scoreValidate = new ScoreTitanic(validation);
/**
* Setup particle swarm.
*/
boolean done = false;
TrainPSO train = new TrainPSO(particles, score);
int iterationNumber = 0;
StringBuilder line = new StringBuilder();
do {
iterationNumber++;
train.iteration();
RBFNetwork best = (RBFNetwork) train.getBestParticle();
double trainingScore = train.getLastError();
double validationScore = scoreValidate.calculateScore(best);
if (validationScore > bestScore) {
System.arraycopy(best.getLongTermMemory(), 0, this.bestNetwork.getLongTermMemory(), 0, best.getLongTermMemory().length);
this.bestScore = validationScore;
}
if (validationScore > localBest) {
noImprove = 0;