package neuralnets; /** * * @author Dustin Stevens-baier * * original code implementation from Ahmed Koshok 2004 * */ import java.util.Random; import java.util.ArrayList; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.File; import java.util.Iterator; public class KWTA { private static int N=20; //the number of nodes private double m=0.0; // the minimum activation private double M=1.0; // the maximum activiation private double [][]W; private double []a; private double []updatedActivation; private double threshold = 0.1; //activation must be within .01 of the max or min private double approxMax; private double approxMin; private boolean converged; public KWTA() { W = new double[N][N]; a = new double[N]; updatedActivation = new double[N]; buildConnectionStrengthMatrix(); this.approxMax = M - threshold; this.approxMin = m + threshold; } static int getN() { return N; } private void buildConnectionStrengthMatrix() { for (int i=0; i this.approxMax) || (a[i] < this.approxMin) ) converged = converged & true; else converged = false; } kData.addEnergyData(counter, energyFunction( ext)); } while (converged == false); kData.setFinalActivations(a); } //Calculate the energy private double energyFunction( double ext) { double sum1 = 0; double sum2 = 0; double energy = 0; for (int i=0; i