public cFeedBackMessage Run() { base.Start(); if (!FeedBackMessage.IsSucceed) return FeedBackMessage; if (this.Input.Count > 1) { this.FeedBackMessage = new cFeedBackMessage(false, this); return this.FeedBackMessage; } #region parameters initialization //object _firstValue = base.ListProperties.FindByName("Number of Clusters"); //int NumOfClusters = 0; //if (_firstValue == null) //{ // base.GenerateError("-Number of Clusters- not found !"); // return base.FeedBackMessage; //} //try //{ // cProperty TmpProp = (cProperty)_firstValue; // NumOfClusters = (int)TmpProp.GetValue(); //} //catch (Exception) //{ // base.GenerateError("-Number of Clusters- cast didn't work"); // return base.FeedBackMessage; //} #endregion cMachineLearning MachineLearning = new cMachineLearning(/*cWell.GlobalInfo*/null); if (ParamAlgoForClustering == null) ParamAlgoForClustering = MachineLearning.AskAndGetClusteringAlgo(); if (ParamAlgoForClustering == null) { FeedBackMessage.IsSucceed = false; FeedBackMessage.Message = "Invalid Parameters"; return FeedBackMessage; } MachineLearning.SelectedClusterer = MachineLearning.BuildClusterer(ParamAlgoForClustering, this.Input); if (MachineLearning.SelectedClusterer != null) { cLinearize L = new cLinearize(); L.SetInputData(this.Input); L.Run(); cExtendedTable Test = L.GetOutPut(); ClusterEvaluation CE = MachineLearning.EvaluteAndDisplayClusterer(/*richTextBoxInfoClustering*/null, null, MachineLearning.CreateInstancesWithoutClass(this.Input)); double[] Assign = CE.getClusterAssignments(); base.Output = new cExtendedTable(this.Input); cExtendedList CL = new cExtendedList("Class ID"); CL.SetInfo(CE.clusterResultsToString()); base.Output.Add(CL); for (int i = 0; i < Assign.Length; i++) base.Output[base.Output.Count-1].Add(Assign[i]); } base.End(); return FeedBackMessage; }
public void PerformScreeningClustering(List<cPlate> ListPlatesToProcess, bool IsOneByOne) { this.Cursor = Cursors.WaitCursor; cMachineLearning MachineLearning = new cMachineLearning(this.GlobalInfo); cParamAlgo ParamAlgoForClustering = MachineLearning.AskAndGetClusteringAlgo(); if (ParamAlgoForClustering == null) { this.Cursor = Cursors.Default; return; } //DataTable dt = new DataTable(); cExtendedTable dt = new cExtendedTable(); for (int IdxDesc = 0; IdxDesc < cGlobalInfo.CurrentScreening.ListDescriptors.Count; IdxDesc++) { if (cGlobalInfo.CurrentScreening.ListDescriptors[IdxDesc].IsActive()) dt.Add(new cExtendedList(cGlobalInfo.CurrentScreening.ListDescriptors[IdxDesc].GetName())); } if (IsOneByOne) { foreach (cPlate itemPlate in ListPlatesToProcess) { cListWells ListWell = new cListWells(null); foreach (var item in itemPlate.ListActiveWells) ListWell.Add(item); dt = ListWell.GetAverageDescriptorValues(cGlobalInfo.CurrentScreening.ListDescriptors.GetActiveDescriptors(), false, false); MachineLearning.SelectedClusterer = MachineLearning.BuildClusterer(ParamAlgoForClustering, dt); if (MachineLearning.SelectedClusterer != null) { double[] Assign = MachineLearning.EvaluteAndDisplayClusterer(richTextBoxInfoClustering, null, MachineLearning.CreateInstancesWithoutClass(dt)).getClusterAssignments(); MachineLearning.Classes = new cExtendedList(); MachineLearning.Classes.AddRange(Assign); } if (MachineLearning.Classes.Max() >= cGlobalInfo.ListWellClasses.Count) { MessageBox.Show("The number of clusters is higher than the supported number of classes. Operation cancelled !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Cursor = Cursors.Default; return; } if (MachineLearning.Classes.IsContainNegative() || (MachineLearning.Classes.Count == 0)) { MessageBox.Show("Negative or null cluster index identified. Operation cancelled !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Cursor = Cursors.Default; return; } // ----- update well classes ------ int IdxWell = 0; foreach (cWell item in itemPlate.ListActiveWells) item.SetClass((int)MachineLearning.Classes[IdxWell++]); } } else { cListWells ListWell = new cListWells(null); foreach (cPlate itemPlate in ListPlatesToProcess) { foreach (cWell item in itemPlate.ListActiveWells) { //cExtendedList ListValues = item.GetAverageValuesList(false); //dt.Rows.Add(); //int RealIdx = 0; //for (int IdxDesc = 0; IdxDesc < CompleteScreening.ListDescriptors.Count; IdxDesc++) //{ // if (CompleteScreening.ListDescriptors[IdxDesc].IsActive()) // dt.Rows[dt.Rows.Count - 1][RealIdx++] = ListValues[IdxDesc]; ListWell.Add(item); //} } } dt = ListWell.GetAverageDescriptorValues(cGlobalInfo.CurrentScreening.ListDescriptors.GetActiveDescriptors(), false, false); MachineLearning.SelectedClusterer = MachineLearning.BuildClusterer(ParamAlgoForClustering, dt); if (MachineLearning.SelectedClusterer != null) { double[] Assign = MachineLearning.EvaluteAndDisplayClusterer(richTextBoxInfoClustering, null, MachineLearning.CreateInstancesWithoutClass(dt)).getClusterAssignments(); MachineLearning.Classes = new cExtendedList(); MachineLearning.Classes.AddRange(Assign); } if (MachineLearning.Classes.Max() >= cGlobalInfo.ListWellClasses.Count) { MessageBox.Show("The number of cluster is higher than the supported number of classes. Operation cancelled !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Cursor = Cursors.Default; return; } if (MachineLearning.Classes.IsContainNegative() || (MachineLearning.Classes.Count == 0)) { MessageBox.Show("Negative or null cluster index identified. Operation cancelled !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Cursor = Cursors.Default; return; } int IdxWell = 0; // ----- update well classes ------ foreach (cPlate itemPlate in ListPlatesToProcess) { foreach (cWell item in itemPlate.ListActiveWells) item.SetClass((int)MachineLearning.Classes[IdxWell++]); } } cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().DisplayDistribution(cGlobalInfo.CurrentScreening.ListDescriptors.GetActiveDescriptor(), false); this.Cursor = Cursors.Default; }
public cFeedBackMessage Run(bool IsDisplayResults) { cMachineLearning MachineLearning = new cMachineLearning(/*cWell.GlobalInfo*/null); ParamAlgoForClustering = MachineLearning.AskAndGetClusteringAlgo(); if (MinObjectsNumber == -1) MinObjectsNumber = (cGlobalInfo.CurrentScreening.Columns * cGlobalInfo.CurrentScreening.Rows * (int)cGlobalInfo.OptionsWindow.numericUpDownSystemMinWellRatio.Value) / 100; foreach (cPlate CurrentPlate in PlatesToProcess) { cExtendedTable CurrentPlateResult = null; foreach (var item in this.DescriptorsToProcess) { cExtendedTable ET = CurrentPlate.GetAverageValueList(item, false); ET.Name = item.GetName(); cExtendedTable ResultTable = this.GenerateArtifactMessage(ET, CurrentPlate); ResultTable.ListRowNames = new List<string>(); ResultTable.ListRowNames.Add(item.GetName()); if (CurrentPlateResult == null) CurrentPlateResult = new cExtendedTable(ResultTable); else { cMerge M = new cMerge(); M.IsHorizontal = false; M.SetInputData(CurrentPlateResult, ResultTable); M.Run(); CurrentPlateResult = M.GetOutPut(); } } CurrentPlateResult.Name = CurrentPlate.GetName(); CurrentPlateResult.Tag = CurrentPlate; this.Output.Add(CurrentPlateResult); } this.Output.Name = "Systematic Errors (" + PlatesToProcess.Count + " plate(s))"; if (IsDisplayResults) { cDisplayToWindow DTW = new cDisplayToWindow(); cDesignerMultiChoices DMC = new cDesignerMultiChoices(); foreach (var item in this.Output) { cDesignerSplitter DS = new cDesignerSplitter(); DS.Orientation = System.Windows.Forms.Orientation.Horizontal; DS.Title = item.Name; cViewerTable VT = new cViewerTable(); VT.SetInputData(item); VT.DigitNumber = 0; VT.Run(); DS.SetInputData(VT.GetOutPut()); cViewerHeatMap VHM = new cViewerHeatMap(); VHM.SetInputData(item); VHM.IsAutomatedMinMax = false; VHM.Min = 0; VHM.Max = 1; VHM.Run(); DS.SetInputData(VHM.GetOutPut()); DS.Run(); cExtendedControl TmpXCtrl = DS.GetOutPut(); TmpXCtrl.Tag = item.Tag; DMC.SetInputData(TmpXCtrl); } DMC.Run(); DTW.SetInputData(DMC.GetOutPut()); DTW.Title = "Systematic Errors [" + PlatesToProcess.Count + " plate(s)]"; DTW.Run(); DTW.Display(); //cDisplayListExtendedTable DLET = new cDisplayListExtendedTable(); //DLET.SetInputData(this.Output); //return DLET.Run(); } return FeedBackMessage; }