/
quadprog_test_case.R
58 lines (43 loc) · 1000 Bytes
/
quadprog_test_case.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
library(rstan)
setwd("~/Desktop/misc/quadprog")
model <- stan_model(file = "quadprog_test_model.stan",
allow_undefined = TRUE,
includes = paste0('\n#include "', file.path(getwd(), 'quadprog.hpp'), '"\n'),
verbose = FALSE)
print(model@model_name)
# test that matches the one in quadprog.cpp
G <- t(matrix(c(2.1, 0.0, 1.0,
1.5, 2.2, 0.0,
1.2, 1.3, 3.1), 3,3))
g0 <- c(6, 1, 1);
CE <- matrix(c(1, 2, -1),3,1);
ce0 <- c(-4);
dim(ce0) <- c(1)
# I had to be careful here so that the matrix actually looks like this:
# [,1] [,2] [,3] [,4]
# [1,] 1 0 0 -1
# [2,] 0 1 0 -1
# [3,] 0 0 1 0
CI <- t(matrix(c(1, 0, 0, -1,
0, 1, 0, -1,
0, 0, 1, 0), 4,3))
ci0 <- c(0, 0, 0, 10);
stan_data = list(
N = 3,
P = 1,
M = 4,
G = G,
g0 = g0,
CI = CI,
ci0 = ci0,
CE = CE,
ce0 = ce0
)
idk = sampling(
model,
stan_data,
iter = 1,
chains = 1
)
idfk = extract(idk)
print(idfk)