library("scatterplot3d")

ps.options(horizontal=FALSE,onefile=FALSE)
ps.options(pagecentre=TRUE)
ps.options(paper="letter")
ps.options(width=7.0,height=9.0)

U <- matrix(data = c(0,1,1,0,-1,1),nrow=3,ncol=2)

n <- 10000

x  <- mat.or.vec(n,1)
y  <- mat.or.vec(n,1)
z  <- mat.or.vec(n,1)

for (i in seq(1,n)){
  v <- c(runif(n=1),runif(n=1))
  w <- U %*% v
  x[i] = w[1]
  y[i] = w[2]
  z[i] = w[3]
}

  xa = x
  ya = y

filename <- "manifold.eps"
postscript(file=filename)

scatterplot3d(x,y,z,pch=".",box=FALSE,
  xlab=expression(theta[1]),
  ylab=expression(theta[2]),
  zlab=expression(theta[3]))

dev.off()

x <- seq(-1,0.5,0.01)

y <- -0.5*x^2

xlim <- c(min(x),max(x))
ylim <- c(min(y)-0.5,max(y)+0.5)

xbeg = 0.0
ybeg = -0.5*xbeg^2
xend = xbeg - 0.75
yend = ybeg 

filename <- "proposal.eps"
postscript(file=filename)
par(mfrow=c(2,1),mar=c(2.5,4,1.5,2)+0.1) # mar=c(bottom,left,top,right)

plot(xlim,ylim,type="n",xlab="",ylab="")
  lines(x,y,lty="solid")
  xbeg = 0.0
  ybeg = -0.5*xbeg^2
  xend = xbeg - 0.75
  yend = ybeg 
  arrows(xbeg,ybeg,xend,yend,length=0.1)
  xbeg = xend
  ybeg = yend
  xend = xend
  yend = -0.5*xend^2
  arrows(xbeg,ybeg,xend,yend,length=0.1)
  xbeg = 0.0
  ybeg = -0.5*xbeg^2
  arrows(xbeg,ybeg,xend,yend,length=0.1)
  text(-0.4,0.05,"v")
  text(-0.8,-0.12,"w")
  text(-0.4,-0.22,"v + w")
  text(0.0,0.0,"o")

plot(xlim,ylim,type="n",xlab="",ylab="")
  lines(x,y,lty="solid")
  xend = xbeg - 0.75
  yend = -0.5*xend^2
  x0 = 0.0
  y0 = 0.0
  x1 = x0 - 0.75/2.0
  y1 = y0
  arrows(x0,y0,x1,y1,length=0.1)
  x2 = x1
  y2 = -0.5*x2^2
  arrows(x1,y1,x2,y2,length=0.1)
  arrows(x0,y0,x2,y2,length=0.1)
  x3 = xend - 0.02
  y3 = y2 - 0.14
  arrows(x2,y2,x3,y3,length=0.1)
  xend = xbeg - 0.75
  yend = -0.5*xend^2
  arrows(x3,y3,xend,yend,length=0.1)
  arrows(x2,y2,xend,yend,length=0.1)
  #arrows(xbeg,ybeg,xend,yend,length=0.1)
  xbeg = xend
  ybeg = yend
  xend = xend
  yend = -0.5*xend^2
  #arrows(xbeg,ybeg,xend,yend,length=0.1)
  xbeg = 0.0
  ybeg = -0.5*xbeg^2
  #arrows(xbeg,ybeg,xend,yend,length=0.1)
  #text(-0.4,0.05,"v")
  #text(-0.8,-0.12,"w")
  #text(-0.4,-0.22,"v + w")
  text(0.0,0.0,"o")
  text(0,-0.1,expression(x_0))
  text(x2,-0.15,expression(x_1))
  text(xend,yend-0.1,expression(x_2))
dev.off()

filename <- "innovation.eps"
postscript(file=filename)
par(mfrow=c(2,1),mar=c(2.5,4,1.5,2)+0.1) # mar=c(bottom,left,top,right)

plot(xlim,ylim,type="n",xlab="",ylab="")
  lines(x,y,lty="solid")
  xbeg = 0.0
  ybeg = -0.5*xbeg^2
  xend = xbeg - 0.75
  yend = ybeg 
  arrows(xbeg,ybeg,xend,yend,length=0.1)
  xbeg = xend
  ybeg = yend
  xend = xend
  yend = -0.5*xend^2
  arrows(xbeg,ybeg,xend,yend,length=0.1)
  xbeg = 0.0
  ybeg = -0.5*xbeg^2
  arrows(xbeg,ybeg,xend,yend,length=0.1)
  text(-0.4,0.05,"v")
  text(-0.8,-0.12,"w")
  text(-0.4,-0.22,"v + w")
  text(0.0,0.0,"o")

plot(xlim,ylim,type="n",xlab="",ylab="")
  lines(x,y,lty="solid")
  xbeg = -0.75
  ybeg = -0.5*xbeg^2
  text(xbeg,ybeg,"o")
  xend = 0.0
  yend = 0.3
  arrows(xbeg,ybeg,xend,yend,length=0.1)
  xbeg = xend
  ybeg = yend
  xend = 0.0
  yend = 0.0
  arrows(xbeg,ybeg,xend,yend,length=0.1)
  text(0.0,0.0,"o")
  text(-0.4,0.05,"v'")
  text(0.05,0.15,"w'")
dev.off()

