Merge branch 'issue-3' into develop
This commit is contained in:
commit
12a33a3933
4 changed files with 51 additions and 36 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
Package: rBAPS
|
Package: rBAPS
|
||||||
Title: Bayesian Analysis of Population Structure
|
Title: Bayesian Analysis of Population Structure
|
||||||
Version: 0.0.0.9013
|
Version: 0.0.0.9014
|
||||||
Date: 2020-11-09
|
Date: 2020-11-09
|
||||||
Authors@R:
|
Authors@R:
|
||||||
c(
|
c(
|
||||||
|
|
|
||||||
16
R/dec2bitv.R
Normal file
16
R/dec2bitv.R
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
dec2bitv <- function(d, n) {
|
||||||
|
# DEC2BITV Convert a decimal integer to a bit vector.
|
||||||
|
# bits <- dec2bitv(d, n) is just like the built - in dec2bin, except the answer is a vector, not a as.character.
|
||||||
|
# n is an optional minimum length on the bit vector.
|
||||||
|
# If d is a vector, each row of the output array will be a bit vector.
|
||||||
|
|
||||||
|
if (nargin() < 2) {
|
||||||
|
n <- 1 # Need at least one digit even for 0.
|
||||||
|
}
|
||||||
|
d <- d[]
|
||||||
|
|
||||||
|
f <- e <- NA
|
||||||
|
c(f, e) <- log2(max(d)) # How many digits do we need to represent the numbers?
|
||||||
|
bits <- floor(d * 2 ^ (seq(1 - max(n, e), 0))) %% 2
|
||||||
|
return(bits)
|
||||||
|
}
|
||||||
67
R/ind2subv.R
67
R/ind2subv.R
|
|
@ -1,38 +1,37 @@
|
||||||
ind2subv <- function(siz, ndx) stop("Needs translation")
|
ind2subv <- function(siz, ndx) {
|
||||||
# function sub = ind2subv(siz, ndx)
|
# IND2SUBV Like the built - in ind2sub, but returns the answer as a row vector.
|
||||||
# % IND2SUBV Like the built-in ind2sub, but returns the answer as a row vector.
|
# sub <- ind2subv(siz, ndx)
|
||||||
# % sub = ind2subv(siz, ndx)
|
# siz and ndx can be row or column vectors.
|
||||||
# %
|
# sub will be of size length(ndx) * length(siz).
|
||||||
# % siz and ndx can be row or column vectors.
|
# Example
|
||||||
# % sub will be of size length(ndx) * length(siz).
|
# ind2subv([2 2 2], 1:8) returns
|
||||||
# %
|
# [1 1 1
|
||||||
# % Example
|
# 2 1 1
|
||||||
# % ind2subv([2 2 2], 1:8) returns
|
# ...
|
||||||
# % [1 1 1
|
# 2 2 2]
|
||||||
# % 2 1 1
|
# That is, the leftmost digit toggle fastest.
|
||||||
# % ...
|
#
|
||||||
# % 2 2 2]
|
# See also SUBV2IND
|
||||||
# % That is, the leftmost digit toggle fastest.
|
|
||||||
# %
|
|
||||||
# % See also SUBV2IND
|
|
||||||
|
|
||||||
# n = length(siz);
|
n <- length(siz)
|
||||||
|
|
||||||
# if n==0
|
if (n == 0) {
|
||||||
# sub = ndx;
|
sub <- ndx
|
||||||
# return;
|
return(sub)
|
||||||
# end
|
}
|
||||||
|
|
||||||
# if all(siz==2)
|
if (all(siz == 2)) {
|
||||||
# sub = dec2bitv(ndx-1, n);
|
sub <- dec2bitv(ndx - 1, n)
|
||||||
# sub = sub(:,n:-1:1)+1;
|
sub <- sub[, seq(n, 1, - 1)] + 1
|
||||||
# return;
|
return(sub)
|
||||||
# end
|
}
|
||||||
|
|
||||||
# cp = [1 cumprod(siz(:)')];
|
cp <- c(1, cumprod(t(siz[])))
|
||||||
# ndx = ndx(:) - 1;
|
ndx <- ndx[] - 1
|
||||||
# sub = zeros(length(ndx), n);
|
sub <- zeros(length(ndx), n)
|
||||||
# for i = n:-1:1 % i'th digit
|
for (i in seq(n, 1, -1)) {# i'th digit
|
||||||
# sub(:,i) = floor(ndx/cp(i))+1;
|
sub[, i] <- floor(ndx / cp[i]) + 1
|
||||||
# ndx = rem(ndx,cp(i));
|
ndx <- ndx %% cp(i)
|
||||||
# end
|
}
|
||||||
|
return(sub)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,5 @@
|
||||||
#' size sortrows squeeze strcmp times zeros disp
|
#' size sortrows squeeze strcmp times zeros disp
|
||||||
#' @importFrom stats runif
|
#' @importFrom stats runif
|
||||||
#' @importFrom zeallot %<-%
|
#' @importFrom zeallot %<-%
|
||||||
#' @importFrom matlab2r nargin
|
#' @importFrom matlab2r nargin log2
|
||||||
NULL
|
NULL
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue