| 1 | /* |
| 2 | * TransposedBlockUpperTriangularMatrixParameter.java |
| 3 | * |
| 4 | * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard |
| 5 | * |
| 6 | * This file is part of BEAST. |
| 7 | * See the NOTICE file distributed with this work for additional |
| 8 | * information regarding copyright ownership and licensing. |
| 9 | * |
| 10 | * BEAST is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU Lesser General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 |
| 13 | * of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * BEAST is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public |
| 21 | * License along with BEAST; if not, write to the |
| 22 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 23 | * Boston, MA 02110-1301 USA |
| 24 | */ |
| 25 | |
| 26 | package dr.inference.model; |
| 27 | |
| 28 | import java.util.ArrayList; |
| 29 | import java.util.List; |
| 30 | |
| 31 | /** |
| 32 | * Created by max on 11/4/14. |
| 33 | */ |
| 34 | public class FastTransposedBlockUpperTriangularMatrixParameter extends FastBlockUpperTriangularMatrixParameter { |
| 35 | public FastTransposedBlockUpperTriangularMatrixParameter(String name, int rows, int cols) { |
| 36 | super(name, cols, rows); |
| 37 | |
| 38 | |
| 39 | int colDim=cols; |
| 40 | // int rowDim=params.length; |
| 41 | |
| 42 | // for(int i=0; i<colDim; i++){ |
| 43 | // if(i<rowDim) |
| 44 | // {params[i].setDimension(i+1); |
| 45 | // this.addParameter(params[i]);} |
| 46 | // else |
| 47 | // {params[i].setDimension(rowDim); |
| 48 | // this.addParameter(params[i]); |
| 49 | //// System.err.print(colDim-rowDim+i+1); |
| 50 | //// System.err.print("\n"); |
| 51 | // } |
| 52 | // } |
| 53 | this.colDim=colDim; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | // public static TransposedBlockUpperTriangularMatrixParameter recast(String name, CompoundParameter compoundParameter) { |
| 58 | // final int count = compoundParameter.getParameterCount(); |
| 59 | // Parameter[] parameters = new Parameter[count]; |
| 60 | // for (int i = 0; i < count; ++i) { |
| 61 | // parameters[i] = compoundParameter.getParameter(i); |
| 62 | // } |
| 63 | // return new TransposedBlockUpperTriangularMatrixParameter(name, parameters); |
| 64 | // } |
| 65 | |
| 66 | // public double getParameterValue(int row, int col){ |
| 67 | // if(col>row){ |
| 68 | // return 0; |
| 69 | // } |
| 70 | // else{ |
| 71 | // return getParameter(col).getParameterValue(row-col); |
| 72 | // } |
| 73 | // } |
| 74 | |
| 75 | protected int getRow(int PID){ |
| 76 | return PID%getRowDimension(); |
| 77 | } |
| 78 | |
| 79 | protected int getColumn(int PID){ |
| 80 | return PID/getRowDimension(); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | boolean matrixCondition(int row, int col) { |
| 85 | return row>=col; |
| 86 | } |
| 87 | |
| 88 | // public void setParameterValue(int row, int col, double value){ |
| 89 | // super.setParameterValue(row,col, value); |
| 90 | // } |
| 91 | // |
| 92 | // public void setParameterValueQuietly(int row, int col, double value){ |
| 93 | // super.setParameterValueQuietly(col, row, value); |
| 94 | // } |
| 95 | |
| 96 | public Parameter getParameter(int index) { |
| 97 | if (slices == null) { |
| 98 | // construct vector_slices |
| 99 | slices = new ArrayList<Parameter>(); |
| 100 | for (int i = 0; i < getColumnDimension(); ++i) { |
| 101 | VectorSliceParameter thisSlice = new VectorSliceParameter(getParameterName() + "." + i, i); |
| 102 | for (int j = i; j < getRowDimension(); ++j) { |
| 103 | thisSlice.addParameter(super.getParameter(j)); |
| 104 | } |
| 105 | slices.add(thisSlice); |
| 106 | } |
| 107 | } |
| 108 | return slices.get(index); |
| 109 | } |
| 110 | |
| 111 | protected int getInnerDimension(int row, int col){ |
| 112 | return row-col; |
| 113 | } |
| 114 | |
| 115 | // public int getRowDimension(){ |
| 116 | // return getParameterCount(); |
| 117 | // } |
| 118 | // |
| 119 | // public int getColumnDimension(){ |
| 120 | // return colDim; |
| 121 | // } |
| 122 | |
| 123 | int colDim; |
| 124 | private List<Parameter> slices = null; |
| 125 | } |