// Path: src/main/options/ExecutionParameters.java
// public class ExecutionParameters {
//     /**
//      * Specify if the verbose mode is activated
//      */
//     public static boolean verbose = false;
// 
//     /**
//      * Specify if we train the program (if we fill and save the Markov chains)
//      */
//     public static boolean train = false;
// 
//     /**
//      * Specify the seed for generation
//      */
//     public static int seed = 3657263;
// 
//     /**
//      * Specify the path to the training set (for writing or reading)
//      */
//     public static Path LSTMTrainingSetPath = Paths.get("assets/abc");
// 
//     /**
//      * Specify the path to the trained data (created after training and used for generation)
//      */
//     public static Path trainedLSTMPath = Paths.get("assets/training/trained-lstm");
// }
// 
// Path: src/tools/Misc.java
// public class Misc {
//     public static String getJarPath() {
//         String path = Misc.class.getProtectionDomain().getCodeSource().getLocation().getPath();
//         String decoded = null;
//         String dir = null;
// 
//         try {
//             decoded = URLDecoder.decode(path, "UTF-8");
//             int lastSlash = decoded.lastIndexOf("/");
// 
//             if (decoded.substring(lastSlash - 7, lastSlash).compareTo("classes") == 0)
//                 dir = decoded.substring(0, lastSlash - 7);
//             else
//                 dir = decoded.substring(0, lastSlash + 1);
//         } catch (UnsupportedEncodingException e) {
//             e.printStackTrace();
//         }
// 
//         return System.getProperty("os.name").contains("indow") ? dir.substring(1) : dir;
//     }
// 
//     public static String getProjectPath() {
//         String path = getJarPath();
//         return path.substring(0, path.lastIndexOf("target"));
//     }
// }


import com.sun.org.apache.xpath.internal.operations.Mod;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import main.options.ExecutionParameters;
import org.deeplearning4j.api.storage.StatsStorage;
import org.deeplearning4j.nn.api.Layer;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
import org.deeplearning4j.nn.conf.BackpropType;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.Updater;
import org.deeplearning4j.nn.conf.layers.GravesLSTM;
import org.deeplearning4j.nn.conf.layers.RnnOutputLayer;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.deeplearning4j.nn.weights.WeightInit;
import org.deeplearning4j.optimize.listeners.ScoreIterationListener;
import org.deeplearning4j.ui.api.UIServer;
import org.deeplearning4j.ui.stats.StatsListener;
import org.deeplearning4j.ui.storage.InMemoryStatsStorage;
import org.deeplearning4j.util.ModelSerializer;
import org.nd4j.linalg.dataset.api.DataSet;
import org.nd4j.linalg.lossfunctions.LossFunctions;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
import tools.Misc;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Random;
import java.io.*;
                .rmsDecay(0.95) // 0.95 original
                .seed(seed_)
                .regularization(true) // true original
                .l2(0.001)
                .weightInit(WeightInit.XAVIER)
                .updater(Updater.RMSPROP)
                .list()
                .layer(0, new GravesLSTM.Builder().nIn(trainingSetIterator_.inputColumns()).nOut(lstmLayerSize_)
                        .activation("tanh").build())
                .layer(1, new GravesLSTM.Builder().nIn(lstmLayerSize_).nOut(lstmLayerSize_)
                        .activation("tanh").build())
                .layer(2, new GravesLSTM.Builder().nIn(lstmLayerSize_).nOut(lstmLayerSize_)
                        .activation("tanh").build())
                .layer(3, new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT).activation("softmax")
                        .nIn(lstmLayerSize_).nOut(nOut).build())
                .backpropType(BackpropType.TruncatedBPTT)
                    .tBPTTForwardLength(truncatedBackPropThroughTimeLength_)
                    .tBPTTBackwardLength(truncatedBackPropThroughTimeLength_)
                .pretrain(false).backprop(true)
                .build();

        lstmNet_ = new MultiLayerNetwork(conf);
        lstmNet_.init();
        //lstmNet_.setListeners(new ScoreIterationListener(1));
        //lstmNet_.setListeners(new HistogramIterationListener(1));
        UIServer uiServer = UIServer.getInstance();
        StatsStorage statsStorage = new InMemoryStatsStorage();
        uiServer.attach(statsStorage);
        lstmNet_.setListeners(new StatsListener(statsStorage));

