private static void AnalyzeCode(ICode code, int errorsCount, int?decodingThreadsCount = null) { var informationWord = Enumerable.Repeat(code.Field.Zero(), code.InformationWordLength).ToArray(); var codeword = code.Encode(informationWord); var processedNoises = 0; Parallel.ForEach( NoiseGenerator.VariatePositionsAndValues(code.Field, code.CodewordLength, errorsCount), new ParallelOptions { MaxDegreeOfParallelism = decodingThreadsCount ?? (int)(Environment.ProcessorCount * 1.5d) }, x => { var decodingResults = code.DecodeViaList(codeword.AddNoise(x), errorsCount); if (decodingResults.Contains(informationWord, WordsComparer) == false) { throw new InvalidOperationException($"Failed to process noise {string.Join<FieldElement>(",", x)}"); } if (Interlocked.Increment(ref processedNoises) % 50 == 0) { Logger.LogInformation($"[{Thread.CurrentThread.ManagedThreadId}]: Current noise value ({string.Join<FieldElement>(",", x)})"); } if (TelemetryCollector.ProcessedSamplesCount % 100 == 0) { Logger.LogInformation(TelemetryCollector.ToString()); } } ); }
public IReadOnlyList <ListsSizesDistribution> Analyze(ICode code, ListsSizesDistributionAnalyzerOptions options = null) { if (code == null) { throw new ArgumentNullException(nameof(code)); } var opts = options ?? new ListsSizesDistributionAnalyzerOptions(); PrepareLogFiles(opts.FullLogsPath, code); var processedCentersCount = 0L; var result = Enumerable.Range(1, code.CodewordLength - 1).Select(x => new ListsSizesDistribution(x)).ToArray(); for (var errorsCount = 0; errorsCount <= code.CodewordLength; errorsCount++) { Parallel.ForEach( _noiseGenerator.VariatePositionsAndValues(code.Field, code.CodewordLength, errorsCount), new ParallelOptions { MaxDegreeOfParallelism = opts.MaxDegreeOfParallelism }, ballCenter => { var lists = result.Select(x => new List <FieldElement[]>()).ToArray(); var codewordsForLargestBall = code.DecodeViaList(ballCenter, code.CodewordLength - 1).Select(code.Encode); foreach (var codeword in codewordsForLargestBall) { for (var i = Math.Max(0, ballCenter.ComputeHammingDistance(codeword) - 1); i < lists.Length; i++) { lists[i].Add(codeword); } } for (var i = 0; i < lists.Length; i++) { result[i].CollectInformation(ballCenter, lists[i]); LogListSize(opts.FullLogsPath, code, i + 1, ballCenter, lists[i].Count); } if (Interlocked.Increment(ref processedCentersCount) % opts.LoggingResolution == 0) { _logger.LogInformation("Processed {processedCentersCount} centers", processedCentersCount); } } ); } return(result); }
public int Analyze(ICode code, MinimalSphereCoveringAnalyzerOptions options = null) { if (code == null) { throw new ArgumentNullException(nameof(code)); } var opts = options ?? new MinimalSphereCoveringAnalyzerOptions(); var minimalRadius = 0; var processedWordsCount = 0L; for (var errorsCount = 0; errorsCount <= code.CodewordLength; errorsCount++) { Parallel.ForEach( _noiseGenerator.VariatePositionsAndValues(code.Field, code.CodewordLength, errorsCount), new ParallelOptions { MaxDegreeOfParallelism = opts.MaxDegreeOfParallelism }, () => 0, (word, loopState, localMinimalRadius) => { var codewordsInLargestBall = code.DecodeViaList(word, code.CodewordLength - 1).Select(code.Encode); if (Interlocked.Increment(ref processedWordsCount) % opts.LoggingResolution == 0) { _logger.LogInformation( "Thread [{managedThreadId}]: processed {processedWordsCount} words, local minimal radius {localMinimalRadius}", Thread.CurrentThread.ManagedThreadId, processedWordsCount, localMinimalRadius ); } return(Math.Max(localMinimalRadius, codewordsInLargestBall.Min(x => x.ComputeHammingDistance(word)))); }, localMinimalRadius => minimalRadius = Math.Max(minimalRadius, localMinimalRadius) ); } return(minimalRadius); }