/// <summary> /// Creates the corresponding grouping strategy out of the CrossPRESSCalculation enumeration in plsOptions. /// </summary> /// <param name="plsOptions">The options for PLS analysis</param> /// <returns>The used grouping strategy. Returns null if no cross validation is choosen.</returns> public static ICrossValidationGroupingStrategy GetGroupingStrategy(MultivariateAnalysisOptions plsOptions) { return GetGroupingStrategy(plsOptions.CrossPRESSCalculation); }
/// <summary> /// Asks the user for the maximum number of factors and the cross validation calculation. /// </summary> /// <param name="options">The PLS options to ask for. On return, this is the user's choice.</param> /// <param name="preprocessOptions">The spectral preprocessing options to ask for (output).</param> /// <returns>True if the user has made his choice, false if the user pressed the Cancel button.</returns> public static bool QuestPLSAnalysisOptions(out MultivariateAnalysisOptions options, out SpectralPreprocessingOptions preprocessOptions) { options = new MultivariateAnalysisOptions(); options.MaxNumberOfFactors =20; options.CrossPRESSCalculation = CrossPRESSCalculationType.ExcludeGroupsOfSimilarMeasurements; PLSStartAnalysisController ctrlAA = new PLSStartAnalysisController(options); PLSStartAnalysisControl viewAA = new PLSStartAnalysisControl(); ctrlAA.View = viewAA; preprocessOptions = new SpectralPreprocessingOptions(); SpectralPreprocessingController ctrlBB = new SpectralPreprocessingController(preprocessOptions); SpectralPreprocessingControl viewBB = new SpectralPreprocessingControl(); ctrlBB.View = viewBB; TabbedElementController tabController = new TabbedElementController(); tabController.AddTab("Factors",ctrlAA,viewAA); tabController.AddTab("Preprocessing", ctrlBB, viewBB); if (Current.Gui.ShowDialog(tabController, "Enter analysis parameters", false)) { options = ctrlAA.Doc; return true; } /* TabbedDialogController dialogctrl = new TabbedDialogController("PLS Analysis",false); dialogctrl.AddTab("Factors",ctrlAA,viewAA); dialogctrl.AddTab("Preprocessing",ctrlBB,viewBB); TabbedDialogView dialogview = new TabbedDialogView(); dialogctrl.View = dialogview; if(dialogctrl.ShowDialog(Current.MainWindow)) { options = ctrlAA.Doc; return true; } */ return false; }
/// <summary> /// Calculate the cross PRESS values and stores the results in the provided table. /// </summary> /// <param name="xOfX">Vector of spectral wavelengths. Necessary to divide the spectras in different regions.</param> /// <param name="matrixX">Matrix of spectra (horizontal oriented).</param> /// <param name="matrixY">Matrix of concentrations.</param> /// <param name="plsOptions">Analysis options.</param> /// <param name="plsContent">Information about this analysis.</param> /// <param name="table">Table to store the results.</param> public virtual void CalculateCrossPRESS( IROVector xOfX, IMatrix matrixX, IMatrix matrixY, MultivariateAnalysisOptions plsOptions, MultivariateContentMemento plsContent, DataTable table ) { IROVector crossPRESSMatrix; Altaxo.Data.DoubleColumn crosspresscol = new Altaxo.Data.DoubleColumn(); double meanNumberOfExcludedSpectra = 0; if (plsOptions.CrossPRESSCalculation != CrossPRESSCalculationType.None) { // now a cross validation - this can take a long time for bigger matrices MultivariateRegression.GetCrossPRESS( xOfX, matrixX, matrixY, plsOptions.MaxNumberOfFactors, GetGroupingStrategy(plsOptions), plsContent.SpectralPreprocessing, this.CreateNewRegressionObject(), out crossPRESSMatrix); VectorMath.Copy(crossPRESSMatrix, DataColumnWrapper.ToVector(crosspresscol, crossPRESSMatrix.Length)); table.DataColumns.Add(crosspresscol, GetCrossPRESSValue_ColumnName(), Altaxo.Data.ColumnKind.V, 4); plsContent.MeanNumberOfMeasurementsInCrossPRESSCalculation = plsContent.NumberOfMeasurements - meanNumberOfExcludedSpectra; } else { table.DataColumns.Add(crosspresscol, GetCrossPRESSValue_ColumnName(), Altaxo.Data.ColumnKind.V, 4); } }
/// <summary> /// Execute an analysis and stores the result in the provided table. /// </summary> /// <param name="matrixX">The matrix of spectra (horizontal oriented), centered and preprocessed.</param> /// <param name="matrixY">The matrix of concentrations, centered.</param> /// <param name="plsOptions">Information how to perform the analysis.</param> /// <param name="plsContent">A structure to store information about the results of the analysis.</param> /// <param name="table">The table where to store the results to.</param> /// <param name="press">On return, gives a vector holding the PRESS values of the analysis.</param> public virtual void ExecuteAnalysis( IMatrix matrixX, IMatrix matrixY, MultivariateAnalysisOptions plsOptions, MultivariateContentMemento plsContent, DataTable table, out IROVector press ) { int numFactors = Math.Min(matrixX.Columns, plsOptions.MaxNumberOfFactors); MultivariateRegression regress = this.CreateNewRegressionObject(); regress.AnalyzeFromPreprocessed(matrixX, matrixY, numFactors); plsContent.NumberOfFactors = regress.NumberOfFactors; plsContent.CrossValidationType = plsOptions.CrossPRESSCalculation; press = regress.GetPRESSFromPreprocessed(matrixX); Import(regress.CalibrationModel, table); }
/// <summary> /// Makes a PLS (a partial least squares) analysis of the table or the selected columns / rows and stores the results in a newly created table. /// </summary> /// <param name="mainDocument">The main document of the application.</param> /// <param name="srctable">The table where the data come from.</param> /// <param name="selectedColumns">The selected columns.</param> /// <param name="selectedRows">The selected rows.</param> /// <param name="selectedPropertyColumns">The selected property column(s).</param> /// <param name="bHorizontalOrientedSpectrum">True if a spectrum is a single row, False if a spectrum is a single column.</param> /// <param name="plsOptions">Provides information about the max number of factors and the calculation of cross PRESS value.</param> /// <param name="preprocessOptions">Provides information about how to preprocess the spectra.</param> /// <returns></returns> public virtual string ExecuteAnalysis( Altaxo.AltaxoDocument mainDocument, Altaxo.Data.DataTable srctable, IAscendingIntegerCollection selectedColumns, IAscendingIntegerCollection selectedRows, IAscendingIntegerCollection selectedPropertyColumns, bool bHorizontalOrientedSpectrum, MultivariateAnalysisOptions plsOptions, SpectralPreprocessingOptions preprocessOptions ) { IMatrix matrixX, matrixY; IROVector xOfX; var plsContent = new MultivariateContentMemento(); plsContent.Analysis = this; // now we have to create a new table where to place the calculated factors and loads // we will do that in a vertical oriented manner, i.e. even if the loads are // here in horizontal vectors: in our table they are stored in (vertical) columns string newName = this.AnalysisName + " of " + Main.ProjectFolder.GetNamePart(srctable.Name); newName = Main.ProjectFolder.CreateFullName(srctable.Name, newName); Altaxo.Data.DataTable table = new Altaxo.Data.DataTable(newName); // Fill the Table using (var suspendToken = table.SuspendGetToken()) { table.SetTableProperty("Content", plsContent); plsContent.OriginalDataTableName = srctable.Name; // Get matrices GetXYMatrices( srctable, selectedColumns, selectedRows, selectedPropertyColumns, bHorizontalOrientedSpectrum, plsContent, out matrixX, out matrixY, out xOfX); StoreXOfX(xOfX, table); // Preprocess plsContent.SpectralPreprocessing = preprocessOptions; IVector meanX, scaleX, meanY, scaleY; MultivariateRegression.PreprocessForAnalysis(preprocessOptions, xOfX, matrixX, matrixY, out meanX, out scaleX, out meanY, out scaleY); StorePreprocessedData(meanX, scaleX, meanY, scaleY, table); // Analyze and Store IROVector press; ExecuteAnalysis( matrixX, matrixY, plsOptions, plsContent, table, out press); this.StorePRESSData(press, table); if (plsOptions.CrossPRESSCalculation != CrossPRESSCalculationType.None) CalculateCrossPRESS(xOfX, matrixX, matrixY, plsOptions, plsContent, table); StoreFRatioData(table, plsContent); StoreOriginalY(table, plsContent); suspendToken.Dispose(); } Current.Project.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); return null; }
public PLSStartAnalysisController(MultivariateAnalysisOptions options) { _doc = options; }
/// <summary> /// Asks the user for the maximum number of factors and the cross validation calculation. /// </summary> /// <param name="options">The PLS options to ask for. On return, this is the user's choice.</param> /// <param name="preprocessOptions">The spectral preprocessing options to ask for (output).</param> /// <returns>True if the user has made his choice, false if the user pressed the Cancel button.</returns> public static bool QuestPLSAnalysisOptions(out MultivariateAnalysisOptions options, out SpectralPreprocessingOptions preprocessOptions) { options = new MultivariateAnalysisOptions(); options.MaxNumberOfFactors = 20; options.CrossPRESSCalculation = CrossPRESSCalculationType.ExcludeGroupsOfSimilarMeasurements; PLSStartAnalysisController ctrlAA = new PLSStartAnalysisController(options); Current.Gui.FindAndAttachControlTo(ctrlAA); preprocessOptions = new SpectralPreprocessingOptions(); SpectralPreprocessingController ctrlBB = new SpectralPreprocessingController(preprocessOptions); Current.Gui.FindAndAttachControlTo(ctrlBB); TabbedElementController tabController = new TabbedElementController(); tabController.AddTab("Factors", ctrlAA, ctrlAA.ViewObject); tabController.AddTab("Preprocessing", ctrlBB, ctrlBB.ViewObject); if (Current.Gui.ShowDialog(tabController, "Enter analysis parameters", false)) { options = ctrlAA.Doc; return true; } return false; }