我正在尝试将Weibull分布的随机数放在一个圆的扇区中。
我生成了随机数,然后将其分配为Weibull分布。现在,我要使用这些Weibull分布式随机数。
RadarSpace GetWeibullClutter()
{
Random _randomNumberGenerator = new Random();
Weibull myweibull = new Weibull(3,2,_randomNumberGenerator);
int n = 50; // number of clutter elements
var maxRange = _detectionModel.MaximumRange;
var centreX = 0; // Centre of the field of view -- X coordinates
var centreY = 0; // Centre of the field of view -- Y coordinates
var minimumAngle = Math.PI / 4; // _detectionModel.MinimumPhi;
var maximumAngle = (3 * Math.PI) / 4; // _detectionModel.MaximumPhir;
var theta = (maximumAngle - minimumAngle) * myweibull + minimumAngle;
var r = maxRange * Math.Sqrt(_randomNumberGenerator.Next(n));
var x = centreX + r * Math.Cos(theta);
var y = centreY + r * Math.Sin(theta);
我希望将Weibull分布的随机数乘以var theta
,但宁可说
运算符'*'不适用于'double'和'weibull'类型的操作数
更新的代码是
RadarSpace GetWeibullClutter()
{
Random _randomNumberGenerator = new Random();
Weibull myweibull = new Weibull(3,2,_randomNumberGenerator);
int n = 50; // number of clutter elements
var maxRange = _detectionModel.MaximumRange;
var centreX = 0; // Centre of the field of view -- X coordinates
var centreY = 0; // Centre of the field of view -- Y coordinates
var minimumAngle = Math.PI / 4; // _detectionModel.MinimumPhi;
var maximumAngle = (3 * Math.PI) / 4; // _detectionModel.MaximumPhir;
var theta = 0.0;
var r = 0.0;
var randomNumbers = new double[n];
myweibull.Samples(randomNumbers);
for (int i = 0; i < n; i++)
{
theta = (maximumAngle - minimumAngle) * randomNumbers[i] + minimumAngle;
r = maxRange * Math.Sqrt(randomNumbers[i]);
}
//var theta = (maximumAngle - minimumAngle) * myweibull.Sample() + minimumAngle;
//var r = maxRange * Math.Sqrt(_randomNumberGenerator.Next(n));
var x = centreX + r * Math.Cos(theta);
var y = centreY + r * Math.Sin(theta);
答案 0 :(得分:1)
您似乎正在使用Math.NET Numerics库。 Weibull distribution class实现了IContinuousDistribution
接口,该接口提供了属性和方法:
double Mode { get; }
double Minimum { get; }
double Maximum { get; }
double Density(double x);
double DensityLn(double x);
double Sample();
void Samples(double[] values);
IEnumerable<double> Samples();
您的变量myweibull
包含Weibull
类的实例,因此您不能将其与double
相乘。
您说您生成了随机数,但没有生成。为此,请使用Sample()
方法:
var theta = (maximumAngle - minimumAngle) * myweibull.Sample() + minimumAngle;
这将为您提供一个韦伯分布的随机数。如果您需要更多随机数,请任一反复呼叫Sample()
:
for( int i = 0; i < n; i++ )
{
var theta = (maximumAngle - minimumAngle) * myweibull.Sample() + minimumAngle;
...
}
或使用 Samples()
var randomNumbers = new double[n];
myweilbull.Samples(randomNumbers);
for( int i = 0; i < n; i++ )
{
var theta = (maximumAngle - minimumAngle) * randomNumbers[i] + minimumAngle;
...
}
对于您的问题,r
和theta
必须是独立的,否则角度和半径将完全相关,并且所有生成的点都在一条线上。
for( int i = 0; i < n; i++ )
{
var theta= (maximumAngle - minimumAngle) * myweibull.Sample() + minimumAngle;
var r = maxRange * Math.Sqrt( myweibull.Sample() );
var x = centreX + r * Math.Cos(theta);
var y = centreY + r * Math.Sin(theta);
// Do something with your generated point (x, y)
}
如果仅为theta
和r
生成50个随机值,但仅计算一次x
和y
,那么您将只有一个随机点。
但是我仍然想知道您要实现什么目标,因为这些点在行业中不会平均分布,而是在Weibull分布。