autoActivation FFNet_Categories_to_Activation (FFNet me, Categories thee) {
	try {
		autoCategories uniq = Categories_selectUniqueItems (thee);

		if (! my outputCategories) {
			Melder_throw (U"The FFNet does not have categories.");
		}
		long nl = OrderedOfString_isSubsetOf (uniq.get(), my outputCategories.get(), 0);
		if (nl == 0) {
			Melder_throw (U"The Categories do not match the categories of the FFNet.");
		}

		autoActivation him = Activation_create (thy size, my nOutputs);
		for (long i = 1; i <= thy size; i ++) {
			const char32 *citem = OrderedOfString_itemAtIndex_c (thee, i);
			long pos = OrderedOfString_indexOfItem_c (my outputCategories.get(), citem);
			if (pos < 1) {
				Melder_throw (U"The FFNet doesn't know the category ", citem, U".");
			}
			his z [i] [pos] = 1.0;
		}
		return him;
	} catch (MelderError) {
		Melder_throw (me, U": no Activation created.");
	}
}
Beispiel #2
0
Any Matrix_to_Activation (I)
{
    iam (Matrix); 
    Activation thee = Activation_create (my ny, my nx);
    if (! thee) return NULL;
    NUMdmatrix_copyElements (my z, thy z, 1, my ny, 1, my nx);
    return thee;
}
Beispiel #3
0
autoActivation Matrix_to_Activation (Matrix me) {
	try {
		autoActivation thee = Activation_create (my ny, my nx);
		NUMmatrix_copyElements (my z, thy z, 1, my ny, 1, my nx);
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": not converted to Activation.");
	}
}
Activation FFNet_Categories_to_Activation (FFNet me, Categories thee)
{
	Activation him = NULL; 
	Categories uniq;
	long i, nl, cSize = thy size, hasCategories = 1;
	
	uniq = Categories_selectUniqueItems (thee, 1);
	if (uniq == NULL)  Melder_error1 (L"There is not enough memory to create a Categories."); 
	
	if (my outputCategories == NULL)
	{
		if (my nUnitsInLayer[my nLayers] == uniq -> size)
		{
			my outputCategories = uniq;
			hasCategories = 0;
		}
		else
		{
			(void) Melder_error1 (L"");
			goto end;
		}
	}
	else if (! ( (nl = OrderedOfString_isSubsetOf (uniq, my outputCategories, NULL)) &&
		nl == uniq -> size && my nOutputs >= uniq -> size))
	{
		 (void) Melder_error1 (L"The Categories do not match the categories of the FFNet.");
		goto end;
	}
	
	him = Activation_create (cSize, my nOutputs);
	if (him == NULL) goto end;
	for (i=1; i <= cSize; i++)
	{
		long pos =  OrderedOfString_indexOfItem_c (my outputCategories, OrderedOfString_itemAtIndex_c (thee, i));
		if (pos < 1)
		{
			 (void) Melder_error3 (L"The FFNet doesn't know the category ", OrderedOfString_itemAtIndex_c (thee, i), L" from Categories.");
				goto end;
		}
		his z[i][pos] = 1.0;
	}
	
end:

	if (hasCategories) forget (uniq);
	if (Melder_hasError ()) forget (him);
	
	return him;
}
Activation FFNet_Pattern_to_Activation (FFNet me, Pattern p, long layer) {
	try {
		if (layer < 1 || layer > my nLayers) {
			layer = my nLayers;
		}
		if (my nInputs != p -> nx) Melder_throw (U"The Pattern and the FFNet do not match. "
			        U"The number of colums in the Pattern (", p -> nx, U") should equal the number of inputs "
			        U"in the FFNet (", my nInputs, U").");
		if (! _Pattern_checkElements (p)) Melder_throw
			(U"The elements in the Activation are not all in the interval [0, 1].\n"
			 U"The output units of the neural net can only process values that are between 0 and 1.\n"
			 U"You could use \"Formula...\" to scale the Activation values first.");

		long nPatterns = p -> ny;
		autoActivation thee = Activation_create (nPatterns, my nUnitsInLayer[layer]);

		for (long i = 1; i <= nPatterns; i++) {
			FFNet_propagateToLayer (me, p -> z[i], thy z[i], layer);
		}
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, U": no Activation created.");
	}
}