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.");
	}
}