/// <summary> /// Asks the user for the preferred number of factors to use for calculation and plotting and stores that number in the /// PLS content tag of the table. /// </summary> /// <param name="table">The table which contains the PLS model.</param> public static void QuestPreferredNumberOfFactors(Altaxo.Data.DataTable table) { MultivariateContentMemento plsMemo = table.GetTableProperty("Content") as MultivariateContentMemento; if(plsMemo==null) return; QuestPreferredNumberOfFactors(plsMemo); }
/// <summary> /// Plots the x (spectral) residuals (of cross prediction) of all spectra invidually in a graph. /// </summary> /// <param name="table">The table with the PLS model data.</param> public static void PlotXCrossResiduals(Altaxo.Data.DataTable table) { MultivariateContentMemento plsMemo = table.GetTableProperty("Content") as MultivariateContentMemento; if(plsMemo==null) return; if(plsMemo.PreferredNumberOfFactors<=0) QuestPreferredNumberOfFactors(plsMemo); for(int nComponent=0;nComponent<plsMemo.NumberOfConcentrationData;nComponent++) { Altaxo.Graph.GUI.IGraphController graphctrl = Current.ProjectService.CreateNewGraph(); PlotXResiduals(table,graphctrl.Doc.Layers[0],nComponent,plsMemo.PreferredNumberOfFactors); } }
/// <summary> /// Plots the x (spectral) leverage into a graph. /// </summary> /// <param name="table">The table with the PLS model data.</param> public static void PlotXLeverage(Altaxo.Data.DataTable table) { MultivariateContentMemento plsMemo = table.GetTableProperty("Content") as MultivariateContentMemento; if(plsMemo==null) return; if(plsMemo.PreferredNumberOfFactors<=0) QuestPreferredNumberOfFactors(plsMemo); Altaxo.Graph.GUI.IGraphController graphctrl = Current.ProjectService.CreateNewGraph(); PlotXLeverage(table,graphctrl.Doc.Layers[0],plsMemo.PreferredNumberOfFactors); }
/// <summary> /// Plots all preprocessed spectra into a newly created graph. /// </summary> /// <param name="table">The table of PLS output data.</param> public static void PlotPredictionScores(Altaxo.Data.DataTable table) { MultivariateContentMemento plsMemo = table.GetTableProperty("Content") as MultivariateContentMemento; if(plsMemo==null) return; if(plsMemo.PreferredNumberOfFactors<=0) QuestPreferredNumberOfFactors(plsMemo); GetAnalysis(table).CalculateAndStorePredictionScores(table, plsMemo.PreferredNumberOfFactors); AscendingIntegerCollection sel = new AscendingIntegerCollection(); for(int i=0;i<plsMemo.NumberOfConcentrationData;i++) { string name = WorksheetAnalysis.GetPredictionScore_ColumnName(i,plsMemo.PreferredNumberOfFactors); if(null!=table[name]) sel.Add(table.DataColumns.GetColumnNumber(table[name])); } Worksheet.Commands.PlotCommands.PlotLine(table,sel,true,false); }
/// <summary> /// Fills a provided table (should be empty) with the preprocessed spectra. The spectra are saved as columns (independently on their former orientation in the original worksheet). /// </summary> /// <param name="calibtable">The table containing the calibration model.</param> /// <param name="desttable">The table where to store the preprocessed spectra. Should be empty.</param> public void CalculatePreprocessedSpectra( Altaxo.Data.DataTable calibtable, Altaxo.Data.DataTable desttable) { MultivariateContentMemento plsMemo = calibtable.GetTableProperty("Content") as MultivariateContentMemento; if(plsMemo==null) throw new ArgumentException("Table does not contain a PLSContentMemento"); IMatrix matrixX = GetRawSpectra(plsMemo); IMultivariateCalibrationModel calib = GetCalibrationModel(calibtable); // do spectral preprocessing plsMemo.SpectralPreprocessing.ProcessForPrediction(matrixX,calib.PreprocessingModel.XMean,calib.PreprocessingModel.XScale); // for the new table, save the spectra as column DoubleColumn xcol = new DoubleColumn(); for(int i=matrixX.Columns;i>=0;i--) xcol[i] = calib.PreprocessingModel.XOfX[i]; desttable.DataColumns.Add(xcol,_XOfX_ColumnName,ColumnKind.X,0); for(int n=0;n<matrixX.Rows;n++) { DoubleColumn col = new DoubleColumn(); for(int i=matrixX.Columns-1;i>=0;i--) col[i] = matrixX[n,i]; desttable.DataColumns.Add(col,n.ToString(),ColumnKind.V,0); } }
/// <summary> /// Plots the x (spectral) residuals (of cross prediction) of all spectra invidually in a graph. /// </summary> /// <param name="table">The table with the PLS model data.</param> public static void PlotXCrossResiduals(Altaxo.Data.DataTable table) { MultivariateContentMemento plsMemo = table.GetTableProperty("Content") as MultivariateContentMemento; if (plsMemo == null) return; if (plsMemo.PreferredNumberOfFactors <= 0) QuestPreferredNumberOfFactors(plsMemo); for (int nComponent = 0; nComponent < plsMemo.NumberOfConcentrationData; nComponent++) { string newName = string.Format("GXCrossResidualsC{0}#{1}F", nComponent, plsMemo.PreferredNumberOfFactors); var graphctrl = CreateNewGraphWithXYLayer(table.GetPropertyContext(), Main.ProjectFolder.CreateFullName(table.Name, newName), table.Name); PlotXResiduals(table, graphctrl.Doc.GetFirstXYPlotLayer(), nComponent, plsMemo.PreferredNumberOfFactors); } }
/// <summary> /// Plots the cross prediction values of all y components invidually in a graph. /// </summary> /// <param name="table">The table with the PLS model data.</param> /// <param name="allowGuiForMessages">If <see langword="true"/> and an error occurs, an error message box is presented to the user.</param> public static void PlotCrossPredictedVersusActualY(Altaxo.Data.DataTable table, bool allowGuiForMessages) { MultivariateContentMemento plsMemo = table.GetTableProperty("Content") as MultivariateContentMemento; if (plsMemo == null) { string msg = string.Format("The table <<{0}>> does not seem to contain multivariate analysis data (content memento is missing)", table.Name); if (allowGuiForMessages) Current.Gui.ErrorMessageBox(msg); else throw new ApplicationException(msg); return; } while (!Current.Project.DataTableCollection.Contains(plsMemo.OriginalDataTableName)) { string msg = string.Format("The table of the original spectral data <<{0}>> does not exist (renamed?)", plsMemo.OriginalDataTableName); if (allowGuiForMessages) { Current.Gui.ErrorMessageBox(msg); string newName = plsMemo.OriginalDataTableName; // TODO replace by a TableChoiceDialogBox if (Current.Gui.ShowDialog(ref newName, "Please enter the table name of original spectral data", false)) plsMemo.OriginalDataTableName = newName; } else throw new WorksheetAnalysis.OriginalDataTableNotFoundException(msg); } if (plsMemo.PreferredNumberOfFactors <= 0) QuestPreferredNumberOfFactors(plsMemo); for (int nComponent = 0; nComponent < plsMemo.NumberOfConcentrationData; nComponent++) { string newName = string.Format("GCrossPredVsActC{0}#{1}F", nComponent, plsMemo.PreferredNumberOfFactors); var graphctrl = CreateNewGraphWithXYLayer(table.GetPropertyContext(), Main.ProjectFolder.CreateFullName(table.Name, newName), table.Name); PlotCrossPredictedVersusActualY(table, graphctrl.Doc.GetFirstXYPlotLayer(), nComponent, plsMemo.PreferredNumberOfFactors); } }
/// <summary> /// Plots the x (spectral) leverage into a graph. /// </summary> /// <param name="table">The table with the PLS model data.</param> public static void PlotXLeverage(Altaxo.Data.DataTable table) { MultivariateContentMemento plsMemo = table.GetTableProperty("Content") as MultivariateContentMemento; if (plsMemo == null) return; if (plsMemo.PreferredNumberOfFactors <= 0) QuestPreferredNumberOfFactors(plsMemo); string newName = string.Format("GXLeverage#{0}F", plsMemo.PreferredNumberOfFactors); newName = Main.ProjectFolder.CreateFullName(table.Name, newName); var graphctrl = CreateNewGraphWithXYLayer(table.GetPropertyContext(), Main.ProjectFolder.CreateFullName(table.Name, newName), table.Name); PlotXLeverage(table, graphctrl.Doc.GetFirstXYPlotLayer(), plsMemo.PreferredNumberOfFactors); }
public PredictionModelExporter(Altaxo.Data.DataTable table, int numberOfFactors) { _table = table; _memento = table.GetTableProperty("Content") as MultivariateContentMemento; _numberOfFactors = numberOfFactors; }