Professional Documents
Culture Documents
java
import java.applet.*;
import java.util.*;
import java.awt.*;
import java.net.*;
import java.io.*;
theta = 0.5;
phi = 0.5;
momentum = 0.995;
NCITY = cscroll.getValue()/10;
NGEONEURON = NCITY*2;
gn = new geoNeuron[NGEONEURON];
r = new double[NGEONEURON][NGEONEURON];
makeR(theta);
counter = 0;
r[i][i]= 1.0;
r[j][i] = r[i][j];
counter++;
idx = (int)(Math.random()*NCITY);
x1 = city[idx].x+(Math.random()*NEAR)-NEAR/2;
x2 = city[idx].y+(Math.random()*NEAR)-NEAR/2;
city[idx].choose++;
mindist = 100000.0;
j = -1;
mindist = d;
j = i;
gn[j].update++;
phi *= momentum;
theta *= momentum;
makeR(theta);
count = (count++)%10;
if(count==0){
paint(this.getGraphics());
try {Thread.sleep(10);}
} } animator = null; }
cscroll.setLineIncrement(10);
cscroll.setPageIncrement(10);
add(cscroll);
kohonenInit();
g.setColor(bkC);
g.fillRect(0, 0, w, h);
g.setColor(bk2C);
g.drawLine(toXReal(0.0),toYReal(i),toXReal(COUNTRY),toYReal(i));
g.drawLine(toXReal(i),toYReal(0.0),toXReal(i),toYReal(COUNTRY)); }
g.setColor(lnC);
g.drawLine( toXReal(gn[i].wx),toYReal(gn[i].wy),toXReal(gn[(i+1)%NGEONEURON].wx),toYReal(gn[(i+1)%
NGEONEURON].wy));
g.drawString(""+i+"-"+(gn[i].update*100/counter)+"%",toXReal(gn[i].wx),toYReal(gn[i].wy)); }
g.setColor(fgC);
}}
g.fillRect(0, 0, w, h);
g.setFont(sF);
g.setColor(fgC);
g.setColor(ln2C);
g.drawLine( to2XReal(gn[i].x),to2YReal(gn[i].y),to2XReal(gn[j].x),to2YReal(gn[j].y));
g.drawString(""+r[i]
[j],to2XReal((gn[i].x+gn[j].x)/2),to2YReal((gn[i].y+gn[j].y)/2));
}
g.setFont(mF);
g.setColor(fgC);
g.drawString("phi="+phi+" theta="+theta,to2XReal(0.0),to2YReal(0.0)+20);
imagewidth = w;
imageheight = h;
Graphics g1 = this.getGraphics();
g1.drawImage(offscreen, 0, 0, this);
//Rectangle(to2XReal(0),to2YReal(0),to2XReal(COUNTRY),to2YReal(COUNTRY));
clip = null;
goff = null;
g1 = null;
System.gc();
g.setColor(bkC);
g.fillRect(w/2+30,0,w/2+130, 20);
g.setColor(fgC);
g.drawString("# of city:"+cscroll.getValue()/10,w/2+30,20);
animator.start();
animator = null;
if (animator != null){
please_stop = true;
}else{
please_stop = false;
animator = new Thread(this);
kohonenInit();
animator.start();
} return true;
City.java
this.x = x;
this.y = y;
update = 0;
choose = 0;
geoNeuron.java
this.wx = Math.random();
this.wy = Math.random();
update = 0;
choose = 0;