MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / train

Function train

examples/machine_learning/perceptron.cpp:33–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33array train(const array &X, const array &Y, double alpha = 0.1,
34 double maxerr = 0.05, int maxiter = 1000, bool verbose = false) {
35 // Initialize parameters to 0
36 array Weights = constant(0, X.dims(1), Y.dims(1));
37
38 for (int i = 0; i < maxiter; i++) {
39 array P = predict(X, Weights);
40 array err = Y - P;
41
42 float mean_abs_err = mean<float>(abs(err));
43 if (mean_abs_err < maxerr) break;
44
45 if (verbose && (i + 1) % 25 == 0) {
46 printf("Iter: %d, Err: %.4f\n", i + 1, mean_abs_err);
47 }
48
49 Weights = Weights + alpha * matmulTN(X, err);
50 }
51
52 return Weights;
53}
54
55void benchmark_perceptron(const array &train_feats, const array &train_targets,
56 const array test_feats) {

Callers 4

benchmark_perceptronFunction · 0.70
perceptron_demoFunction · 0.70
distanceFunction · 0.70
distanceFunction · 0.70

Calls 5

constantFunction · 0.85
matmulTNFunction · 0.85
predictFunction · 0.70
absFunction · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected