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

#include <stdio.h>
#include <math.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/types.h>
#ifdef X
#include "X/box.h"
#endif
#include "defs.h"

activate_net()
{
	extern int nlayers;
	extern int linflag;
	extern int array;
	extern int *layer_descp;
	extern float noise;
	extern float **layerp;
	extern float **weightp;
	extern float **deltap;
	extern float **biasp;
	register int i;
	float **wp;
	float **bp;
	float **lp;
	int    *ldp;

	/*
	 * do activation differently depending on
	 * how the network was originally configured
	 */
	if (array == 1) {
		activate2();
	} else if (array == 0) {
		wp = weightp;
		lp = layerp;
		ldp = layer_descp;
		bp = biasp;

		for (i = 0; i < (nlayers - 1); i++) {
			if (i == 0) {
				activate1(*lp, *ldp, *(lp + 1), *(ldp + 1), *wp, *(bp + 1), noise, NONLINEAR);
			} else if (i == (nlayers - 2) && (linflag == LINEAR)) {
				activate1(*lp, *ldp, *(lp + 1), *(ldp + 1), *wp, *(bp + 1), 0.0, LINEAR); 
			} else {
				activate1(*lp, *ldp, *(lp + 1), *(ldp + 1), *wp, *(bp + 1), 0.0, NONLINEAR);
			}
			ldp++;
			lp++;
			wp++;
			bp++;
		}
	}
}
