int cmd_exec(struct command_t* command){ if(error1(command)) return -1; if(error2(command)) return -2; if(error3(command)) return -3; if(error4(command)) return -4; if(error5(command)) return -5; if(isNum(command->token[0])){ command->arg1 = atoi(command->token[0]); strcpy(command->operation, command->token[1]); command->arg2 = atoi(command->token[2]); } else{ strcpy(command->operation, command->token[0]); command->arg1 = atoi(command->token[1]); } DoOperation(command); return 0; }
Distributions Distributions_Transition_map (Distributions me, Transition map) { Distributions thee = NULL; /* * Preconditions: matrix matching. */ if (map -> numberOfStates != my numberOfRows) error5 (L"Number of data (", Melder_integer (map -> numberOfStates), L") in mapping matrix " "does not match number of data (", Melder_integer (my numberOfRows), L") in distribution.") /* * Create the output object. */ thee = (structDistributions *)Data_copy (me); cherror /* * Compute the elements of the surface distributions. */ for (long row = 1; row <= my numberOfRows; row ++) for (long col = 1; col <= my numberOfColumns; col ++) { thy data [row] [col] = 0.0; for (long m = 1; m <= map -> numberOfStates; m ++) thy data [row] [col] += my data [m] [col] * map -> data [m] [row]; } end: iferror { forget (thee); return (structDistributions *)Melder_errorp1 (L"Distributions & Transition: Mapping not performed."); } return thee; }
inline void subMonomial::incrementStart() { #ifdef CAREFUL if (_start + _length > _mono.numberOfFactors()) { error5(); } else #endif { ++start_iterator;++_start; } };
Transition Distributions_to_Transition (Distributions underlying, Distributions surface, long environment, Transition adjacency, int greedy) { if (underlying == NULL) return NULL; Transition thee = NULL; /* * Preconditions: range check and matrix matching. */ if (environment < 1 || environment > underlying -> numberOfColumns) error5 (L"Environment (", Melder_integer (environment), L") out of range (1-", Melder_integer (underlying -> numberOfColumns), L").") if (surface && (underlying -> numberOfColumns != surface -> numberOfColumns || underlying -> numberOfRows != surface -> numberOfRows)) error1 (L"Sizes of underlying and surface distributions do not match.") if (adjacency && adjacency -> numberOfStates != underlying -> numberOfColumns) error5 (L"Number of states (", Melder_integer (adjacency -> numberOfStates), L") in adjacency matrix " "does not match number of distributions (", Melder_integer (underlying -> numberOfColumns), L")") /* * Defaults. */ if (surface == NULL) surface = underlying; /* * Create the output object. */ thee = Transition_create (underlying -> numberOfColumns); cherror /* * Copy labels and set name. */ for (long i = 1; i <= thy numberOfStates; i ++) { thy stateLabels [i] = Melder_wcsdup_e (underlying -> columnLabels [i]); cherror } Thing_setName (thee, underlying -> columnLabels [environment]); cherror /* * Compute the off-diagonal elements of the transition matrix in environment 'environment'. */ for (long i = 1; i <= thy numberOfStates; i ++) { /* * How many states are available for the learner to step to (excluding current state)? */ long numberOfAdjacentStates; if (adjacency) { numberOfAdjacentStates = 0; for (long j = 1; j <= thy numberOfStates; j ++) if (i != j && adjacency -> data [i] [j]) numberOfAdjacentStates ++; } else { numberOfAdjacentStates = thy numberOfStates - 1; } /* * Try all possible steps to adjacent states. */ for (long j = 1; j <= thy numberOfStates; j ++) if (i != j) { /* * Local: grammar step only possible to adjacent grammar. */ if (adjacency && adjacency -> data [i] [j] == 0) continue; /* * Compute element (i, j): sum over all possible data. */ for (long m = 1; m <= underlying -> numberOfRows; m ++) { /* * Error-driven: grammar step only triggered by positive evidence. * If the datum does not conflict with the current hypothesis (i), ignore it. */ if (underlying -> data [m] [i]) continue; /* * Greedy: grammar step only taken if new grammar accepts datum. */ if (greedy && underlying -> data [m] [j] == 0) continue; /* * The step is taken if this datum occurs and this grammar (j) is chosen. */ thy data [i] [j] += surface -> data [m] [environment] / numberOfAdjacentStates; } } } /* * Compute the elements on the diagonal, so that the sum of each row is unity. */ for (long i = 1; i <= thy numberOfStates; i ++) { double sum = 0.0; for (long j = 1; j <= thy numberOfStates; j ++) if (j != i) sum += thy data [i] [j]; thy data [i] [i] = sum > 1.0 ? 0.0 : 1.0 - sum; /* Guard against rounding errors. */ } end: iferror { forget (thee); return (structTransition *)Melder_errorp1 (L"Distributions to Transition: not performed."); } return thee; }