Changeset 14404 for branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Utilities.cs
- Timestamp:
- 11/21/16 15:52:53 (8 years ago)
- Location:
- branches
- Files:
-
- 2 edited
- 2 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches
-
Property
svn:global-ignores
set to
bin
-
Property
svn:global-ignores
set to
-
branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Utilities.cs
r14269 r14404 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 1 using System.Collections.Generic; 6 2 using HeuristicLab.Data; 7 3 8 4 namespace HeuristicLab.Algorithms.MOCMAEvolutionStrategy { 9 internal class Utilities {5 internal static class Utilities { 10 6 internal static double[][] ToArray(DoubleMatrix m) { 11 inti = m.Rows - 1;12 double[][]a = new double[i][];7 var i = m.Rows - 1; 8 var a = new double[i][]; 13 9 for (i--; i >= 0; i--) { 14 intj = m.Columns;10 var j = m.Columns; 15 11 a[i] = new double[j]; 16 12 for (j--; j >= 0; j--) a[i][j] = m[i, j]; … … 19 15 } 20 16 17 public static int ArgMin<T>(IEnumerable<T> values, IComparer<T> comparer) { 18 var mindex = 0; 19 var min = default(T); 20 var i = 0; 21 foreach (var v in values) { 22 if (mindex < 0 || comparer.Compare(v, min) < 0) { 23 min = v; 24 mindex = i; 25 } 26 i++; 27 } 28 return mindex; 29 30 } 31 public static int ArgMax<T>(IEnumerable<T> values, IComparer<T> comparer) { 32 var mindex = 0; 33 var min = default(T); 34 var i = 0; 35 foreach (var v in values) { 36 if (mindex < 0 || comparer.Compare(v, min) > 0) { 37 min = v; 38 mindex = i; 39 } 40 i++; 41 } 42 return mindex; 43 } 44 private class DoubleComparer : IComparer<double> { 45 public int Compare(double x, double y) { 46 return x.CompareTo(y); 47 } 48 } 49 public static int ArgMax(this IEnumerable<double> values) { 50 return ArgMax(values, new DoubleComparer()); 51 } 52 public static int ArgMin(this IEnumerable<double> values) { 53 return ArgMin(values, new DoubleComparer()); 54 } 21 55 } 22 56 }
Note: See TracChangeset
for help on using the changeset viewer.