Commit e5849ef7 authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Use a true random initialization for the weights

parent 5522472e
......@@ -37,14 +37,14 @@ main (int argc, char *argv[])
parse_options (argc, argv);
perceptron =
tarot_perceptron_alloc (n_hidden_layers, hidden_sizes, learning_rate);
/* Initial weights are too low */
/* Initial weights are not initialized correctly */
tarot_perceptron_save_alloc (perceptron, &n_weights, &weights);
for (i = 0; i < n_weights; i++)
{
/* We also need to add some random noise, because the
* initialization is weak */
double mini = 800;
double maxi = 1200;
double mini = -2;
double maxi = 2;
size_t random_n;
size_t random_max = (size_t) (-1);
uint8_t random_data[sizeof (random_n)];
......@@ -52,7 +52,7 @@ main (int argc, char *argv[])
yarrow256_random (&generator, sizeof (random_data), random_data);
memcpy (&random_n, random_data, sizeof (random_data));
t = ((double) random_n) / ((double) random_max);
weights[i] *= (mini * (1 - t) + maxi * t);
weights[i] = (mini * (1 - t) + maxi * t);
}
tarot_perceptron_load (perceptron, 0, n_weights, weights);
free (weights);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment