Пример #1
0
 public override void SetCalibrationModel(IMultivariateCalibrationModel calib)
 {
   if(calib is PLS2CalibrationModel)
     _calib = (PLS2CalibrationModel) calib;
   else
     throw new ArgumentException("Expecting argument of type PLS2CalibrationModel, but actual type is " + calib.GetType().ToString());
 }
Пример #2
0
        public override void Import(
            IMultivariateCalibrationModel calibrationSet,
            DataTable table)
        {
            PLS1CalibrationModel calib = (PLS1CalibrationModel)calibrationSet;

            for (int yn = 0; yn < calib.NumberOfY; yn++)
            {
                // store the x-loads - careful - they are horizontal in the matrix
                for (int i = 0; i < calib.XLoads[yn].Rows; i++)
                {
                    Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn();

                    for (int j = 0; j < calib.XLoads[yn].Columns; j++)
                    {
                        col[j] = calib.XLoads[yn][i, j];
                    }

                    table.DataColumns.Add(col, GetXLoad_ColumnName(yn, i), Altaxo.Data.ColumnKind.V, 0);
                }


                // now store the y-loads - careful - they are horizontal in the matrix
                for (int i = 0; i < calib.YLoads[yn].Rows; i++)
                {
                    Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn();

                    for (int j = 0; j < calib.YLoads[yn].Columns; j++)
                    {
                        col[j] = calib.YLoads[yn][i, j];
                    }

                    table.DataColumns.Add(col, GetYLoad_ColumnName(yn, i), Altaxo.Data.ColumnKind.V, 1);
                }

                // now store the weights - careful - they are horizontal in the matrix
                for (int i = 0; i < calib.XWeights[yn].Rows; i++)
                {
                    Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn();

                    for (int j = 0; j < calib.XWeights[yn].Columns; j++)
                    {
                        col[j] = calib.XWeights[yn][i, j];
                    }

                    table.DataColumns.Add(col, GetXWeight_ColumnName(yn, i), 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 < calib.CrossProduct[yn].Columns; j++)
                    {
                        col[j] = calib.CrossProduct[yn][0, j];
                    }
                    table.DataColumns.Add(col, GetCrossProduct_ColumnName(yn), Altaxo.Data.ColumnKind.V, 3);
                }
            } // for all y (constituents)
        }
Пример #3
0
        public override void Import(
            IMultivariateCalibrationModel calibrationSet,
            DataTable table)
        {
            var calib = (PCRCalibrationModel)calibrationSet;

            int numFactors     = calib.NumberOfFactors;
            int numberOfY      = calib.NumberOfY;
            int numberOfPoints = calib.XLoads.RowCount;

            // store the x-loads - careful - they are horizontal
            for (int i = 0; i < numFactors; i++)
            {
                var col = new Altaxo.Data.DoubleColumn();

                for (int j = 0; j < calib.XLoads.ColumnCount; 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++)
            {
                var col = new Altaxo.Data.DoubleColumn();

                for (int j = 0; j < calib.XScores.RowCount; 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++)
            {
                var 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
            {
                var 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);
            }
        }
    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);
    }

    
    }
Пример #5
0
        public override void Import(
            IMultivariateCalibrationModel calibrationSet,
            DataTable table)
        {
            var calib = (PLS2CalibrationModel)calibrationSet;

            // store the x-loads - careful - they are horizontal in the matrix
            for (int i = 0; i < calib.XLoads.RowCount; i++)
            {
                var col = new Altaxo.Data.DoubleColumn();

                for (int j = 0; j < calib.XLoads.ColumnCount; j++)
                {
                    col[j] = calib.XLoads[i, j];
                }

                table.DataColumns.Add(col, GetXLoad_ColumnName(i), Altaxo.Data.ColumnKind.V, 0);
            }

            // now store the y-loads - careful - they are horizontal in the matrix
            for (int i = 0; i < calib.YLoads.RowCount; i++)
            {
                var col = new Altaxo.Data.DoubleColumn();

                for (int j = 0; j < calib.YLoads.ColumnCount; j++)
                {
                    col[j] = calib.YLoads[i, j];
                }

                table.DataColumns.Add(col, GetYLoad_ColumnName(i), Altaxo.Data.ColumnKind.V, 1);
            }

            // now store the weights - careful - they are horizontal in the matrix
            for (int i = 0; i < calib.XWeights.RowCount; i++)
            {
                var col = new Altaxo.Data.DoubleColumn();

                for (int j = 0; j < calib.XWeights.ColumnCount; j++)
                {
                    col[j] = calib.XWeights[i, j];
                }

                table.DataColumns.Add(col, GetXWeight_ColumnName(i), Altaxo.Data.ColumnKind.V, 0);
            }

            // now store the cross product vector - it is a horizontal vector
            {
                var col = new Altaxo.Data.DoubleColumn();

                for (int j = 0; j < calib.CrossProduct.ColumnCount; j++)
                {
                    col[j] = calib.CrossProduct[0, j];
                }
                table.DataColumns.Add(col, GetCrossProduct_ColumnName(), Altaxo.Data.ColumnKind.V, 3);
            }
        }
    public override void Import(
      IMultivariateCalibrationModel calibrationSet,
      DataTable table)
    {
      PLS1CalibrationModel calib = (PLS1CalibrationModel)calibrationSet;

      for(int yn=0;yn<calib.NumberOfY;yn++)
      {
        // store the x-loads - careful - they are horizontal in the matrix
        for(int i=0;i<calib.XLoads[yn].Rows;i++)
        {
          Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn();

          for(int j=0;j<calib.XLoads[yn].Columns;j++)
            col[j] = calib.XLoads[yn][i,j];
          
          table.DataColumns.Add(col,GetXLoad_ColumnName(yn,i),Altaxo.Data.ColumnKind.V,0);
        }


        // now store the y-loads - careful - they are horizontal in the matrix
        for(int i=0;i<calib.YLoads[yn].Rows;i++)
        {
          Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn();
        
          for(int j=0;j<calib.YLoads[yn].Columns;j++)
            col[j] = calib.YLoads[yn][i,j];
        
          table.DataColumns.Add(col,GetYLoad_ColumnName(yn,i),Altaxo.Data.ColumnKind.V,1);
        }

        // now store the weights - careful - they are horizontal in the matrix
        for(int i=0;i<calib.XWeights[yn].Rows;i++)
        {
          Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn();
      
          for(int j=0;j<calib.XWeights[yn].Columns;j++)
            col[j] = calib.XWeights[yn][i,j];
        
          table.DataColumns.Add(col,GetXWeight_ColumnName(yn,i),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<calib.CrossProduct[yn].Columns;j++)
          col[j] = calib.CrossProduct[yn][0,j];
        table.DataColumns.Add(col,GetCrossProduct_ColumnName(yn),Altaxo.Data.ColumnKind.V,3);
      }

      
      } // for all y (constituents)


    }
