예제 #1
0
        public cWindowToDisplayHisto(cScreening CompleteScreening0, cExtendedList RawValues0)
        {
            this.CompleteScreening = CompleteScreening0;

            this.parametersToolStripMenuItem.Click += new System.EventHandler(this.parametersToolStripMenuItem_Click);

            RequestWindow.label3.Text = "Bin Number";

            this.RawValues = RawValues0;

            CurrentChartArea = new ChartArea();
            CurrentChartArea.BorderColor = Color.Black;

            this.chartForSimpleForm.ChartAreas.Add(CurrentChartArea);
            CurrentChartArea.Axes[0].MajorGrid.Enabled = false;
            if(CompleteScreening!=null)
                CurrentChartArea.Axes[0].Title = CompleteScreening.ListDescriptors[CompleteScreening.ListDescriptors.CurrentSelectedDescriptorIdx].GetName();
            CurrentChartArea.Axes[1].Title = "Sum";
            CurrentChartArea.AxisX.LabelStyle.Format = "N2";

            this.chartForSimpleForm.TextAntiAliasingQuality = TextAntiAliasingQuality.High;

            if (CompleteScreening != null)
                CurrentChartArea.BackColor = Color.White;

            this.chartForSimpleForm.ChartAreas[0].CursorX.IsUserEnabled = true;
            this.chartForSimpleForm.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
            this.chartForSimpleForm.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
            this.chartForSimpleForm.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;

            if ((CompleteScreening != null) && (cGlobalInfo.OptionsWindow.FFAllOptions.checkBoxHistoDisplayStats.Checked))
            {
                StripLine AverageLine = new StripLine();
                AverageLine.BackColor = Color.Black;
                AverageLine.IntervalOffset = RawValues.Mean();
                AverageLine.StripWidth = double.Epsilon;
                CurrentChartArea.AxisX.StripLines.Add(AverageLine);
                AverageLine.Text = String.Format("{0:0.###}", AverageLine.IntervalOffset);

                StripLine StdLine = new StripLine();
                StdLine.BackColor = Color.FromArgb(64, Color.Black);
                double Std = RawValues.Std();
                StdLine.IntervalOffset = AverageLine.IntervalOffset - 0.5 * Std;
                StdLine.StripWidth = Std;
                CurrentChartArea.AxisX.StripLines.Add(StdLine);
                AverageLine.StripWidth = 0.0001;
            }

            SerieForHisto = new Series();
            SerieForHisto.ShadowOffset = 1;
            SerieForHisto.ChartType = SeriesChartType.Column;
            if (CompleteScreening != null)
            SerieForHisto.Color = cGlobalInfo.ListWellClasses[1].ColourForDisplay;

            List<double[]> HistoPos = RawValues.CreateHistogram(this.BinNumber, false);
            if (HistoPos.Count == 0) return;

            for (int IdxValue = 0; IdxValue < HistoPos[0].Length; IdxValue++)
            {
                SerieForHisto.Points.AddXY(HistoPos[0][IdxValue], HistoPos[1][IdxValue]);
                SerieForHisto.Points[IdxValue].ToolTip = HistoPos[1][IdxValue].ToString();
                if (CompleteScreening != null)
                {
                    if (CompleteScreening.SelectedClass == -1)
                        SerieForHisto.Points[IdxValue].Color = Color.Black;
                    else
                        SerieForHisto.Points[IdxValue].Color = cGlobalInfo.ListWellClasses[CompleteScreening.SelectedClass].ColourForDisplay;
                }
            }
            this.chartForSimpleForm.Series.Add(SerieForHisto);
        }
예제 #2
0
파일: cHisto.cs 프로젝트: cyrenaique/HCSA
 public cHisto(cExtendedList OriginalValues, int NumBin)
 {
     List<double[]> Res= OriginalValues.CreateHistogram(NumBin, false);
     ListValuesX = Res[0];
     ListValuesY = Res[1];
 }
