double neuron_function_output(Neuron* neuron, Vector* input){ #if REGRESSION double output = output_function(activation_function_lin(propagation_function(neuron, input))); // double denormalised_output = // (MAX_VALUES_INPUT[DIMENSION_INPUT]*(output + 1.0) - MIN_VALUES_INPUT[DIMENSION_INPUT]*(output - 1.0))/2.0; neuron->stored_output = output; return output; #elif CLASSIFICATION double rounded_output = (output->scalars[0] >= 0)? 1.0 : -1.0; neuron->stored_output = rounded_output; return rounded_output; #endif }
/***************************************************************************************** * Advance the state of this FMU from the current communication point to that point plus * the specified step size. * @param c The FMU. * @param currentCommunicationPoint The time at the start of the step interval. * @param communicationStepSize The width of the step interval. * @param noSetFMUStatePriorToCurrentPoint True to assert that the master will not subsequently * restore the state of this FMU or call fmiDoStep with a communication point less than the * current one. An FMU may use this to determine that it is safe to take actions that have side * effects, such as printing outputs. This FMU ignores this argument. * @return fmi2Discard if the FMU rejects the step size, otherwise fmi2OK. */ fmi2Status fmiDoStep(fmi2Component c, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) { ModelInstance* component = (ModelInstance *) c; // If current time is greater than period * (value + 1), then it is // time for another increment. double endOfStepTime = currentCommunicationPoint + communicationStepSize; double targetTime = TICK_PERIOD * (component->currentCount + 1); if (endOfStepTime >= targetTime - EPSILON) { // It is time for an increment. // Is it too late for the increment? if (endOfStepTime > targetTime + EPSILON) { // Indicate that the last successful time is // at the target time. component->lastSuccessfulTime = targetTime; fflush(stdout); return fmi2Discard; } // We are at the target time. Are we // ready for the increment yet? Have to have already // completed one firing at this time. if (component->atBreakpoint) { // Not the first firing. Go ahead an increment. component->currentCount++; input_function(component->controller,component->input,component->dInput); transition_function(component->controller); output_function(component->controller,component->output); // Reset the indicator that the increment is needed. component->atBreakpoint = fmi2False; } else { // This will complete the first firing at the target time. // We don't want to increment yet, but we set an indicator // that we have had a firing at this time. fflush(stdout); component->atBreakpoint = fmi2True; } } component->lastSuccessfulTime = endOfStepTime; fflush(stdout); return fmi2OK; }
//process the current window, and advance to the next one. //Returns a negative number on a failure, a zero when there are still more windows to go, and a 1 when done. static inline int process_window(ctr_crypto_interface *io, write_window *window, size_t sector_size, size_t block_size, void (*input_function)(void *io, void *buffer, uint64_t block, size_t block_count), void (*output_function)(void *io, void *buffer, uint64_t block, size_t block_count)) { //FIXME what if we try to read more than there is disk? Return zeros? size_t sectors_to_read = (window->window_size - window->window_offset) / sector_size; int res = ctr_io_read_sector(io->lower_io, window->window + window->window_offset, window->window_size - window->window_offset, window->current_sector, sectors_to_read); if (res) return -1; size_t block_start_offset = window->block_offset; uint8_t *pos = window->window + block_start_offset; size_t amount_to_copy = window->window_size - window->window_offset; if (amount_to_copy > window->buffer_size - window->buffer_offset) amount_to_copy = window->buffer_size - window->buffer_offset; //In the case that blocks are aligned to sectors, this is not necessary... FIXME //only process parts that won't be overwritten completely // from block_start_offset to window->window_offset size_t blocks_to_process = CEIL(window->window_offset - block_start_offset, block_size); if (!blocks_to_process) blocks_to_process = 1; output_function(io, pos, window->block, blocks_to_process); //now copy data from buffer memcpy(window->window + window->window_offset, window->buffer + window->buffer_offset, amount_to_copy); window->buffer_offset += amount_to_copy; blocks_to_process = CEIL(amount_to_copy + window->window_offset - block_start_offset, block_size); input_function(io, pos, window->block, blocks_to_process); //We need to write out the full blocks processed actually, not just the sectors size_t sectors_processed = (amount_to_copy + window->window_offset) / sector_size; size_t sectors_to_copy = CEIL(blocks_to_process * block_size, sector_size); res = ctr_io_write_sector(io->lower_io, window->window, sectors_to_copy * sector_size, window->sector); if (res) return -2; //Copy sector that contain part of next block update_window(window, sectors_processed); return window->buffer_offset >= window->buffer_size; }
/***************************************************************************************** * Initialize the FMU for co-simulation. * @param c The FMU. * @param relativeTolerance Suggested (local) tolerance in case the slave utilizes a * numerical integrator with variable step size and error estimation (ignored by this FMU). * @param tStart The start time (ignored by this FMU). * @param stopTimeDefined fmi2True to indicate that the stop time is defined (ignored by this FMU). * @param tStop The stop time (ignored if stopTimeDefined is fmi2False) (ignored by this FMU). * @return fmi2OK */ fmi2Status fmiInitializeSlave(fmi2Component c, fmi2Real relativeTolerance, fmi2Real tStart, fmi2Boolean stopTimeDefined, fmi2Real tStop) { ModelInstance* component = (ModelInstance *) c; printf("%s: Invoked fmiIntializeSlave: start: %g, StopTimeDefined: %d, tStop: %g..\n", component->instanceName, tStart, stopTimeDefined, tStop); fflush(stdout); component->lastSuccessfulTime = tStart; component->atBreakpoint = fmi2False; init_controller(component->controller); printf("successful init controller\n"); fflush(stdout); output_function(component->controller,component->output); return fmi2OK; }
int main(int argc, char **argv) { FILE *infile = stdin; char tmp[4096]; #ifdef __mc68000__ if(system("perl machdep/cpuopti")==-1) { perror("perl machdep/cpuopti"); return 10; } else return 0; #endif /* For debugging... */ if (argc == 2) infile = fopen (argv[1], "r"); for(;;) { char *s; if ((fgets(tmp, 4095, infile)) == NULL) break; s = strchr (tmp, '\n'); if (s != NULL) *s = 0; if (strncmp(tmp, ".globl op_", 10) == 0) { struct line *first_line = NULL, *prev = NULL; struct line **nextp = &first_line; struct func f; int nr_rets = 0; int can_opt = 1; do { struct line *current; if (strcmp (tmp, "#APP") != 0 && strcmp (tmp, "#NO_APP") != 0) { current = *nextp = (struct line *)malloc(sizeof (struct line)); nextp = ¤t->next; current->prev = prev; prev = current; current->next = NULL; current->delet = 0; current->data = strdup (tmp); if (match (current, "movl %esp,%ebp") || match (current, "enter")) { fprintf (stderr, "GCC failed to eliminate fp: %s\n", first_line->data); can_opt = 0; } if (match (current, "ret")) nr_rets++; } if ((fgets(tmp, 4095, infile)) == NULL) oops(); s = strchr (tmp, '\n'); if (s != NULL) *s = 0; } while (strncmp (tmp,".Lfe", 4) != 0); f.first_line = first_line; f.last_line = prev; if (nr_rets == 1 && can_opt) do_function(&f); /*else fprintf(stderr, "Too many RET instructions: %s\n", first_line->data);*/ output_function(&f); } printf("%s\n", tmp); } return 0; }
double neuron_function_hidden(Neuron* neuron, Vector* input){ double output = output_function(activation_function_tanh(propagation_function(neuron, input))); neuron->stored_output = output; return output; }
static int internal_nprintf(void (*output_function)(char c), const char *fmt, va_list ap) { unsigned int width; unsigned int flags; unsigned int base = 0; char *ptr = NULL; outlength = 0; while (*fmt) { while (1) { if (*fmt == 0) goto end; if (*fmt == '%') { fmt++; if (*fmt != '%') break; } output_function(*fmt++); } flags = 0; width = 0; /* read all flags */ do { if (flags < FLAG_WIDTH) { switch (*fmt) { case '0': flags |= FLAG_ZEROPAD; continue; case '-': flags |= FLAG_LEFTADJ; continue; case ' ': flags |= FLAG_BLANK; continue; case '+': flags |= FLAG_FORCESIGN; continue; } } if (flags < FLAG_LONG) { if (*fmt >= '0' && *fmt <= '9') { unsigned char tmp = *fmt - '0'; width = 10*width + tmp; flags |= FLAG_WIDTH; continue; } if (*fmt == 'h') continue; if (*fmt == 'l') { flags |= FLAG_LONG; continue; } } break; } while (*fmt++); /* Strings */ if (*fmt == 'c' || *fmt == 's') { switch (*fmt) { case 'c': buffer[0] = va_arg(ap, int); ptr = buffer; break; case 's': ptr = va_arg(ap, char *); break; } goto output; } /* Numbers */ switch (*fmt) { case 'u': flags |= FLAG_UNSIGNED; case 'd': base = 10; break; case 'o': base = 8; flags |= FLAG_UNSIGNED; break; case 'p': // pointer output_function('0'); output_function('x'); width -= 2; case 'x': base = 16; flags |= FLAG_UNSIGNED; break; } unsigned int num; if (!(flags & FLAG_UNSIGNED)) { int tmp = va_arg(ap, int); if (tmp < 0) { num = -tmp; flags |= FLAG_NEGATIVE; } else num = tmp; } else {