Demo package EBSpatCGAL

Indications

  • Cliquer sur les titres pour les ouvrir
  • Pour des codes R cliquer sur le bouton pour copier le code afin de le coller dans RStudio

Graphe de Delaunay

Graphe de Delaunay
require(EBSpatCGAL)
del2 <- Delaunay()
insert(del2,x=runif(100),y=runif(100),m=rUnif(100,supp=c(1,2)))
##out | short=7,...,5
vertices(del2,"all")
R> require(EBSpatCGAL)
R> del2 <- Delaunay()
R> insert(del2,x=runif(100),y=runif(100),m=rUnif(100,supp=c(1,2)))
R> vertices(del2,"all")
             x           y m
1   0.11204203 0.739391953 1
2   0.03969415 0.382938783 2
3   0.39126219 0.193812428 2
4   0.23203213 0.421074094 2
5   0.71929143 0.366691000 1
6   0.99238673 0.788615259 2
...
96  0.94252140 0.262269409 1
97  0.10063119 0.289568867 1
98  0.18963108 0.255010305 2
99  0.56113406 0.651751125 1
100 0.88979642 0.154346140 2

image
# plot Delaunay par défaut
plot(del2)
image
# avec Couleurs selon Marques
plot(del2,col=m)
image
# Graphe de Voronoï avec Couleurs selon Marques
plot(del2,"vor",col=m)
image
# Création de Scène Graphique (Expérimental)
sc <- Scene(graph=del2)
sc %<<% window2d(xlab="x",ylab="y",main="User-defined plot!")
sc %<<% lines(graph) %<<% points(graph,col=m) %<<% lines(graph,"vor")
plot(sc)
image
# Réutilisation de la Scène en changeant graph
del2bis <- Delaunay()
insert(del2bis,
  x=runif(n<-20),
  y=runif(n),
  m=rUnif(n,supp=c(1,2))
)
# same scene plotted with del2bis
plot(sc,graph=del2bis)
Delaunay en 3D (Code à executer dans une session R)
require(rgl)
require(EBSpatCGAL)
del3 <- Delaunay(3)
insert(del3,
   x=runif(100),y=runif(100),
   z=runif(100),m=rUnif(100,supp=c(1,2))
)
vertices(del3,"all")
plot(del3,radius=0.01)
plot(del3,col=m,radius=0.01)
R> require(rgl)
R> require(EBSpatCGAL)
R> del3 <- Delaunay(3)
R> insert(del3,
R>    x=runif(100),y=runif(100),
R>    z=runif(100),m=rUnif(100,supp=c(1,2))
R> )
R> vertices(del3,"all")
R> plot(del3,radius=0.01)
R> plot(del3,col=m,radius=0.01)

image
# Deux graphes de Delaunay
del2 <- Delaunay();del2bis<-Delaunay()
insert(del2,x=runif(n<-20),y=runif(n))
insert(del2bis,x=runif(n,1,2),y=runif(n,1,2))
sc2 <- Scene(gr=del2,gr2=del2bis)
sc2 %<<% window2d(c(0,2),c(0,2),xlab="",ylab="")
sc2 %<<% lines(gr,col="blue") %<<% points(gr,col="blue")
sc2 %<<% lines(gr2,col="red") %<<% points(gr2,col="red");plot(sc2)
image
# Distinguer les classes de distances des arêtes
del2 <- Delaunay()
insert(del2,
    x=runif(n<-300,-350,350),
    y=runif(n,-350,350)
)
sc2g <- Scene(gr=del2) %<<% window2d(c(-350,350),c(-350,350))
sc2g %<<% lines(gr,when=40<length & length <= 80) %<<%
lines(gr,col="red",lwd=2,when= length <= 40)  %<<%
lines(gr,col="violet",lty=2,lwd=2,when=80<length) %<<%
points(gr);plot(sc2g)

Graphe de Laguerre (Regular graph)

