<commit_before>/*
 * EmpiricalTreeDistributionModel.java
 *
 * Copyright (c) 2002-2015 <NAME>, <NAME> and <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.evomodel.tree;

import dr.evolution.io.Importer;
import dr.evolution.io.NexusImporter;
import dr.evolution.io.TreeImporter;
import dr.evolution.tree.NodeRef;
import dr.evolution.tree.Tree;
import dr.evolution.util.Taxon;
import dr.inference.operators.OperatorFailedException;
import dr.math.MathUtils;
import dr.inference.model.Statistic;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

/**
 * @author <NAME>
 * @version $Id$
 */
public class EmpiricalTreeDistributionModel extends TreeModel {

    /**
     * This constructor takes an array of trees and jumps randomly amongst them.
     * @param trees
     * @param startingTree
     */
    public EmpiricalTreeDistributionModel(final Tree[] trees, int startingTree) {
        this(trees, null, startingTree);
    }

    /**
     * This constructor takes a TreeImporter and reads the trees one by one to the end (and
     * then starts throwing exceptions).
     * @param importer
     * @param startingTree
     */
    public EmpiricalTreeDistributionModel(final TreeImporter importer, int startingTree) {
        this(null, importer, startingTree);
    }

    private EmpiricalTreeDistributionModel(final Tree[] trees, final TreeImporter importer, int startingTree) {
        super(EMPIRICAL_TREE_DISTRIBUTION_MODEL);

        this.trees = trees;
        this.importer = importer;
        drawTreeIndex(startingTree);

        addStatistic(new Statistic.Abstract("Current Tree")  {

            public int getDimension() {
                return 1;
            }

            public double getStatisticValue(int dim) {
                return currentTreeIndex;
            }
        });
    }

    protected void storeState() {
        storedCurrentTree = currentTree;
    }

    protected void restoreState() {
        currentTree = storedCurrentTree;
    }

    protected void acceptState() {
    }

    public void drawTreeIndex() {
        drawTreeIndex(-1);
    }

    private void drawTreeIndex(int treeNumber) {
//        System.err.print("Drawing new tree, (old tree = " + currentTreeIndex);

        if (treeNumber == -1) {
            if (importer != null) {
                try {
                    if (importer.hasTree() == false) {
                        throw new RuntimeException("EmpiricalTreeDistributionModel has run out of trees");
                    }
                    currentTree = importer.importNextTree();
                } catch (IOException e) {
                    throw new RuntimeException("EmpiricalTreeDistributionModel unable to load next tree");
                } catch (Importer.ImportException e) {
                    throw new RuntimeException("EmpiricalTreeDistributionModel unable to load next tree");
                }
                currentTreeIndex += 1;
            } else {
                currentTreeIndex = MathUtils.nextInt(trees.length);
                currentTree = trees[currentTreeIndex];
            }
        } else {
            currentTreeIndex = treeNumber;
            currentTree = trees[currentTreeIndex];
        }

        // Force computation of node heights now rather than later in the evaluation
        // where multithreading may get conflicts.
        currentTree.getNodeHeight(currentTree.getRoot());

//        System.err.println(") new tree = " + currentTreeIndex);

        fireModelChanged(new TreeModel.TreeChangedEvent());
    }

    public NodeRef getRoot() {
        return currentTree.getRoot();
    }

    public int getNodeCount() {
        return currentTree.getNodeCount();
    }

    public NodeRef getNode(final int i) {
        return currentTree.getNode(i);
    }<commit_msg>Created a operator schedule that runs each nested schedule for a certain number of states and then switches to the next.<commit_after>/*
 * EmpiricalTreeDistributionModel.java
 *
 * Copyright (c) 2002-2015 <NAME>, <NAME> and <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.evomodel.tree;

import dr.evolution.io.Importer;
import dr.evolution.io.NexusImporter;
import dr.evolution.io.TreeImporter;
import dr.evolution.tree.NodeRef;
import dr.evolution.tree.Tree;
import dr.evolution.util.Taxon;
import dr.inference.operators.OperatorFailedException;
import dr.math.MathUtils;
import dr.inference.model.Statistic;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

/**
 * @author <NAME>
 * @version $Id$
 */
public class EmpiricalTreeDistributionModel extends TreeModel {

    /**
     * This constructor takes an array of trees and jumps randomly amongst them.
     * @param trees
     * @param startingTree
     */
    public EmpiricalTreeDistributionModel(final Tree[] trees, int startingTree) {
        this(trees, null, startingTree);
    }

    /**
     * This constructor takes a TreeImporter and reads the trees one by one to the end (and
     * then starts throwing exceptions).
     * @param importer
     * @param startingTree
     */
    public EmpiricalTreeDistributionModel(final TreeImporter importer, int startingTree) {
        this(null, importer, startingTree);
    }

    private EmpiricalTreeDistributionModel(final Tree[] trees, final TreeImporter importer, int startingTree) {
        super(EMPIRICAL_TREE_DISTRIBUTION_MODEL);

        this.trees = trees;
        this.importer = importer;
        drawTreeIndex(startingTree);

        addStatistic(new Statistic.Abstract("Current Tree")  {

            public int getDimension() {
                return 1;
            }

            public double getStatisticValue(int dim) {
                return currentTreeIndex;
            }
        });
    }

    protected void storeState() {
        storedCurrentTree = currentTree;
    }

    protected void restoreState() {
        currentTree = storedCurrentTree;
    }

    protected void acceptState() {
    }

    public void drawTreeIndex() {
        drawTreeIndex(-1);
    }

    private void drawTreeIndex(int treeNumber) {
//        System.err.print("Drawing new tree, (old tree = " + currentTreeIndex);

        if (importer != null) {
            try {
                if (importer.hasTree() == false) {
                    throw new RuntimeException("EmpiricalTreeDistributionModel has run out of trees");
                }
                currentTree = importer.importNextTree();
            } catch (IOException e) {
                throw new RuntimeException("EmpiricalTreeDistributionModel unable to load next tree");
            } catch (Importer.ImportException e) {
                throw new RuntimeException("EmpiricalTreeDistributionModel unable to load next tree");
            }
            currentTreeIndex += 1;
        } else {
            if (treeNumber == -1) {
                currentTreeIndex = MathUtils.nextInt(trees.length);
                currentTree = trees[currentTreeIndex];
            } else {
                currentTreeIndex = treeNumber;
                currentTree = trees[currentTreeIndex];
            }
        }

        // Force computation of node heights now rather than later in the evaluation
        // where multithreading may get conflicts.
        currentTree.getNodeHeight(currentTree.getRoot());

//        System.err.println(") new tree = " + currentTreeIndex);

        fireModelChanged(new TreeModel.TreeChangedEvent());
    }

    public NodeRef getRoot() {
        return currentTree.getRoot();
    }

    public int getNodeCount() {
        return currentTree.getNodeCount();
    }

    public NodeRef getNode(final int i) {
        return currentTree.getNode(i);
    }
{'fraction_non_alphanumeric': 0.08114431564394342, 'fraction_numerical': 0.0051047538019780925, 'mean_word_length': 2.5486792452830187, 'pattern_counts': {'":': 0, '<': 11, '<?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': '2400299', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2363, 'n_words': 796}