我想了解如何使用蒙特卡洛方法来搜索一些系统的极限概率S.如何使用蒙特卡洛方法来搜索极限概率
例如:
S0 S1 S2 S3
S0 0.1 0.9 0 0
S1 0 0.2 0.3 0.5
S2 0.2 0.1 0.5 0.2
S3 0.5 0 0.4 0.1
据我了解的方法,我们需要生成一些数量(X),然后比较概率:
if x
0 <= x < 0.1 => S0 -> S0
0.1 <= x < 0.9 => S0 -> S1
0.9 <= x < 0.9 => S0 -> S2
0.9 <= x < 0.9 => S0 -> S3
0.9 <= x < 1 => S0 -> S4
当S4 - 极限(境)
对于其他州也是如此。
按照这一办法,我可以算的转换数目:
static double[] SimpleMonte(double[][] a, int iter = 1)
{
var n = a.GetLength(0);
var p =
a
.Select(x => x.Select((_, i) => x.Take(i + 1).Sum()).ToArray())
.ToArray();
Random rand = new Random();
double[] X = new double[n];
for (int x = 0; x < n; x++)
{
double count = 0;
for (int i = 0; i < iter; i++)
{
int row = x;
bool notG = true;
Console.Write("{0} -> ", row);
while (notG)
{
var e = rand.NextDouble();
Console.Write("({0})", Math.Round(e, 2));
bool ch = false;
for (int j = 0; j < n - 1; j++)
{
if (p[row][j] <= e && e < p[row][j + 1])
{
row = j + 1;
ch = true;
break;
}
}
if (!ch)
notG = false;
else
{
Console.Write("{0} -> ", row);
count++;
}
}
Console.WriteLine();
}
X[x] = count/iter;
}
return X;
}
https://dotnetfiddle.net/nJF5sm
,我会很高兴听到就做什么来解决这个问题的提示。
你能澄清你的问题吗?你想解决'S x = x',即找到静止的设置吗? –