
/*
 * Copyright (1987) Jeff Elman.  University of California, San Diego
 * This software may be redistributed without charge; this notice
 * should be preserved.
 */

#include  "defs.h"

constrain_weights() {
	extern	struct constraint constraints[];
	extern	float **weightp;
	extern	int numtotal;
	register float **wp;
	register struct constraint *csp;
	register int i;
	register int j;
	float	sum;
	float	av;
	int	t1, t2; 
	float	*t3;

	/*
	 * go thru contraint matrix and change all constrained weights
	 * to be average of the weights * in the constraint group
	 */
	wp = weightp;
	for (i=0, csp=constraints; i<256; i++, csp++) {
		if (csp->num == 0)
			continue;
		sum = av = 0.0;
		for (j=0; j<csp->num; j++) {
			t1 = csp->up[j].from;
			t2 = csp->up[j].to;
			t3 = *(wp+t1)+t2;
			sum += *t3;
			/*
			sum += *(*(wp+csp->up[j].from)+csp->up[j].to);
			 */
		}
		av = sum/csp->num;
		for (j=0; j<csp->num; j++) {
			t1 = csp->up[j].from;
			t2 = csp->up[j].to;
			t3 = *(wp+t1)+t2;
			*t3 = av;
		}
	}
}
