<commit_before>/*
 * BranchSpecific.java
 *
 * Copyright (c) 2002-2013 <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.app.beagle.evomodel.branchmodel.lineagespecific;

import dr.app.beagle.evomodel.branchmodel.BranchModel;
import dr.app.beagle.evomodel.branchmodel.HomogeneousBranchModel;
import dr.app.beagle.evomodel.branchmodel.BranchModel.Mapping;
import dr.app.beagle.evomodel.sitemodel.GammaSiteRateModel;
import dr.app.beagle.evomodel.substmodel.FrequencyModel;
import dr.app.beagle.evomodel.substmodel.MG94CodonModel;
import dr.app.beagle.evomodel.substmodel.SubstitutionModel;
import dr.app.beagle.evomodel.treelikelihood.BeagleTreeLikelihood;
import dr.app.beagle.evomodel.treelikelihood.PartialsRescalingScheme;
import dr.app.beagle.tools.BeagleSequenceSimulator;
import dr.app.beagle.tools.Partition;
import dr.evolution.alignment.Alignment;
import dr.evolution.alignment.ConvertAlignment;
import dr.evolution.datatype.Codons;
import dr.evolution.datatype.GeneticCode;
import dr.evolution.datatype.Nucleotides;
import dr.evolution.io.NewickImporter;
import dr.evolution.tree.NodeRef;
import dr.evomodel.branchratemodel.BranchRateModel;
import dr.evomodel.branchratemodel.CountableBranchCategoryProvider;
import dr.evomodel.branchratemodel.DefaultBranchRateModel;
import dr.evomodel.tree.TreeModel;
import dr.inference.model.AbstractModel;
import dr.inference.model.Model;
import dr.inference.model.Parameter;
import dr.inference.model.Variable;
import dr.inference.model.Variable.ChangeType;
import dr.math.MathUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SuppressWarnings("serial")
public class BranchSpecific extends AbstractModel implements BranchModel {

    private boolean setupMapping = true;
	
    private Map<NodeRef, Mapping> nodeMap; // = new HashMap<NodeRef, Mapping>();
    private List<SubstitutionModel> substitutionModels;
    private TreeModel treeModel;
    private FrequencyModel rooFrequencyModel;
    
    private CountableBranchCategoryProvider uCategoriesProvider;
    private Parameter uCategoriesParameter;

	public BranchSpecific(TreeModel treeModel, //
			FrequencyModel rootFrequencyModel, //
			List<SubstitutionModel> substitutionModels, //
			CountableBranchCategoryProvider uCategoriesProvider, //
			Parameter uCategoriesParameter //
	) {

		super("");

		this.treeModel = treeModel;
		this.substitutionModels = substitutionModels;
		this.uCategoriesProvider = uCategoriesProvider;
		this.uCategoriesParameter = uCategoriesParameter;
		this.rooFrequencyModel = rootFrequencyModel;

		this.nodeMap = new HashMap<NodeRef, Mapping>();

		for (SubstitutionModel model : this.substitutionModels) {
			addModel(model);
		}

		addModel(this.treeModel);
		addVariable(this.uCategoriesParameter);
        
	}// END: Constructor

    @Override
    public Mapping getBranchModelMapping(NodeRef branch) {

        if (setupMapping) {
            setupNodeMap(branch);
        }

        return nodeMap.get(branch);
    }//END: getBranchModelMapping

    public void setupNodeMap(NodeRef branch) {
    	
        // TODO How about: return new Mapping() that points to uCategory?
    	
        int branchCategory = uCategoriesProvider.getBranchCategory(treeModel, branch);
        final int uCategory = (int) uCategoriesParameter.getParameterValue(branchCategory);
        
//        System.out.println("FUBAR1:" + branchCategory);
        System.out.println("FUBAR2:" + uCategory);
        
        nodeMap.put(branch, new Mapping() {
        	
			@Override
			public int[] getOrder() {
				return new int[] { uCategory };
			}

			@Override
			public double[] getWeights() {
				return new double[] { 1.0 };
            }
            
        });
        
    }// END: setupNodeMap

    @Override
    public List<SubstitutionModel> getSubstitutionModels() {
    	return substitutionModels;
    }
<commit_msg>boolean to hide debug messages<commit_after>/*
 * BranchSpecific.java
 *
 * Copyright (c) 2002-2013 <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.app.beagle.evomodel.branchmodel.lineagespecific;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import dr.app.beagle.evomodel.branchmodel.BranchModel;
import dr.app.beagle.evomodel.branchmodel.HomogeneousBranchModel;
import dr.app.beagle.evomodel.sitemodel.GammaSiteRateModel;
import dr.app.beagle.evomodel.substmodel.FrequencyModel;
import dr.app.beagle.evomodel.substmodel.MG94CodonModel;
import dr.app.beagle.evomodel.substmodel.SubstitutionModel;
import dr.app.beagle.evomodel.treelikelihood.BeagleTreeLikelihood;
import dr.app.beagle.evomodel.treelikelihood.PartialsRescalingScheme;
import dr.app.beagle.tools.BeagleSequenceSimulator;
import dr.app.beagle.tools.Partition;
import dr.evolution.alignment.Alignment;
import dr.evolution.alignment.ConvertAlignment;
import dr.evolution.datatype.Codons;
import dr.evolution.datatype.GeneticCode;
import dr.evolution.datatype.Nucleotides;
import dr.evolution.io.NewickImporter;
import dr.evolution.tree.NodeRef;
import dr.evomodel.branchratemodel.BranchRateModel;
import dr.evomodel.branchratemodel.CountableBranchCategoryProvider;
import dr.evomodel.branchratemodel.DefaultBranchRateModel;
import dr.evomodel.tree.TreeModel;
import dr.inference.model.AbstractModel;
import dr.inference.model.Model;
import dr.inference.model.Parameter;
import dr.inference.model.Variable;
import dr.inference.model.Variable.ChangeType;
import dr.math.MathUtils;

@SuppressWarnings("serial")
public class BranchSpecific extends AbstractModel implements BranchModel {

	private static final boolean DEBUG = false;
	
    private boolean setupMapping = true;
	
    private Map<NodeRef, Mapping> nodeMap; // = new HashMap<NodeRef, Mapping>();
    private List<SubstitutionModel> substitutionModels;
    private TreeModel treeModel;
    private FrequencyModel rooFrequencyModel;
    
    private CountableBranchCategoryProvider uCategoriesProvider;
    private Parameter uCategoriesParameter;

	public BranchSpecific(TreeModel treeModel, //
			FrequencyModel rootFrequencyModel, //
			List<SubstitutionModel> substitutionModels, //
			CountableBranchCategoryProvider uCategoriesProvider, //
			Parameter uCategoriesParameter //
	) {

		super("");

		this.treeModel = treeModel;
		this.substitutionModels = substitutionModels;
		this.uCategoriesProvider = uCategoriesProvider;
		this.uCategoriesParameter = uCategoriesParameter;
		this.rooFrequencyModel = rootFrequencyModel;

		this.nodeMap = new HashMap<NodeRef, Mapping>();

		for (SubstitutionModel model : this.substitutionModels) {
			addModel(model);
		}

		addModel(this.treeModel);
		addVariable(this.uCategoriesParameter);
        
	}// END: Constructor

    @Override
    public Mapping getBranchModelMapping(NodeRef branch) {

        if (setupMapping) {
            setupNodeMap(branch);
        }

        return nodeMap.get(branch);
    }//END: getBranchModelMapping

    public void setupNodeMap(NodeRef branch) {
    	
        // TODO How about: return new Mapping() that points to uCategory?
    	
        int branchCategory = uCategoriesProvider.getBranchCategory(treeModel, branch);
        final int uCategory = (int) uCategoriesParameter.getParameterValue(branchCategory);
        
        if(DEBUG){
      System.out.println("FUBAR2:" + uCategory);
	  System.out.println("branch length: " + treeModel.getBranchLength(branch));
        }
	  
//		for (int i = 0; i < treeModel.getChildCount(branch); i++) {
//
//			NodeRef child = treeModel.getChild(branch, i);
//
//			System.out.println("child " + i + " length: " + treeModel.getBranchLength(child));
//
//		}
        
       
        nodeMap.put(branch, new Mapping() {
        	
			@Override
			public int[] getOrder() {
				return new int[] { uCategory };
			}

			@Override
			public double[] getWeights() {
				return new double[] { 1.0 };
            }
            
        });
        
    }// END: setupNodeMap

    @Override
    public List<SubstitutionModel> getSubstitutionModels() {
    	return substitutionModels;
    }

{'fraction_non_alphanumeric': 0.08950523214467133, 'fraction_numerical': 0.00528294219242101, 'mean_word_length': 4.009669211195929, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 21, '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': '831797', 'n_tokens_mistral': 3040, 'n_tokens_neox': 2796, 'n_words': 715}