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."); } }
Categories FFNet_Activation_to_Categories (FFNet me, Activation activation, int labeling) { Categories thee = NULL, categories = my outputCategories; long i, (*labelingFunction) (I, const double act[]); if (! my outputCategories) { (void) Melder_error1 (L"FFNet & Activation: To Categories\n"); return Melder_errorp1 (L"The neural net has no Categories (has the FFNet been trained yet?)."); } if (my nOutputs != activation->nx) { (void) Melder_error1 (L"FFNet & Activation: To Categories\n"); return Melder_errorp1 (L"The number of columns in the Activation must equal the number of outputs of FFNet."); } thee = Categories_create (); if (thee == NULL) return NULL; labelingFunction = labeling == 2 ? stochastic : winnerTakesAll; for (i = 1; i <= activation->ny; i++) { long index = labelingFunction (me, activation->z[i]); Data item = Data_copy (categories->item[index]); if (item == NULL || ! Collection_addItem (thee, item)) { forget (thee); return Melder_errorp3 (L"FFNet & Activation: To Categories\n\nError creating label ", Melder_integer (i), L"."); } } return thee; }
static void CategoriesEditorCommand_init (CategoriesEditorCommand me, const char32 *name, Thing boss, Command_Callback execute, Command_Callback undo, int /*nCategories*/, int nSelected) { my nSelected = nSelected; Command_init (me, name, boss, execute, undo); my categories = Categories_create(); my selection = NUMvector<long> (1, nSelected); }
autoCategories ResultsMFC_to_Categories_responses (ResultsMFC me) { try { autoCategories thee = Categories_create (); for (long trial = 1; trial <= my numberOfTrials; trial ++) { autoSimpleString category = SimpleString_create (my result [trial]. response); thy addItem_move (category.move()); } return thee; } catch (MelderError) { Melder_throw (me, U": responses not converted to Categories."); } }
Categories ResultsMFC_to_Categories_responses (ResultsMFC me) { try { autoCategories thee = Categories_create (); for (long trial = 1; trial <= my numberOfTrials; trial ++) { autoSimpleString category = SimpleString_create (my result [trial]. response); Collection_addItem (thee.peek(), category.transfer()); } return thee.transfer(); } catch (MelderError) { Melder_throw (me, U": responses not converted to Categories."); } }
autoCategories OrderedOfString_to_Categories (OrderedOfString me) { try { autoCategories thee = Categories_create(); for (long i = 1; i <= my size; i++) { autoSimpleString item = Data_copy ( (SimpleString) my item [i]); Collection_addItem_move (thee.peek(), item.move()); } return thee; } catch (MelderError) { Melder_throw (me, U": not converted to Categories."); } }
autoCategories TableOfReal_to_CategoriesColumn (TableOfReal me) { try { autoCategories thee = Categories_create (); for (long i = 1; i <= my numberOfColumns; i++) { if (my columnLabels[i]) { autoSimpleString s = SimpleString_create (my columnLabels[i]); Collection_addItem_move (thee.peek(), s.move()); } } return thee; } catch (MelderError) { Melder_throw (me, U": columnlabels not converted to Categories."); } }
Categories ClassificationTable_to_Categories_maximumProbability (ClassificationTable me) { try { autoCategories thee = Categories_create (); for (long i = 1; i <= my numberOfRows; i++) { double max = my data[i][1]; long col = 1; for (long j = 2; j <= my numberOfColumns; j++) { if (my data[i][j] > max) { max = my data[i][j]; col = j; } } OrderedOfString_append (thee.peek(), my columnLabels[col]); } return thee.transfer(); } catch (MelderError) { Melder_throw (me, U": no Categories created."); } }
autoCategories FFNet_Activation_to_Categories (FFNet me, Activation activation, int labeling) { try { long (*labelingFunction) (FFNet me, const double act[]); if (! my outputCategories) { Melder_throw (U"No Categories (has the FFNet been trained yet?)."); } if (my nOutputs != activation -> nx) { Melder_throw (U"Number of columns and number of outputs must be equal."); } autoCategories thee = Categories_create (); labelingFunction = labeling == 2 ? stochastic : winnerTakesAll; for (long i = 1; i <= activation->ny; i++) { long index = labelingFunction (me, activation -> z[i]); autoSimpleString item = Data_copy (my outputCategories->at [index]); thy addItem_move (item.move()); } return thee; } catch (MelderError) { Melder_throw (me, U": no Categories created."); } }
WORD (L"Name", L"1x1") NATURAL (L"Dimension of a pattern", L"1") NATURAL (L"Number of patterns", L"1") OK DO praat_new (Pattern_create (GET_INTEGER (L"Number of patterns"), GET_INTEGER (L"Dimension of a pattern")), GET_STRING (L"Name")); END /**************** New Categories ***************************/ FORM (Categories_create, L"Create Categories", L"") WORD (L"Name", L"empty") OK DO praat_new (Categories_create (), GET_STRING (L"Name")); END DIRECT (FFNet_help) Melder_help (L"Feedforward neural networks"); END DIRECT (FFNet_getMinimum) LOOP { iam (FFNet); Melder_information (Melder_double (FFNet_getMinimum (me))); } END FORM (FFNet_reset, L"FFNet: Reset", L"FFNet: Reset...") LABEL (L"", L"Warning: this command destroys all previous learning.") LABEL (L"", L"New weights will be randomly chosen from the interval [-range, +range].") POSITIVE (L"Range", L"0.1")