Graphe de Laguerre
require(EBSpatCGAL)
reg2 <- Regular()
insert(reg2,x=runif(100),y=runif(100),w=runif(100))
##out | short=7,...,5
vertices(reg2)
R> require(EBSpatCGAL)
R> reg2 <- Regular()
R> insert(reg2,x=runif(100),y=runif(100),w=runif(100))
R> vertices(reg2)
             [,1]        [,2]
 [1,] 0.962736276 0.119468953
 [2,] 0.871959598 0.701895077
 [3,] 0.209989528 0.872756889
 [4,] 0.979528536 0.003618682
 [5,] 0.029740213 0.057277399
 [6,] 0.374684063 0.980861908
...
[22,] 0.701069751 0.130484080
[23,] 0.112103307 0.241883016
[24,] 0.442970233 0.252561653
[25,] 0.048738342 0.678763224
[26,] 0.677131450 0.993796061

Graphe de Laguerre
image
R> sc <- Scene()
R> sc %<<% window2d(xlab="x",ylab="y",main="Regular and dual graphs")
R> sc %<<% lines(graph) %<<% points(graph) %<<% lines(graph,"vor")
R> plot(sc,graph=reg2)

Graphe de Laguerre en 3D (Code à executer dans une session R)
require(rgl)
require(EBSpatCGAL)
reg3 <- Regular(3)
insert(reg3,
   x=runif(100),y=runif(100),
   z=runif(100),w=runif(100)
)
vertices(reg3)
(sc3 <- Scene()) %<<% window3d(windowRect=c(0,0,800,800))
sc3 %<<% lines(gr) %<<% points(gr,col="blue",radius=0.02)

plot(sc3,gr=reg3)
R> require(rgl)
R> require(EBSpatCGAL)
R> reg3 <- Regular(3)
R> insert(reg3,
R>    x=runif(100),y=runif(100),
R>    z=runif(100),w=runif(100)
R> )
R> vertices(reg3)
R> (sc3 <- Scene()) %<<% window3d(windowRect=c(0,0,800,800))
R> sc3 %<<% lines(gr) %<<% points(gr,col="blue",radius=0.02)

R> plot(sc3,gr=reg3)

Modèle de Gibbs à interaction de type Delaunay

Simulation

Simulation 2D
require(EBSpatCGAL)
# Delaunay
del2 <- Delaunay()
del2bis <- Delaunay()
# Gibbs simulation
gd2 <- SimGibbs(
  del2 ~ 2 + Del2(th[1]*(l<=20)+th[2]*(20<l & l<=80),th=c(2,4)),
  domain=Domain(c(-350,-350),c(350,350))
)
# Marked one
del2m <- Delaunay()
gd2m <- SimGibbs(
  del2m ~ 2 + Del2(th[1]*(l<=20) + th[2]*(20<l & l<=80)
        * abs(v[[1]]$m-v[[2]]$m), th=c(2,4))| m ~ Unif(supp=c(1,2))
)
R> require(EBSpatCGAL)
R> # Delaunay
R> del2 <- Delaunay()
R> del2bis <- Delaunay()
R> # Gibbs simulation
R> gd2 <- SimGibbs(
+   del2 ~ 2 + Del2(th[1]*(l<=20)+th[2]*(20<l & l<=80),th=c(2,4)),
+   domain=Domain(c(-350,-350),c(350,350))
+ )
R> # Marked one
R> del2m <- Delaunay()
R> gd2m <- SimGibbs(
+   del2m ~ 2 + Del2(th[1]*(l<=20) + th[2]*(20<l & l<=80)
+         * abs(v[[1]]$m-v[[2]]$m), th=c(2,4))| m ~ Unif(supp=c(1,2))
+ )

image
# run the simulator and plot the resulted Delaunay graph
run(gd2)
plot(del2)
image
# run the simulator and plot the resulted Delaunay graph
run(gd2)
plot(del2)
image
# one can run the simulator with another Delaunay graph
run(gd2,current=del2bis)
plot(del2bis)
image
# run the simulator with the marked Delaunay graph
run(gd2m)
plot(del2m,col=m)
Simulation 3D (à executer dans une session R)
del3 <- Delaunay(3)

