Skip to content

Commit

Permalink
run v fmt -w . in the top of the project
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Jul 29, 2024
1 parent cb8f49b commit aedcbf8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 10 additions & 5 deletions ml/svm.v
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ pub fn train_svm(data []DataPoint, kernel KernelFunction, config SVMConfig) &SVM
continue
}

eta := 2 * model.kernel(data[i].x, data[j].x) - model.kernel(data[i].x, data[i].x) - model.kernel(data[j].x, data[j].x)
eta := 2 * model.kernel(data[i].x, data[j].x) - model.kernel(data[i].x,
data[i].x) - model.kernel(data[j].x, data[j].x)

if eta >= 0 {
continue
Expand All @@ -109,11 +110,16 @@ pub fn train_svm(data []DataPoint, kernel KernelFunction, config SVMConfig) &SVM
continue
}

model.alphas[i] = alpha_i_old + f64(data[i].y * data[j].y) * (alpha_j_old - model.alphas[j])
model.alphas[i] = alpha_i_old +
f64(data[i].y * data[j].y) * (alpha_j_old - model.alphas[j])

b1 := model.b - ei - f64(data[i].y) * (model.alphas[i] - alpha_i_old) * model.kernel(data[i].x, data[i].x) - f64(data[j].y) * (model.alphas[j] - alpha_j_old) * model.kernel(data[i].x, data[j].x)
b1 := model.b - ei - f64(data[i].y) * (model.alphas[i] - alpha_i_old) * model.kernel(data[i].x,
data[i].x) - f64(data[j].y) * (model.alphas[j] - alpha_j_old) * model.kernel(data[i].x,
data[j].x)

b2 := model.b - ej - f64(data[i].y) * (model.alphas[i] - alpha_i_old) * model.kernel(data[i].x, data[j].x) - f64(data[j].y) * (model.alphas[j] - alpha_j_old) * model.kernel(data[j].x, data[j].x)
b2 := model.b - ej - f64(data[i].y) * (model.alphas[i] - alpha_i_old) * model.kernel(data[i].x,
data[j].x) - f64(data[j].y) * (model.alphas[j] - alpha_j_old) * model.kernel(data[j].x,
data[j].x)

if 0 < model.alphas[i] && model.alphas[i] < model.config.c {
model.b = b1
Expand Down Expand Up @@ -219,4 +225,3 @@ pub fn predict_multiclass(model &MulticlassSVM, x []f64) int {

return predicted_class
}

1 change: 0 additions & 1 deletion ml/svm_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,3 @@ fn test_kernels() {
test_predict_multiclass_svm()
}
}

0 comments on commit aedcbf8

Please sign in to comment.