当前位置: 首页>>代码示例>>C#>>正文


C# Tuple.OrderByDescending方法代码示例

本文整理汇总了C#中Tuple.OrderByDescending方法的典型用法代码示例。如果您正苦于以下问题:C# Tuple.OrderByDescending方法的具体用法?C# Tuple.OrderByDescending怎么用?C# Tuple.OrderByDescending使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tuple的用法示例。


在下文中一共展示了Tuple.OrderByDescending方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Prune

        /// <summary>
        /// This is meant to be a generic prune method.  It returns the top weights, and normalizes them so the sum of the smaller
        /// set is the same as the sum of the larger set
        /// </summary>
        private static Tuple<int, double>[] Prune(double[] weights, int count)
        {
            // Convert the weights into a list with the original index
            Tuple<int, double>[] weightsIndexed = new Tuple<int, double>[weights.Length];
            for (int cntr = 0; cntr < weights.Length; cntr++)
            {
                weightsIndexed[cntr] = new Tuple<int, double>(cntr, weights[cntr]);
            }

            if (count > weights.Length)
            {
                // This method shouldn't have been called, there is nothing to do
                return weightsIndexed;
            }

            Tuple<int, double>[] topWeights = weightsIndexed.OrderByDescending(o => Math.Abs(o.Item2)).Take(count).ToArray();

            double sumWeights = weights.Sum(o => Math.Abs(o));
            double sumTop = topWeights.Sum(o => Math.Abs(o.Item2));

            double ratio = sumWeights / sumTop;
            if (double.IsNaN(ratio))
            {
                ratio = 1d;		// probably divide by zero
            }

            // Normalize the top weights
            return topWeights.Select(o => new Tuple<int, double>(o.Item1, o.Item2 * ratio)).ToArray();
        }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:33,代码来源:Neural.cs

示例2: unique

    private Tuple<Point, List<Point>>[] unique(Tuple<Point, List<Point>>[] killPoints)
    {
        var uniqueEffects = new List<Tuple<Point, List<Point>>>();
        foreach (var killPoint in killPoints.OrderByDescending(t=>t.Item2.Count))
        {
            var isCoveredByExistingPoint =
                uniqueEffects.Any(existingKillPoint =>
                    killPoint.Item2.All(p=> existingKillPoint.Item2.Contains(p))
                );

            if (!isCoveredByExistingPoint)
            {
                //Console.Error.WriteLine("    + Adding test of {0}", killPoint.Item1);
                uniqueEffects.Add(killPoint);
            }
            else
            {
                //Console.Error.WriteLine("    - Skipping test of {0}", killPoint.Item1);
            }
        }
        return uniqueEffects.ToArray();
    }
开发者ID:aquamoth,项目名称:CodeinGame,代码行数:22,代码来源:Program.cs

示例3: sanitizeVars

 public static string sanitizeVars(this string inputCode)
 {
     replacementVars = memory.getVariableNames().Select((m, i) => new Tuple<string, string>(m, createHash(i))).ToArray();
     replacementVars = replacementVars.OrderByDescending(n => n.Item1.Length).ToArray();
     for (int i = 0; i < replacementVars.Length; i++)
     {
         inputCode = inputCode.Replace(replacementVars[i].Item1, "(" + replacementVars[i].Item2 + ")");
     }
     Array.Reverse(replacementVars);
     return inputCode;
 }
开发者ID:timopomer,项目名称:ListSharp,代码行数:11,代码来源:codeProcessing.cs

示例4: Main


