本文整理汇总了C#中Matrix.Row方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Row方法的具体用法?C# Matrix.Row怎么用?C# Matrix.Row使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.Row方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateClustering
/// <summary>Generates a clustering.</summary>
/// <param name="X">The Matrix to process.</param>
/// <param name="linker">The linker.</param>
/// <param name="data">(Optional) the data.</param>
/// <returns>The clustering.</returns>
private Cluster GenerateClustering(Matrix X, ILinker linker, object[] data = null)
{
// Initialize
Linker = linker;
var clusters = new List<Cluster>();
var distances = new Dictionary<Tuple<int, int>, double>();
// Create a new cluster for each data point
for (int i = 0; i < X.Rows; i++)
clusters.Add(new Cluster
{
Id = i,
Points = new Vector[] { (Vector)X.Row(i) },
Members = data != null ? new object[] { data[i] } : new object[] { X.Row(i) }
});
// Set the current closest distance/pair to the first pair of clusters
var key = new Tuple<int, int>(0, 0);
var distance = 0.0;
var clusterId = X.Rows;
while (clusters.Count > 1)
{
var closestClusters = new Tuple<int, int>(0, 1);
var smallestDistance = Linker.Distance(clusters[0].Points, clusters[1].Points);
// this needs to be parallelized....
// Loop through each of the clusters looking for the two closest
for (int i = 0; i < clusters.Count; i++)
{
for (int j = i + 1; j < clusters.Count; j++)
{
key = new Tuple<int, int>(clusters[i].Id, clusters[j].Id);
// Cache the distance if it hasn't been calculated yet
if (!distances.ContainsKey(key))
distances.Add(key, Linker.Distance(clusters[i].Points, clusters[j].Points));
// Update closest clusters and distance if necessary
distance = distances[key];
if (distance < smallestDistance)
{
smallestDistance = distance;
closestClusters = new Tuple<int, int>(i, j);
}
}
}
// order clusters by distance
var min = System.Math.Min(closestClusters.Item1, closestClusters.Item2);
var max = System.Math.Max(closestClusters.Item1, closestClusters.Item2);
var newCluster = new Cluster(clusterId, clusters[min], clusters[max]);
// Remove the merged clusters
clusters.RemoveAt(min);
clusters.RemoveAt(max - 1);
// Add new cluster
clusters.Add(newCluster);
clusterId++;
}
return clusters.Single();
}
示例2: SetVariablesValuessByOne
/// <summary>
/// Каждый элемент матрицы - вектора значений подставляется в соответсвующую строку исходной матрицы.
/// Не знаю зачем этот метод.
/// </summary>
/// <param name="valuesVector"></param>
/// <returns></returns>
public Matrix SetVariablesValuessByOne(Matrix valuesVector)
{
if (!(this[0, 0] is FunctionMatrixElement))
return new Matrix(this);
Matrix m = new Matrix(this.Rows, this.Cols, new FunctionMatrixElement());
for (int i = 0; i < this.Rows; i++)
{
for (int j = 0; j < this.Cols; j++)
{
var temp = valuesVector.Row(i);
Matrix tempM = new Matrix(1, temp.Length);
int k = 0;
foreach (var item in temp)
{
tempM[0, k] = temp[k++];
}
m[i, j] = new FunctionMatrixElement((this[i, j] as FunctionMatrixElement).Function.SetVariablesValues(tempM));
}
}
return m;
}
示例3: GaussianElimination
/// <summary>
/// Return a new matrix after GaussianElimination (row reduction) of the original matrix
/// </summary>
/// <returns></returns>
public Matrix GaussianElimination()
{
//if (Height != Width)
// throw new Exception();
Matrix newM = new Matrix(this);
int position = -1;
double param = 0;
int count = 0;
Vector positionV = new Vector(Width);
for (int i = 0; i < Width; i++)
{
if (position != -1)
{
newM.SwitchRow(position, count);
count++;
position = -1;
}
for (int j = count; j < Height; j++)
{
if (newM.field[i, j] != 0)
{
if (position != -1)
newM.SetRow(j, newM.Row(j) - positionV * newM[i, j] / param);
else
{
position = j;
param = newM[i, j];
newM.SetRow(j, newM.Row(j));
positionV = newM.Row(j);
}
}
}
}
return newM;
}
示例4: HorizontalConcat
public static Matrix HorizontalConcat(Matrix A, Matrix B)
{
Matrix C = A.Row(1);
for (int i = 2; i <= A.RowCount; i++)
{
C.InsertRow(A.Row(i), i);
}
for (int i = 1; i <= B.RowCount; i++)
{
C.InsertRow(B.Row(i), C.RowCount + 1);
}
return C;
}
示例5: Extract_last_row
public int[] Extract_last_row(string input)
{
var matrix = new Matrix(input);
return matrix.Row(matrix.Rows - 1);
}
示例6: Extract_first_row
public int[] Extract_first_row(string input)
{
var matrix = new Matrix(input);
return matrix.Row(0);
}