@@ -0,0 +1,3295 @@
+package org.deeplearning4j.optimize.listeners;%0A%0Aimport org.deeplearning4j.berkeley.Pair;%0Aimport org.deeplearning4j.nn.api.Model;%0Aimport org.deeplearning4j.optimize.api.IterationListener;%0A%0Aimport java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.OutputStream;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * CollectScoresIterationListener simply stores the model scores internally (along with the iteration) every 1 or N%0A * iterations (this is configurable). These scores can then be obtained or exported.%0A *%0A * @author Alex Black%0A */%0Apublic class CollectScoresIterationListener implements IterationListener %7B%0A%0A    private int frequency;%0A    private int iterationCount = 0;%0A    private List%3CPair%3CInteger, Double%3E%3E scoreVsIter = new ArrayList%3C%3E();%0A%0A    /**%0A     * Constructor for collecting scores with default saving frequency of 1%0A     */%0A    public CollectScoresIterationListener() %7B%0A        this(1);%0A    %7D%0A%0A    /**%0A     * Constructor for collecting scores with the specified frequency.%0A     * @param frequency    Frequency with which to collect/save scores%0A     */%0A    public CollectScoresIterationListener(int frequency) %7B%0A        if (frequency %3C= 0) frequency = 1;%0A        this.frequency = frequency;%0A    %7D%0A%0A    @Override%0A    public boolean invoked() %7B%0A        return false;%0A    %7D%0A%0A    @Override%0A    public void invoke() %7B%0A%0A    %7D%0A%0A    @Override%0A    public void iterationDone(Model model, int iteration) %7B%0A        if (++iterationCount %25 frequency == 0) %7B%0A            double score = model.score();%0A            scoreVsIter.add(new Pair%3C%3E(iterationCount, score));%0A        %7D%0A    %7D%0A%0A    public List%3CPair%3CInteger, Double%3E%3E getScoreVsIter() %7B%0A        return getScoreVsIter();%0A    %7D%0A%0A    /**%0A     * Export the scores in tab-delimited (one per line) UTF-8 format.%0A     */%0A    public void exportScores(OutputStream outputStream) throws IOException %7B%0A        exportScores(outputStream, %22%5Ct%22);%0A    %7D%0A%0A    /**%0A     * Export the scores in delimited (one per line) UTF-8 format with the specified delimiter%0A     *%0A     * @param outputStream Stream to write to%0A     * @param delimiter    Delimiter to use%0A     */%0A    public void exportScores(OutputStream outputStream, String delimiter) throws IOException %7B%0A        StringBuilder sb = new StringBuilder();%0A        sb.append(%22Iteration%22).append(delimiter).append(%22Score%22);%0A        for (Pair%3CInteger, Double%3E p : scoreVsIter) %7B%0A            sb.append(%22%5Cn%22).append(p.getFirst()).append(delimiter).append(p.getSecond());%0A        %7D%0A        outputStream.write(sb.toString().getBytes(%22UTF-8%22));%0A    %7D%0A%0A    /**%0A     * Export the scores to the specified file in delimited (one per line) UTF-8 format, tab delimited%0A     *%0A     * @param file File to write to%0A     */%0A    public void exportScores(File file) throws IOException %7B%0A        exportScores(file, %22%5Ct%22);%0A    %7D%0A%0A    /**%0A     * Export the scores to the specified file in delimited (one per line) UTF-8 format, using the specified delimiter%0A     *%0A     * @param file      File to write to%0A     * @param delimiter Delimiter to use for writing scores%0A     */%0A    public void exportScores(File file, String delimiter) throws IOException %7B%0A        try (FileOutputStream fos = new FileOutputStream(file)) %7B%0A            exportScores(fos, delimiter);%0A        %7D%0A    %7D%0A%0A%7D%0A

Add CollectScoresIterationListener