Dennis Duncan
RUID No. 046-00-9156
Please answer the following questions in electronic form and upload and submit your files to the blackboard site, before the due date. Make sure to push the submit button. You can typeset your answer using MS Word (and MS equation for mathematical formulas), or LaTeX, or you may simply hand write your note and scan and turn it into a single pdf format file and upload to the blackboard. Please provide your code as well as a separate file, we may need to run your code.
Below are some (simplified version of) objectives that arise frequently in machine learning. For simplicity, we provide the objectives in dimension two as a function of \[x = [x1,x2]^T\]. Plot these functions and argue whether they are convex, concave or non-convex. (Mathematical proof is not needed, the purpose is to visualize these functions and decide about their convexity by looking at their 3d visualizations).
library(ggplot2)
library(plotly)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
x1=seq(0,50,length=500)
x2=seq(0,50,length=500)
#x=rbind(x1,x2)
fxa<-function(p1,p2){return((1-p1*p2)^2)}
zfxa=outer(x1,x2,fxa)
fig <- plot_ly(x=x1,y=x2,z=zfxa,type = "surface")
#
t=seq(-1,0,length=20)
xl <- numeric(length(t))
yl <- numeric(length(t))
zl <- numeric(length(t))
for(i in seq_along(t)) {
xl[i] <- 50+10*t[i]
yl[i] = 40-10*t[i]
zl[i] = (1-50*40)^2
}
fig <- fig %>% add_trace(x = xl,y = yl,z= zl, type = 'scatter3d',color = I('red'),opacity = 1,mode = 'lines',
line = list(width =6))
fig
NA
The function is not convex. That is evident as shown above with the majority of the data found below the two arbitrary points.
p1=seq(-100,100,length=1000)
p2=seq(-100,100,length=1000)
w=matrix(runif(20),2,1)
w1=w[1,]
w2=w[2,]
fxb<-function(x1,x2){return(log(1+exp(-as.vector(t(w1)*x1-as.vector(t(w2)*x2)))))}
zfxb=outer(p1,p2,fxb)
Recycling array of length 1 in array-vector arithmetic is deprecated.
Use c() or as.vector() instead.
Recycling array of length 1 in array-vector arithmetic is deprecated.
Use c() or as.vector() instead.
plot_ly(x=p1,y=p2,z=zfxb,type="surface")