📄 computegng.java
字号:
// ========================================================================== ;// ;// Copyright (1996-1998) Hartmut S. Loos ;// ;// Institut f"ur Neuroinformatik ND 03 ;// Ruhr-Universit"at Bochum ;// 44780 Bochum ;// ;// Tel : +49 234 7007845 ;// Email: Hartmut.Loos@neuroinformatik.ruhr-uni-bochum.de ;// ;// For version information and parameter explanation have a look at ;// the file 'DemoGNG.java'. ;// ;// ========================================================================== ;// ;// Copyright 1996-1998 Hartmut S. Loos ;// ;// This program is free software; you can redistribute it and/or modify ;// it under the terms of the GNU General Public License as published by ;// the Free Software Foundation; either version 1, or (at your option) ;// any later version. ;// ;// This program is distributed in the hope that it will be useful, ;// but WITHOUT ANY WARRANTY; without even the implied warranty of ;// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;// GNU General Public License for more details. ;// ;// You should have received a copy of the GNU General Public License ;// along with this program; if not, write to the Free Software ;// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ;// ;// ========================================================================== ;import java.awt.*;/** * A class which implements the algorithms. * This class is an overkill. It implements many functions/algorithms. * The most important method is 'learn()' which implements the different * methods. * */class ComputeGNG extends Panel implements Runnable { /** * The flag for debugging. */ protected final boolean DEBUG = false; /** * The maximum number of elements to draw/calculate for the distributions. */ protected final int MAX_COMPLEX = 58; /** * The maximum number of nodes. */ protected final int MAX_NODES = 250; /** * The maximum number of edges (3 * maximum number of nodes). */ protected final int MAX_EDGES = 3 * MAX_NODES; /** * The maximum number of Voronoi lines (5 * maximum number of nodes). */ protected final int MAX_V_LINES = 6 * MAX_NODES; /** * The maximum stepsize. */ protected final int MAX_STEPSIZE = 200; /** * The maximum number of discrete signals. */ protected final int MAX_DISCRETE_SIGNALS = 500; /** * The maximum x size of the grid array. */ protected final int MAX_GRID_X = 30; /** * The maximum y size of the grid array. */ protected final int MAX_GRID_Y = 15; /** * The number of errors added for the mean square error. */ protected final int NUM_GLOBAL_GRAPH = 500; /** * The factor for the ring-thickness (distribution). */ protected final float RING_FACTOR = 0.4f; // Factor < 1 /** * The version of the Growing Neural Gas Demo. */ protected final String DGNG_VERSION = "v1.5"; /** * The current maximum number of nodes. */ protected int maxNodes = 100; /** * The current number of runs to insert a new node (GNG). */ protected int NUM_NEW_NODE = 600; /** * The current number of runs. */ protected int numRun = 0; /** * The temporal backup of a run. */ protected int numRunTmp = 0; /** * The x-position of the actual signal. */ protected int SignalX = 0; /** * The y-position of the actual signal. */ protected int SignalY = 0; /** * The initial width of the drawing area. * This value can only be changed by resizing the appletviewer. */ protected int INIT_WIDTH = 550; /** * The initial height of the drawing area. * This value can only be changed by resizing the appletviewer. */ protected int INIT_HEIGHT = 310; protected DemoGNG graph; /** * The actual number of nodes. */ protected int nnodes = 0; /** * The array of the actual used nodes. */ protected NodeGNG nodes[] = new NodeGNG[MAX_NODES]; /** * The sorted array of indices of nodes. * The indices of the nodes are sorted by their distance from the actual * signal. snodes[1] is the index of the nearest node. */ protected int snodes[] = new int[MAX_NODES + 1]; /** * This array of sites is sorted by y-coordinate (2nd y-coordinate). * vsites[1] is the index of the bottom node. */ protected SiteVoronoi vsites[] = new SiteVoronoi[MAX_NODES + 1]; /** * The array of the nodes in the grid. */ protected GridNodeGNG grid[][] = new GridNodeGNG[MAX_GRID_X][MAX_GRID_Y]; /** * The array of the last computed signals (x-coordinate). */ protected float lastSignalsX[] = new float[MAX_STEPSIZE]; /** * The array of the last computed signals (y-coordinate). */ protected float lastSignalsY[] = new float[MAX_STEPSIZE]; /** * The array of the discrete signals (x-coordinate). */ protected int discreteSignalsX[] = new int[MAX_DISCRETE_SIGNALS]; /** * The array of the discrete signals (y-coordinate). */ protected int discreteSignalsY[] = new int[MAX_DISCRETE_SIGNALS]; /** * The array of the best distance (discrete signals). */ protected float discreteSignalsD1[] = new float[MAX_DISCRETE_SIGNALS]; /** * The array of the second best distance (discrete signals). */ protected float discreteSignalsD2[] = new float[MAX_DISCRETE_SIGNALS]; /** * The array of the second best distance (discrete signals). */ protected FPoint Cbest[] = new FPoint[MAX_NODES]; /** * The current number of discrete signals. */ protected int numDiscreteSignals = 500; /** * The actual number of edges. */ protected int nedges = 0; /** * The array of the actual used edges. */ protected EdgeGNG edges[] = new EdgeGNG[MAX_EDGES]; /** * The actual number of Voronoi lines. */ protected int nlines = 0; /** * The array of the actual used lines. */ protected LineGNG lines[] = new LineGNG[MAX_V_LINES]; /** * The array of boolean to distinguish between Voronoi and Delaunay lines. */ protected boolean vd[] = new boolean[MAX_V_LINES]; Thread relaxer; GraphGNG errorGraph; /** * The flag for playing the sound for a new inserted node. */ protected boolean insertedSoundB = false; /** * The flag for a white background. Useful for making hardcopies */ protected boolean whiteB = false; /** * The flag for random init. The nodes will be placed only in the specified * distribution or not. */ protected boolean rndInitB = false; /** * The flag for entering the fine-tuning phase (GG). */ protected boolean fineTuningB = false; /** * The flag for showing the signal. * This variable can be set by the user and shows the last input signals. */ protected boolean signalsB = false; /** * The flag for inserting new nodes. * This variable can be set by the user. If true no new nodes are * inserted (GNG, GG). */ protected boolean noNodesB = false; /** * The flag for stopping the demo. * This variable can be set by the user. If true no calculation is done. */ protected boolean stopB = false; /** * The flag for the sound. * This variable can be set by the user. If false no sound is played. */ protected boolean soundB = false; /** * The flag for the teach-mode. * This variable can be set by the user. If true a legend is displayed * which discribe the new form and color of some nodes. Furthermore * all calculation is very slow. */ protected boolean teachB = false; /** * The flag for variable movement (HCL). * This variable can be set by the user. */ protected boolean variableB = false; /** * The flag for displaying the edges. * This variable can be set by the user. */ protected boolean edgesB = true; /** * The flag for displaying the nodes. * This variable can be set by the user. */ protected boolean nodesB = true; /** * The flag for displaying the error graph. * This variable can be set by the user. */ protected boolean errorGraphB = false; /** * The flag for the global error (more signals). * This variable can be set by the user. */ protected boolean globalGraphB = true; /** * The flag for displaying the Voronoi diagram. * This variable can be set by the user. */ protected boolean voronoiB = false; /** * The flag for displaying the Delaunay triangulation. * This variable can be set by the user. */ protected boolean delaunayB = false; /** * The flag for any moved nodes (to compute the Voronoi diagram/Delaunay * triangulation). */ protected boolean nodesMovedB = true; /** * The flag for using utility (GNG-U). */ protected boolean utilityGNGB = false; /** * The flag for changed number of nodes. */ protected boolean nNodesChangedB = true; /** * The flag for only discrete signals */ protected boolean discreteSigB = true; /** * The flag for LBG-U method */ protected boolean LBG_U_B = false; /** * The flag for end of calculation (LBG) */ protected boolean readyLBG_B = false; /** * The selected distribution. * This variable can be set by the user. */ protected int distribution = 0; /** * The selected algorithm. * This variable can be set by the user. */ protected int algo = 0; /** * The current maximum number to delete an old edge (GNG,NGwCHL). * This variable can be set by the user. */ protected int MAX_EDGE_AGE = 88; /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -