// Neuron class : a very simple neuron model
// by Yoonsuck Choe <yschoe@cs.utexas.edu>
// Fri Apr  4 05:01:50 CST 1997

import java.util.Random ;

public class Neuron {
  public int   input_dimension;
  public float afferent[];
  public float activity;

  // constructor
  public Neuron() { 
	this(0);
  }

  // constructor with argument
  public Neuron(int n) { 
	input_dimension = n;
	activity = 0;
  }

  // Allocate and initialize afferent weight vector.
  // This function MUST be called at least once in the 
  // beginning to allocate and setup the afferent weights
  public void setup_afferents(int n, int size, int x, int y) {
	input_dimension = n;
	// System.out.println("Okay, i'm in setup_aff");
	afferent = new float [input_dimension];
	for (int i=0; i<input_dimension; ++i)
	{
		// afferent[i] = (i==0) ? x: y; 
		afferent[i] = (float)size * (float) Math.random(); 
	}
  }

  // calculate weighted sum and set this.activity, return that value
  public float weighted_sum(float input[]) {
	activity = (float) 0.0;
 	for (int i=0; i<input_dimension; ++i)
	{
	   activity += afferent[i] * input[i];
	}
	return activity;
  }

  // calculate euclidian distance and set this.activity, return that value
  public float euclidian_distance(float input[]) {
	activity = (float) 0.0;
 	for (int i=0; i<input_dimension; ++i)
	{
	   activity += (afferent[i]-input[i])*(afferent[i]-input[i]);
	}
	return (float) Math.sqrt(activity);
  }

  // modify weights (using delta rule)
  public void delta_rule(float update_rate, float input[]) {
 	for (int i=0; i<input_dimension; ++i)
	{
	   afferent[i] +=  update_rate * (input[i] - afferent[i]);
	}
		
  }		
}