Пример #7
0
 public override void SetCalibrationModel(IMultivariateCalibrationModel calib)
 {
     if (calib is PLS2CalibrationModel)
     {
         _calib = (PLS2CalibrationModel)calib;
     }
     else
     {
         throw new ArgumentException("Expecting argument of type PLS2CalibrationModel, but actual type is " + calib.GetType().ToString());
     }
 }
Пример #8
0
		/// <summary>
		/// For a given set of spectra, predicts the y-values and stores them in the matrix <c>predictedY</c>
		/// </summary>
		/// <param name="mcalib">The calibration model of the analysis.</param>
		/// <param name="preprocessOptions">The information how to preprocess the spectra.</param>
		/// <param name="matrixX">The matrix of spectra to predict. Each spectrum is a row in the matrix.</param>
		/// <param name="numberOfFactors">The number of factors used for prediction.</param>
		/// <param name="predictedY">On return, this matrix holds the predicted y-values. Each row in this matrix corresponds to the same row (spectrum) in matrixX.</param>
		/// <param name="spectralResiduals">If you set this parameter to a appropriate matrix, the spectral residuals will be stored in this matrix. Set this parameter to null if you don't need the residuals.</param>
		public virtual void CalculatePredictedY(
			IMultivariateCalibrationModel mcalib,
			SpectralPreprocessingOptions preprocessOptions,
			IMatrix matrixX,
			int numberOfFactors,
			MatrixMath.BEMatrix predictedY,
			IMatrix spectralResiduals)
		{
			MultivariateRegression.PreprocessSpectraForPrediction(mcalib, preprocessOptions, matrixX);

			MultivariateRegression regress = this.CreateNewRegressionObject();
			regress.SetCalibrationModel(mcalib);

			regress.PredictedYAndSpectralResidualsFromPreprocessed(matrixX, numberOfFactors, predictedY, spectralResiduals);

			MultivariateRegression.PostprocessY(mcalib.PreprocessingModel, predictedY);
		}
Пример #9
0
		/// <summary>
		///
		/// </summary>
		/// <param name="mcalib"></param>
		/// <param name="groupingStrategy"></param>
		/// <param name="preprocessOptions"></param>
		/// <param name="xOfX"></param>
		/// <param name="matrixX">Matrix of horizontal spectra, centered and preprocessed.</param>
		/// <param name="matrixY">Matrix of concentrations, centered.</param>
		/// <param name="numberOfFactors"></param>
		/// <param name="predictedY"></param>
		/// <param name="spectralResiduals"></param>
		public virtual void CalculateCrossPredictedY(
			IMultivariateCalibrationModel mcalib,
			ICrossValidationGroupingStrategy groupingStrategy,
			SpectralPreprocessingOptions preprocessOptions,
			IROVector xOfX,
			IMatrix matrixX,
			IMatrix matrixY,
			int numberOfFactors,
			IMatrix predictedY,
			IMatrix spectralResiduals)
		{
			MultivariateRegression.GetCrossYPredicted(xOfX,
				matrixX, matrixY, numberOfFactors, groupingStrategy, preprocessOptions,
				this.CreateNewRegressionObject(),
				predictedY);
		}
Пример #10
0
		/// <summary>
		/// Stores the calibrationSet into the data table table.
		/// </summary>
		/// <param name="calibrationSet">The data source.</param>
		/// <param name="table">The table where to store the data of the calibrationSet.</param>
		public abstract void Import(IMultivariateCalibrationModel calibrationSet, DataTable table);
 /// <summary>
 /// This sets the calibration model data of the analysis to the provided data. This can be used to set back previously stored
 /// calibration data for use in the prediction functions.
 /// </summary>
 /// <param name="calib">The calibration set for use in the analysis. The provided calibration model have to correspond to
 /// the type of analysis.</param>
 public abstract void SetCalibrationModel(IMultivariateCalibrationModel calib);
 /// <summary>
 /// This will convert the raw spectra (horizontally in matrixX) to preprocessed spectra according to the calibration model.
 /// </summary>
 /// <param name="calib">The calibration model containing the instructions to process the spectra.</param>
 /// <param name="preprocessOptions">Contains the information how to preprocess the spectra.</param>
 /// <param name="matrixX">The matrix of spectra. Each spectrum is a row of the matrix.</param>
 public static void PreprocessSpectraForPrediction(
   IMultivariateCalibrationModel calib, 
   SpectralPreprocessingOptions preprocessOptions,
   IMatrix matrixX)
 {
   preprocessOptions.ProcessForPrediction(matrixX,calib.PreprocessingModel.XMean,calib.PreprocessingModel.XScale);
 }