}
ConnectionFactory cf = new ConnectionFactory();
Properties properties = new Properties();
properties.setParameter(Constants.CONNECTION_FACTORY, cf);
StackedAutoencoder result = new StackedAutoencoder(new Layer());
result.setProperties(properties);
for (int i = 1; i < layers.length; i++) {
Autoencoder ae = new Autoencoder();
ae.setProperties(new Properties());
ae.getProperties().setParameter(Constants.CONNECTION_FACTORY, cf);
ae.addLayer(result.getOutputLayer());
NNFactory.addFullyConnectedLayer(ae, new Layer(), cf, layers[i - 1], layers[i], addBias);
NNFactory.addFullyConnectedLayer(ae, new Layer(), cf, layers[i], layers[i - 1], addBias);
result.addNeuralNetwork(ae);
}
return result;