예제 #3
0
파일: cWell.cs 프로젝트: cyrenaique/HCS
        private void DisplayHisto(object sender, EventArgs e)
        {
            if ((Parent.ListDescriptors == null) || (Parent.ListDescriptors.Count == 0)) return;

            cExtendedList Pos = new cExtendedList();

            cWell TempWell;

            int NumberOfPlates = Parent.GlobalInfo.PlateListWindow.listBoxPlateNameToProcess.Items.Count;

            // loop on all the plate
            for (int PlateIdx = 0; PlateIdx < NumberOfPlates; PlateIdx++)
            {
                cPlate CurrentPlateToProcess = Parent.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());
                        }
                    }
            }

            if (Pos.Count == 0)
            {
                MessageBox.Show("No well of class " + Parent.SelectedClass + " selected !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            List<double[]> HistoPos = Pos.CreateHistogram((int)Parent.GlobalInfo.OptionsWindow.numericUpDownHistoBin.Value);
            if (HistoPos == null) return;
            SimpleForm NewWindow = new SimpleForm();

            Series SeriesPos = new Series();
            SeriesPos.ShadowOffset = 1;

            if (HistoPos.Count == 0) return;

            for (int IdxValue = 0; IdxValue < HistoPos[0].Length; IdxValue++)
            {
                SeriesPos.Points.AddXY(HistoPos[0][IdxValue], HistoPos[1][IdxValue]);
                SeriesPos.Points[IdxValue].ToolTip = HistoPos[1][IdxValue].ToString();

                if (this.ClassForClassif == -1)
                    SeriesPos.Points[IdxValue].Color = Color.Black;
                else
                    SeriesPos.Points[IdxValue].Color = Parent.GlobalInfo.GetColor(this.ClassForClassif);
            }

            ChartArea CurrentChartArea = new ChartArea();
            CurrentChartArea.BorderColor = Color.Black;

            NewWindow.chartForSimpleForm.ChartAreas.Add(CurrentChartArea);
            CurrentChartArea.Axes[0].MajorGrid.Enabled = false;
            CurrentChartArea.Axes[0].Title = Parent.ListDescriptors[Parent.ListDescriptors.CurrentSelectedDescriptor].GetName();
            CurrentChartArea.Axes[1].Title = "Sum";
            CurrentChartArea.AxisX.LabelStyle.Format = "N2";

            NewWindow.chartForSimpleForm.TextAntiAliasingQuality = TextAntiAliasingQuality.High;
            CurrentChartArea.BackGradientStyle = GradientStyle.TopBottom;
            CurrentChartArea.BackColor = Parent.GlobalInfo.OptionsWindow.panel1.BackColor;
            CurrentChartArea.BackSecondaryColor = Color.White;

            SeriesPos.ChartType = SeriesChartType.Column;
            // SeriesPos.Color = Parent.GetColor(1);
            NewWindow.chartForSimpleForm.Series.Add(SeriesPos);

            NewWindow.chartForSimpleForm.ChartAreas[0].CursorX.IsUserEnabled = true;
            NewWindow.chartForSimpleForm.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
            NewWindow.chartForSimpleForm.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
            NewWindow.chartForSimpleForm.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;

            StripLine AverageLine = new StripLine();
            AverageLine.BackColor = Color.Red;
            AverageLine.IntervalOffset = this.ListDescriptors[Parent.ListDescriptors.CurrentSelectedDescriptor].GetValue();
            AverageLine.StripWidth = 0.0001;
            AverageLine.Text = String.Format("{0:0.###}", this.ListDescriptors[Parent.ListDescriptors.CurrentSelectedDescriptor].GetValue());
            CurrentChartArea.AxisX.StripLines.Add(AverageLine);

            if (Parent.GlobalInfo.OptionsWindow.checkBoxDisplayHistoStats.Checked)
            {
                StripLine NAverageLine = new StripLine();
                NAverageLine.BackColor = Color.Black;
                NAverageLine.IntervalOffset = Pos.Mean();
                NAverageLine.StripWidth = 0.0001;// double.Epsilon;
                CurrentChartArea.AxisX.StripLines.Add(NAverageLine);
                NAverageLine.Text = String.Format("{0:0.###}", NAverageLine.IntervalOffset);

                StripLine StdLine = new StripLine();
                StdLine.BackColor = Color.FromArgb(64, Color.Black);
                double Std = Pos.Std();
                StdLine.IntervalOffset = NAverageLine.IntervalOffset - 0.5 * Std;
                StdLine.StripWidth = Std;
                CurrentChartArea.AxisX.StripLines.Add(StdLine);
                //NAverageLine.StripWidth = 0.01;
            }

            Title CurrentTitle = new Title(this.StateForClassif + " - " + Parent.ListDescriptors[Parent.ListDescriptors.CurrentSelectedDescriptor].GetName() + " histogram.");
            CurrentTitle.Font = new System.Drawing.Font("Arial", 11, FontStyle.Bold);
            NewWindow.chartForSimpleForm.Titles.Add(CurrentTitle);

            NewWindow.Text = CurrentTitle.Text;
            NewWindow.Show();
            NewWindow.chartForSimpleForm.Update();
            NewWindow.chartForSimpleForm.Show();
            NewWindow.Controls.AddRange(new System.Windows.Forms.Control[] { NewWindow.chartForSimpleForm });

            return;
        }
        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();
        }