Esempio n. 1
0
// Volumetric 2D Convolution
mat conv2d(cube image, cube kernel){
 
    dbg_assert(image.n_rows == image.n_cols);
    dbg_assert(kernel.n_rows == kernel.n_cols);
    dbg_assert(kernel.n_rows <= image.n_rows);
    dbg_assert(kernel.n_slices == image.n_slices);

    int kernel_size = kernel.n_rows;
    int image_size  = image.n_rows;

    int result_size = image_size - kernel_size + 1;
    mat result      = zeros<mat>(result_size, result_size);

    for(int row=0; row < result_size; row++){
        for(int col=0; col < result_size; col++){
            result(row, col) = accu(
                                 image.tube(
                                    row, 
                                    col, 
                                    row + kernel_size - 1,
                                    col + kernel_size - 1
                                 ) % kernel 
                               );
        }
    }
    
    return(result);
       
}
Esempio n. 2
0
// converts a cube to a board by filling board(i,j) with the index
// of the largest index of Q(i,j,:)
Board cube2Board(const cube& Q){
  int n = Q.n_rows;
  Board solvedBoard(n);
  uword ix;
  vec A;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++){
      A = Q.tube(i,j);
      A.max(ix);
      solvedBoard(i,j) = (int)ix + 1;
    }
  return solvedBoard;
}
Esempio n. 3
0
void setupDX_io(cube& xio, const mat& x, const mat& xion, icube& shiftio, const unsigned numMols, const unsigned numIons, const rowvec& box)
{
    rowvec x_row(DIMS);
    irowvec shift_row(DIMS);

    for (unsigned i1=0; i1<numIons; i1++)
        for (unsigned i2=0; i2<numMols; i2++)
        {
            findDx(x_row, xion.row(i1), x.row(i2), box, shift_row);
            xio.tube(i1,i2) = x_row;
            shiftio.tube(i1,i2) = shift_row;
        }
}
Esempio n. 4
0
void setupDX(cube& xoo, cube& xio, cube& xii, mat& roo2, mat& rio2, mat& rii2, const mat& x, const mat& xion, icube& shiftoo,
                    icube& shiftio, icube& shiftii, const unsigned numMols, const unsigned numIons, const rowvec& box)
{
    rowvec x_row(DIMS);
    irowvec shift_row(DIMS);

    for (unsigned i1=0; i1<numMols; i1++)
        for (unsigned i2=i1+1; i2<numMols; i2++)
        {
            findDx(x_row, x.row(i1), x.row(i2), box, shift_row);
            xoo.tube(i1,i2) = x_row;
            shiftoo.tube(i1,i2) = shift_row;
            xoo.tube(i2,i1) = -1.0*x_row;
            shiftoo.tube(i2,i1) = -1*shift_row;
            roo2(i2,i1) = roo2(i1,i2) = dot(x_row,x_row);
        }
    for (unsigned i1=0; i1<numIons; i1++)
    {
        for (unsigned i2=0; i2<numMols; i2++)
        {
            findDx(x_row, xion.row(i1), x.row(i2), box, shift_row);
            xio.tube(i1,i2) = x_row;
            shiftio.tube(i1,i2) = shift_row;
            rio2(i2,i1) = rio2(i1,i2) = dot(x_row,x_row);
        }
        for (unsigned i2=i1+1; i2<numIons; i2++)
        {
            findDx(x_row, xion.row(i1), xion.row(i2), box, shift_row);
            xii.tube(i1,i2) = x_row;
            shiftii.tube(i1,i2) = shift_row;
            xii.tube(i2,i1) = -1.0*x_row;
            shiftii.tube(i2,i1) = -1*shift_row;
            rii2(i2,i1) = rii2(i1,i2) = dot(x_row,x_row);
        }
    }
}