/* INITIALIZE_PARAMETERS 15dec94 wmt: add params FILE *log_file_fp, FILE *stream, exit for "Too many classes for available data" This is to be applied to a classification which has just had its wts reset. It updates the parameters and does two base-cycle's to assure that the weights and parameters are in approximate agreement. With delete-duplicates, it then eliminates any obvious duplicates. */ int initialize_parameters( clsf_DS clsf, int display_wts, int delete_duplicates, unsigned int initial_cycles_p, FILE *log_file_fp, FILE *stream) { int converge_cycle_p = FALSE; if (clsf->n_classes > clsf_DS_max_n_classes(clsf)) { to_screen_and_log_file("ERROR: too many classes for available data!!!\n", log_file_fp, stream, TRUE); exit(1); } clsf->log_p_x_h_pi_theta = 0.0; update_parameters(clsf); update_ln_p_x_pi_theta(clsf, FALSE); update_approximations(clsf); if (display_wts == TRUE) display_step( clsf, stream); if (initial_cycles_p == TRUE) { base_cycle(clsf, stream, display_wts, converge_cycle_p); if (delete_duplicates == TRUE) while (class_duplicatesp(clsf->n_classes, clsf->classes) == TRUE) { if (stream != NULL) fprintf( stream, "Before class_duplicatesp, n_classes is %d\n", clsf->n_classes); clsf->classes = delete_class_duplicates(&(clsf->n_classes), clsf->classes); if (stream != NULL) fprintf( stream, "After class_duplicatesp, n_classes is %d\n", clsf->n_classes); base_cycle(clsf, stream, display_wts, converge_cycle_p); } } return(clsf->n_classes); }
int main(int ac, char** av) { t_vm* vm = vm_initialize(); t_process* process = (t_process*) malloc(sizeof(t_process)); int32 i; t_display* display; int32 update_display = 0; int32 was_pressed = 0; t_ring_buffer* ring_buffer; ring_buffer = ring_buffer_initialize(10, free); if (load_cores(vm, ac, av) <= 0) return -1; display = display_initialize(800, 600); vm_set_print_callback(vm, main_debug_print, ring_buffer); if (1) { while (vm->process_count && !display_should_exit(display)) { vm->cycle_current++; update_display = 1; int process_count = vm->process_count; for (i = 0; i < process_count; ++i) { t_process* process = vm->processes[i]; if (process->cycle_wait <= 0) { update_display = 0; vm_reset_process_io_op(process); if (process->current_opcode) vm_execute(vm, process); vm_get_opcode(vm, process); } else process->cycle_wait--; } if (vm->cycle_current > vm->cycle_to_die) { vm->cycle_current = 0; vm_kill_process_if_no_live(vm); } vm_clean_dead_process(vm); // update_display = 0; if (display_update_input(display) || update_display == 0) { display_print_ring_buffer(display, 0, 0, ring_buffer); display_step(vm, display); } } } else { int32 execute_one = 0; int32 current_keys_state[GLFW_KEY_LAST]; int32 previous_keys_state[GLFW_KEY_LAST]; memset(previous_keys_state, 0, GLFW_KEY_LAST * sizeof(int32)); memset(current_keys_state, 0, GLFW_KEY_LAST * sizeof(int32)); display_step(vm, display); while (vm->process_count && !display_should_exit(display)) { int32 executed = 0; int32 print_processes; int32 process_count = 0; current_keys_state[GLFW_KEY_S] = display_key_pressed(display, GLFW_KEY_S); current_keys_state[GLFW_KEY_P] = display_key_pressed(display, GLFW_KEY_P); if (!execute_one) execute_one = previous_keys_state[GLFW_KEY_S] && !current_keys_state[GLFW_KEY_S]; print_processes = previous_keys_state[GLFW_KEY_P] && !current_keys_state[GLFW_KEY_P]; memcpy(previous_keys_state, current_keys_state, sizeof(int32) * GLFW_KEY_LAST); if (execute_one) vm->cycle_current++; for (i = 0; i < vm->process_count; ++i) { t_process* process = vm->processes[i]; if (print_processes) vm_debug_print_process(vm, process); if (execute_one) { if (process->cycle_wait <= 0) { vm_reset_process_io_op(process); vm_execute(vm, process); vm_get_opcode(vm, process); executed++; if (vm->live_count >= NBR_LIVE) { vm->live_count = 0; vm->cycle_to_die -= vm->cycle_delta; } } process->cycle_wait--; } } if (executed) execute_one = 0; if (vm->cycle_current > vm->cycle_to_die) { vm->cycle_current = 0; vm_kill_process_if_no_live(vm); } vm_clean_dead_process(vm); executed += display_update_input(display); if (executed) display_step(vm, display); else glfwPollEvents(); } } ring_buffer_destroy(ring_buffer); display_destroy(display); vm_destroy(vm); }