本文整理汇总了C#中DotNetMatrix.GeneralMatrix.GetElement方法的典型用法代码示例。如果您正苦于以下问题:C# GeneralMatrix.GetElement方法的具体用法?C# GeneralMatrix.GetElement怎么用?C# GeneralMatrix.GetElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DotNetMatrix.GeneralMatrix
的用法示例。
在下文中一共展示了GeneralMatrix.GetElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: displayMatrix
//display specified matrix
static void displayMatrix(GeneralMatrix displayMat)
{
for (int i = 0; i < displayMat.RowDimension; i++)
{
for (int j = 0; j < displayMat.ColumnDimension; j++)
{
Console.Write(displayMat.GetElement(i, j) + ",");
}
Console.WriteLine();
}
}
示例2: Hessian
public void Hessian()
{
double eps = 1e-5;
double[] vector = {0,0,0};
double[][] result = {new double[]{10.0, 2.0, -2.0},
new double[]{ 2.0, 4.0, 2.0},
new double[]{-2.0, 2.0, 4.0}};
GeneralMatrix expectedMatrix = new GeneralMatrix(result);
TestFunction f = new TestFunction();
GeneralMatrix hessian = f.CalculateHessian(vector);
for (int i=0;i<3; i++)
for (int j=0;j<3; j++)
Assert.IsTrue(System.Math.Abs(hessian.GetElement(i,j)-expectedMatrix.GetElement(i,j))<eps);
}
示例3: PCalc
/// <summary>
/// Average values of the priority matrix over sum of columns.
/// set values of sum of averaged rows into a new matrix
/// </summary>
/// <param name="argMatrix"></param>
/// <param name="selection"></param>
public void PCalc(GeneralMatrix argMatrix, GeneralMatrix selection)
{
int n = argMatrix.ColumnDimension;
GeneralMatrix sMatrix = new GeneralMatrix(argMatrix.ArrayCopy);
double c=0.0;
int i,j;
for (i=0;i<sMatrix.ColumnDimension; i++)
{
c=0.0;
for (j=0; j<sMatrix.RowDimension; j++)
c+=sMatrix.GetElement(j,i);
selection.SetElement(i,0,c);
}
for (i=0;i<sMatrix.ColumnDimension; i++)
{
for (j=0; j<sMatrix.RowDimension; j++)
sMatrix.SetElement(j,i,sMatrix.GetElement(j,i)/selection.GetElement(i,0));
}
for (i=0;i<sMatrix.RowDimension; i++)
{
c=0.0;
for (j=0; j<sMatrix.ColumnDimension; j++)
c+=sMatrix.GetElement(i,j);
selection.SetElement(i,0,c/n);
}
}
示例4: SetMatrix
/// <summary>
/// Set a submatrix.
/// </summary>
/// <param name = "r"> Array of row indices.
/// </param>
/// <param name = "j0"> Initial column index
/// </param>
/// <param name = "j1"> Final column index
/// </param>
/// <param name = "x"> A(r(:),j0:j1)
/// </param>
/// <exception cref = "System.IndexOutOfRangeException"> Submatrix indices
/// </exception>
public virtual void SetMatrix(int[] r, int j0, int j1, GeneralMatrix x)
{
try
{
for (int i = 0; i < r.Length; i++)
{
for (int j = j0; j <= j1; j++)
{
_a[r[i]][j] = x.GetElement(i, j - j0);
}
}
}
catch (IndexOutOfRangeException e)
{
throw new IndexOutOfRangeException("Submatrix indices", e);
}
}
示例5: SetMatrix
/// <summary>Set a submatrix.</summary>
/// <param name="i0"> Initial row index
/// </param>
/// <param name="i1"> Final row index
/// </param>
/// <param name="c"> Array of column indices.
/// </param>
/// <param name="X"> A(i0:i1,c(:))
/// </param>
/// <exception cref="System.IndexOutOfRangeException"> Submatrix indices
/// </exception>
public virtual void SetMatrix(int i0, int i1, int[] c, GeneralMatrix X)
{
try
{
for (int i = i0; i <= i1; i++)
{
for (int j = 0; j < c.Length; j++)
{
A[i][c[j]] = X.GetElement(i - i0, j);
}
}
}
catch (System.IndexOutOfRangeException e)
{
throw new System.IndexOutOfRangeException("Submatrix indices", e);
}
}
示例6: CalculateNextPoint
private double[] CalculateNextPoint(double[] pX, double[] pGrad, GeneralMatrix hessian)
{
int i=0;
double xmin=0;
double step = _step;
GeneralMatrix alfaX = new GeneralMatrix(_nDim,1);
GeneralMatrix prevX = new GeneralMatrix(pX,_nDim);
GeneralMatrix prevGrad = new GeneralMatrix(pGrad,_nDim);
double[] intermediate = new double[_nDim];;
alfaX = hessian.Multiply(prevGrad);
//doing a line search to minimize alpha
OneDWrapper wrapper = new OneDWrapper(_f,prevX,alfaX);
LineSearch search = new LineSearch();
double[] interval = new double[Constants.BRACKET_POINTS];
int it1 = search.FindMinInterval(wrapper,_alpha,step,50,ref interval);
int it2 = search.FindMinimumViaBrent(wrapper,interval[0],interval[1],interval[2],50,_epsilon, ref xmin);
for (i=0;i<_nDim; i++)
intermediate[i] = prevX.GetElement(i,0) - xmin*alfaX.GetElement(i,0);
_alpha = xmin;
return intermediate;
}
示例7: ConstructionFromAPackedArrayDoesNotAltersOriginalArrayValues
public void ConstructionFromAPackedArrayDoesNotAltersOriginalArrayValues()
{
double[] packedColumns = new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 };
int numRows = 3; /* leading dimension of intended test Matrices */
var b = new GeneralMatrix(packedColumns, numRows); //B still references array underneath
var temp = b.GetElement(0, 0);
packedColumns[0] = 0.0;
Assert.IsTrue((temp - b.GetElement(0, 0)) == 0.0);
}
示例8: Substraction
public void Substraction()
{
double[] columnwise = new double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
double[][] avals = {new double[]{1.0, 4.0, 7.0, 10.0}, new double[]{2.0, 5.0, 8.0, 11.0}, new double[]{3.0, 6.0, 9.0, 12.0}};
int validld = 3; /* leading dimension of intended test Matrices */
//one dimensional array of doubles packed by columns ala Fortran
//is passed to the constructor
//the integer value tell the constructor how to
//breakup one domensional value into mulidimensional column
GeneralMatrix A = new GeneralMatrix(columnwise, validld);
GeneralMatrix B = new GeneralMatrix(avals);
double tmp = B.GetElement(0, 0);
avals[0][0] = 0.0;
GeneralMatrix C = B.Subtract(A);
avals[0][0] = tmp;
B = GeneralMatrix.Create(avals);
tmp = B.GetElement(0, 0);
avals[0][0] = 0.0;
Assert.IsTrue(tmp==B.GetElement(0, 0));
}
示例9: TestChoiceMatrix
public void TestChoiceMatrix()
{
double[][] mat1 = new double[][]
{
new double[] {1,2,3,4},
new double[] {0,1,2,5},
new double[] {0,0,1,5},
new double[] {0,0,0,1}
};
GeneralMatrix gmat1 = new GeneralMatrix(mat1);
gmat1 = AHPModel.ExpandUtility(gmat1);
double[][] mat2 = new double[][]
{
new double[] {1,2,3,1},
new double[] {0,1,2,3},
new double[] {0,0,1,9},
new double[] {0,0,0,1}
};
GeneralMatrix gmat2 = new GeneralMatrix(mat2);
gmat2 = AHPModel.ExpandUtility(gmat2);
double[][] mat3 = new double[][]
{
new double[] {1,4,2,2},
new double[] {0,1,2,4},
new double[] {0,0,1,4},
new double[] {0,0,0,1}
};
GeneralMatrix gmat3 = new GeneralMatrix(mat3);
gmat3 = AHPModel.ExpandUtility(gmat3);
//3 criteria 4 choices
AHPModel model = new AHPModel(3,4);
model.AddCriterionRatedChoices(0,mat1);
model.AddCriterionRatedChoices(1,mat2);
model.AddCriterionRatedChoices(2,mat3);
GeneralMatrix matrix = model.ChoiceMatrix;
GeneralMatrix nmat1 = matrix.GetMatrix(0,3,0,3);
GeneralMatrix nmat2 = matrix.GetMatrix(0,3,4,7);
GeneralMatrix nmat3 = matrix.GetMatrix(0,3,8,11);
bool alarm = false;
int i,j;
for (i=0;i<nmat1.ColumnDimension;i++)
for (j=0;j<nmat1.RowDimension;j++)
if (nmat1.GetElement(i,j)!=gmat1.GetElement(i,j))
alarm=true;
for (i=0;i<nmat2.ColumnDimension;i++)
for (j=0;j<nmat2.RowDimension;j++)
if (nmat2.GetElement(i,j)!=gmat2.GetElement(i,j))
alarm=true;
for (i=0;i<nmat3.ColumnDimension;i++)
for (j=0;j<nmat3.RowDimension;j++)
if (nmat3.GetElement(i,j)!=gmat3.GetElement(i,j))
alarm=true;
Assert.IsFalse(alarm);
}
示例10: ConstructionFromAnArrayAltersOriginalArrayValues
public void ConstructionFromAnArrayAltersOriginalArrayValues()
{
double[][] array = avals;
var b = new GeneralMatrix(array); //B still references avals underneath
var temp = b.GetElement(0, 0);
array[0][0] = 0.0;
Assert.IsTrue((temp - b.GetElement(0, 0)) != 0.0);
}
示例11: init
/// <summary>Initializes this Metric object from metric matrix (called by constructor) </summary>
/// <param name="m">The NxN metric matrix</param>
private void init(DotNetMatrix.GeneralMatrix m)
{
if (!Util.IsSymmetric(m))
throw new Exception("The metric matrix must be symmetric");
m_matrix = m.Copy();
// System.Console.WriteLine("m_matrix: " + Util.ToString(m_matrix));
// compute eigen value decomposition
m_eig = new DotNetMatrix.EigenvalueDecomposition(m_matrix);
// System.Console.WriteLine("m_eig: " + Util.ToString(m_eig.GetV()));
m_invEigMatrix = m_eig.GetV().Transpose();
m_eigenMetric = m_eig.RealEigenvalues;
// {
// DotNetMatrix.GeneralMatrix D = Util.Diagonal(m_eigenMetric);
// DotNetMatrix.GeneralMatrix tmp = m_eig.GetV().Multiply(D).Multiply(m_invEigMatrix);
// System.Console.WriteLine("input_matrix = " + Util.ToString(tmp));
// }
m_isDiagonal = Util.IsDiagonal(m_matrix);
if (!m_isDiagonal)
{
m_isEuclidean = m_isAntiEuclidean = false;
}
else
{
m_isEuclidean = m_isAntiEuclidean = true;
for (int i = 0; i < m.RowDimension; i++)
{
if (m_matrix.GetElement(i, i) != 1.0)
m_isEuclidean = false;
if (m_matrix.GetElement(i, i) != -1.0)
m_isAntiEuclidean = false;
}
}
}
示例12: GetSVs
// Take SV columns from the U matrix
private static GeneralMatrix GetSVs(GeneralMatrix matrix, int sv)
{
GeneralMatrix toPass = new GeneralMatrix(matrix.RowDimension, sv);
for (int j = 0; j < sv; j++) {
for (int i = 0; i < matrix.RowDimension; i++) {
toPass.SetElement(i, j, matrix.GetElement(i, j));
}
}
return toPass;
}
示例13: PrintMatrix
void PrintMatrix(GeneralMatrix matrix, StreamWriter output)
{
for (int j = 0; j < matrix.ColumnDimension; j++) {
for (int i = 0; i < matrix.RowDimension; i++) {
output.Write(matrix.GetElement(i, j) + ", ");
}
output.Write("\n");
}
output.Write("\n");
}
示例14: GetElement
public void GetElement()
{
double[][] avals = {new double[]{1.0, 4.0, 7.0, 10.0}, new double[]{2.0, 5.0, 8.0, 11.0}, new double[]{3.0, 6.0, 9.0, 12.0}};
GeneralMatrix B = new GeneralMatrix(avals);
Assert.AreEqual(B.GetElement(B.RowDimension-1,B.ColumnDimension-1),avals[B.RowDimension-1][B.ColumnDimension-1]);
}
示例15: SetElementCorrectlySetsAMatrixElement
public void SetElementCorrectlySetsAMatrixElement()
{
var matrix = new GeneralMatrix(avals);
matrix.SetElement(ib,jb,0.0);
Assert.AreEqual(0.0,matrix.GetElement(ib,jb));
}