<commit_before>/*
 * CompositeParameter.java
 *
 * Copyright (C) 2002-2013 <NAME>, <NAME> & <NAME>
 *
 * This file is part of BEAST.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership and licensing.
 *
 * BEAST is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 *  BEAST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with BEAST; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

package dr.inference.model;

import java.util.ArrayList;

/**
 * A parameter which controls the values of a set of other parameters
 *
 * @author <NAME>
 * @version $Id$
 */
public class JointParameter extends Parameter.Abstract implements VariableListener {

    public JointParameter(String name, Parameter[] params) {
        this(name);

        for (Parameter parameter : params) {
            addParameter(parameter);
        }
    }

    public JointParameter(String name) {
        this.name = name;
        dimension = 0;
    }

    public void addParameter(Parameter param) {

        if (dimension == 0) {
            dimension = param.getDimension();
        }
        if (param.getDimension() != dimension) {
            throw new RuntimeException("subsequent parameters do not match the dimensionality of the first");
        }

        param.addParameterListener(this);
        parameters.add(param);
    }

    /**
     * @return name if the parameter has been given a specific name, else it returns getId()
     */
    public final String getParameterName() {
        if (name != null) return name;
        return getId();
    }

    public final String getDimensionName(int dim) {
        return parameters.get(0).getDimensionName(dim);
    }

    public int getDimension() {
        return dimension;
    }

    public void setDimension(int dim) {
        throw new RuntimeException();
    }<commit_msg>Set the intial value of the subsequent contained parameters to that of the first.<commit_after>/*
 * CompositeParameter.java
 *
 * Copyright (C) 2002-2013 <NAME>, <NAME> & <NAME>
 *
 * This file is part of BEAST.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership and licensing.
 *
 * BEAST is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 *  BEAST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with BEAST; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

package dr.inference.model;

import java.util.ArrayList;

/**
 * A parameter which controls the values of a set of other parameters
 *
 * @author <NAME>
 * @version $Id$
 */
public class JointParameter extends Parameter.Abstract implements VariableListener {

    public JointParameter(String name, Parameter[] params) {
        this(name);

        for (Parameter parameter : params) {
            addParameter(parameter);
        }
    }

    public JointParameter(String name) {
        this.name = name;
        dimension = 0;
    }

    public void addParameter(Parameter param) {

        if (dimension == 0) {
            dimension = param.getDimension();
        } else {
            for (int dim = 0; dim < dimension; dim++) {
                param.setParameterValue(dim, parameters.get(0).getParameterValue(dim));
            }
            if (param.getDimension() != dimension) {
                throw new RuntimeException("subsequent parameters do not match the dimensionality of the first");
            }
        }

        // AR - I think we ignore the messages from the containing parameters. Possibly would be a good
        // idea to check they don't change independently of this one.
//        param.addParameterListener(this);

        parameters.add(param);
    }

    /**
     * @return name if the parameter has been given a specific name, else it returns getId()
     */
    public final String getParameterName() {
        if (name != null) return name;
        return getId();
    }

    public final String getDimensionName(int dim) {
        return parameters.get(0).getDimensionName(dim);
    }

    public int getDimension() {
        return dimension;
    }

    public void setDimension(int dim) {
        throw new RuntimeException();
    }
{'fraction_non_alphanumeric': 0.08076190476190476, 'fraction_numerical': 0.009142857142857144, 'mean_word_length': 2.732054015636105, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4728461', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1309, 'n_words': 567}