/** Constructs and returns a new row and column permuted <i>selection view</i> of matrix <tt>A</tt>; equivalent to {@link DoubleMatrix2D#viewSelection(int[],int[])}. The returned matrix is backed by this matrix, so changes in the returned matrix are reflected in this matrix, and vice-versa. Use idioms like <tt>result = permute(...).copy()</tt> to generate an independent sub matrix. @return the new permuted selection view. */ public DoubleMatrix2D permute(DoubleMatrix2D A, int[] rowIndexes, int[] columnIndexes) { return A.viewSelection(rowIndexes,columnIndexes); } /**
/** Constructs and returns a new row and column permuted <i>selection view</i> of matrix <tt>A</tt>; equivalent to {@link DoubleMatrix2D#viewSelection(int[],int[])}. The returned matrix is backed by this matrix, so changes in the returned matrix are reflected in this matrix, and vice-versa. Use idioms like <tt>result = permute(...).copy()</tt> to generate an independent sub matrix. @return the new permuted selection view. */ public DoubleMatrix2D permute(DoubleMatrix2D A, int[] rowIndexes, int[] columnIndexes) { return A.viewSelection(rowIndexes,columnIndexes); } /**
/** * Returns a view of the original matrix that contains all rows and all columns * except for the specified column. * * The view is backed by the original matrix, that is, all changes to the * returned matrix will be reflected by the original matrix. * * @param src The matrix to have a column "removed". * @param colIdx The index of the column to be hidden * ({@code 0 <= colIdx < src.columns()} . * @return A view of the original matrix with column {@code colIdx} removed. */ public DoubleMatrix2D hideColumn(final DoubleMatrix2D src, final int colIdx) { // create array of column indices to be preserved final int[] keepColumns = new int[src.columns() - 1]; for (int i = 0; i < keepColumns.length; i++) { keepColumns[i] = ((i < colIdx) ? i : i + 1); } return src.viewSelection(null /* keep ALL rows */, keepColumns); }
/** */ public static void doubleTest11() { int rows = 4; int columns = 5; // make a 1*1 matrix DoubleMatrix2D master = new DenseDoubleMatrix2D(1,1); master.assign(2); System.out.println("\n"+master); int[] rowIndexes = new int[rows]; int[] columnIndexes = new int[columns]; DoubleMatrix2D view1 = master.viewSelection(rowIndexes,columnIndexes); System.out.println(view1); master.assign(1); System.out.println("\n"+master); System.out.println(view1); } /**
/** */ public static void doubleTest7() { int rows = 4; int columns = 5; // make a 4*5 matrix DoubleMatrix2D master = Factory2D.ascending(rows,columns); //master.assign(1); // set all cells to 1 System.out.println("\n"+master); //master.viewPart(2,0,2,3).assign(2); // set [2,1] .. [3,3] to 2 //System.out.println("\n"+master); int[] rowIndexes = {0,1,3,0}; int[] columnIndexes = {0,2}; DoubleMatrix2D view1 = master.viewSelection(rowIndexes,columnIndexes); System.out.println("view1="+view1); DoubleMatrix2D view2 = view1.viewPart(0,0,2,2); System.out.println("view2="+view2); view2.assign(-1); System.out.println("master replaced"+master); System.out.println("flip1 replaced"+view1); System.out.println("flip2 replaced"+view2); } /**
/** */ public static void doubleTest11() { int rows = 4; int columns = 5; // make a 1*1 matrix DoubleMatrix2D master = new DenseDoubleMatrix2D(1,1); master.assign(2); System.out.println("\n"+master); int[] rowIndexes = new int[rows]; int[] columnIndexes = new int[columns]; DoubleMatrix2D view1 = master.viewSelection(rowIndexes,columnIndexes); System.out.println(view1); master.assign(1); System.out.println("\n"+master); System.out.println(view1); } /**
/** */ public static void doubleTest7() { int rows = 4; int columns = 5; // make a 4*5 matrix DoubleMatrix2D master = Factory2D.ascending(rows,columns); //master.assign(1); // set all cells to 1 System.out.println("\n"+master); //master.viewPart(2,0,2,3).assign(2); // set [2,1] .. [3,3] to 2 //System.out.println("\n"+master); int[] rowIndexes = {0,1,3,0}; int[] columnIndexes = {0,2}; DoubleMatrix2D view1 = master.viewSelection(rowIndexes,columnIndexes); System.out.println("view1="+view1); DoubleMatrix2D view2 = view1.viewPart(0,0,2,2); System.out.println("view2="+view2); view2.assign(-1); System.out.println("master replaced"+master); System.out.println("flip1 replaced"+view1); System.out.println("flip2 replaced"+view2); } /**
public static double[] totalInstabilityDir(DoubleMatrix2D xi, List<Node> vars){ if (vars.size()!= xi.columns() || vars.size()!= xi.rows()) { throw new IllegalArgumentException("stability mat must have same number of rows and columns as there are vars"); } double[] D = new double[4]; int[] discInds = MixedUtils.getDiscreteInds(vars); int[] contInds = MixedUtils.getContinuousInds(vars); int p = contInds.length; int q = discInds.length; D[0] = xi.zSum()/ ((p+q-1)*(p+q)/2); D[1] = xi.viewSelection(contInds, contInds).zSum()/(p*(p-1)); D[2] = xi.viewSelection(contInds, discInds).zSum()/(p*q); D[3] = xi.viewSelection(discInds, discInds).zSum()/(q*(q-1)); return D; }
DoubleMatrix2D view1 = master.viewPart(1,1,4,5).viewSelection(rowIndexes,columnIndexes); System.out.println("\nview1="+view1); DoubleMatrix2D view9 = view1.viewStrides(2,2).viewStrides(2,1); System.out.println("\nview9="+view9); view1 = view1.viewSelection(rowIndexes2,columnIndexes2); System.out.println("\nview1="+view1); DoubleMatrix2D view2 = view1.viewPart(1,1,2,2);
DoubleMatrix2D view1 = master.viewPart(1,1,4,5).viewSelection(rowIndexes,columnIndexes); System.out.println("\nview1="+view1); DoubleMatrix2D view9 = view1.viewStrides(2,2).viewStrides(2,1); System.out.println("\nview9="+view9); view1 = view1.viewSelection(rowIndexes2,columnIndexes2); System.out.println("\nview1="+view1); DoubleMatrix2D view2 = view1.viewPart(1,1,2,2);
varMap[i] = variables.indexOf(initVariables.get(i)); outMat = outMat.viewSelection(varMap, varMap);
return matrix.viewSelection(rowIndexes,null);
return matrix.viewSelection(rowIndexes,null);
return matrix.viewSelection(rowIndexes,null);
DoubleMatrix2D Z = data.viewSelection(zRows, zCols); DoubleMatrix1D x = data.viewColumn(xIndex); DoubleMatrix2D Zt = new Algebra().transpose(Z);
DoubleMatrix2D Z = data.viewSelection(zRows, zCols); DoubleMatrix1D x = data.viewColumn(xIndex); DoubleMatrix2D Zt = new Algebra().transpose(Z);
return matrix.viewSelection(rowIndexes,null);
public static double[] totalInstabilityUndir(DoubleMatrix2D xi, List<Node> vars){ if (vars.size()!= xi.columns() || vars.size()!= xi.rows()) { throw new IllegalArgumentException("stability mat must have same number of rows and columns as there are vars"); } Algebra al = new Algebra(); //DoubleMatrix2D xiu = MGM.upperTri(xi.copy().assign(al.transpose(xi)),1); DoubleMatrix2D xiu = xi.copy().assign(xi.copy().assign(Functions.minus(1.0)), Functions.mult).assign(Functions.mult(-2.0)); double[] D = new double[4]; int[] discInds = MixedUtils.getDiscreteInds(vars); int[] contInds = MixedUtils.getContinuousInds(vars); int p = contInds.length; int q = discInds.length; double temp = MGM.upperTri(xiu.copy(),1).zSum(); D[0] = temp/ ((p+q-1.0)*(p+q)/2.0); temp = MGM.upperTri(xiu.viewSelection(contInds, contInds).copy(), 1).zSum(); D[1] = temp/(p*(p-1.0)/2.0); temp = xiu.viewSelection(contInds, discInds).zSum(); D[2] = temp/(p*q); temp = MGM.upperTri(xiu.viewSelection(discInds, discInds).copy(), 1).zSum(); D[3] = temp/(q*(q-1.0)/2.0); return D; }
return viewSelection(matches.elements(), null); // take all columns
return viewSelection(matches.elements(), null); // take all columns