<commit_before>///////////////////////////////////////////////////////////////////////////////
//  Copyright 2010 <NAME> <<EMAIL>>.
// 
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
// 
//       http://www.apache.org/licenses/LICENSE-2.0
// 
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//  under the License.
///////////////////////////////////////////////////////////////////////////////
package opennlp.rlda.apps;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.IllegalFormatConversionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class ExperimentParameters {

    protected static SAXBuilder builder = new SAXBuilder();
    /**
     * Hyperparameter of topic prior
     */
    protected double alpha = 1;
    /**
     * Hyperparameter for word/topic prior
     */
    protected double beta = 0.1;
    /**
     * Number of training iterations
     */
    protected int trainIterations = 100;
    /**
     * Number to seed random number generator. If 0 is passed from the commandline,
     * it means that a true random seed will be used (i.e. one based on the current time).
     * Otherwise, any value that has been passed to it from the command line be
     * used. If nothing is passed from the commandline, the random number
     * generator will be seeded with 1.
     */
    protected int randomSeed = 1;
    /**
     * Temperature at which to start annealing process
     */
    protected double initialTemperature = 1;
    /**
     * Decrement at which to reduce the temperature in annealing process
     */
    protected double temperatureDecrement = 0.1;
    /**
     * Stop changing temperature after the following temp has been reached.
     */
    protected double targetTemperature = 1;
    /**
     * Number of regions
     */
    protected int regions = 50;
    /**
     * Number of samples to take
     */
    protected int samples = 100;
    /**
     * Number of trainIterations between samples
     */
    protected int lag = 10;
    /**
     * Path to array of tokens, toponym status. Should be a file.
     */
    protected String tokenArrayInputPath = null;
    /**
     * Path to array of tokens, toponym status. Should be a file.
     */
    protected String tokenArrayOutputPath = null;
    /**
     * Path of model that has been saved from previous training runs
     */
    protected String trainedModelPath = null;

    /**
     *
     * @param cline
     * @throws IOException
     */
    public ExperimentParameters(String _paramFilepath) throws IOException {

        File file = new File(_paramFilepath);

        Document doc = null;
        try {
            doc = builder.build(file);
            Element root = doc.getRootElement();
            ArrayList<Element> params = new ArrayList<Element>(root.getChild("ExperimentStage").getChildren());
            for (Element param : params) {
                try {
                    String fieldName = param.getName();
                    String fieldValue = param.getValue();

                    String fieldTypeName = param.getAttributeValue("type");
                    if (fieldTypeName.equals("int")) {
                        int value = Integer.parseInt(fieldValue);
                        this.getClass().getField(fieldName).setInt(root, lag);
                    } else if (fieldTypeName.equals("double")) {
                        double value = Double.parseDouble(fieldValue);
                        this.getClass().getField(fieldName).setDouble(this, value);
                    } else if (fieldTypeName.equals("string")) {
                        this.getClass().getField(fieldName).set(this, fieldValue);
                    } else {
                        continue;
                    }
                    
                } catch (NoSuchFieldException ex) {
                    Logger.getLogger(ExperimentParameters.class.getName()).log(Level.SEVERE, null, ex);
                    System.exit(1);
                } catch (SecurityException ex) {
                    Logger.getLogger(ExperimentParameters.class.getName()).log(Level.SEVERE, null, ex);
                    System.exit(1);
                } catch (IllegalArgumentException ex) {
                    Logger.getLogger(ExperimentParameters.class.getName()).log(Level.SEVERE, null, ex);
                    System.exit(1);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(ExperimentParameters.class.getName()).log(Level.SEVERE, null, ex);
                    System.exit(1);
                }
            }

        } catch (JDOMException ex) {
            Logger.getLogger(ExperimentParameters.class.getName()).log(Level.SEVERE, null, ex);
            System.exit(1);
        }
    }

    public ExperimentParameters() {
    }

    public void dumpFieldsToXML(String _outputPath) {
        Element root = new Element("root");
        Document doc = new Document(root);<commit_msg>expanding rlda<commit_after>///////////////////////////////////////////////////////////////////////////////
//  Copyright 2010 <NAME> <<EMAIL>>.
// 
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
// 
//       http://www.apache.org/licenses/LICENSE-2.0
// 
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//  under the License.
///////////////////////////////////////////////////////////////////////////////
package opennlp.rlda.apps;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.IllegalFormatConversionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class ExperimentParameters {

    protected static SAXBuilder builder = new SAXBuilder();
    /**
     * Hyperparameter of topic prior
     */
    protected double alpha = 1;
    /**
     * Hyperparameter for word/topic prior
     */
    protected double beta = 0.1;
    /**
     * Number of training iterations
     */
    protected int trainIterations = 100;
    /**
     * Number to seed random number generator. If 0 is passed from the commandline,
     * it means that a true random seed will be used (i.e. one based on the current time).
     * Otherwise, any value that has been passed to it from the command line be
     * used. If nothing is passed from the commandline, the random number
     * generator will be seeded with 1.
     */
    protected int randomSeed = 1;
    /**
     * Temperature at which to start annealing process
     */
    protected double initialTemperature = 1;
    /**
     * Decrement at which to reduce the temperature in annealing process
     */
    protected double temperatureDecrement = 0.1;
    /**
     * Stop changing temperature after the following temp has been reached.
     */
    protected double targetTemperature = 1;
    /**
     * Number of regions
     */
    protected int regions = 50;
    /**
     * Number of samples to take
     */
    protected int samples = 100;
    /**
     * Number of trainIterations between samples
     */
    protected int lag = 10;
    /**
     * Path to array of tokens, toponym status. Should be a file.
     */
    protected String tokenArrayInputPath = null;
    /**
     * Path to array of tokens, toponym status. Should be a file.
     */
    protected String tokenArrayOutputPath = null;
    /**
     * Path of model that has been saved from previous training runs
     */
    protected String trainedModelPath = null;

    public ExperimentParameters() {
    }

    public void dumpFieldsToXML(String _outputPath) {
        Element root = new Element("root");
        Document doc = new Document(root);
{'fraction_non_alphanumeric': 0.12513781697905182, 'fraction_numerical': 0.006725468577728776, 'mean_word_length': 2.056266846361186, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5209821', 'n_tokens_mistral': 2363, 'n_tokens_neox': 2249, 'n_words': 781}