Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用hitandrun包R生成随机数_R_Random - Fatal编程技术网

使用hitandrun包R生成随机数

使用hitandrun包R生成随机数,r,random,R,Random,我试图用R的hitandrun包生成均匀随机数。我使用不等式和等式约束。这是我的代码: library(hitandrun) ineq.constr<-mergeConstraints(lowerBoundConstraint(16,1,0),upperBoundConstraint(16,1,1)) for(i in 2:16){ ineq.constr<-mergeConstraints(ineq.constr, lowerBoundConstraint(16,i,0),upp

我试图用R的hitandrun包生成均匀随机数。我使用不等式和等式约束。这是我的代码:

library(hitandrun)

ineq.constr<-mergeConstraints(lowerBoundConstraint(16,1,0),upperBoundConstraint(16,1,1))
for(i in 2:16){
ineq.constr<-mergeConstraints(ineq.constr,
lowerBoundConstraint(16,i,0),upperBoundConstraint(16,i,1))
}
add.constr<- mergeConstraints(
list(constr= c(1,1,1,-1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,-1), dir='<=', rhs=4),
list(constr= c(-1,-1,-1,1,1,1,1,-1,1,1,1,-1,-1,-1,-1,1), dir='<=', rhs=-2))
ineq.constr<-mergeConstraints(ineq.constr,add.constr)

eq.constr<- mergeConstraints(
list(constr= c(1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0), dir='=', rhs=1),
list(constr= c(0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0), dir='=', rhs=1),
list(constr= c(0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0), dir='=', rhs=1),
list(constr= c(0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1), dir='=', rhs=1),
list(constr= c(1,-1,0,0,1,-1,0,0,0,0,0,0,0,0,0,0), dir='=', rhsh=0),
list(constr= c(0,0,1,-1,0,0,1,-1,0,0,0,0,0,0,0,0), dir='=', rhsh=0),
list(constr= c(0,0,0,0,0,0,0,0,1,-1,0,0,1,-1,0,0), dir='=', rhsh=0),
list(constr= c(0,0,0,0,0,0,0,0,0,0,1,-1,0,0,1,-1), dir='=', rhsh=0),
list(constr= c(1,0,-1,0,0,0,0,0,1,0,-1,0,0,0,0,0), dir='=', rhsh=0),
list(constr= c(0,1,0,-1,0,0,0,0,0,1,0,-1,0,0,0,0), dir='=', rhsh=0),
list(constr= c(0,0,0,0,1,0,-1,0,0,0,0,0,1,0,-1,0), dir='=', rhsh=0),
list(constr= c(0,0,0,0,0,1,0,-1,0,0,0,0,0,1,0,-1), dir='=', rhsh=0))
constr<-mergeConstraints(ineq.constr, eq.constr)
samples <- hitandrun(constr, n.samples=2000000)
stopifnot(dim(samples) == c(2000000, 16))
df<-matrix(unlist(samples), nrow=2000000, ncol=16)
df<-data.frame(df)
write.table(df, file="har_samples.txt", row.names=FALSE, col.names=FALSE)
库(hitandrun)
工程量清单
add.constr<- mergeConstraints(
list(constr= c(1,1,1,-1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,-1), dir='<=', rhs=4),
list(constr= c(-1,-1,-1,1,1,1,1,-1,1,1,1,-1,-1,-1,-1,1), dir='<=', rhs=-2))
ineq.constr<-mergeConstraints(ineq.constr,add.constr)