/** * Test of the library */ int main(int argc, char **argv) { double in[32]; double out[12]; int i; mlp_neural_network_t *n; int ls[] = { 16, 512, 8 }; n = mlp_new(ls, 3); n->transf_func = &sigmodial; n->transf_func_derivate = &sigmodial_derivate; mlp_set_learning_rate(n, 0.6); //char string[12]; long long string = 0; //for(i = 0; i < 12; i++) // string[i] = 0; //printf("%d\n", sizeof(string)); for(i = 0; i < 10000; i++) { int j; char md5[16]; string++; //MD5((char *) &string, 8, md5); char string2[32]; strcpy(string2, "ciaooooo"); MD5((char *) &string2, 8, md5); printf("%lld - \n", string); //for(j = 0; j < 16; j++) // printf("%x", (unsigned char) md5[j]); //printf("\n"); str2double((char *) &md5, 16, in); str2double((char *) &string, 8, out); mlp_back_propagate(n, in, out); } // Facciamo un test char test[] = "ciaooooo"; char md5[16]; MD5((char *) &test, 8, md5); str2double((char *) md5, 16, in); mlp_execute(n, in, out); char output_s[20]; double2str(out, 8, output_s); printf("\n\t"); //for(i = 0; i < 8; i++) // printf("'%lf' ", out[i]); //printf("\n"); printf("'%s' - ", output_s); for(i = 0; i < 8; i++) printf("'%c' ", output_s[i]); printf("\n"); mlp_delete(n); return 0; }
/* Create the network */ void new_do_cb() { int i; int l[3]; l[0] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(input_spin)); l[1] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(hidden_spin)); l[2] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(output_spin)); nn = mlp_new(l, 3); nn->transf_func = &heavyside; nn->transf_func_derivate = &heavyside_derivate; nn->learning_rate = gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON(learning_spin)); gtk_mlp_set_network(GTK_MLP(mlp), nn); // Add the input boxes in the main window neural_input = (GtkWidget **) malloc(sizeof(GtkWidget *) * l[0]); neural_output = (GtkWidget **) malloc(sizeof(GtkWidget *) * l[2]); gtk_box_pack_start(GTK_BOX(entry_box),gtk_label_new("Input values"),FALSE,FALSE,0); for(i = 0; i < l[0]; i++) { char str_c[16]; sprintf(str_c, "Neuron %d ", i); GtkWidget *tmp_box = gtk_hbox_new(0, 0); neural_input[i] = gtk_spin_button_new( GTK_ADJUSTMENT( gtk_adjustment_new((nn->input[i]).value, 0.0, 1.0, 0.02, (nn->input)[i].value, 0.1)), 1.0, 2); gtk_box_pack_start(GTK_BOX(tmp_box),gtk_label_new(str_c),FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(tmp_box),neural_input[i],TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(entry_box),tmp_box,FALSE,FALSE,0); gtk_widget_show_all(window); } gtk_box_pack_start(GTK_BOX(entry_box),gtk_label_new("Output values"),FALSE,FALSE,0); for(i = 0; i < l[2]; i++) { char str_c[16]; sprintf(str_c, "Neuron %d ", i); GtkWidget *tmp_box = gtk_hbox_new(0, 0); neural_output[i] = gtk_spin_button_new( GTK_ADJUSTMENT( gtk_adjustment_new((nn->output)[i].value, 0.0, 1.0, 0.02, (nn->output)[i].value, 0.1)), 1.0, 2); gtk_box_pack_start(GTK_BOX(tmp_box),gtk_label_new(str_c),FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(tmp_box),neural_output[i],TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(entry_box),tmp_box,FALSE,FALSE,0); gtk_widget_show_all(window); } gtk_statusbar_push(GTK_STATUSBAR(status_bar), 0, "Network created."); // Destroy the window gtk_widget_destroy(new_w); }
struct mlp * build_mlp (void) { return mlp_new (6, 4, 6, 8, 16, LAYER_MLP_OUTPUT_COUNT); }