/*************************************************** Starter code for CS182 Assignment 4: Backpropagation Unit.java **************************************************/ import java.util.*; /** * Unit is the basic unit of a neural network. */ public class Unit { // Unit attributes // The following Unit attributes are suggested starting points // for the assignment. You may wish to modify them as necessary // for your particular implementation. Vector in; // input Units for this Unit Vector out; // output Units for this Unit double[] inWeights; // current (input) weights for this Unit // I.E. inWeights[1] is the weight from the in[1] unit. double activation; // this unit's activation level double error; // this unit's error double delta; // this unit's delta double[] weightChange; // weight changes for each weight double[] weightChangeMomentum; int index; // index number for this Unit Net net; // network this unit belongs to /** * Constructor for Unit class. Takes an index number and Net to which Unit * belongs. * */ public Unit() { in = new Vector(); out = new Vector(); } public void addIncomingUnit(Unit inUnit) { this.in.add(inUnit); } public void setOutgoingUnit(Unit outUnit) { this.out.add(outUnit); } /** * initalize() Randomize all incoming weights between the network's minimum * and maximum weights, including bias weights. */ public void initialize() { activation = 0; inWeights = new double[in.size()]; weightChange = new double[in.size()]; weightChangeMomentum = new double[in.size()]; for (int i=0; i