approxProfileExtrema: Approximate profile extrema functions

Description Usage Arguments Value Author(s) Examples

View source: R/profExtremaNumOpt.R

Description

Evaluate profile extrema for a set of Psi with approximations at few values

Usage

1
approxProfileExtrema(f, fprime = NULL, d, allPsi, opts = NULL)

Arguments

f

the function to be evaluated

fprime

derivative of the function

d

dimension of the input domain

allPsi

a list containing the matrices Psi (dim pxd) for which to compute the profile extrema

opts

a list containing the options for this function and the subfunctions getProfileSup_optim, getProfileInf_optim or getProfileExtrema. The options only for approxProfileExtrema are

  • limits:an optional list with the upper and lower limits of input space dimension, if NULL then limits=list(upper=rep(1,d),lower=rep(0,d))

  • smoother:Select which smoother to use:a string that selects which smoother to use:

    • "1order": first order interpolation with gradient

    • "splineSmooth": smoothing spline with default degrees of freedom (DEFAULT OPTION)

    • "quantSpline": profile inf and profile sup approximated with quantile spline regression at levels 0.1 and 0.9 respectively

  • heavyReturn:If TRUE returns also all minimizers, default is FALSE.

  • initDesign:A list of the same length as allPsi containing the designs of few points where the expensive sup is evaluated. If Null it is automatically initialized

  • fullDesignSize:The full design where the function is approximated.

  • multistart:number of multistarts for optim procedure.

  • numMCsamples:number of MC samples for the sup.

  • plts:If TRUE, plots the max/min functions at each coordinate, default is FALSE.

  • verb:If TRUE, outputs intermediate results, default is FALSE.

Value

a list of two data frames (min, max) of the evaluations of f_sup(x_i) = sup_{x_j \neq i} f(x_1,…,x_d) and f_inf(x_i) = inf_{x_j \neq i} f(x_1,…,x_d) for each i at the design Design. By default Design is a 100 equally spaced points for each dimension. It can be changed by defining it in options$Design

Author(s)

Dario Azzimonti

Examples

 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
59
60
61
# Compute the oblique profile extrema with approximate optimization on 2d example

# Define the function
testF <- function(x,params,v1=c(1,0),v2=c(0,1)){
return(sin(crossprod(v1,x)*params[1]+params[2])+cos(crossprod(v2,x)*params[3]+params[4])-1.5)
}

testFprime <- function(x,params,v1=c(1,0),v2=c(0,1)){
  return(matrix(c(params[1]*v1[1]*cos(crossprod(v1,x)*params[1]+params[2])-
                  params[3]*v2[1]*sin(crossprod(v2,x)*params[3]+params[4]),
                 params[1]*v1[2]*cos(crossprod(v1,x)*params[1]+params[2])-
                  params[3]*v2[2]*sin(crossprod(v2,x)*params[3]+params[4])),ncol=1))
}


# Define the main directions of the function
theta=pi/6
pparams<-c(1,0,10,0)
vv1<-c(cos(theta),sin(theta))
vv2<-c(cos(theta+pi/2),sin(theta+pi/2))

# Define optimizer friendly function
f <-function(x){
return(testF(x,pparams,vv1,vv2))
}
fprime <- function(x){
 return(testFprime(x,pparams,vv1,vv2))
}

# Define list of directions where to evaluate the profile extrema
all_Psi <- list(Psi1=vv1,Psi2=vv2)

# Evaluate profile extrema along directions of all_Psi
allOblique<-approxProfileExtrema(f=f,fprime = fprime,d = 2,allPsi = all_Psi,
                                 opts = list(plts=FALSE,heavyReturn=TRUE))


# Consider threshold=0
threshold <- 0

# Plot oblique profile extrema functions
plotMaxMin(allOblique,allOblique$Design,threshold = threshold)

## Since the example is two dimensional we can visualize the regions excluded by the profile extrema
# evaluate the function at a grid for plots
inDes<-seq(0,1,,100)
inputs<-expand.grid(inDes,inDes)
outs<-apply(X = inputs,MARGIN = 1,function(x){return(testF(x,pparams,v1=vv1,v2=vv2))})

# obtain the points where the profiles take the threshold value
cccObl<-getChangePoints(threshold = threshold,allRes = allOblique,Design = allOblique$Design)

# visualize the functions and the regions excluded

image(inDes,inDes,matrix(outs,ncol=100),col=grey.colors(20),main="Example and oblique profiles")
contour(inDes,inDes,matrix(outs,ncol=100),add=TRUE,nlevels = 20)
contour(inDes,inDes,matrix(outs,ncol=100),add=TRUE,levels = c(threshold),col=4,lwd=1.5)
plotOblique(cccObl$alwaysEx$`0`[[1]],all_Psi[[1]],col=3)
plotOblique(cccObl$alwaysEx$`0`[[2]],all_Psi[[2]],col=3)
plotOblique(cccObl$neverEx$`0`[[1]],all_Psi[[1]],col=2)
plotOblique(cccObl$neverEx$`0`[[2]],all_Psi[[2]],col=2)

profExtrema documentation built on March 22, 2020, 1:07 a.m.