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