public cExtendedList GetYvalues() { cExtendedList List = new cExtendedList(); List.AddRange(ListValuesY); return List; }
private void Process() { double[,] DataForLDA = Input.CopyToArray(); //double[,] Basis; //double[] s2; int Info; /************************************************************************* Linear least squares fitting. QR decomposition is used to reduce task to MxM, then triangular solver or SVD-based solver is used depending on condition number of the system. It allows to maximize speed and retain decent accuracy. INPUT PARAMETERS: Y - array[0..N-1] Function values in N points. FMatrix - a table of basis functions values, array[0..N-1, 0..M-1]. FMatrix[I, J] - value of J-th basis function in I-th point. N - number of points used. N>=1. M - number of basis functions, M>=1. OUTPUT PARAMETERS: Info - error code: * -4 internal SVD decomposition subroutine failed (very rare and for degenerate systems only) * 1 task is solved C - decomposition coefficients, array[0..M-1] Rep - fitting report. Following fields are set: * Rep.TaskRCond reciprocal of condition number * R2 non-adjusted coefficient of determination (non-weighted) * RMSError rms error on the (X,Y). * AvgError average error on the (X,Y). * AvgRelError average relative error on the non-zero Y * MaxError maximum error NON-WEIGHTED ERRORS ARE CALCULATED ERRORS IN PARAMETERS This solver also calculates different kinds of errors in parameters and fills corresponding fields of report: * Rep.CovPar covariance matrix for parameters, array[K,K]. * Rep.ErrPar errors in parameters, array[K], errpar = sqrt(diag(CovPar)) * Rep.ErrCurve vector of fit errors - standard deviations of empirical best-fit curve from "ideal" best-fit curve built with infinite number of samples, array[N]. errcurve = sqrt(diag(F*CovPar*F')), where F is functions matrix. * Rep.Noise vector of per-point estimates of noise, array[N] NOTE: noise in the data is estimated as follows: * for fitting without user-supplied weights all points are assumed to have same level of noise, which is estimated from the data * for fitting with user-supplied weights we assume that noise level in I-th point is inversely proportional to Ith weight. Coefficient of proportionality is estimated from the data. NOTE: we apply small amount of regularization when we invert squared Jacobian and calculate covariance matrix. It guarantees that algorithm won't divide by zero during inversion, but skews error estimates a bit (fractional error is about 10^-9). However, we believe that this difference is insignificant for all practical purposes except for the situation when you want to compare ALGLIB results with "reference" implementation up to the last significant digit. -- ALGLIB -- Copyright 17.08.2009 by Bochkanov Sergey *************************************************************************/ double[] weights = null; int fitResult = 0; double[] resultData = new double[this.Input[0].Count]; //alglib.lsfit.lsfitreport rep = new alglib.lsfit.lsfitreport(); //alglib.lsfit.lsfitlinear(resultData, DataForLDA, this.Input[0].Count, this.Input.Count, ref fitResult, ref weights, rep); //alglib.lsfitstate state; int info; //double[] c = new double[] { 0, 0, 0, 0 }; //alglib.lsfitreport Nrep; //alglib.lsfitresults(state, out info, out c, out Nrep); // alglib.fisherldan(DataForLDA, this.Input[0].Count, this.Input.Count - 1, (int)this.Input[this.Input.Count - 1].Max() + 1, out Info, out Basis); //Output = new cExtendedTable(Basis); alglib.linearmodel LM = null; alglib.lrreport Lreport = null; alglib.lrbuild(DataForLDA, this.Input[0].Count, this.Input.Count-1, out info, out LM, out Lreport); //RelativeError = rep.avgrelerror; //LM.innerobj.w[0] = 1; double[] Coeff = null; int NVars; alglib.lrunpack(LM, out Coeff, out NVars); cExtendedList CL = new cExtendedList(); CL.AddRange(Coeff); CL.Name = "Coefficients"; this.Output = new cExtendedTable(CL); this.Output.ListRowNames = new List<string>(); for (int i = 0; i < this.Output[0].Count; i++) this.Output.ListRowNames.Add("Coeff_" + i); double RelativeError = Lreport.avgrelerror; this.Output.ListRowNames.Add("Relative Error"); CL.Add(RelativeError); Output.Name = "Linear regression coeff. of (" + this.Input.Name + ")"; //foreach (var item in Output) //{ // item.ListTags = new List<object>(); // for (int i = 0; i < Output[0].Count; i++) // item.ListTags.Add(this.Input[i].Tag); //} //for (int IdxLDA = 0; IdxLDA < Output.Count; IdxLDA++) //{ // Output[IdxLDA].Name = "LDA_" + (IdxLDA + 1); // Output.ListRowNames.Add(this.Input[IdxLDA].Name); //} }
// List<cWell> ListWellsForReference; //public List<cWell> GetReferenceWells() //{ // return this.ListWellsForReference; //} //public cReference(cListWells WellsForReference) //{ // this.ListWellsForReference = WellsForReference; // //int IdxDesc = 0; // //// main loop over the descriptors // //foreach (cDescriptor Desc in WellsForReference[0].ListDescriptors) // //{ // // cExtendedList NewList = new cExtendedList(); // // for (int i = 0; i < Desc.GetAssociatedType().GetBinNumber(); i++) // // { // // double CurrentVal = 0; // // foreach (cWell CurrentWell in WellsForReference) // // { // // CurrentVal += CurrentWell.ListDescriptors[IdxDesc].GetHistovalues()[i];// Desc.Getvalue(i); // // } // // CurrentVal /= (double)WellsForReference.Count; // // NewList.Add(CurrentVal); // // } // // this.Add(NewList); // // IdxDesc++; // //} //} public cExtendedList GetValues(int DescriptorIdx) { cExtendedList ListValue = new cExtendedList(); foreach (cWell TmpWell in this) { ListValue.AddRange(TmpWell.ListSignatures[DescriptorIdx].GetOriginalValues()); } return ListValue; }
public cWindowToDisplaySingleMatrix(cPanelForDisplayArray PanelToDisplay, eDistances Dist) { //this.CellSize = SizeSquare; this.Text = "Distance Matrix ( " + Dist.ToString() + ")"; this.XNumber = 1; this.checkBoxDisplayClasses.Visible = false; this.checkBoxGlobalNormalization.Visible = false; cExtendedList GlobalValues = new cExtendedList(); GlobalValues.AddRange(PanelToDisplay.GetListValues()); double Max_ = GlobalValues.Max(); double Min_ = GlobalValues.Min(); PanelToDisplay.GlobalMin = Min_; PanelToDisplay.GlobalMax = Max_; this.PanelList = new List<cPanelForDisplayArray>(); this.PanelList.Add(PanelToDisplay); this.Width = PanelToDisplay.Width + 500; this.Height = PanelToDisplay.Height + 500; RefreshDisplay(false); this.Show(); }
public cWindowToDisplayEntireScreening(List<cPanelForDisplayArray> PanelList, string Text, int XNumber) { this.XNumber = XNumber; this.Text += " : " + Text; cExtendedList GlobalValues = new cExtendedList(); for (int i = 0; i < PanelList.Count; i++) { cExtendedList TmpList = PanelList[i].GetListValues(); if (TmpList == null) continue; GlobalValues.AddRange(TmpList); } double Max_ = GlobalValues.Max(); double Min_ = GlobalValues.Min(); for (int i = 0; i < PanelList.Count; i++) { PanelList[i].GlobalMin = Min_; PanelList[i].GlobalMax = Max_; PanelList[i].ParentWindow = this; } this.PanelList = PanelList; this.comboBoxDistances.Visible = false; RefreshDisplay(false); this.Show(); }
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(); }
cFeedBackMessage Process() { this.Output = new cExtendedTable(); this.Output.Name = "Histogram (" + this.Input.Name + ")"; List<double[]> Res = null; if (IsBinNumberMode) { if (double.IsNaN(this.Min) || double.IsNaN(this.Max)) Res = Input[0].CreateHistogram(this.BinNumber, this.IsNormalized); else Res = Input[0].CreateHistogram(this.Min, this.Max, (int)this.BinNumber, this.IsNormalized); } else { //if (double.IsNaN(this.Min) || double.IsNaN(this.Max)) // Res = Input[0].CreateHistogram(this.BinNumber, this.IsNormalized); //else Res = Input[0].CreateHistogram(this.Min, this.Max, this.BinSize); } if (Res.Count == 0) { base.FeedBackMessage.IsSucceed = false; base.FeedBackMessage.Message = "Histogram failure"; return base.FeedBackMessage; } string ColName = "Frequency"; if (IsNormalized) ColName = "Normalized " + ColName; cExtendedList ListY = new cExtendedList(ColName); if (this.Input[0].Name == "") ColName = "Value"; else ColName = this.Input[0].Name; cExtendedList ListX = new cExtendedList(ColName); ListX.AddRange(Res[0]); ListY.AddRange(Res[1]); this.Output.Add(ListX); this.Output.Add(ListY); return base.FeedBackMessage; }