void FFNet_PatternList_drawActivation (FFNet me, PatternList pattern, Graphics g, long index) { if (index < 1 || index > pattern->ny) { return; } FFNet_propagate (me, pattern->z[index], nullptr); FFNet_drawActivation (me, g); }
autoCategories FFNet_Pattern_to_Categories (FFNet me, Pattern thee, int labeling) { try { if (! my outputCategories) { Melder_throw (U"The FFNet has no output categories."); } if (my nInputs != thy nx) { Melder_throw (U"The number of colums in the Pattern (", thy nx, U") should equal the number of inputs in the FFNet (", my nInputs, U")."); } if (! _Pattern_checkElements (thee)) { Melder_throw (U"All Pattern elements must be in the interval [0, 1].\nYou could use \"Formula...\" to scale the Pattern values first."); } autoCategories him = Categories_create (); for (long k = 1; k <= thy ny; k++) { FFNet_propagate (me, thy z[k], nullptr); long index = FFNet_getWinningUnit (me, labeling); autoDaata item = Data_copy ((Daata) my outputCategories -> item[index]); Collection_addItem_move (him.peek(), item.move()); } return him; } catch (MelderError) { Melder_throw (me, U": no Categories created."); } }
Categories FFNet_Pattern_to_Categories (FFNet me, Pattern thee, int labeling) { try { if (my outputCategories == 0) { Melder_throw (U"The FFNet has no output categories."); } if (my nInputs != thy nx) Melder_throw (U"The number of colums in the Pattern (", thy nx, U") should equal the number of inputs in the FFNet (", my nInputs, U")."); if (! _Pattern_checkElements (thee)) Melder_throw (U"The elements in the Pattern are not all in the interval [0, 1].\n" U"The input of the neural net can only process values that are between 0 and 1.\n" U"You could use \"Formula...\" to scale the Pattern values first."); autoCategories him = Categories_create (); for (long k = 1; k <= thy ny; k++) { FFNet_propagate (me, thy z[k], 0); long index = FFNet_getWinningUnit (me, labeling); autoDaata item = Data_copy ( (Daata) my outputCategories -> item[index]); Collection_addItem (him.peek(), item.transfer()); } return him.transfer(); } catch (MelderError) { Melder_throw (me, U": no Categories created."); } }
void FFNet_propagateToLayer (FFNet me, const double input[], double activity[], long layer) { long i, k = 0; Melder_assert (activity); FFNet_propagate (me, input, NULL); for (i = 0; i < layer; i++) k += my nUnitsInLayer[i] + 1; for (i = 1; i <= my nUnitsInLayer[layer]; i++) activity[i] = my activity[k+i]; }
void FFNet_propagateToLayer (FFNet me, const double input[], double activity[], long layer) { Melder_assert (activity); long k = 0; FFNet_propagate (me, input, nullptr); for (long i = 0; i < layer; i++) { k += my nUnitsInLayer[i] + 1; } for (long i = 1; i <= my nUnitsInLayer[layer]; i++) { activity[i] = my activity[k + i]; } }
double FFNet_Pattern_Activation_getCosts_total (FFNet me, Pattern p, Activation a, int costFunctionType) { try { _FFNet_Pattern_Activation_checkDimensions (me, p, a); FFNet_setCostFunction (me, costFunctionType); double cost = 0; for (long i = 1; i <= p -> ny; i++) { FFNet_propagate (me, p -> z[i], NULL); cost += FFNet_computeError (me, a -> z[i]); } return cost; } catch (MelderError) { return NUMundefined; } }
static double func (Daata object, const double p[]) { FFNet me = (FFNet) object; Minimizer thee = my minimizer; double fp = 0; for (long j = 1, k = 1; k <= my nWeights; k++) { my dw[k] = 0.0; if (my wSelected[k]) { my w[k] = p[j++]; } } for (long i = 1; i <= my nPatterns; i++) { FFNet_propagate (me, my inputPattern[i], NULL); fp += FFNet_computeError (me, my targetActivation[i]); FFNet_computeDerivative (me); /* derivative (cumulative) */ for (long k = 1; k <= my nWeights; k++) { my dw[k] += my dwi[k]; } } thy funcCalls++; return fp; }