Last change
on this file since 14404 was
14404,
checked in by bwerth, 8 years ago
|
#2592 several fixes and cleanups to adapt a more HeuristicLab-Code-Style + renaming of folders and Plugin
|
File size:
1.5 KB
|
Line | |
---|
1 | using System.Collections.Generic;
|
---|
2 | using HeuristicLab.Data;
|
---|
3 |
|
---|
4 | namespace HeuristicLab.Algorithms.MOCMAEvolutionStrategy {
|
---|
5 | internal static class Utilities {
|
---|
6 | internal static double[][] ToArray(DoubleMatrix m) {
|
---|
7 | var i = m.Rows - 1;
|
---|
8 | var a = new double[i][];
|
---|
9 | for (i--; i >= 0; i--) {
|
---|
10 | var j = m.Columns;
|
---|
11 | a[i] = new double[j];
|
---|
12 | for (j--; j >= 0; j--) a[i][j] = m[i, j];
|
---|
13 | }
|
---|
14 | return a;
|
---|
15 | }
|
---|
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 | }
|
---|
55 | }
|
---|
56 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.