Displaying 1 result from an estimated 1 matches for "sample_m".
Did you mean:
sample_1
2009 Jul 23
1
Help with Loop!
...or your help!
## Generate a linearly separable data set in R2
sample <- as.data.frame(cbind(runif(n=100),runif(n=100)))
sample$Y <- ifelse(sample$V1>sample$V2,1,-1)
## Plot data;
attach(sample)
plot(V1, V2, type="p", pch=Y,main="Sample Data")
##Perceptron algorithm
sample_m <- as.matrix(sample)
w <- c(0,0); b <- 0; k <- 0; nu <- 1e-3
R <- max(sqrt(V1^2+V2^2))
repeat {
for (i in 1:nrow(sample_m)){
if (sample_m[i,3]*(t(w)%*%sample_m[i,1:2] + b) <= 0)
w <- w + nu*sample_m[i,3]*sample_m[i,1:2]
b <- b +nu*sample_m[i,3]*...