// Path: src/main/options/ExecutionParameters.java
// public class ExecutionParameters {
//     /**
//      * Specify if the verbose mode is activated
//      */
//     public static boolean verbose = false;
// 
//     /**
//      * Specify if we train the program (if we fill and save the Markov chains)
//      */
//     public static boolean train = false;
// 
//     /**
//      * Specify the seed for generation
//      */
//     public static int seed = 3657263;
// 
//     /**
//      * Specify the path to the training set (for writing or reading)
//      */
//     public static Path LSTMTrainingSetPath = Paths.get("assets/abc");
// 
//     /**
//      * Specify the path to the trained data (created after training and used for generation)
//      */
//     public static Path trainedLSTMPath = Paths.get("assets/training/trained-lstm");
// }
// 
// Path: src/tools/Misc.java
// public class Misc {
//     public static String getJarPath() {
//         String path = Misc.class.getProtectionDomain().getCodeSource().getLocation().getPath();
//         String decoded = null;
//         String dir = null;
// 
//         try {
//             decoded = URLDecoder.decode(path, "UTF-8");
//             int lastSlash = decoded.lastIndexOf("/");
// 
//             if (decoded.substring(lastSlash - 7, lastSlash).compareTo("classes") == 0)
//                 dir = decoded.substring(0, lastSlash - 7);
//             else
//                 dir = decoded.substring(0, lastSlash + 1);
//         } catch (UnsupportedEncodingException e) {
//             e.printStackTrace();
//         }
// 
//         return System.getProperty("os.name").contains("indow") ? dir.substring(1) : dir;
//     }
// 
//     public static String getProjectPath() {
//         String path = getJarPath();
//         return path.substring(0, path.lastIndexOf("target"));
//     }
// }


// Path: src/lstm/LSTMTrainer.java
import com.sun.org.apache.xpath.internal.operations.Mod;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import main.options.ExecutionParameters;
import org.deeplearning4j.api.storage.StatsStorage;
import org.deeplearning4j.nn.api.Layer;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
import org.deeplearning4j.nn.conf.BackpropType;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.Updater;
import org.deeplearning4j.nn.conf.layers.GravesLSTM;
import org.deeplearning4j.nn.conf.layers.RnnOutputLayer;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.deeplearning4j.nn.weights.WeightInit;
import org.deeplearning4j.optimize.listeners.ScoreIterationListener;
import org.deeplearning4j.ui.api.UIServer;
import org.deeplearning4j.ui.stats.StatsListener;
import org.deeplearning4j.ui.storage.InMemoryStatsStorage;
import org.deeplearning4j.util.ModelSerializer;
import org.nd4j.linalg.dataset.api.DataSet;
import org.nd4j.linalg.lossfunctions.LossFunctions;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
import tools.Misc;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Random;
import java.io.*;

                .rmsDecay(0.95) // 0.95 original
                .seed(seed_)
                .regularization(true) // true original
                .l2(0.001)
                .weightInit(WeightInit.XAVIER)
                .updater(Updater.RMSPROP)
                .list()
                .layer(0, new GravesLSTM.Builder().nIn(trainingSetIterator_.inputColumns()).nOut(lstmLayerSize_)
                        .activation("tanh").build())
                .layer(1, new GravesLSTM.Builder().nIn(lstmLayerSize_).nOut(lstmLayerSize_)
                        .activation("tanh").build())
                .layer(2, new GravesLSTM.Builder().nIn(lstmLayerSize_).nOut(lstmLayerSize_)
                        .activation("tanh").build())
                .layer(3, new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT).activation("softmax")
                        .nIn(lstmLayerSize_).nOut(nOut).build())
                .backpropType(BackpropType.TruncatedBPTT)
                    .tBPTTForwardLength(truncatedBackPropThroughTimeLength_)
                    .tBPTTBackwardLength(truncatedBackPropThroughTimeLength_)
                .pretrain(false).backprop(true)
                .build();

        lstmNet_ = new MultiLayerNetwork(conf);
        lstmNet_.init();
        //lstmNet_.setListeners(new ScoreIterationListener(1));
        //lstmNet_.setListeners(new HistogramIterationListener(1));
        UIServer uiServer = UIServer.getInstance();
        StatsStorage statsStorage = new InMemoryStatsStorage();
        uiServer.attach(statsStorage);
        lstmNet_.setListeners(new StatsListener(statsStorage));

        if (ExecutionParameters.verbose) {