[16137] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Data;
|
---|
| 24 | using System;
|
---|
| 25 | using System.Linq;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Analysis.FitnessLandscape {
|
---|
| 28 | public static class DoubleMatrixCharacteristics {
|
---|
| 29 | public static double CoeffVariation(DoubleMatrix m) {
|
---|
| 30 | var avg = m.Average();
|
---|
| 31 | var stdDev = m.StandardDeviation();
|
---|
| 32 | return stdDev / avg;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | public static double Sparsity(DoubleMatrix m) {
|
---|
| 36 | return m.Count(x => x == 0) / (double)(m.Rows * m.Columns);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public static double Disparity(DoubleMatrix m) {
|
---|
| 40 | if (m.Rows != m.Columns) throw new ArgumentException("not a quadratic matrix", "m");
|
---|
| 41 | var n = m.Rows;
|
---|
| 42 | var avg = m.Sum() / n;
|
---|
| 43 | var disparity = 0.0;
|
---|
| 44 | for (var i = 0; i < n; i++) {
|
---|
| 45 | var tmp = 0.0;
|
---|
| 46 | for (var j = 0; j < n; j++) {
|
---|
| 47 | tmp += m[i, j];
|
---|
| 48 | }
|
---|
| 49 | disparity += (tmp - avg) * (tmp - avg);
|
---|
| 50 | }
|
---|
| 51 | return Math.Sqrt(disparity / n) / avg;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | public static double Skewness(DoubleMatrix m) {
|
---|
| 55 | double mean = 0, variance = 0, skewness = 0, kurtosis = 0;
|
---|
| 56 | alglib.basestat.samplemoments(m.ToArray(), m.Rows * m.Columns, ref mean, ref variance, ref skewness, ref kurtosis);
|
---|
| 57 | return skewness;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public static double Asymmetry(DoubleMatrix m) {
|
---|
| 61 | if (m.Rows != m.Columns) throw new ArgumentException("not a quadratic matrix", "m");
|
---|
| 62 | var n = m.Rows;
|
---|
| 63 | var count = 0;
|
---|
| 64 | for (var i = 0; i < n; i++) {
|
---|
| 65 | for (var j = 0; j < i; j++) {
|
---|
| 66 | var v = Math.Abs(m[i, j] - m[j, i]);
|
---|
| 67 | if (v > 0) {
|
---|
| 68 | count++;
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | return count / (n * (n - 1) / 2.0);
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | }
|
---|