public LeastSquaresSolver(int Row_number, int Column_number) { m_A = MathNetNumLin.Matrix <double> .Build.Dense(Row_number, Column_number); m_xInitial = MathNetNumLin.Vector <double> .Build.Dense(Column_number, 1); m_xLowerBound = MathNetNumLin.Vector <double> .Build.Dense(Column_number, 1); m_xUpperBound = MathNetNumLin.Vector <double> .Build.Dense(Column_number, 1); m_b = MathNetNumLin.Vector <double> .Build.Dense(Row_number, 1); m_results = MathNetNumLin.Vector <double> .Build.Dense(Column_number, 1); RowNumber = m_A.RowCount; ColumnNumber = m_A.ColumnCount; }
public MathNetNumLin.Matrix <Complex> LeastSquareEstimationInequalityConstrained(MathNetNumLin.Matrix <Complex> b, MathNetNumLin.Matrix <Complex> A) { int Row_number = A.RowCount; int Column_number = A.ColumnCount; MathNetNumLin.Matrix <double> A_realpart = MathNetNumLin.Matrix <double> .Build.Dense(Row_number, Column_number); MathNetNumLin.Matrix <double> A_imagpart = MathNetNumLin.Matrix <double> .Build.Dense(Row_number, Column_number); MathNetNumLin.Vector <double> b_realpart = MathNetNumLin.Vector <double> .Build.Dense(Row_number); MathNetNumLin.Vector <double> b_imagpart = MathNetNumLin.Vector <double> .Build.Dense(Row_number); for (int idx0 = 0; idx0 < Row_number; idx0++) { for (int idx1 = 0; idx1 < Column_number; idx1++) { A_realpart[idx0, idx1] = A[idx0, idx1].Real; A_imagpart[idx0, idx1] = A[idx0, idx1].Imaginary; } b_realpart[idx0] = b[idx0, 0].Real; b_imagpart[idx0] = b[idx0, 0].Imaginary; } MathNetNumLin.Vector <double> xInitial_realpart = MathNetNumLin.Vector <double> .Build.Dense(Column_number); MathNetNumLin.Vector <double> xInitial_imagpart = MathNetNumLin.Vector <double> .Build.Dense(Column_number); MathNetNumLin.Vector <double> xLowerBound_realpart = MathNetNumLin.Vector <double> .Build.Dense(Column_number); MathNetNumLin.Vector <double> xLowerBound_imagpart = MathNetNumLin.Vector <double> .Build.Dense(Column_number); MathNetNumLin.Vector <double> xUpperBound_realpart = MathNetNumLin.Vector <double> .Build.Dense(Column_number); MathNetNumLin.Vector <double> xUpperBound_imagpart = MathNetNumLin.Vector <double> .Build.Dense(Column_number); for (int idx2 = 0; idx2 < Column_number; idx2++) { xInitial_realpart[idx2] = 1; xInitial_imagpart[idx2] = 0; xLowerBound_realpart[idx2] = 0.9452; xLowerBound_imagpart[idx2] = -0.1005; xUpperBound_realpart[idx2] = 1.0526; xUpperBound_imagpart[idx2] = 0.1005; } MathNetNumLin.Matrix <Complex> Beta = MathNetNumLin.Matrix <Complex> .Build.Random(Column_number, 1); MathNetNumLin.Vector <double> RealBeta = MathNetNumLin.Vector <double> .Build.Random(Column_number); LeastSquaresSolver RealPartSolver = new LeastSquaresSolver(Row_number, Column_number); RealPartSolver.A = A_realpart; RealPartSolver.b = b_realpart; RealPartSolver.xInitial = xInitial_realpart; RealPartSolver.xLowerBound = xLowerBound_realpart; RealPartSolver.xUpperBound = xUpperBound_realpart; RealPartSolver.LeastSqauresInequalityConstrainedEstimation(); for (int idx3 = 0; idx3 < RealPartSolver.Results.Count; idx3++) { RealBeta[idx3] = RealPartSolver.Results[idx3]; } LeastSquaresSolver ImagPartSolver = new LeastSquaresSolver(Row_number, Column_number); ImagPartSolver.A = A_imagpart; ImagPartSolver.b = b_imagpart; ImagPartSolver.xInitial = xInitial_imagpart; ImagPartSolver.xLowerBound = xLowerBound_imagpart; ImagPartSolver.xUpperBound = xUpperBound_imagpart; ImagPartSolver.LeastSqauresInequalityConstrainedEstimation(); for (int idx4 = 0; idx4 < RealPartSolver.Results.Count; idx4++) { Beta[idx4, 0] = new Complex(RealBeta[idx4], ImagPartSolver.Results[idx4]); } return(Beta); }