本文整理汇总了C#中Matrix.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.GetLength方法的具体用法?C# Matrix.GetLength怎么用?C# Matrix.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.GetLength方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LSH
private Dictionary<int,int>[] sigMat; //gets hash value from column
#endregion Fields
#region Constructors
public LSH(Matrix utilMat, int r, int b, CF filter)
{
this.filter = filter;
this.numSets = utilMat.GetLength(1);
this.r = r;
this.b = b;
sigMat = new Dictionary<int, int>[b];
revSigMat = new MultiDictionary<int, int>[b];
for (int bandInd = 0; bandInd < b; bandInd++)
{
sigMat[bandInd] = new Dictionary<int, int>();
revSigMat[bandInd] = new MultiDictionary<int, int>(true);
}
compSigMatEntries(utilMat);
}
示例2: Learn
public void Learn(Matrix[] input, Matrix[] output, double alpha, double lambda, int maxItr)
{
while (maxItr > 0)
{
var grad = GetGrad(Thetas, input, output, input.Length, lambda);
UpdateThetas(input.GetLength(0), grad, alpha, lambda, input, output);
maxItr--;
}
}
示例3: GetGrad
public Matrix[] GetGrad(Matrix[] thetas, Matrix[] input, Matrix[] output, int m, double lambda)
{
var L_deltas = InitializeLDeltas();
for (int idx = 0; idx < input.GetLength(0); idx++)
{
Matrix[] z = null;
var values = ForwardProp(input[idx], thetas, ref z);
BackProp(L_deltas, output[idx], values, z);
}
var grad = GetGrad(thetas, L_deltas, input.Length, lambda);
return grad;
}
示例4: MergeMatrix
/// <summary>
/// This property returns the matrix as an array.
/// </summary>
public static Matrix MergeMatrix(Matrix[,] subMatrixs)
{
int TotRow=0, TotCol=0;
Matrix mat0 = subMatrixs[0, 0];
for (int row = 1; row < subMatrixs.GetLength(0); row++)
{
for (int col = 1; col < subMatrixs.GetLength(1); col++)
{
Matrix mat = subMatrixs[row, col];
if (mat.NoRows != mat0.NoRows || mat.NoCols != mat.NoCols)
throw new Exception("all sub matrix need same dimension!");
}
}
TotRow = mat0.NoRows * subMatrixs.GetLength(0);
TotCol = mat0.NoCols * subMatrixs.GetLength(1);
double[,] ret = new double[TotRow, TotCol];
for (int row = 0; row < subMatrixs.GetLength(0); row++)
{
for (int col = 0; col < subMatrixs.GetLength(1); col++)
{
Matrix mat = subMatrixs[row, col];
for(int i=0;i< mat.NoRows;i++)
for (int j = 0; j < mat.NoCols; j++)
{
ret[row * mat0.NoRows + i, col * mat0.NoCols + j] = mat[i, j];
}
}
}
return new Matrix(ret);
}
示例5: Mul
//Will Multiply a Matrix by "Multiply_By".
public Matrix Mul(Matrix Multiply_By)
{
double[,] product = new double[data.GetLength(0), Multiply_By.GetLength(1)];//Creates dimensions for new matrix "product".
if (data.GetLength(1) == Multiply_By.GetLength(0))//Checks dimensions to make sure that matrix multiplication is allowed.
{
for (int i = 0; i < product.GetLength(0); i++)
{
for (int j = 0; j < product.GetLength(1); j++)
{
product[i, j] = 0;
for (int k = 0; k < data.GetLength(1); k++)
{
product[i, j] += data[i, k] * Multiply_By[k, j];
}
}
}
//Prints Matrix "product".
for (int i = 0; i < product.GetLength(0); i++)
{
for (int j = 0; j < product.GetLength(1); j++)
{
Console.Write(product[i, j] + " ");
}
Console.WriteLine();
}
}
//If matrix multiplication is not defined prints error message.
else
Console.Write("Dimensions of two matrices do not agree, please try again");
return product;
}
示例6: Inverse
public static Matrix Inverse(Matrix m)
{
if (m.matrixData.GetLength (r) != m.matrixData.GetLength (c))
return null; // The graceful fail
if(m.matrixData.GetLength (r) == 2)
{
float det = Det (m);
float[,] invDat = new float[m.matrixData.GetLength(r),m.matrixData.GetLength(c)];
invDat [0,0] = m.matrixData[1,1];
invDat [1,1] = m.matrixData[0,0];
invDat [1,0] = -m.matrixData[1,0];
invDat [0,1] = -m.matrixData[0,1];
Debug.Log(new Matrix(invDat));
invDat [0,0] /= det;
invDat [1,0] /= det;
invDat [0,1] /= det;
invDat [1,1] /= det;
return new Matrix(invDat);
}
if(m.matrixData.GetLength (r) == 3)
{
float det = Matrix.Det(m);
Matrix[,] dm = new Matrix[3,3]; /// Det Matrix, D.M. dm.
float[,] dpf = new float[3,3]; /// Det Product Float, D.P.F. dpf.
dm[0,0] = new Matrix(new float [,] {{m[1,1],m[1,2]},{m[2,1],m[2,2]}});
dm[0,1] = new Matrix(new float [,] {{m[0,2],m[0,1]},{m[2,2],m[2,1]}});
dm[0,2] = new Matrix(new float [,] {{m[0,1],m[0,2]},{m[1,1],m[1,2]}});
dm[1,0] = new Matrix(new float [,] {{m[1,2],m[1,0]},{m[2,2],m[2,0]}});
dm[1,1] = new Matrix(new float [,] {{m[0,0],m[0,2]},{m[2,0],m[2,2]}});
dm[1,2] = new Matrix(new float [,] {{m[0,2],m[0,0]},{m[1,2],m[1,0]}});
dm[2,0] = new Matrix(new float [,] {{m[1,0],m[1,1]},{m[2,0],m[2,1]}});
dm[2,1] = new Matrix(new float [,] {{m[0,1],m[0,0]},{m[2,1],m[2,0]}});
dm[2,2] = new Matrix(new float [,] {{m[0,0],m[0,1]},{m[1,0],m[1,1]}});
for (int r1=0; r1 < dm.GetLength(r); r1++)
{
for (int c1=0; c1 < dm.GetLength(c); c1++)
{
dpf[r1,c1] = Matrix.Det(dm[r1,c1])/det;
}
}
return new Matrix(dpf);
}
return null;
}
示例7: compSigMatEntries
/* produces signature matrix from original matrix, for compression purposes
* @arguments: takes in the original matrix
*/
private void compSigMatEntries(Matrix utilMat)
{
int[] bandArr = new int[b];
for (int i=0;i<b;i++)
bandArr[i]=i;
Parallel.For<Dictionary<int, Dictionary<int, int>>>(0, b,
() => new Dictionary<int, Dictionary<int, int>>(),
(bandInd, foo, sigMatLocal) =>
{
sigMatLocal[bandInd] = new Dictionary<int, int>();
int[][] currBand = compRandVec(utilMat.GetLength(0));
for (int col = 0; col < this.numSets; col++)
{
string tmpHash = "";
for (int vecInd = 0; vecInd < r; vecInd++)
{
double result = 0;
for (int row = 0; row < utilMat.GetLength(0); row++)
{
if (utilMat.get(row, col) == -1)
continue;
result += currBand[vecInd][row] * utilMat.get(row, col);
}
if (result >= 0)
tmpHash += 1;
else
tmpHash += 0;
}
int hashCode = Convert.ToInt32(tmpHash, 2);
sigMatLocal[bandInd].Add(col, hashCode);
}
return sigMatLocal;
},
(sigMatLocal) =>
{
foreach (int bandInd in sigMatLocal.Keys)
{
foreach (int colInd in sigMatLocal[bandInd].Keys)
{
lock(this.sigMat){
this.sigMat[bandInd].Add(colInd, sigMatLocal[bandInd][colInd]);
}
lock(this.revSigMat){
this.revSigMat[bandInd].Add(sigMatLocal[bandInd][colInd], colInd);
}
}
}
});
}