insert(del3,matrix(runif(300,-350,350),ncol=3))

# init gibbs
gd3 <- SimGibbs(del3 ~ 14 + Del2(th[1]*(l<=20)+th[2]*(20<l & l<=80),th=c(-2,35)),domain=Domain(c(-350,-350,-350),c(350,350,350)))

run(gd3)
R> del3 <- Delaunay(3)

R> insert(del3,matrix(runif(300,-350,350),ncol=3))

R> # init gibbs
R> gd3 <- SimGibbs(del3 ~ 14 + Del2(th[1]*(l<=20)+th[2]*(20<l & l<=80),th=c(-2,35)),domain=Domain(c(-350,-350,-350),c(350,350,350)))

R> run(gd3)

A executer dans une session R
# inside domain
domIn <- Domain(c(-250,-250),c(250,250))
#take a boundary of 1
del2m1 <- Delaunay()
insert(del2m1,x=runif(n<-500,-350,350),y=runif(n,-350,350),m=1)
delete(del2m1,inside=domIn)
#take a boundary of 2
del2m2 <- Delaunay()
insert(del2m2,x=runif(n<-500,-350,350),y=runif(n,-350,350),m=2)
delete(del2m2,inside=domIn)

plot(del2m1,col=m)
run(gd2m,current=del2m1,domain=domIn)
plot(del2m1,col=m)
plot(del2m2,col=m)

run(gd2m,current=del2m2,domain=domIn)
plot(del2m2,col=m)
R> # inside domain
R> domIn <- Domain(c(-250,-250),c(250,250))
R> #take a boundary of 1
R> del2m1 <- Delaunay()
R> insert(del2m1,x=runif(n<-500,-350,350),y=runif(n,-350,350),m=1)
R> delete(del2m1,inside=domIn)
R> #take a boundary of 2
R> del2m2 <- Delaunay()
R> insert(del2m2,x=runif(n<-500,-350,350),y=runif(n,-350,350),m=2)
R> delete(del2m2,inside=domIn)

R> plot(del2m1,col=m)
R> run(gd2m,current=del2m1,domain=domIn)
R> plot(del2m1,col=m)
R> plot(del2m2,col=m)

R> run(gd2m,current=del2m2,domain=domIn)
R> plot(del2m2,col=m)

Simulation 3D (à executer dans une session R)
# Delaunay
del3 <- Delaunay(3)
insert(del3,matrix(runif(300,-350,350),ncol=3))
# Gibbs simulation
gd3 <- SimGibbs(
  del3 ~ 14 + Del2(th[1]*(l<=20)+th[2]*(20<l & l<=80),th=c(-2,10)),
  domain=Domain(c(-350,-350,-350),c(350,350,350))
)
run(gd3)
# scene 3D
(sc3 <- Scene()) %<<%
window3d(gd3,windowRect=c(0,0,800,800)) %<<%
points(gr,col="violet",radius=5) %<<%
lines(gr,col="red",lwd=5,when= length <= 20)  %<<%
lines(gr,lwd=5,col="green",when=20<length & length <= 80) %<<%
lines(gr,col="blue",when=80<length)

plot(sc3,gr=del3)
R> # Delaunay
R> del3 <- Delaunay(3)
R> insert(del3,matrix(runif(300,-350,350),ncol=3))
R> # Gibbs simulation
R> gd3 <- SimGibbs(
R>   del3 ~ 14 + Del2(th[1]*(l<=20)+th[2]*(20<l & l<=80),th=c(-2,10)),
R>   domain=Domain(c(-350,-350,-350),c(350,350,350))
R> )
R> run(gd3)
R> # scene 3D
R> (sc3 <- Scene()) %<<%
R> window3d(gd3,windowRect=c(0,0,800,800)) %<<%
R> points(gr,col="violet",radius=5) %<<%
R> lines(gr,col="red",lwd=5,when= length <= 20)  %<<%
R> lines(gr,lwd=5,col="green",when=20<length & length <= 80) %<<%
R> lines(gr,col="blue",when=80<length)

