本文整理汇总了C#中MersenneTwister.NextFullRangeInt32方法的典型用法代码示例。如果您正苦于以下问题:C# MersenneTwister.NextFullRangeInt32方法的具体用法?C# MersenneTwister.NextFullRangeInt32怎么用?C# MersenneTwister.NextFullRangeInt32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MersenneTwister
的用法示例。
在下文中一共展示了MersenneTwister.NextFullRangeInt32方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CBS
/// <summary>
/// CBS: circular binary segmentation porting the R function segment in DNAcopy
/// </summary>
/// <param name="alpha">Now in this.Alpha</param>
/// <param name="nPerm"></param>
/// <param name="pMethod">"hybrid" or "perm"</param>
/// <param name="minWidth"></param>
/// <param name="kMax"></param>
/// <param name="nMin"></param>
/// <param name="eta"></param>
/// <param name="sbdry"></param>
/// <param name="trim"></param>
/// <param name="undoSplit">"none" or "prune" or "sdundo"; now in this.UndoMethod</param>
/// <param name="undoPrune"></param>
/// <param name="undoSD"></param>
/// <param name="verbose"></param>
private void CBS(uint nPerm = 10000, string pMethod = "hybrid", int minWidth = 2, int kMax = 25,
uint nMin = 200, double eta = 0.05, uint[] sbdry = null, double trim = 0.025,
double undoPrune = 0.05, double undoSD = 3, int verbose = 1)
{
if (minWidth < 2 || minWidth > 5)
{
Console.Error.WriteLine("Minimum segment width should be between 2 and 5");
Environment.Exit(1);
}
if (nMin < 4 * kMax)
{
Console.Error.WriteLine("nMin should be >= 4 * kMax");
Environment.Exit(1);
}
if (sbdry == null)
{
GetBoundary.ComputeBoundary(nPerm, this.Alpha, eta, out sbdry);
}
Dictionary<string, int[]> inaByChr = new Dictionary<string, int[]>();
Dictionary<string, double[]> finiteScoresByChr = new Dictionary<string, double[]>();
List<ThreadStart> tasks = new List<ThreadStart>();
foreach (KeyValuePair<string, double[]> scoreByChrKVP in ScoreByChr)
{
tasks.Add(new ThreadStart(() =>
{
string chr = scoreByChrKVP.Key;
int[] ina;
Helper.GetFiniteIndices(scoreByChrKVP.Value, out ina); // not NaN, -Inf, Inf
double[] scores;
if (ina.Length == scoreByChrKVP.Value.Length)
{
scores = scoreByChrKVP.Value;
}
else
{
Helper.ExtractValues<double>(scoreByChrKVP.Value, ina, out scores);
}
lock (finiteScoresByChr)
{
finiteScoresByChr[chr] = scores;
inaByChr[chr] = ina;
}
}));
}
//Parallel.ForEach(tasks, t => { t.Invoke(); });
Isas.Shared.Utilities.DoWorkParallelThreads(tasks);
// Quick sanity-check: If we don't have any segments, then return a dummy result.
int n = 0;
foreach (var list in finiteScoresByChr.Values)
{
n += list.Length;
}
if (n == 0)
{
this.SegmentationResults = this.GetDummySegmentationResults();
return;
}
double trimmedSD = Math.Sqrt(ChangePoint.TrimmedVariance(finiteScoresByChr, trim: trim));
Dictionary<string, Segment[]> segmentByChr = new Dictionary<string, Segment[]>();
// when parallelizing we need an RNG for each chromosome to get deterministic results
Random seedGenerator = new MersenneTwister(0);
Dictionary<string, Random> perChromosomeRandom = new Dictionary<string, Random>();
foreach (string chr in this.ScoreByChr.Keys)
{
perChromosomeRandom[chr] = new MersenneTwister(seedGenerator.NextFullRangeInt32(), true);
}
tasks = new List<ThreadStart>();
foreach (string chr in ScoreByChr.Keys)
{
tasks.Add(new ThreadStart(() =>
{
int[] ina = inaByChr[chr];
int[] lengthSeg;
double[] segmentMeans;
ChangePoint.ChangePoints(this.ScoreByChr[chr], sbdry, out lengthSeg, out segmentMeans, perChromosomeRandom[chr],
dataType: this.DataType, alpha: this.Alpha, nPerm: nPerm,
//.........这里部分代码省略.........
示例2: Wavelets
/// <summary>
/// Wavelets: unbalanced HAAR wavelets segmentation
/// </summary>
/// <param name="threshold">wavelets coefficient threshold</param>
private void Wavelets(bool isGermline, double thresholdLower = 5, double thresholdUpper = 80, int minSize = 10, int verbose = 1)
{
Dictionary<string, int[]> inaByChr = new Dictionary<string, int[]>();
Dictionary<string, double[]> finiteScoresByChr = new Dictionary<string, double[]>();
List<ThreadStart> tasks = new List<ThreadStart>();
foreach (KeyValuePair<string, double[]> scoreByChrKVP in ScoreByChr)
{
tasks.Add(new ThreadStart(() =>
{
string chr = scoreByChrKVP.Key;
int[] ina;
Helper.GetFiniteIndices(scoreByChrKVP.Value, out ina); // not NaN, -Inf, Inf
double[] scores;
if (ina.Length == scoreByChrKVP.Value.Length)
{
scores = scoreByChrKVP.Value;
}
else
{
Helper.ExtractValues<double>(scoreByChrKVP.Value, ina, out scores);
}
lock (finiteScoresByChr)
{
finiteScoresByChr[chr] = scores;
inaByChr[chr] = ina;
}
}));
}
Isas.Shared.Utilities.DoWorkParallelThreads(tasks);
// Quick sanity-check: If we don't have any segments, then return a dummy result.
int n = 0;
foreach (var list in finiteScoresByChr.Values)
{
n += list.Length;
}
if (n == 0)
{
this.SegmentationResults = this.GetDummySegmentationResults();
return;
}
Dictionary<string, Segment[]> segmentByChr = new Dictionary<string, Segment[]>();
// when parallelizing we need an RNG for each chromosome to get deterministic results
Random seedGenerator = new MersenneTwister(0);
Dictionary<string, Random> perChromosomeRandom = new Dictionary<string, Random>();
foreach (string chr in this.ScoreByChr.Keys)
{
perChromosomeRandom[chr] = new MersenneTwister(seedGenerator.NextFullRangeInt32(), true);
}
tasks = new List<ThreadStart>();
foreach (string chr in ScoreByChr.Keys)
{
tasks.Add(new ThreadStart(() =>
{
int[] ina = inaByChr[chr];
List<int> breakpoints = new List<int>();
int sizeScoreByChr = this.ScoreByChr[chr].Length;
if (sizeScoreByChr > minSize)
{
WaveletSegmentation.HaarWavelets(this.ScoreByChr[chr].ToArray(), thresholdLower, thresholdUpper, breakpoints, isGermline);
}
List<int> startBreakpointsPos = new List<int>();
List<int> endBreakpointPos = new List<int>();
List<int> lengthSeg = new List<int>();
if (breakpoints.Count() >= 2 && sizeScoreByChr > 10)
{
startBreakpointsPos.Add(breakpoints[0]);
endBreakpointPos.Add(breakpoints[1] - 1);
lengthSeg.Add(breakpoints[1] - 1);
for (int i = 1; i < breakpoints.Count - 1; i++)
{
startBreakpointsPos.Add(breakpoints[i]);
endBreakpointPos.Add(breakpoints[i + 1] - 1);
lengthSeg.Add(breakpoints[i + 1] - 1 - breakpoints[i]);
}
startBreakpointsPos.Add(breakpoints[breakpoints.Count - 1]);
endBreakpointPos.Add(sizeScoreByChr - 1);
lengthSeg.Add(sizeScoreByChr - breakpoints[breakpoints.Count - 1] - 1);
}
else
{
startBreakpointsPos.Add(0);
endBreakpointPos.Add(sizeScoreByChr - 1);
lengthSeg.Add(sizeScoreByChr - 1);
}
// estimate segment means
//.........这里部分代码省略.........