/// <summary> /// This sets up a Savitzky-Golay filter. /// </summary> /// <param name="numberOfPoints">Number of points. Must be an odd number, otherwise it is rounded up.</param> /// <param name="derivativeOrder">Order of derivative you want to obtain. Set 0 for smothing.</param> /// <param name="polynomialOrder">Order of the fitting polynomial. Usual values are 2 or 4.</param> public SavitzkyGolay(int numberOfPoints, int derivativeOrder, int polynomialOrder) { numberOfPoints = 1 + 2 * (numberOfPoints / 2); int numberOfSide = (numberOfPoints - 1) / 2; _left = JaggedArrayMath.GetMatrixArray(numberOfSide, numberOfPoints); _right = JaggedArrayMath.GetMatrixArray(numberOfSide, numberOfPoints); _middle = new double[numberOfPoints]; GetCoefficients(numberOfSide, numberOfSide, derivativeOrder, polynomialOrder, VectorMath.ToVector(_middle)); for (int i = 0; i < numberOfSide; i++) { GetCoefficients(i, 2 * numberOfSide - i, derivativeOrder, polynomialOrder, VectorMath.ToVector(_left[i])); GetCoefficients(2 * numberOfSide - i, i, derivativeOrder, polynomialOrder, VectorMath.ToVector(_right[i])); } }
public static void ExecuteAnalysis( IROMatrix <double> X, // matrix of spectra (a spectra is a row of this matrix) IROMatrix <double> Y, // matrix of concentrations (a mixture is a row of this matrix) ref int numFactors, out IROMatrix <double> xLoads, // out: the loads of the X matrix out IROMatrix <double> xScores, // matrix of weighting values out IROVector <double> V // vector of cross products ) { var matrixX = new MatrixMath.LeftSpineJaggedArrayMatrix <double>(X.RowCount, X.ColumnCount); MatrixMath.Copy(X, matrixX); var decompose = new MatrixMath.SingularValueDecomposition(matrixX); numFactors = Math.Min(numFactors, matrixX.ColumnCount); numFactors = Math.Min(numFactors, matrixX.RowCount); xLoads = JaggedArrayMath.ToTransposedROMatrix(decompose.V, Y.RowCount, X.ColumnCount); xScores = JaggedArrayMath.ToMatrix(decompose.U, Y.RowCount, Y.RowCount); V = VectorMath.ToROVector(decompose.Diagonal, numFactors); }