本文整理汇总了C#中System.Matrix.GetRowSum方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.GetRowSum方法的具体用法?C# Matrix.GetRowSum怎么用?C# Matrix.GetRowSum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Matrix
的用法示例。
在下文中一共展示了Matrix.GetRowSum方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NAPTStageOneHelper2
// For steps 25-33 in stage one
private static Matrix NAPTStageOneHelper2(Matrix CAP, Matrix SRG, Matrix FA1, Matrix UA11, Matrix REL, Vector AOC, int stage, int networkid)
{
// 25. Generate a Non-Aggression matrix NAG
Matrix NAG = new Matrix(FA1.Rows, FA1.Cols);
for (int i = 0; i < FA1.Rows; i++)
{
for (int j = 0; j < FA1.Cols; j++)
{
if (FA1[i, j] == 2)
NAG[i, j] = 1;
else
NAG[i, j] = 0;
}
}
Vector NAG_vec = new Vector(NAG.Rows);
for (int i = 0; i < NAG_vec.Size; i++)
{
NAG_vec[i] = NAG.GetRowSum(i);
}
// 26. Generate an Allies Attractiveness matrix AAT = DP1 * UA11
// Calculate the sum row entry
Matrix AAT = new Matrix(UA11.Rows, UA11.Cols);
/*
for (int i = 0; i < DP1.Rows; i++)
for (int j = 0; j < UA11.Cols; j++)
AAT[i, j] = DP1[i, j] * UA11[i, j];
*/
//FA1.Binarize();
for (int i = 0; i < FA1.Rows; i++)
for (int j = 0; j < FA1.Cols; j++)
if (FA1[i, j] != 1)
FA1[i, j] = 0;
// Generate the vector DEF for Output Matrix
Vector DEF = new Vector(FA1.Rows);
for (int i = 0; i < DEF.Size; i++)
{
DEF[i] = FA1.GetRowSum(i);
}
// follows the excel instructions
for (int i = 0; i < FA1.Rows; i++)
{
for (int j = 0; j < UA11.Cols; j++)
{
//AAT[i, j] = (FA1[i, j] == 1 ? 1 : 0) * UA11[i, j];
AAT[i, j] = FA1[i, j] * UA11[i, j];
}
}
// 27. Generate the attractiveness coefficient atc for each row
/*
double[] atc = new double[AAT.Rows];
for (int i = 0; i < AAT.Rows; i++)
atc[i] = AAT.GetRowSum(i) * DP1.GetRowSum(i);
*/
// follow excel instructions
//double[] ATC = new double[AAT.Rows];
Vector ATC = new Vector(AAT.Rows);
for (int i = 0; i < AAT.Rows; i++)
{
if (FA1.GetRowSum(i) > 0)
ATC[i] = AAT.GetRowSum(i) / FA1.GetRowSum(i);
else
ATC[i] = 0;
}
// 28. Generate an Allies Reliability matrix ARE = BFA1 * REL (where BAF1 is the binarized FA1 matrix)
//FA1.Binarize();
Matrix ARE = new Matrix(FA1.Rows, REL.Cols);
if (stage == 1)
{
for (int i = 0; i < FA1.Rows; i++)
for (int j = 0; j < REL.Cols; j++)
ARE[i, j] = FA1[i, j] * REL[i, i]; // may need to be changed to [j, j]
}
else
{
for (int i = 0; i < FA1.Rows; i++)
for (int j = 0; j < REL.Cols; j++)
ARE[i, j] = NAG[i, j] * REL[j, j];
}
Vector REC = new Vector(ARE.Rows);
if (stage == 1)
{
for (int i = 0; i < REC.Size; i++)
{
if ((DEF[i] + NAG_vec[i]) > 0)
REC[i] = ARE.GetRowSum(i) / (DEF[i] + NAG_vec[i]);
else
REC[i] = 0;
}
}
else
{
for (int i = 0; i < REC.Size; i++)
//.........这里部分代码省略.........
示例2: SimulateNAPTStageTwo
private static Matrix SimulateNAPTStageTwo(Matrix FA1, Matrix SRG1, Matrix DP1, Matrix CAP, Matrix REL, Matrix UA11, int rowColSize, Matrix output, ref Matrix SRGOutput, ref Matrix EAOutput, int stage, string EAOutputFile, string outputfile, bool overwrite, bool EADyadic, bool outputDyadic, int networkid)
{
//int networkid = SRG1.NetworkId;
// 2. Generate Allies of Enemies matrix AE2 = SRG1 x DP1
Matrix AE2 = SRG1 * DP1;
// 3. Generate SRG2
Matrix SRG2 = new Matrix(rowColSize, rowColSize);
for (int i = 0; i < SRG2.Rows; i++)
{
for (int j = 0; j < SRG2.Cols; j++)
{
if (FA1[i, j] > 0)
SRG2[i, j] = 0;
else if (SRG1[i, j] == 1 || AE2[i, j] > 0)
SRG2[i, j] = 1;
else
SRG2[i, j] = 0;
}
}
// 4. Generate an Allies Capabilities Matrix AC20 = DP1 * C. Sum over rows of AC20
// Method from excel sheet
Matrix AC20 = new Matrix(rowColSize, rowColSize);
for (int i = 0; i < rowColSize; i++)
{
for (int j = 0; j < rowColSize; j++)
{
if (i == j || FA1[i, j] == 1)
AC20[i, j] = CAP[j, j];
else
AC20[i, j] = 0;
}
}
// 5. Generate an SRG Capabilities Matrix SRGC20 = SRGC * C. Sum across rows
Matrix SRGC20 = new Matrix(rowColSize, rowColSize);
for (int i = 0; i < rowColSize; i++)
{
for (int j = 0; j < rowColSize; j++)
{
SRGC20[i, j] = SRG2[i, j] * CAP[j, j];
}
}
// 6. Generate an Alliance Opportunity Cost Vector AOC20
Vector AOC20 = new Vector(rowColSize);
for (int i = 0; i < rowColSize; i++)
{
if (AC20.GetRowSum(i) >= SRGC20.GetRowSum(i))
AOC20[i] = 0;
else
AOC20[i] = SRGC20.GetRowSum(i) - AC20.GetRowSum(i);
}
// 7. Generate a Potential Alliance Network T2 PAN2
// method from excel sheet
Matrix PAN2 = new Matrix(rowColSize, rowColSize);
for (int i = 0; i < rowColSize; i++)
{
for (int j = 0; j < rowColSize; j++)
{
if (i == j || FA1[i, j] > 0)
PAN2[i, j] = 0;
else
PAN2[i, j] = 1 - SRG2[i, j];
}
}
// 8. Generate a Utility for Potential Ally matrix UA21 = PAN2 * UA11. Calulate the max row for UA21
/*
Matrix UA21 = new Matrix(rowColSize, rowColSize);
for (int i = 0; i < rowColSize; i++)
{
for (int j = 0; j < rowColSize; j++)
{
if (i != j)
UA21[i, j] = PAN2[i, j] * UA11[i, j];
else
UA21[i, j] = 0;
}
}
*/
Matrix UA21 = new Matrix(UA11);
// 9. Calculate the Potential Ally Capabilities matrix CUA21
// method from excel sheet
Matrix CUA21 = new Matrix(rowColSize, rowColSize);
for (int i = 0; i < rowColSize; i++)
{
for (int j = 0; j < rowColSize; j++)
{
if (i != j && UA21[i, j] == UA21.GetMaxInRow(i))
CUA21[i, j] = CAP[j, j];
else
CUA21[i, j] = 0;
}
}
Matrix DP2 = new Matrix(rowColSize, rowColSize);
//.........这里部分代码省略.........
示例3: NAPTStageOneHelper1
// for steps 13-24 in stage one
private static void NAPTStageOneHelper1(Matrix CAP, Matrix SRG, Matrix SRGC, Matrix PAN, Matrix UA11, Matrix CUA11, Vector AOC,
ref Matrix DP1, ref Matrix FA1, int stage, Matrix AC)
{
// 13. Calculate the expected alliance matrix A11
// Sum across rows of A11?
Matrix A11 = new Matrix(CUA11.Rows, CUA11.Cols);
if (stage == 1)
{
for (int i = 0; i < CUA11.Rows; i++)
{
for (int j = 0; j < CUA11.Cols; j++)
{
if (i == j)
A11[i, j] = CAP[i, i];
else if (CUA11[i, j] == CUA11.GetMaxInRow(i))
A11[i, j] = CAP[j, j];
else
A11[i, j] = 0;
}
}
}
else // stage 2 is different
{
for (int i = 0; i < CUA11.Rows; i++)
{
for (int j = 0; j < CUA11.Cols; j++)
{
if (AC[i, j] > 0)
A11[i, j] = AC[i, j];
else if (CUA11[i, j] > 0)
A11[i, j] = CUA11[i, j];
else
A11[i, j] = 0;
}
}
}
/*
// 14. Update the AOC vector to AOC11
Vector AOC11 = new Vector(AOC.Size);
for (int i = 0; i < A11.Rows; i++)
{
if (A11.GetRowSum(i) >= AOC[i])
AOC11[i] = 0;
else
AOC11[i] = AOC[i] - A11.GetRowSum(i);
}
*/
// 14. Update the AOC vector to AOC11
// (modified to compare to SRG CAP instead of AOC) -------- this one is correct ------
Vector AOC11 = new Vector(AOC.Size);
for (int i = 0; i < A11.Rows; i++)
{
if (A11.GetRowSum(i) >= SRGC.GetRowSum(i))
AOC11[i] = 0;
else
AOC11[i] = SRGC.GetRowSum(i) - A11.GetRowSum(i);
}
// 17. Subtract Sum(AOC12) - Sum(AOC11). If result is equal to zero, stop run and go back to step #x
// If the result is less than zero, repeat steps 11-16 by calculating UA13, CUA13, A13, AOC13
//
// This method incorporates steps 15-16
Matrix new_A = UpdateAOC(UA11, CUA11, AOC11, CAP, SRGC, A11, PAN, stage);
// 18. Generate an aliiance offer matrix AO1 which is a binarized version of A1x (where x is the number
// of the last A matrix
//new_A.Binarize();
// Recently updated as of 3:59AM 7/17/2012 (subject to change)
Matrix AO1 = new Matrix(new_A.Rows, new_A.Cols);
for (int i = 0; i < AO1.Rows; i++)
{
for (int j = 0; j < AO1.Cols; j++)
{
if (i == j)
AO1[i, j] = 0;
else if (new_A[i, j] > 0)
AO1[i, j] = 1;
else
AO1[i, j] = 0;
}
}
// 19. Transpose AO1
Matrix AO1_T = AO1.GetTranspose();
// 20. Generate a Defence Pacts matrix DP1 = AO1 * AO1'
DP1 = new Matrix(AO1.Rows, AO1_T.Cols);
for (int i = 0; i < AO1.Rows; i++)
for (int j = 0; j < AO1_T.Cols; j++)
DP1[i, j] = AO1[i, j] * AO1_T[i, j];
// 21. Generate an Allies of Enemies AE1 matrix AE1 = SRG x DP1
Matrix AE1 = SRG * DP1;
//.........这里部分代码省略.........
示例4: UpdateSimplifiedRealistStageTwo
/// <summary>
/// Simulates stage two of the realist network formation simulation.
/// </summary>
/// <param name="C">Capability matrix for stage two</param>
/// <param name="R">Policy relevance matrix (SRG)</param>
/// <param name="EAF">EAF matrix from stage one</param>
/// <param name="M">MID matrix</param>
/// <returns>Expected alliance matrix</returns>
/// <returns>EA matrix for stage two</returns>
private static Matrix UpdateSimplifiedRealistStageTwo(Matrix C, Matrix R, Matrix M, Matrix BEA, string outputFile, double br)
{
int n = C.Rows;
Matrix AE = M * BEA;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
{
if (R[i, j] == 1 || AE[i, j] > 0 ) R[i, j] = 1;
else R[i, j] = 0;
}
R.ZeroDiagonal();
Matrix SRC = R * C;
Vector SRGC = new Vector(n);
for (int i = 0; i < n; ++i)
SRGC[i] = SRC.GetRowSum(i) * br;
Matrix EAC = BEA * C;
Vector AOC = new Vector(n);
for (int i = 0; i < n; ++i)
{
if (EAC.GetRowSum(i) + C[i, i] >= SRGC[i]) AOC[i] = 0;
else AOC[i] = 1 - ((EAC.GetRowSum(i) + C[i, i]) / SRGC[i]);
}
Matrix F = Matrix.Ones(n, n);
F.ZeroDiagonal();
Matrix PAN = F - R;
Matrix PAC = PAN * C;
Matrix EE = M * M;
EE.ZeroDiagonal();
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (EE[i, j] != 0) EE[i, j] = 1;
Matrix EEC = EE * C;
Vector EEM = new Vector(n);
for (int i = 0; i < n; ++i)
EEM[i] = Algorithms.MaxValue<double>(EEC.GetRowEnumerator(i));
Matrix EA = new Matrix(n, n);
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (EAC[i, j] > 0 || AOC[i] <= 0)
EA[i, j] = EAC[i, j];
else if (PAN[i, j] > 0 && EEC[i, j] == EEM[i])
EA[i, j] = EEC[i, j];
else
EA[i, j] = 0;
//Copied from Stage 1
Vector SEA = new Vector(n);
Matrix previousEA = new Matrix(n);
Matrix TempEEC = new Matrix(n);
EEC.CloneTo(TempEEC);
do
{
EA.CloneTo(previousEA);
for (int i = 0; i < n; ++i)
SEA[i] = EA.GetRowSum(i) + C[i, i];
for (int i = 0; i < n; ++i)
{
if (SRGC[i] <= SEA[i]) AOC[i] = 0;
else AOC[i] = 1 - SEA[i] / SRGC[i];
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (EEC[i, j] == EEM[i]) EEC[i, j] = 0;
for (int i = 0; i < n; ++i)
EEM[i] = Algorithms.MaxValue<double>(EEC.GetRowEnumerator(i));
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
//.........这里部分代码省略.........
示例5: UpdateEAMatrix
private static Vector UpdateEAMatrix(Vector AO, Matrix Q, Matrix EA)
{
int n = AO.Size;
Vector MQ = new Vector(n);
Vector SEA = Vector.Zero(n);
Vector RS = null;
while (true)
{
for (int i = 0; i < SEA.Size; ++i)
SEA[i] = EA.GetRowSum(i);
RS = AO - SEA;
for (int i = 0; i < MQ.Size; ++i)
MQ[i] = Algorithms.MaxValue<double>(Q.GetRowEnumerator(i));
for (int i = 0; i < EA.Rows; ++i)
{
if (RS[i] < double.Epsilon)
continue;
for (int j = 0; j < EA.Cols; ++j)
if (EA[i, j] == 0 && Q[i, j] == MQ[i])
EA[i, j] = Q[i, j];
}
for (int i = 0; i < Q.Rows; ++i)
for (int j = 0; j < Q.Cols; ++j)
if (Q[i, j] == MQ[i])
Q[i, j] = 0;
if (Algorithms.MaxValue<double>(RS) < double.Epsilon)
break;
if (Algorithms.MaxValue<double>(MQ) < double.Epsilon)
break;
}
return RS;
}
示例6: UpdateAOC
//.........这里部分代码省略.........
for (int i = 0; i < UA.Rows; i++)
{
for (int j = 0; j < UA.Cols; j++)
{
if (UA[i, j] != UA.GetMaxInRow(i))
CUA[i, j] = 0;
else if (UA[i, j] == UA.GetMaxInRow(i) && UA[i, j] > 0 && i != j) // needs PAN and i!=j conditions
CUA[i, j] = CAP[j, j];
}
}
}
// Calculate the expected alliance matrix A11
//
// ****** Calculated completely different in excel sheet ******
//
/*
Matrix A = new Matrix(CUA.Rows, CUA.Cols);
for (int i = 0; i < CUA.Rows; i++)
{
for (int j = 0; j < CUA.Cols; j++)
{
if (i == j)
A[i, j] = CAP[i, i];
else if (CUA[i, j] == CUA.GetMaxInRow(i))
A[i, j] = CAP[j, j];
else
A[i, j] = 0;
}
}
*/
// This version may be wrong; might need to use above version
Matrix A = new Matrix(CUA.Rows, CUA.Cols);
if (stage == 1)
{
for (int i = 0; i < CUA.Rows; i++)
{
for (int j = 0; j < CUA.Cols; j++)
{
if (_A[i, j] > 0 || _AOC[i] == 0)
A[i, j] = _A[i, j];
else
{
if (CUA[i, j] > 0)
A[i, j] = CUA[i, j];
else
A[i, j] = 0;
}
}
}
}
else
{
for (int i = 0; i < CUA.Rows; i++)
{
for (int j = 0; j < CUA.Cols; j++)
{
if (_A[i, j] > 0)
A[i, j] = _A[i, j];
else if (CUA[i, j] > 0)
A[i, j] = CUA[i, j];
else
A[i, j] = 0;
}
}
}
/*
// Update the AOC vector to AOC11
Vector AOC = new Vector(_AOC.Rows);
for (int i = 0; i < A.Rows; i++)
{
if (A.GetRowSum(i) >= _AOC[i])
AOC[i] = 0;
else
AOC[i] = _AOC[i] - A.GetRowSum(i);
}
*/
// Update the AOC vector to AOC11 --------- this one is correct ---------
Vector AOC = new Vector(_AOC.Size);
for (int i = 0; i < A.Rows; i++)
{
if (A.GetRowSum(i) >= SRGC.GetRowSum(i))
AOC[i] = 0;
else
AOC[i] = SRGC.GetRowSum(i) - A.GetRowSum(i);
}
// Calculate sum for AOC12
for (int i = 0; i < AOC.Size; i++)
sum2 += AOC[i];
if ((sum2 - sum1) > 0)
throw new Exception("The difference of sum cannot be greater than zero!");
if ((sum2 - sum1) < 0)
return UpdateAOC(UA, CUA, AOC, CAP, SRGC, A, PAN, stage);
else
return A;
}
示例7: SimulateSimplifiedRealistStageOne
/// <summary>
/// Simulates stage one of the SIMPLIFIED realist network formation simulation.
/// </summary>
/// <param name="C">Capability matrix</param>
/// <param name="R">Policy relevance matrix (SRG)</param>
/// <param name="M">MID matrix</param>
/// <returns>Expected alliance matrix</returns>
private static Matrix SimulateSimplifiedRealistStageOne(Matrix C, Matrix R, Matrix M, string outputFile, double br)
{
int n = C.Rows;
Matrix SRC = R * C;
Vector SRGC = new Vector(n);
for (int i = 0; i < n; ++i)
SRGC[i] = SRC.GetRowSum(i) * br;
Vector AOC = new Vector(n);
for (int i = 0; i < n; ++i)
{
if (SRGC[i] <= C[i, i]) AOC[i] = 0;
else AOC[i] = 1 - C[i, i] / SRGC[i];
}
Matrix F = Matrix.Ones(n, n);
F.ZeroDiagonal();
Matrix PAN = F - R;
Matrix PAC = PAN * C;
Matrix EE = M * M;
EE.ZeroDiagonal();
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (EE[i, j] != 0) EE[i, j] = 1;
Matrix EEC = EE * C;
Vector EEM = new Vector(n);
for (int i = 0; i < n; ++i)
EEM[i] = Algorithms.MaxValue<double>(EEC.GetRowEnumerator(i));
Matrix EA = new Matrix(n, n);
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (EEC[i, j] == EEM[i] && PAN[i, j] == 1 && AOC[i] != 0)
EA[i, j] = EEC[i, j];
else
EA[i, j] = 0;
Vector SEA = new Vector(n);
Matrix previousEA = new Matrix(n);
do
{
EA.CloneTo(previousEA);
for (int i = 0; i < n; ++i)
SEA[i] = EA.GetRowSum(i) + C[i, i];
for (int i = 0; i < n; ++i)
{
if (SRGC[i] <= SEA[i]) AOC[i] = 0;
else AOC[i] = 1 - SEA[i] / SRGC[i];
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (EEC[i, j] == EEM[i]) EEC[i, j] = 0;
for (int i = 0; i < n; ++i)
EEM[i] = Algorithms.MaxValue<double>(EEC.GetRowEnumerator(i));
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
{
//if (AOC[i] != 0 && EEC[i, j] == EEM[i] && EA[i, j] == 0)
// EA[i, j] = EEC[i, j];
if (AOC[i] == 0 || EA[i, j] != 0);
else if (PAN[i, j] > 0 && EEC[i, j] == EEM[i])
EA[i, j] = EEC[i, j];
else EA[i, j] = 0;
}
} while ((!previousEA.IsSameAs(EA)) && !EEC.IsAllZero && !AOC.IsZeroVector);
if (!AOC.IsZeroVector)
{
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (PAC[i, j] > 0 && EEC[i, j] != 0) PAC[i, j] = 0;
Vector PAM = new Vector(n);
for (int i = 0; i < n; ++i)
PAM[i] = Algorithms.MaxValue<double>(PAC.GetRowEnumerator(i));
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
//.........这里部分代码省略.........