<commit_before>/*
* File CompoundProbabilityDistribution.java
*
* Copyright (C) 2010 <NAME> <EMAIL>
*
* This file is part of BEAST2.
* 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 beast.core.util;

import beast.core.Description;
import beast.core.Input;
import beast.core.ProbabilityDistribution;
import beast.core.State;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Description("Takes a collection of uncertainties, typically a number of likelihoods " +
        "and priors and combines them into the compound of these uncertainties " +
        "typically interpreted as the posterior.")
public class CompoundProbabilityDistribution extends ProbabilityDistribution {
    public Input<List<ProbabilityDistribution>> pDistributions = new Input<List<ProbabilityDistribution>>("probabilityDistribution", "individual probability distributions, e.g. the likelihood and prior making up a posterior", new ArrayList<ProbabilityDistribution>());

    @Override
    public double calculateLogP(State state) throws Exception {
        logP = 0;
        for (int i = 0; i < pDistributions.get().size(); i++) {
            double f = pDistributions.get().get(i).calculateLogP(state);
            logP += f;
        }
        return logP;
    }

    @Override
    public void sample(State state, Random random) {

        for (int i = 0; i < pDistributions.get().size(); i++) {
            pDistributions.get().get(i).sample(state, random);
        }
    }

    @Override
    public List<String> getArguments() {
        List<String> arguments = new ArrayList<String>();
        for (int i = 0; i < pDistributions.get().size(); i++) {
            arguments.addAll(pDistributions.get().get(i).getArguments());
        }
        return arguments;
    }

    @Override
    public List<String> getConditions() {
        List<String> conditions = new ArrayList<String>();
        for (int i = 0; i < pDistributions.get().size(); i++) {
            conditions.addAll(pDistributions.get().get(i).getConditions());
        }
        return conditions;
    }

    @Override
    public void restore(int nSample) {
        for (ProbabilityDistribution likelihood : pDistributions.get()) {
            likelihood.restore(nSample);
        }
    }

    @Override
    public void store(int nSample) {
        for (ProbabilityDistribution likelihood : pDistributions.get()) {
            likelihood.store(nSample);
        }
    }

} // class CompoundProbabilityDistribution<commit_msg>store/restore fix in CompoundProbabilityDistribution<commit_after>/*
* File CompoundProbabilityDistribution.java
*
* Copyright (C) 2010 <NAME> <EMAIL>
*
* This file is part of BEAST2.
* 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 beast.core.util;

import beast.core.Description;
import beast.core.Input;
import beast.core.ProbabilityDistribution;
import beast.core.State;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Description("Takes a collection of uncertainties, typically a number of likelihoods " +
        "and priors and combines them into the compound of these uncertainties " +
        "typically interpreted as the posterior.")
public class CompoundProbabilityDistribution extends ProbabilityDistribution {
    public Input<List<ProbabilityDistribution>> pDistributions = new Input<List<ProbabilityDistribution>>("probabilityDistribution", "individual probability distributions, e.g. the likelihood and prior making up a posterior", new ArrayList<ProbabilityDistribution>());

    @Override
    public double calculateLogP(State state) throws Exception {
        logP = 0;
        for (int i = 0; i < pDistributions.get().size(); i++) {
            double f = pDistributions.get().get(i).calculateLogP(state);
            logP += f;
        }
        return logP;
    }

    @Override
    public void sample(State state, Random random) {

        for (int i = 0; i < pDistributions.get().size(); i++) {
            pDistributions.get().get(i).sample(state, random);
        }
    }

    @Override
    public List<String> getArguments() {
        List<String> arguments = new ArrayList<String>();
        for (int i = 0; i < pDistributions.get().size(); i++) {
            arguments.addAll(pDistributions.get().get(i).getArguments());
        }
        return arguments;
    }

    @Override
    public List<String> getConditions() {
        List<String> conditions = new ArrayList<String>();
        for (int i = 0; i < pDistributions.get().size(); i++) {
            conditions.addAll(pDistributions.get().get(i).getConditions());
        }
        return conditions;
    }

    @Override
    public void restore(int nSample) {
        super.restore(nSample);
        for (ProbabilityDistribution likelihood : pDistributions.get()) {
            likelihood.restore(nSample);
        }
    }

    @Override
    public void store(int nSample) {
        super.store(nSample);
        for (ProbabilityDistribution likelihood : pDistributions.get()) {
            likelihood.store(nSample);
        }
    }

} // class CompoundProbabilityDistribution
{'fraction_non_alphanumeric': 0.09692883895131087, 'fraction_numerical': 0.006591760299625468, 'mean_word_length': 3.2603701340140394, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 29, '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': '2765317', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1716, 'n_words': 616}