List<SampleVector> trainList = new ArrayList<SampleVector>();
List<SampleVector> testList = new ArrayList<SampleVector>();
DataInput.splitList(samples, trainList, testList, 0.7);
RBM rbm = new RBM(x_feature, n_hidden);
SGDTrainConfig config = new SGDTrainConfig();
config.setUseCG(true);
config.setCgEpochStep(50);
config.setCgTolerance(0);
config.setCgMaxIterations(30);
config.setMaxEpochs(50);
config.setNbrModelReplica(4);
config.setMinLoss(0.01);
config.setPrintLoss(true);
logger.info("Start to train RBM.");
DownpourSGDTrain.train(rbm, trainList, config);
double[] reconstruct_x = new double[x_feature];
double totalError = 0;
for(SampleVector test : testList) {
rbm.reconstruct(test.getX(), reconstruct_x);
totalError += ClassVerify.squaredError(test.getX(), reconstruct_x);
}
logger.info("Mean square error is " + totalError / testList.size());
} catch(Throwable e) {
logger.error("", e);