/* * BlockUpperTriangularMatrixParameter.java * * Copyright (c) 2002-2015 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 dr.inference.model; /* @author Max Tolkoff */ public class FastBlockUpperTriangularMatrixParameter extends FastMatrixParameter { private int rowDim; private Bounds bounds = null; // public TransposedBlockUpperTriangularMatrixParameter transposeBlock(){ // return TransposedBlockUpperTriangularMatrixParameter.recast(getVariableName(), this); // } public FastBlockUpperTriangularMatrixParameter(String name, int rows, int cols) { super(name, cols, rows, 1); boolean diagonalRestriction=false; if(diagonalRestriction) { for (int i = 0; i < getColumnDimension(); i++) { if (i < getRowDimension()) { double[] uppers = new double[i + 1]; double[] lowers = new double[i + 1]; for (int j = 0; j < uppers.length; j++) { uppers[j] = Double.POSITIVE_INFINITY; lowers[j] = Double.NEGATIVE_INFINITY; } lowers[i] = 0; getParameter(i).addBounds(new DefaultBounds(uppers, lowers)); } } } } // @Override // public int getRowDimension() { // return rowDim; // } // public void setRowDimension(int rowDim){ // this.rowDim=rowDim; // } // public double[][] getParameterAsMatrix(){ // double[][] answer=new double[getRowDimension()][getColumnDimension()]; // for(int i=0; i=getColumnDimension()-row; } public double getParameterValue(int id){ int row=getRow(id); int col=getColumn(id); if(matrixCondition(row, col)){ return getParameterValue(row, col); } else { return 0; } } public void addBounds(Bounds boundary) { if (bounds == null) { bounds = new BUTMPBounds(); // return; } //else { IntersectionBounds newBounds = new IntersectionBounds(getDimension()); newBounds.addBounds(bounds); // } ((IntersectionBounds) bounds).addBounds(boundary); } public Bounds getBounds() { if (bounds == null) { bounds = new BUTMPBounds(); } return bounds; } protected int getInnerDimension(int row, int col){ return row; } private class BUTMPBounds implements Bounds{ //TODO test! public Double getUpperLimit(int dim) { int row=getRow(dim); int col=getColumn(dim); if(matrixCondition(row, col)){ return getParameter(col).getBounds().getUpperLimit(getInnerDimension(row, col)); } else return 0.0; } public Double getLowerLimit(int dim) { int row=getRow(dim); int col=getColumn(dim); if(matrixCondition(row, col)){ return getParameter(col).getBounds().getLowerLimit(getInnerDimension(row, col)); // System.out.println(getParameters().get(dim-row).getBounds().getLowerLimit(getPindex().get(dim-row))); // return getParameters().get(dim-row).getBounds().getLowerLimit(getPindex().get(dim-row)); } else return 0.0; } public int getBoundsDimension() { // int nBlanks = 0; // for (int i = 0; i