//.........这里部分代码省略.........
            //Common.SaveAndShowImage(filtersInt);

            int size = nBands * nSectors*nFilters;

            int num = 60000;

            List<double>[] dbase = new List<double>[num];
            var rand = new Random();
            for (int w = 0; w < num; w++)
            {
                var lst = new List<double>();
                for(int s=0;s<size;s++)
                {
                    lst.Add(rand.NextDouble() * 128.0f);
                }
                dbase[w] = lst;
            }

            using (FileStream fs = new FileStream("C:\\temp\\fusrodah_cpu_results.csv", FileMode.Create))
            {
                using (StreamWriter streamWriter = new StreamWriter(fs))
                {
                    streamWriter.WriteLine("Find;Create;Match;Top");
                    for (int n = 0; n < 20; n++)
                    {
                        int radius = nBands*bandRadius + holeRadius + 16; //mask size

                        var sw = new Stopwatch();
                        sw.Start();
                        PerformNewDetectionAlgorithmTestfire(imgBytes);
                        streamWriter.Write(sw.ElapsedMilliseconds + ";");
                        sw.Stop();


                        sw.Restart();
                        var normalizedImage =
                            NormalizeImage(imgBytes, nBands, holeRadius, bandRadius,
                                           265, 292);
                        //Common.SaveAndShowImage(normalizedImage);
                        var filteredImages = new List<int[,]>();
                        for (int i = 0; i < nFilters; i++) filteredImages.Add(null);
                        Parallel.ForEach(filterbank, new ParallelOptions() {MaxDegreeOfParallelism = 4},
                                         filter =>
                                             {

                                                 var filtered = FilterWithGaborFilter(normalizedImage,
                                                                                      filter, nBands, holeRadius,
                                                                                      bandRadius,
                                                                                      265, 292);
                                                 //Common.SaveAndShowImage(filtered);
                                                 filteredImages[filterbank.IndexOf(filter)] = filtered;
                                             }

                            );
                        var fingercode = new List<double>();
                        for (int i = 0; i < nFilters*nBands*nSectors; i++)
                        {
                            fingercode.Add(0);
                        }
                        Parallel.ForEach(filteredImages,
                                         new ParallelOptions {MaxDegreeOfParallelism = 4},
                                         filteredImgBytes =>
                                             {
                                                 var fingercodePart = FormFingerCode(filteredImgBytes, nSectors, nBands,
                                                                                     holeRadius,
                                                                                     bandRadius);
                                                 int startIndex = filteredImages.IndexOf(filteredImgBytes)*
                                                                  nBands*nSectors;
                                                 foreach (var d in fingercodePart)
                                                 {
                                                     fingercode[startIndex++] = d;
                                                 }
                                             });
                        sw.Stop();
                        streamWriter.Write(sw.ElapsedMilliseconds + ";");
                        //Common.SaveFingerCode(fingercode, nBands, nSectors, nFilters, bandRadius, holeRadius);
                        sw.Restart();
                        Tuple<int, double>[] result = new Tuple<int, double>[num];

                        Parallel.ForEach(new[] {0, 1, 2, 3}, new ParallelOptions() {MaxDegreeOfParallelism = 4},
                                         (offset) =>
                                             {
                                                 for (int i = 0; i < num/4; i++)
                                                 {
                                                     var index = i*4 + offset;
                                                     result[index] = Tuple.Create(index,
                                                                                  CalculateDistance(fingercode,
                                                                                                    dbase[index]));
                                                 }
                                             });
                        sw.Stop();
                        streamWriter.Write(sw.ElapsedMilliseconds + ";");
                        sw.Restart();
                        result = result.OrderByDescending(x => x.Item2).ToArray();
                        sw.Stop();
                        streamWriter.WriteLine(sw.ElapsedMilliseconds);
                    }
                }
            }
        }
开发者ID:Cool2Feel,项目名称:cuda-fingerprinting,代码行数:101,代码来源:Program.cs

示例5: BeamSerach

        public static Tuple<int[], int, int[], int, int> BeamSerach(int[] board)
        {
            var results = new Tuple<int[], int, int[], int, int>[30];//board, score, route, startRow, startColumn;
            Parallel.For(0, 6 * 5, idx =>
            {
                var route = new int[50];
                int tmpScore = 0;

                fixed (int* b = board, r = route)
                {
                    tmpScore = BeamSearch(b, 1, 42, 400, idx / 6, idx % 6, r);
                }

                results[idx] = Tuple.Create(route, tmpScore, route, idx / 6, idx % 6);
            });
            return results.OrderByDescending(x => x.Item2).First();
        }
开发者ID:tnkt37,项目名称:PazzDraVisualizer,代码行数:17,代码来源:Form1.cs

示例6: Prune_Pre

        private static Tuple<Point3D, Point3D, double>[] Prune_Pre(Tuple<Point3D, Point3D, double>[] existing, int count)
        {
            // Sort it so the smaller links have a higher chance of being removed
            var retVal = existing.
                OrderByDescending(o => Math.Abs(o.Item3)).      // the weights could be negative, so sort on distance from zero
                ToList();

            Random rand = StaticRandom.GetRandomForThread();

            while (retVal.Count > count)
            {
                // Choose a random item to remove - favor the end of the list (where the smallest links are)
                double percent = rand.NextPow(10);
                int index = UtilityCore.GetIndexIntoList(percent, retVal.Count);

                retVal.RemoveAt(index);
            }

            return retVal.ToArray();
        }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:20,代码来源:ItemLinker.cs


注:本文中的Tuple.OrderByDescending方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。