/* * EigendecompositionTest.java * * Copyright (c) 2002-2012 Alexei Drummond, Andrew Rambaut and Marc Suchard * * 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 test.dr.evomodel.substmodel; import dr.evomodel.substmodel.ComplexSubstitutionModel; import dr.evomodel.substmodel.EigenDecomposition; import dr.evomodel.substmodel.FrequencyModel; import dr.evolution.datatype.GeneralDataType; import dr.inference.model.Parameter; import dr.math.MathUtils; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class EigendecompositionTest { int dim; int[][] columnNumberLookup; double tolerance; GeneralDataType dataType; Parameter.Default freqVector; Parameter.Default rateMatrix; FrequencyModel freqModel; public EigendecompositionTest(int dim, double tolerance){ this.dim = dim; this.tolerance = tolerance; columnNumberLookup = new int[dim][dim]; int columnCount=0; for(int row=0; rowcolumn){ columnNumberLookup[row][column]=columnCount; columnCount++; } } } String[] labels = new String[dim]; for(Integer i=0; i indicators = makeMatrices(getAllPossibilities(dim), columnNumberLookup); for(Integer[] ind:indicators){ int successED = 0; int[] successTP = new int[dim]; int[] zeroRows = new int[dim]; for(int row=0; row getAllPossibleZeroRows(int dim){ ArrayList allPossibleZeroRows = new ArrayList(); for(int zeroRow=0; zeroRow makeMatrices(ArrayList configs, int[][] lookup){ ArrayList out = new ArrayList(); int dim = configs.get(0).length; for(Integer[] config: configs){ boolean allZeroes = true; for(int i=0; i getAllPossibilities(int length){ ArrayList allPossibilities = new ArrayList(); if(length == 1){ Integer[] one = new Integer[1]; one[0] = 1; Integer[] zero = new Integer[1]; zero[0] = 0; allPossibilities.add(one); allPossibilities.add(zero); } else { for(Integer[] tail: getAllPossibilities(length - 1)){ Integer[] one = new Integer[1]; one[0] = 1; Integer[] zero = new Integer[1]; zero[0] = 0; Integer[] onePlus = concat(one,tail); Integer[] zeroPlus = concat(zero,tail); allPossibilities.add(onePlus); allPossibilities.add(zeroPlus); } } return allPossibilities; } public static T[] concat(T[] first, T[] second) { T[] result = Arrays.copyOf(first, first.length + second.length); System.arraycopy(second, 0, result, first.length, second.length); return result; } private static Parameter.Default normalise(Parameter.Default matrix){ double sum = getMatrixSum(matrix); int dim = matrix.getDimension(); for(int i=0; itolerance){ out = false; } } } return out; } private static double getMatrixSum(Parameter.Default matrix){ double sum = 0; for(int i=0; i