#maximize the sin function
sin1 <- genoud(sin, nvars=1, max=TRUE);
#minimize the sin function
sin2 <- genoud(sin, nvars=1, max=FALSE);
#maximize a univariate normal mixture which looks like a claw and
#plot it
claw <- function(xx) {
Nd <- function(x, mu, sigma) {
w <- (1.0/sqrt(2.0*pi*sigma*sigma)) ;
z <- (x-mu)/sigma;
w <- w*exp(-0.5*z*z) ;
as.double(w);
}
x <- xx[1];
y <- (0.46*(Nd(x,-1.0,2.0/3.0) + Nd(x,1.0,2.0/3.0)) +
(1.0/300.0)*(Nd(x,-0.5,.01) + Nd(x,-1.0,.01) + Nd(x,-1.5,.01)) +
(7.0/300.0)*(Nd(x,0.5,.07) + Nd(x,1.0,.07) + Nd(x,1.5,.07))) ;
as.double(y);
}
claw1 <- genoud(claw, nvars=1,P9=100,max=TRUE);
xx <- seq(-3,3,.05);
plot(xx,lapply(xx,claw),type="l",xlab="Parameter",ylab="Fit",main="RGENOUD: Maximize the Claw Density");
points(claw1$par,claw1$value,col="red");
#maximize a bivariate normal mixture which looks like a claw
biclaw <- function(xx) {
mNd2 <- function(x1, x2, mu1, mu2, sigma1, sigma2, rho)
{
z1 <- (x1-mu1)/sigma1;
z2 <- (x2-mu2)/sigma2;
w <- (1.0/(2.0*pi*sigma1*sigma2*sqrt(1-rho*rho))) ;
w <- w*exp(-0.5*(z1*z1 - 2*rho*z1*z2 + z2*z2)/(1-rho*rho)) ;
as.double(w);
}
x1 <- xx[1]+1;
x2 <- xx[2]+1;
y <- (0.5*mNd2(x1,x2,0.0,0.0,1.0,1.0,0.0) +
0.1*(mNd2(x1,x2,-1.0,-1.0,0.1,0.1,0.0) +
mNd2(x1,x2,-0.5,-0.5,0.1,0.1,0.0) +
mNd2(x1,x2,0.0,0.0,0.1,0.1,0.0) +
mNd2(x1,x2,0.5,0.5,0.1,0.1,0.0) +
mNd2(x1,x2,1.0,1.0,0.1,0.1,0.0)));
as.double(y);
}
biclaw1 <- genoud(biclaw, nvars=2,P9=100,max=TRUE);
Run the code above in your browser using DataLab