<commit_before>
package magpie.models.regression;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.TreeMap;
import magpie.data.BaseEntry;
import magpie.data.Dataset;
import magpie.data.materials.CompositionDataset;
import magpie.data.materials.CompositionEntry;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.math3.stat.regression.MillerUpdatingRegression;
import org.apache.commons.math3.stat.regression.SimpleRegression;

/**
 * Estimate formation energy for ternary+ alloys using a metallurgical heuristic. 
 * Works by estimating multi-component formation energy based on formation energies of binaries.
 * See <a href="http://www.cambridge.org/us/academic/subjects/engineering/materials-science/phase-equilibria-phase-diagrams-and-phase-transformations-their-thermodynamic-basis-2nd-edition">
 * Hillert's</a> text for a detailed description.
 * 
 * <p>You can also compute correction factors using the technique demonstrated
 * by <a href="http://link.aps.org/doi/10.1103/PhysRevB.89.094104">Meredig and
 * Agrawal <i>et al.</i></a>, where:
 * 
 * <br> &Delta;H<sub>modified</sub> = a * &Delta;H<sub>heuristic</sub> + b
 * 
 * <p><usage><b>Usage</b>: $&lt;hull data> [-correction]
 * <br><pr><i>hull data</i>: A {@linkplain CompositionDataset} containing formation energies for all known binary compounds.
 * <br><pr><i>-correction</i>: Compute correction factors</usage>
 * 
 * @author <NAME>
 */
public class MetallurgicalHeuristicRegression extends BaseRegression {
	/** Holds binary convex hulls */
	private BinaryConvexHullHolder HullHolder;
    /** Whether to fit correction factors */
    private boolean FitCorrection = false;
    /** Correction slope term */
    private double FitSlope;
    /** Correction intercept term */
    private double FitIntercept;

	@Override
	public void setOptions(List<Object> Options) throws Exception {
		try {
			setBinaryConvexHulls((CompositionDataset) Options.get(0));
            if (Options.size() == 2) {
                if (Options.get(1).toString().equalsIgnoreCase("-correction")) {
                    setUseCorrection(true);
                }
            }
		} catch (Exception e) {
			throw new Exception(printUsage());
		}
	}

	@Override
	public String printUsage() {
		return "Usage: $<convex hull data>";
	}
	
	/**
	 * Define binary convex hull data. Should contain compositions and formation energies
	 * (&quot;delta_e&quot;) for each known binary and elemental compounds that 
	 * <b>are on the convex hull</b>. You also should output the formation energy
	 * for each element (which may be non-zero if your dataset uses fitted reference states).
	 * 
	 * <p>This code does not currently have the capability to calculate convex hulls. Since, this
	 * class is intended to be used with data from <a href="https://github.com/wolverton-research-group/qmpy">qmpy</a> I 
	 * figured that you can just use that code's capabilities.
	 * 
	 * @param hullData Dataset holding all known compounds to be used for calculating delta_e
	 */
	public void setBinaryConvexHulls(CompositionDataset hullData) {
		HullHolder = new BinaryConvexHullHolder(hullData);
	}
    
    /**
     * Set whether to employ correction factors
     * @param x Desired setting
     */
    public void setUseCorrection(boolean x) {
        FitCorrection = x;
    }
<commit_msg>Improved setOptions and printUsage of MetallurgicalHeuristicRegression<commit_after>
package magpie.models.regression;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.TreeMap;
import magpie.data.BaseEntry;
import magpie.data.Dataset;
import magpie.data.materials.CompositionDataset;
import magpie.data.materials.CompositionEntry;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.math3.stat.regression.MillerUpdatingRegression;
import org.apache.commons.math3.stat.regression.SimpleRegression;

/**
 * Estimate formation energy for ternary+ alloys using a metallurgical heuristic. 
 * Works by estimating multi-component formation energy based on formation energies of binaries.
 * See <a href="http://www.cambridge.org/us/academic/subjects/engineering/materials-science/phase-equilibria-phase-diagrams-and-phase-transformations-their-thermodynamic-basis-2nd-edition">
 * Hillert's</a> text for a detailed description.
 * 
 * <p>You can also compute correction factors using the technique demonstrated
 * by <a href="http://link.aps.org/doi/10.1103/PhysRevB.89.094104">Meredig and
 * Agrawal <i>et al.</i></a>, where:
 * 
 * <br> &Delta;H<sub>modified</sub> = a * &Delta;H<sub>heuristic</sub> + b
 * 
 * <p><usage><b>Usage</b>: $&lt;hull data> [-correction]
 * <br><pr><i>hull data</i>: A {@linkplain CompositionDataset} containing formation energies for all known binary compounds.
 * <br><pr><i>-correction</i>: Compute correction factors</usage>
 * 
 * @author <NAME>
 */
public class MetallurgicalHeuristicRegression extends BaseRegression {
	/** Holds binary convex hulls */
	private BinaryConvexHullHolder HullHolder;
    /** Whether to fit correction factors */
    private boolean FitCorrection = false;
    /** Correction slope term */
    private double FitSlope;
    /** Correction intercept term */
    private double FitIntercept;

	@Override
	public void setOptions(List<Object> Options) throws Exception {
		try {
			setBinaryConvexHulls((CompositionDataset) Options.get(0));
            if (Options.size() == 2) {
                if (Options.get(1).toString().equalsIgnoreCase("-correction")) {
                    setUseCorrection(true);
                } else {
                    throw new Exception();
                }
            }
		} catch (Exception e) {
			throw new Exception(printUsage());
		}
	}

	@Override
	public String printUsage() {
		return "Usage: $<convex hull data> [-correction]";
	}
	
	/**
	 * Define binary convex hull data. Should contain compositions and formation energies
	 * (&quot;delta_e&quot;) for each known binary and elemental compounds that 
	 * <b>are on the convex hull</b>. You also should output the formation energy
	 * for each element (which may be non-zero if your dataset uses fitted reference states).
	 * 
	 * <p>This code does not currently have the capability to calculate convex hulls. Since, this
	 * class is intended to be used with data from <a href="https://github.com/wolverton-research-group/qmpy">qmpy</a> I 
	 * figured that you can just use that code's capabilities.
	 * 
	 * @param hullData Dataset holding all known compounds to be used for calculating delta_e
	 */
	public void setBinaryConvexHulls(CompositionDataset hullData) {
		HullHolder = new BinaryConvexHullHolder(hullData);
	}
    
    /**
     * Set whether to employ correction factors
     * @param x Desired setting
     */
    public void setUseCorrection(boolean x) {
        FitCorrection = x;
    }

{'fraction_non_alphanumeric': 0.1096200028252578, 'fraction_numerical': 0.00593304139002684, 'mean_word_length': 3.8626373626373627, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 71, 'https://': 2, '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': '418257', 'n_tokens_mistral': 2210, 'n_tokens_neox': 2006, 'n_words': 588}