联结神经元问题中优化问题的建立

Set-up of Optimisation Problem in Connectionist Neuron problem

我想建立一个优化程序,根据带有二进制标识符的联结神经元模型,通过在 [-3, 3]$ 中选取值 $\theta_{optimal} 来识别最高预测准确度。由于无法包含乳胶代码,因此我提供了 model/formula 的图像:

假设我已经确定了某个权重向量 $w=(w_1 w_2)^T$。因此,我可以将计算写为

w <- c(0.9396926, 0.3420201)
X <- as.matrix(t(ex[,1:2])) 

# with theta = 0
result <- as.data.frame(sign(t(w %*% X)))
result[result == -1] <- 0
# where result is a df with dimension 15x1, and df$V1 are the predicted y labels 

为了缩短示例代码,我可以详细说明真实标签和预测标签(值)之间的欧式距离,而不是计算预测准确度:

euclidean <- function(a, b){
  sqrt(sum((a - b)^2))
} 
euclidean(as.integer(ex$y) ,result$V1)

因为我从来没有做过这样的事情,所以我不知道如何建立这样一个

的迭代优化过程

如果有人能给我提示,link 类似的设置,或指导我完成一些步骤,我将不胜感激。


示例数据: dput(data[, 1:15])

ex <- structure(list(x.1 = c(0.365, 0.543, -0.401, 0.866, -0.386, -0.443, 
-0.519, 0.332, 0.211, -0.208), x.2 = c(0.708, -0.268, 0.643, 
-0.796, 0.742, 0.615, 0.818, -0.211, -0.237, -0.656), y = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("0", "1"), class = "factor")), row.names = c(NA, 
10L), class = "data.frame")

x.1y.1是各自的坐标,y是已知的真实标签。

我们可以使用 optimize

尝试下面的代码
f <- function(theta) sqrt(sum((as.integer(ex$y) - (t(w %*% X) >= theta))^2))
xmin <- optimize(f, c(-3, 3))

这给出了

> xmin
$minimum
[1] -1.583516

$objective
[1] 0