Description Usage Details Examples
View source: R/constraint_definition.R
Find the space where points where observed. Send back a function to check if a/several point(s) belong to the space where the points where observed
1 2 3 4 5 6 |
@param X matrix of dimension n x d observed points @param alpha probability to deal with the trade-off false positive false negatif. Alpha closed to 1 mean low false positive and vice versa @param path_tracking path where to write the step of the running function.
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 | library(tidyverse)
library(optisure)
#parameters constraint
alpha = 0.05
#parameters data
n = 1000
d1 = 2
mini = rep(0, d1)
maxi = rep(10, d1)
b = matrix(c(0, 0, 5, 5), byrow = T, ncol = d1)
B = matrix(c(4, 4, 10, 10), byrow = T, ncol = d1)
p = NROW(B) #nombre de "foyer"
#generate data
X_U = sapply(seq_len(d1), function(i){
sapply(seq_len(p), function(k){
runif(n/p, b[k,i], B[k,i])
})
}) %>% as.data.frame()
#Monte Carlo simulation of 5000 points to check the constraint
n_MC = 5000
X_MC = sapply(seq_len(d1), function(i){
runif(n_MC, mini[i], maxi[i])
})
#visualisation
res = def_cstr_X_space(X=X_U, alpha = alpha)
feasible_X_MC = res$g(x = X_MC)
cols <- c("FALSE" = "red", "training" = "blue", "TRUE" = "green")
ggplot(data.frame(X_MC, feasible = feasible_X_MC)) +
geom_point(aes(x = X1, y = X2, colour = feasible)) +
geom_point(data = X_U, aes(x = V1, y = V2, colour = "training"),
shape = 17, size = 1) +
scale_colour_manual(values = cols)
# verification avec les aires de MC
# aire theorique de 95% de la surface
A_true_uni = (1-alpha) * sum(apply(B-b, 1, prod))
A_true_uni
# Aire estime par Monte Carlo
A_MC = prod(maxi - mini)
A_estime = A_MC*sum(feasible_X_MC)/n_MC
A_estime
(A_estime - A_true_uni)/A_true_uni #ratio
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.