gaclust.java
来自「clustering data for the different techni」· Java 代码 · 共 1,955 行 · 第 1/5 页
JAVA
1,955 行
if (K < 2) { GALogTextArea.append(Strings.KMORETHAN2 + Strings.endl); JTextTools.dealWithInvalidValue(NClassesClustTextField); } crossoverRate = JTextTools.getDouble(CrossRateTextField, GALogTextArea, Strings.CROSSRATEERRMSG); if (crossoverRate < 0 || crossoverRate > 1) { GALogTextArea.append(Strings.CROSSRATEINTERVAL + Strings.endl); JTextTools.dealWithInvalidValue(CrossRateTextField); } mutationRate = JTextTools.getDouble(MutRateTextField, GALogTextArea, Strings.MUTRATEERRMSG); if (mutationRate < 0 || mutationRate > 1) { GALogTextArea.append(Strings.MUTRATEINTERVAL + Strings.endl); JTextTools.dealWithInvalidValue(MutRateTextField); } if (mutationRate + crossoverRate == 1) { GALogTextArea.append(Strings.CROSSMUTSUM + Strings.endl); if (crossoverRate > mutationRate) { GALogTextArea.append(Strings.ADJUSTCROSS + Strings.endl); JTextTools.dealWithInvalidValue(CrossRateTextField); } else { GALogTextArea.append(Strings.ADJUSTMUT + Strings.endl); JTextTools.dealWithInvalidValue(MutRateTextField); } } String selection = (String)ClassFitnessComboBox.getSelectedItem(); if (selection.equals(Strings.CF_SYM_DIFF)) classFitnessType = Partition.CF_SYM_DIFF; else if (selection.equals(Strings.CF_PROD)) classFitnessType = Partition.CF_PROD; else if (selection.equals(Strings.CF_DIV)) classFitnessType = Partition.CF_DIV; else classFitnessType = Partition.CF_POW; selection = (String)CrossTypeComboBox.getSelectedItem(); if (selection.equals(Strings.CROSS_RAND)) crossoverType = Chromosome.CROSS_RAND; else if (selection.equals(Strings.CROSS_X_2RAND_CLASS)) crossoverType = Chromosome.CROSS_X_2RAND_CLASS; else if (selection.equals(Strings.CROSS_AM_X_BEST_CLASS)) crossoverType = Chromosome.CROSS_AM_X_BEST_CLASS; else if (selection.equals(Strings.CROSS_AM_X_BEST_WORST)) crossoverType = Chromosome.CROSS_AM_X_BEST_WORST; else // if (selection.equals(Strings.CROSS_AM_X_2RAND_CLASS)) crossoverType = Chromosome.CROSS_AM_X_2RAND_CLASS; selection = (String)MutTypeComboBox.getSelectedItem(); if (selection.equals(Strings.MUT_RAND)) mutationType = Chromosome.MUT_RAND; else if (selection.equals(Strings.MUT_MOVE_ELEM)) mutationType = Chromosome.MUT_MOVE_ELEM; else // if (selection.equals(Strings.MUT_SWAP_ELEM)) mutationType = Chromosome.MUT_SWAP_ELEM; selection = (String)DistrTypeComboBox.getSelectedItem(); if (selection.equals(Strings.DISTRIB_NONE)) distributionType = Chromosome.DISTRIB_NONE; else if (selection.equals(Strings.DISTRIB_RAND)) distributionType = Chromosome.DISTRIB_RAND; else //if (selection.equals(Strings.DISTRIB_TO_EVEN)) distributionType = Chromosome.DISTRIB_TO_EVEN; selection = (String)EntropyMeasureComboBox.getSelectedItem(); if (selection.equals(Strings.GINI)) entropyMeasure = ImpurityMeasure.GINI; else if (selection.equals(Strings.ENTROPY)) entropyMeasure = ImpurityMeasure.ENTROPY; else if (selection.equals(Strings.PEAK)) entropyMeasure = ImpurityMeasure.PEAK; else if (selection.equals(Strings.CIRCLE)) entropyMeasure = ImpurityMeasure.CIRCLE; else if (selection.equals(Strings.SINE)) entropyMeasure = ImpurityMeasure.SINE; else if (selection.equals(Strings.SQ)) entropyMeasure = ImpurityMeasure.SQ; else // if (selection.equals(Strings.GE)) entropyMeasure = ImpurityMeasure.GE; selection = (String)FitnessMeasureComboBox.getSelectedItem(); if (selection.equals(Strings.FM_PA_P)) fitnessMeasure = Global.FM_PA_P; else if (selection.equals(Strings.FM_P_PA)) fitnessMeasure = Global.FM_P_PA; else if (selection.equals(Strings.FM_BOTH)) fitnessMeasure = Global.FM_BOTH; else if (selection.equals(Strings.FM_BOTH_SCALED)) fitnessMeasure = Global.FM_BOTH_SCALED; else if (selection.equals(Strings.FM_Q)) fitnessMeasure = Global.FM_Q; else if (selection.equals(Strings.FM_L)) fitnessMeasure = Global.FM_L; else if (selection.equals(Strings.FM_QR)) fitnessMeasure = Global.FM_QR; else if (selection.equals(Strings.FM_LR)) fitnessMeasure = Global.FM_LR; else if (selection.equals(Strings.FM_Q_QR)) fitnessMeasure = Global.FM_Q_QR; else if (selection.equals(Strings.FM_ALTERNATE_HAVG)) fitnessMeasure = Global.FM_ALTERNATE_HAVG; else if (selection.equals(Strings.FM_ALTERNATE)) fitnessMeasure = Global.FM_ALTERNATE; else if (selection.equals(Strings.FM_MOD)) fitnessMeasure = Global.FM_MOD; else if (selection.equals(Strings.FM_NORM_W)) fitnessMeasure = Global.FM_NORM_W; else // if (selection.equals(Strings.FM_WE)) fitnessMeasure = Global.FM_WE; fitnessThreshold = JTextTools.getDouble(FitnessThresholdTextField, GALogTextArea, Strings.FTHRESERRMSG); if (fitnessThreshold < 0) { GALogTextArea.append(Strings.FTHRESPOSITIVE + Strings.endl); JTextTools.dealWithInvalidValue(FitnessThresholdTextField); } consecItrs = JTextTools.getInt(ConsecItrsTextField, GALogTextArea, Strings.CITRSERRMSG); if (consecItrs <= 0) { GALogTextArea.append(Strings.CITRSPOSITIVE + Strings.endl); JTextTools.dealWithInvalidValue(ConsecItrsTextField); } randseed = JTextTools.getInt(RandomSeedGATextField, GALogTextArea, Strings.RANDSEEDERRMSG); if (randseed < 0) { GALogTextArea.append(Strings.RANDSEEDPOSITIVE + Strings.endl); JTextTools.dealWithInvalidValue(RandomSeedGATextField); } useTarget = 0; targetId = 0; if (UseTargetCheckBox.isSelected() == true) { useTarget = 1; targetId = JTextTools.getInt(TargetIDTextField, GALogTextArea, Strings.TIDERRMSG); if (targetId < 0) { GALogTextArea.append(Strings.TIDPOSITIVE + Strings.endl); JTextTools.dealWithInvalidValue(TargetIDTextField); } } useWeights = 0; sampleDBPct = 0; if (UseWeightsCheckBox.isSelected() == true) { useWeights = 1; sampleDBPct = JTextTools.getDouble(SampleDBPctTextField, GALogTextArea, Strings.SPCTERRMSG); if (sampleDBPct <= 0) { GALogTextArea.append(Strings.SPCTINTERVAL + Strings.endl); JTextTools.dealWithInvalidValue(SampleDBPctTextField); } } excludeAttr = 0; noRemAttr = 0; if (ExcludeAttrCheckBox.isSelected() == true) { excludeAttr = 1; noRemAttr = JTextTools.getInt(NRemAttrTextField, GALogTextArea, Strings.NRATTRERRMSG); if (noRemAttr <= 0) { GALogTextArea.append(Strings.NRATTRPOSITIVE + Strings.endl); JTextTools.dealWithInvalidValue(NRemAttrTextField); } } selection = (String)MinimizationComboBox.getSelectedItem(); if (selection.equals(Strings.FO_MIN)) minimization = 1; else // if (selection.equals(Strings.FO_MAX)) minimization = 0; if (fitnessMeasure == Global.FM_Q || fitnessMeasure == Global.FM_L || fitnessMeasure == Global.FM_QR || fitnessMeasure == Global.FM_LR || fitnessMeasure == Global.FM_Q_QR) { // we need maximization for this type of fitness // measure if (minimization == 1) { GALogTextArea.append(Strings.MAXNEEDED + Strings.endl); MinimizationComboBox.setSelectedIndex(1); minimization = 0; } } else // we need minimization for this type of fitness measure if (minimization == 0) { GALogTextArea.append(Strings.MINNEEDED + Strings.endl); MinimizationComboBox.setSelectedIndex(0); minimization = 1; } if ((fitnessMeasure == Global.FM_NORM_W || fitnessMeasure == Global.FM_WE) && useWeights == 0) { GALogTextArea.append(Strings.WSPCTNEEDED + Strings.endl); UseWeightsCheckBox.setSelected(true); JTextTools.dealWithInvalidValue(SampleDBPctTextField); } if ((fitnessMeasure == Global.FM_NORM_W || fitnessMeasure == Global.FM_WE) && useTarget == 0) { GALogTextArea.append(Strings.TARGETNEEDED + Strings.endl); UseTargetCheckBox.setSelected(true); JTextTools.dealWithInvalidValue(TargetIDTextField); } if (fitnessMeasure == Global.FM_WE && excludeAttr == 0) { GALogTextArea.append(Strings.EXCLATTRNEEDED + Strings.endl); ExcludeAttrCheckBox.setSelected(true); JTextTools.dealWithInvalidValue(NRemAttrTextField); } } catch (IllegalArgumentException invalid_input) { // wait for user to input something reasonable return; } ClusterButton.setEnabled(false); ClusterAbortButton.setEnabled(true); // start the clustering algorithm cluster(); } else if (event.getSource() == ClusterAbortButton) { ClusterButton.setEnabled(true); ClusterAbortButton.setEnabled(false); ga.abort(); } else if (event.getSource() == GenerateButton) { try { // get parameters if (UseDefaultNamingCheckBox.isSelected() == false) { DBName = GenDBNameTextField.getText(); if (DBName.compareTo("") == 0) { GenLogTextArea.append(Strings.DBINVALID + Strings.endl); GenDBNameTextField.requestFocus(); return; } } nRows = JTextTools.getInt(GenNRowsTextField, GenLogTextArea, Strings.NROWSERRMSG); if (nRows <= 0) { GenLogTextArea.append(Strings.NROWSPOSITIVE + Strings.endl); JTextTools.dealWithInvalidValue(GenNRowsTextField); } nCols = JTextTools.getInt(GenNAttrTextField, GenLogTextArea, Strings.NATTRERRMSG); if (nCols <= 1) { GenLogTextArea.append(Strings.NROWSMORETHAN2 + Strings.endl); JTextTools.dealWithInvalidValue(GenNAttrTextField); } nDBClasses = JTextTools.getInt(GenNClassesTextField, GenLogTextArea, Strings.KERRMSG); if (nDBClasses < 2) { GenLogTextArea.append(Strings.KDBMORETHAN2 + Strings.endl); JTextTools.dealWithInvalidValue(GenNClassesTextField); } DBSeed = JTextTools.getInt(GenRandomSeedTextField, GenLogTextArea, Strings.RANDSEEDERRMSG); if (DBSeed < 0) { GenLogTextArea.append(Strings.RANDSEEDPOSITIVE + Strings.endl); JTextTools.dealWithInvalidValue(GenRandomSeedTextField); } } catch (IllegalArgumentException invalid_input) { // wait for user to input something reasonable return; } generateLarge = 0; if (GenerateLargeCheckBox.isSelected() == true) generateLarge = 1; if (UseDefaultNamingCheckBox.isSelected() == true) { DBName = "DBr" + nRows + "a" + nCols + "k" + nDBClasses + "s" + DBSeed + (generateLarge == 1 ? "L" : ""); GenDBNameTextField.setText(DBName); } db = new Partition[nCols]; for (int i = 0; i < nCols; i++) db[i] = new Partition(nRows, nDBClasses); isGenerating = true; GenProgressBar.setMaximum(nRows); GenLogTextArea.append(Strings.DBGENERATING + Strings.endl); genSynDB = new GenSynDB(this, GenProgressBar, db, nRows, nCols, nDBClasses, DBName, DBSeed, generateLarge, GenLogTextArea); GenAbortButton.setEnabled(true); status = GENDB_RUNNING; genSynDB.start(); } else if (event.getSource() == GenAbortButton) { GenerateButton.setEnabled(true); GenAbortButton.setEnabled(false); genSynDB.abort(); } else if (event.getSource() == ForceGCMenuItem) { gcThreaded(); } else if (event.getSource() == ExitMenuItem) { exitFrame(); } else if (event.getSource() == TopicsMenuItem) { new HelpDialog(this, true).show(); } else if (event.getSource() == AboutMenuItem) { new AboutDialog(this, true).show(); } } /** clusters the currently selected database */ private void cluster() { rand = new Random(randseed); // number of columns as far as clustering is concern nColsClust = nCols; nColsClust_copy = nCols; if (useTarget == 1) { // flipping the target should be done once per database // openning if (flipTarget == true) { // rearrange the database such that the target attribute is // the last attribute Partition temp = db[nCols-1]; db[nCols-1] = db[targetId]; db_copy[nCols-1] = db_copy[targetId]; db[targetId] = temp; db_copy[targetId] = temp; flipTarget = false; } // reference partition is the last attribute
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?