public override void SetCalibrationModel(IMultivariateCalibrationModel calib) { if(calib is PCRCalibrationModel) _calib = (PCRCalibrationModel) calib; else throw new ArgumentException("Expecting argument of type PCRCalibrationModel, but actual type is " + calib.GetType().ToString()); }
public override void SetCalibrationModel(IMultivariateCalibrationModel calib) { if (calib is PCRCalibrationModel) { _calib = (PCRCalibrationModel)calib; } else { throw new ArgumentException("Expecting argument of type PCRCalibrationModel, but actual type is " + calib.GetType().ToString()); } }
/// <summary> /// Exports a table to a PLS2CalibrationSet /// </summary> /// <param name="table">The table where the calibration model is stored.</param> /// <param name="calibrationSet"></param> public static void Export( DataTable table, out PCRCalibrationModel calibrationSet) { int numberOfX = GetNumberOfX(table); int numberOfY = GetNumberOfY(table); int numberOfFactors = GetNumberOfFactors(table); int numberOfMeasurements = GetNumberOfMeasurements(table); calibrationSet = new PCRCalibrationModel(); calibrationSet.NumberOfX = numberOfX; calibrationSet.NumberOfY = numberOfY; calibrationSet.NumberOfFactors = numberOfFactors; MultivariatePreprocessingModel preprocessSet = new MultivariatePreprocessingModel(); MultivariateContentMemento plsMemo = table.GetTableProperty("Content") as MultivariateContentMemento; if (plsMemo != null) preprocessSet.PreprocessOptions = plsMemo.SpectralPreprocessing; calibrationSet.SetPreprocessingModel(preprocessSet); Altaxo.Collections.AscendingIntegerCollection sel = new Altaxo.Collections.AscendingIntegerCollection(); Altaxo.Data.DataColumn col; col = table.DataColumns.TryGetColumn(GetXOfX_ColumnName()); if (col == null || !(col is INumericColumn)) NotFound(GetXOfX_ColumnName()); preprocessSet.XOfX = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector((INumericColumn)col, numberOfX); col = table.DataColumns.TryGetColumn(GetXMean_ColumnName()); if (col == null) NotFound(GetXMean_ColumnName()); preprocessSet.XMean = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector(col, numberOfX); col = table.DataColumns.TryGetColumn(GetXScale_ColumnName()); if (col == null) NotFound(GetXScale_ColumnName()); preprocessSet.XScale = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector(col, numberOfX); sel.Clear(); col = table.DataColumns.TryGetColumn(GetYMean_ColumnName()); if (col == null) NotFound(GetYMean_ColumnName()); sel.Add(table.DataColumns.GetColumnNumber(col)); preprocessSet.YMean = DataColumnWrapper.ToROVector(col, numberOfY); sel.Clear(); col = table.DataColumns.TryGetColumn(GetYScale_ColumnName()); if (col == null) NotFound(GetYScale_ColumnName()); sel.Add(table.DataColumns.GetColumnNumber(col)); preprocessSet.YScale = DataColumnWrapper.ToROVector(col, numberOfY); sel.Clear(); for (int i = 0; i < numberOfFactors; i++) { string colname = GetXScore_ColumnName(i); col = table.DataColumns.TryGetColumn(colname); if (col == null) NotFound(colname); sel.Add(table.DataColumns.GetColumnNumber(col)); } calibrationSet.XScores = DataTableWrapper.ToROColumnMatrix(table.DataColumns, sel, numberOfMeasurements); sel.Clear(); for (int i = 0; i < numberOfFactors; i++) { string colname = GetXLoad_ColumnName(i); col = table.DataColumns.TryGetColumn(colname); if (col == null) NotFound(colname); sel.Add(table.DataColumns.GetColumnNumber(col)); } calibrationSet.XLoads = DataTableWrapper.ToRORowMatrix(table.DataColumns, sel, numberOfX); sel.Clear(); for (int i = 0; i < numberOfY; i++) { string colname = GetYLoad_ColumnName(i); col = table.DataColumns.TryGetColumn(colname); if (col == null) NotFound(colname); sel.Add(table.DataColumns.GetColumnNumber(col)); } calibrationSet.YLoads = DataTableWrapper.ToROColumnMatrix(table.DataColumns, sel, numberOfMeasurements); sel.Clear(); col = table.DataColumns.TryGetColumn(GetCrossProduct_ColumnName()); if (col == null) NotFound(GetCrossProduct_ColumnName()); calibrationSet.CrossProduct = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector(col, numberOfFactors); }
public override void Reset() { _calib = new PCRCalibrationModel(); base.Reset(); }
public override void Import( IMultivariateCalibrationModel calibrationSet, DataTable table) { PCRCalibrationModel calib = (PCRCalibrationModel)calibrationSet; int numFactors = calib.NumberOfFactors; int numberOfY = calib.NumberOfY; int numberOfPoints = calib.XLoads.Rows; // store the x-loads - careful - they are horizontal for (int i = 0; i < numFactors; i++) { Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int j = 0; j < calib.XLoads.Columns; j++) { col[j] = calib.XLoads[i, j]; } table.DataColumns.Add(col, GetXLoad_ColumnName(i), Altaxo.Data.ColumnKind.V, 0); } // now store the scores - careful - they are vertical in the matrix for (int i = 0; i < numFactors; i++) { Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int j = 0; j < calib.XScores.Rows; j++) { col[j] = calib.XScores[j, i]; } table.DataColumns.Add(col, GetXScore_ColumnName(i), Altaxo.Data.ColumnKind.V, 0); } // now store the y-loads (this are the preprocessed y in this case for (int cn = 0; cn < numberOfY; cn++) { Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int i = 0; i < numberOfPoints; i++) { col[i] = calib.YLoads[i, cn]; } table.DataColumns.Add(col, GetYLoad_ColumnName(cn), Altaxo.Data.ColumnKind.V, 0); } // now store the cross product vector - it is a horizontal vector { Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int j = 0; j < numFactors; j++) { col[j] = calib.CrossProduct[j]; } table.DataColumns.Add(col, GetCrossProduct_ColumnName(), Altaxo.Data.ColumnKind.V, 3); } }
/// <summary> /// Exports a table to a PLS2CalibrationSet /// </summary> /// <param name="table">The table where the calibration model is stored.</param> /// <param name="calibrationSet"></param> public static void Export( DataTable table, out PCRCalibrationModel calibrationSet) { int numberOfX = GetNumberOfX(table); int numberOfY = GetNumberOfY(table); int numberOfFactors = GetNumberOfFactors(table); int numberOfMeasurements = GetNumberOfMeasurements(table); calibrationSet = new PCRCalibrationModel(); calibrationSet.NumberOfX = numberOfX; calibrationSet.NumberOfY = numberOfY; calibrationSet.NumberOfFactors = numberOfFactors; MultivariatePreprocessingModel preprocessSet = new MultivariatePreprocessingModel(); MultivariateContentMemento plsMemo = table.GetTableProperty("Content") as MultivariateContentMemento; if (plsMemo != null) { preprocessSet.PreprocessOptions = plsMemo.SpectralPreprocessing; } calibrationSet.SetPreprocessingModel(preprocessSet); Altaxo.Collections.AscendingIntegerCollection sel = new Altaxo.Collections.AscendingIntegerCollection(); Altaxo.Data.DataColumn col; col = table[GetXOfX_ColumnName()]; if (col == null || !(col is INumericColumn)) { NotFound(GetXOfX_ColumnName()); } preprocessSet.XOfX = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector((INumericColumn)col, numberOfX); col = table[GetXMean_ColumnName()]; if (col == null) { NotFound(GetXMean_ColumnName()); } preprocessSet.XMean = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector(col, numberOfX); col = table[GetXScale_ColumnName()]; if (col == null) { NotFound(GetXScale_ColumnName()); } preprocessSet.XScale = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector(col, numberOfX); sel.Clear(); col = table[GetYMean_ColumnName()]; if (col == null) { NotFound(GetYMean_ColumnName()); } sel.Add(table.DataColumns.GetColumnNumber(col)); preprocessSet.YMean = DataColumnWrapper.ToROVector(col, numberOfY); sel.Clear(); col = table[GetYScale_ColumnName()]; if (col == null) { NotFound(GetYScale_ColumnName()); } sel.Add(table.DataColumns.GetColumnNumber(col)); preprocessSet.YScale = DataColumnWrapper.ToROVector(col, numberOfY); sel.Clear(); for (int i = 0; i < numberOfFactors; i++) { string colname = GetXScore_ColumnName(i); col = table[colname]; if (col == null) { NotFound(colname); } sel.Add(table.DataColumns.GetColumnNumber(col)); } calibrationSet.XScores = DataTableWrapper.ToROColumnMatrix(table.DataColumns, sel, numberOfMeasurements); sel.Clear(); for (int i = 0; i < numberOfFactors; i++) { string colname = GetXLoad_ColumnName(i); col = table[colname]; if (col == null) { NotFound(colname); } sel.Add(table.DataColumns.GetColumnNumber(col)); } calibrationSet.XLoads = DataTableWrapper.ToRORowMatrix(table.DataColumns, sel, numberOfX); sel.Clear(); for (int i = 0; i < numberOfY; i++) { string colname = GetYLoad_ColumnName(i); col = table[colname]; if (col == null) { NotFound(colname); } sel.Add(table.DataColumns.GetColumnNumber(col)); } calibrationSet.YLoads = DataTableWrapper.ToROColumnMatrix(table.DataColumns, sel, numberOfMeasurements); sel.Clear(); col = table[GetCrossProduct_ColumnName()]; if (col == null) { NotFound(GetCrossProduct_ColumnName()); } calibrationSet.CrossProduct = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector(col, numberOfFactors); }