private void buttonCluster_Click(object sender, EventArgs e) { if (CompleteScreening == null) return; if (!CompleteScreening.IsSelectedDescriptors()) { MessageBox.Show("You have to check at least one descriptor !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.Cursor = Cursors.WaitCursor; // -------------- K - Means --------------------------- if (comboBoxClusteringMethod.SelectedIndex == 0) { if (radioButtonClusterPlateByPlate.Checked) { int NumberOfPlates = CompleteScreening.ListPlatesActive.Count; // loop on all the plate for (int PlateIdx = 0; PlateIdx < NumberOfPlates; PlateIdx++) { cPlate CurrentPlateToProcess = CompleteScreening.ListPlatesActive.GetPlate(CompleteScreening.ListPlatesActive[PlateIdx].Name); KMeans((int)numericUpDownClusterNumber.Value, CurrentPlateToProcess); } richTextBoxInfoClustering.AppendText("\nPlate by plate clustering done !"); } else { KMeansFullScreen((int)numericUpDownClusterNumber.Value); richTextBoxInfoClustering.AppendText("\nGlobal clustering done !"); } } else if (comboBoxClusteringMethod.SelectedIndex == 1) // ---------------- EM -------------------------- { FormForEMInfo WindowEMinfo = new FormForEMInfo(); if (WindowEMinfo.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; if (checkBoxAutomatedClusterNumber.Checked) { string feedback = ClusteringEM(radioButtonClusterFullScreen.Checked, -1, WindowEMinfo); if (feedback != null) { FormForCellByCellClusteringResults WindowFormForCellByCellClusteringResults = new FormForCellByCellClusteringResults(); WindowFormForCellByCellClusteringResults.richTextBoxResults.Clear(); WindowFormForCellByCellClusteringResults.richTextBoxResults.AppendText(feedback); WindowFormForCellByCellClusteringResults.buttonPerformLearning.Text = "Ok"; WindowFormForCellByCellClusteringResults.ShowDialog(); } } else { string feedback = ClusteringEM(radioButtonClusterFullScreen.Checked, (int)numericUpDownClusterNumber.Value, WindowEMinfo); if (feedback != null) { FormForCellByCellClusteringResults WindowFormForCellByCellClusteringResults = new FormForCellByCellClusteringResults(); WindowFormForCellByCellClusteringResults.richTextBoxResults.Clear(); WindowFormForCellByCellClusteringResults.richTextBoxResults.AppendText(feedback); WindowFormForCellByCellClusteringResults.buttonPerformLearning.Text = "Ok"; WindowFormForCellByCellClusteringResults.ShowDialog(); } } } else if (comboBoxClusteringMethod.SelectedIndex == 2) // ---------------- Hierarchical -------------------------- { if (checkBoxAutomatedClusterNumber.Checked) ClusteringHierarchical(radioButtonClusterFullScreen.Checked, -1); else ClusteringHierarchical(radioButtonClusterFullScreen.Checked, (int)numericUpDownClusterNumber.Value); } //CompleteScreening.GetPlate(CompleteScreening.CurrentDisplayPlate).DisplayClasses(CompleteScreening.PanelForPlate); // tabControlMain.SelectedTab = tabPageDistribution; this.Cursor = Cursors.Default; CompleteScreening.GetCurrentDisplayPlate().DisplayDistribution(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor, false); }
private void buttonStartCluster_Click(object sender, EventArgs e) { FormSingleCellClusteringInfo WindowClusteringInfo = new FormSingleCellClusteringInfo(GlobalInfo); if (WindowClusteringInfo.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; Instances ListInstances = GlobalInfo.CurrentScreen.CellBasedClassification.CreateInstancesWithoutClass(dt); if ((WindowClusteringInfo.radioButtonAutomated.Checked) && (WindowClusteringInfo.radioButtonEM.Checked)) { ClusterEvaluation eval; Classes = new cExtendedList(); weka.clusterers.EM EMCluster = new EM(); if(WindowClusteringInfo.checkBoxEMAutomated.Checked) EMCluster.setNumClusters(-1); else EMCluster.setNumClusters((int)WindowClusteringInfo.numericUpDownClassNumber.Value); EMCluster.buildClusterer(ListInstances); EMCluster.getClusterModelsNumericAtts(); eval = new ClusterEvaluation(); eval.setClusterer(EMCluster); eval.evaluateClusterer(ListInstances); Classes.AddRange(eval.getClusterAssignments()); NumClusters= eval.getNumClusters(); ReDraw(); FormForCellByCellClusteringResults WindowFormForCellByCellClusteringResults = new FormForCellByCellClusteringResults(); WindowFormForCellByCellClusteringResults.richTextBoxResults.Clear(); WindowFormForCellByCellClusteringResults.richTextBoxResults.AppendText(eval.clusterResultsToString()); if (WindowFormForCellByCellClusteringResults.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; } else if (WindowClusteringInfo.radioButtonDescriptorBased.Checked) { Classes = new cExtendedList(); DataTable FinalDataTable = new DataTable(); int IdxDescForClassSelect = WindowClusteringInfo.comboBoxDescriptorForClass.SelectedIndex; for (int IdxWell = 0; IdxWell < GlobalInfo.ListSelectedWell.Count; IdxWell++) { cWell TmpWell = GlobalInfo.ListSelectedWell[IdxWell]; // if (IdxWell == 0) if (TmpWell.ListDescriptors[IdxDescForClassSelect].GetAssociatedType().DataType == eDataType.HISTOGRAM) { Classes.AddRange(TmpWell.ListDescriptors[IdxDescForClassSelect].GetOriginalValues()); } else { double ClasseValue = TmpWell.ListDescriptors[IdxDescForClassSelect].GetValue(); for (int IdxCell = 0; IdxCell < TmpWell.CellNumber; IdxCell++) Classes.Add(ClasseValue); //TmpWell.AddDescriptors } } List<double> ListClassValues = new List<double>(); foreach (var item in Classes.Distinct()) { ListClassValues.Add(item); } //(List<double>)Classes.Distinct(); NumClusters = ListClassValues.Count(); //Classes = new cExtendedList(); for (int IdxClust = 0; IdxClust < Classes.Count; IdxClust++) { for (int IdxCl = 0; IdxCl < ListClassValues.Count; IdxCl++) { if (ListClassValues[IdxCl] == Classes[IdxClust]) { Classes[IdxClust] = IdxCl; break; } } //Classes[IdxClust] = ListClassValues.Find(Classes[IdxClust]); } //int NumClusters = ReDraw(); } // ReDraw(); //if (MessageBox.Show("Do you want perform a j48 training process ?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes) return; weka.core.FastVector attVals = new FastVector(); for (int i = 0; i < NumClusters; i++) attVals.addElement("Class__" + (i).ToString()); ListInstances.insertAttributeAt(new weka.core.Attribute("Class__", attVals), ListInstances.numAttributes()); for (int i = 0; i < Classes.Count; i++) { ListInstances.get(i).setValue(ListInstances.numAttributes() - 1, Classes[i]); } ListInstances.setClassIndex(ListInstances.numAttributes() - 1); GlobalInfo.CurrentScreen.CellBasedClassification.ClassificationModel_CellBased = new weka.classifiers.trees.J48(); GlobalInfo.CurrentScreen.CellBasedClassification.SetJ48Tree((weka.classifiers.trees.J48)GlobalInfo.CurrentScreen.CellBasedClassification.ClassificationModel_CellBased,Classes.Count); GlobalInfo.CurrentScreen.CellBasedClassification.J48Model.setMinNumObj((int)GlobalInfo.OptionsWindow.numericUpDownJ48MinNumObjects.Value); weka.core.Instances train = new weka.core.Instances(ListInstances, 0, ListInstances.numInstances()); GlobalInfo.CurrentScreen.CellBasedClassification.ClassificationModel_CellBased.buildClassifier(train); GlobalInfo.ConsoleWriteLine(GlobalInfo.CurrentScreen.CellBasedClassification.ClassificationModel_CellBased.ToString()); GlobalInfo.CurrentScreen.CellBasedClassification.evaluation = new weka.classifiers.Evaluation(ListInstances); GlobalInfo.CurrentScreen.CellBasedClassification.evaluation.crossValidateModel(GlobalInfo.CurrentScreen.CellBasedClassification.ClassificationModel_CellBased, ListInstances, 2, new java.util.Random(1)); GlobalInfo.CurrentScreen.CellBasedClassification.DisplayTree(GlobalInfo).Show(); FormForCellbyCellClassif WindowFormForCellbyCellClassif = new FormForCellbyCellClassif(); if (WindowFormForCellbyCellClassif.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; int DescrCount = GlobalInfo.CurrentScreen.ListDescriptors.Count; // first we update the descriptor for (int i = 0; i < ListInstances.numClasses(); i++) GlobalInfo.CurrentScreen.ListDescriptors.AddNew(new cDescriptorsType("Ratio_Class " + i, true, 1, GlobalInfo)); FormForProgress ProgressWindow = new FormForProgress(); ProgressWindow.Show(); int IdxProgress = 0; int MaxProgress = 0; foreach (cPlate CurrentPlateToProcess in GlobalInfo.CurrentScreen.ListPlatesAvailable) MaxProgress += CurrentPlateToProcess.ParentScreening.Columns * CurrentPlateToProcess.ParentScreening.Rows; ProgressWindow.progressBar.Maximum = MaxProgress; attVals = new FastVector(); for (int i = 0; i < NumClusters; i++) attVals.addElement(i.ToString()); //ParallelOptions options = new ParallelOptions(); //options.MaxDegreeOfParallelism = -1; // -1 is for unlimited. 1 is for sequential. //Stopwatch stopwatch = new Stopwatch(); //stopwatch.Start(); //////for (int PlateIdx = 0; PlateIdx < NumberOfPlates; PlateIdx++) //int NumberOfPlates = CompleteScreening.ListPlatesAvailable.Count; //Parallel.For(0, NumberOfPlates, options, (PlateIdx) => //{ // cPlate CurrentPlateToProcess = CompleteScreening.ListPlatesActive.GetPlate((string)Parent.GlobalInfo.PlateListWindow.listBoxPlateNameToProcess.Items[PlateIdx]); // for (int row = 0; row < Parent.Rows; row++) // for (int col = 0; col < Parent.Columns; col++) // { // TempWell = CurrentPlateToProcess.GetWell(col, row, false); // if (TempWell == null) continue; // else // { // if (TempWell.GetClass() == this.ClassForClassif) // Pos.Add(TempWell.ListDescriptors[Parent.ListDescriptors.CurrentSelectedDescriptor].GetValue()); // } // } //} //); foreach (cPlate CurrentPlateToProcess in GlobalInfo.CurrentScreen.ListPlatesAvailable) //Parallel.ForEach(GlobalInfo.CurrentScreen.ListPlatesActive, options, CurrentPlateToProcess => { //Parallel.ForEach(CurrentPlateToProcess.ListActiveWells, options, TmpWell => for(int j=0;j<CurrentPlateToProcess.ParentScreening.Rows;j++) for (int k = 0; k < CurrentPlateToProcess.ParentScreening.Columns; k++) { cWell TmpWell = CurrentPlateToProcess.GetWell(k, j, false); if (TmpWell == null) continue; ProgressWindow.progressBar.Value = IdxProgress++; //DataTable FinalDataTable = new DataTable(); //TmpWell.AssociatedPlate.DBConnection = new cDBConnection(TmpWell.AssociatedPlate, TmpWell.SQLTableName); //TmpWell.AssociatedPlate.DBConnection.AddWellToDataTable(TmpWell, FinalDataTable, false); DataTable FinalDataTable = TmpWell.GetDescDataTable(true); Instances ListInstancesTOClassify = GlobalInfo.CurrentScreen.CellBasedClassification.CreateInstancesWithoutClass(FinalDataTable); ListInstancesTOClassify.insertAttributeAt(new weka.core.Attribute("Class", attVals), ListInstancesTOClassify.numAttributes()); ListInstancesTOClassify.setClassIndex(ListInstancesTOClassify.numAttributes() - 1); cExtendedList ListClasses = new cExtendedList(); for (int i = 0; i < ListInstancesTOClassify.numInstances(); i++) { double classId = GlobalInfo.CurrentScreen.CellBasedClassification.ClassificationModel_CellBased.classifyInstance(ListInstancesTOClassify.instance(i)); ListClasses.Add(classId); } List<double[]> Histo = ListClasses.CreateHistogram(0, ListInstances.numClasses() - 1, ListInstances.numClasses() - 1); List<cDescriptor> LDesc = new List<cDescriptor>(); for (int IdxHisto = 0; IdxHisto < Histo[1].Length; IdxHisto++) { double Value = (100.0 * Histo[1][IdxHisto]) / (double)ListInstancesTOClassify.numInstances(); cDescriptor NewDesc = new cDescriptor(Value, GlobalInfo.CurrentScreen.ListDescriptors[IdxHisto + DescrCount], GlobalInfo.CurrentScreen); LDesc.Add(NewDesc); } TmpWell.AddDescriptors(LDesc); //TmpWell.AssociatedPlate.DBConnection.DB_CloseConnection(); }//); } ProgressWindow.Close(); if (WindowFormForCellbyCellClassif.checkBoxKeepOriginalDesc.Checked == false) { // int DescNumToRemove = GlobalInfo.CurrentScreen.ListDescriptors.Count - for (int IdxDesc = 0; IdxDesc < DescrCount; IdxDesc++) GlobalInfo.CurrentScreen.ListDescriptors.RemoveDesc(GlobalInfo.CurrentScreen.ListDescriptors[0], GlobalInfo.CurrentScreen); } GlobalInfo.CurrentScreen.ListDescriptors.UpDateDisplay(); GlobalInfo.CurrentScreen.UpDatePlateListWithFullAvailablePlate(); for (int idxP = 0; idxP < GlobalInfo.CurrentScreen.ListPlatesActive.Count; idxP++) GlobalInfo.CurrentScreen.ListPlatesActive[idxP].UpDataMinMax(); if (WindowFormForCellbyCellClassif.checkBoxKeepOriginalDesc.Checked == false) GlobalInfo.CurrentScreen.GetCurrentDisplayPlate().DisplayDistribution(0, false); //WindowFormForCellbyCellClassif.Close(); //WindowClusteringInfo.Close(); }