R> plot(sc3,gr=del3)

Estimation

Estimation des modèles de Gibbs (à exécuter dans une session R)
require(EBSpatCGAL)
pseudo <- Pseudo(del2~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)),
	runs=10000L,
	domain=Domain(c(-250,-250),c(250,250)),
	expo=TRUE
)
run(pseudo,Single=0,Th=c(0,0))

pseudo3 <- Pseudo(del3~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)),
  runs=10000L,
  domain=Domain(c(-250,-250,-250),c(250,250,250)),
  expo=TRUE
)

run(pseudo3,Single=0,Th=c(0,0))

tkinv <- TKInverse(del2~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)),
	runs=10000L,
	domain=Domain(c(-250,-250),c(250,250))
)
run(tkinv,Single=0,Th=c(0,0))

tkinv3 <- TKInverse(del3~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)),
  runs=10000L,
  domain=Domain(c(-250,-250,-250),c(250,250,250))
)

run(tkinv3,Single=0,Th=c(0,0))

gnz <- GNZCache(
  del2~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)) ,
  1,del2(l<=20), del2(20<l & l<=80),
  runs=10000L,
  domain=Domain(c(-250,-250),c(250,250))
)
run(gnz,Single=2,Th=c(2,4))


res <- Resid(
  del2~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)) ,
  1,del2(l<=20), del2(20<l & l<=80),
  runs=10000L,
  domain=Domain(c(-250,-250),c(250,250))
)
run(res,Single=2,Th=c(2,4))

resid <- Resid(
  del2~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)) ,
  1,del2(l<=20), del2(20<l & l<=80),
  all2(range=100|l<=20),
  all2(range=100|20<l & l<80),
  del3(ta),
  runs=10000L,
  domain=Domain(c(-250,-250),c(250,250))
)
run(resid,Single=2,Th=c(2,4))
R> require(EBSpatCGAL)
R> pseudo <- Pseudo(del2~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)),
R> 	runs=10000L,
R> 	domain=Domain(c(-250,-250),c(250,250)),
R> 	expo=TRUE
R> )
R> run(pseudo,Single=0,Th=c(0,0))

R> pseudo3 <- Pseudo(del3~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)),
R>   runs=10000L,
R>   domain=Domain(c(-250,-250,-250),c(250,250,250)),
R>   expo=TRUE
R> )

R> run(pseudo3,Single=0,Th=c(0,0))

R> tkinv <- TKInverse(del2~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)),
R> 	runs=10000L,
R> 	domain=Domain(c(-250,-250),c(250,250))
R> )
R> run(tkinv,Single=0,Th=c(0,0))

R> tkinv3 <- TKInverse(del3~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)),
R>   runs=10000L,
R>   domain=Domain(c(-250,-250,-250),c(250,250,250))
R> )

R> run(tkinv3,Single=0,Th=c(0,0))

R> gnz <- GNZCache(
R>   del2~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)) ,
R>   1,del2(l<=20), del2(20<l & l<=80),
R>   runs=10000L,
R>   domain=Domain(c(-250,-250),c(250,250))
R> )
R> run(gnz,Single=2,Th=c(2,4))


R> res <- Resid(
R>   del2~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)) ,
R>   1,del2(l<=20), del2(20<l & l<=80),
R>   runs=10000L,
R>   domain=Domain(c(-250,-250),c(250,250))
R> )
R> run(res,Single=2,Th=c(2,4))

R> resid <- Resid(
R>   del2~Del2(Th[1]*(l<=20)+Th[2]*(20<l & l<=80)) ,
R>   1,del2(l<=20), del2(20<l & l<=80),
R>   all2(range=100|l<=20),
R>   all2(range=100|20<l & l<80),
R>   del3(ta),
R>   runs=10000L,
R>   domain=Domain(c(-250,-250),c(250,250))
R> )
R> run(resid,Single=2,Th=c(2,4))