⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gensyndb.java

📁 clustering data for the different techniques of data mining
💻 JAVA
字号:
/*
  GenSynDB.java

  Definition of the class GenSynDB which generates
  a collection of partitions from a reference partition
  and saves also the result in a file
  
  (P)2002  Dana Cristofor

*/

/*

GAClust - Clustering categorical databases using genetic algorithms
Copyright (C) 2002  Dana Cristofor


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 2 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA

GAClust was written by Dana Cristofor (dana@cs.umb.edu).

*/

import laur.tools.*;

import javax.swing.*;
import java.util.*;
import java.io.*;

/**
 * GenSynDB
 *
 * @version 	1.0
 * @author	Dana Cristofor
 */
public class GenSynDB extends MonitoredThread
{
  Partition[] db;
  int NROWS;
  int NCOLS;
  int K;
  String fname;
  int dbRandSeed;
  int genLarge;
  int currRowNo;
  JProgressBar GenProgressBar;
  JTextArea LogTextArea;

  /** generates a synthetic database; save results in file
   * <code>fname</code>; the last column in <code>db</code> is the
   * reference partition; <code>NCOLS</code> is the total number of
   * columns, including also the reference partition */
  GenSynDB(ThreadMonitor monitor, JProgressBar GenProgressBar,
	   Partition[] db, int NROWS, int NCOLS, int K,
	   String fname, int dbRandSeed, int genLarge,
	   JTextArea LogTextArea)
  {
    this.db = db;
    this.NROWS = NROWS;
    this.NCOLS = NCOLS;
    this.K = K;
    this.fname = fname;
    this.dbRandSeed = dbRandSeed;
    this.genLarge = genLarge;
    this.monitor = monitor;
    this.GenProgressBar = GenProgressBar;
    this.LogTextArea = LogTextArea;
  }

  /** generates a synthetic database; save results in file
   * <code>fname</code>; the last column in <code>db</code> is the
   * reference partition; <code>NCOLS</code> is the total number of
   * columns, including also the reference partition */
  public void execute()
  {
    try
      {
	PrintWriter out = new PrintWriter(new FileWriter(fname));

	// initialize seed for the random number generator
	Random rand = new Random(dbRandSeed);

	// only used if genLarge is 1!
	int turn = 1; // any second row will have a value of 1
	// the resulting partition will have the class 1
	// with the greatest cardinality 
    
	GenProgressBar.setValue(0);
	for (int j = 0; j < NROWS; j++)
	  {
	    int n;
	    // the first K numbers are not random, that
	    // will ensure that we have exactly K classes
	    // in the database
	    if (j < K)
	      n = j + 1;
	    else
	      {
		if (genLarge ==1 && (turn++ % 2 == 0))
		  n = 1;
		else
		  // pick a number from [1, K]
		  n = rand.nextInt(K) + 1;
	      }
	
	    db[NCOLS-1].set(j, n);
	
	    // pick a number from [0, NCOLS - 2]
	    int c = rand.nextInt(NCOLS-1);
	
	    for (int i = 0; i < NCOLS-1; i++)
	      {
		if (i != c)
		  {
		    db[i].set(j, n);
		    out.print(n);
		  }
		else
		  {
		    // pick a different number from [1, K]
		    int t = n;
		    while (t == n)					
		      t = rand.nextInt(K) + 1;
		    db[i].set(j , t);
		    out.print(t);
		  }
		if (i != NCOLS - 2)
		  {
		    out.print(',');
		    out.print(' ');
		  }
		else
		  {		   
		    out.print(',');
		    out.print(' ');
		    out.print(n);
		    out.println();
		  }
	      }
	    currRowNo = j + 1;
	    GenProgressBar.setValue(j + 1);
	    checkAbort();
	  }

	out.close();
      }
    catch(IOException e)
      {
	LogTextArea.append(Strings.ERROR + e + Strings.endl);
      }
  }

  /** @return the real number of rows */
  public int getRealRowNo()
  {
    return currRowNo;
  }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -