Help us understand the problem. What is going on with this article?

ADMMs

More than 1 year has passed since last update.

#ADMMs p.215

library(dplyr)

data=data.frame(num=1:20,y=c(0.20, 0.10, 0.49, 0.26, 0.92, 0.95, 0.18, 0.19, 0.44, 0.79, 0.61, 0.41, 0.49, 0.34, 0.62, 0.99, 0.38, 0.22,0.71,0.40),x1=c(84,87,86,85,82,87,92,94,88,84.9,78,90,88,87,82,84,86,83,85.2,82),x2=c(61,55.5,57,57,50,50,66.5,65,60.5,49.5,49.5,61,59.5,58.4,53.5,54,60,58.8,54,56),x3=c(24.5,24,23,22.5,22,24,25,26,25,24,23,21,26,25.5,24,23,24,24,24,22))

p=10;lambda=50



ite=10000

Y=data$y;X=as.matrix(data[,colnames(data) %in% c("x1","x2")])

X=t((t(X)-apply(X,2,mean))/apply(X,2,sd))

A=cbind(rep(1,nrow(X)),X)

x=rep(1,ncol(A))

z=x;guzai=rep(0,ncol(A))

eta=0.0001;

for(j in 1:ite){

vec=x  

for(i in 1:length(x)){

x_sub=vec;x_sub[i]=x_sub[i]+0.01

dx1=sum((Y-A%*%x_sub)^2)+p*sum((x_sub-z+u)^2)

dx2=sum((Y-A%*%x)^2)+p*sum((x-z+u)^2)

x[i]=x[i]-eta*(dx1-dx2)/0.01

}  

vec=z

for(i in 1:length(z)){

z_sub=vec;z_sub[i]=z_sub[i]+0.01

dz1=lambda*sum(abs(z_sub))+p*sum((x-z_sub+u)^2)

dz2=lambda*sum(abs(z))+p*sum((x-z+u)^2)

z[i]=z[i]-eta*(dz1-dz2)/0.01

}

guzai=guzai+p*(x-z);u=guzai/p  

cost=sum((Y-A%*%x)^2)+lambda*sum(abs(z))+p*sum((x-z+u)^2)/2

print(cost)

}


kozakai-ryouta
自身で実装することに生きがいを感じています。 ここは自身の作成プログラムメモです。 作りが粗いものもあるかもしれません(笑)
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away