Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/29/11 01:42:41 (13 years ago)
Author:
abeham
Message:

#1330

  • Fixed calculation of normalized stress value
  • Fixed a few bugs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/QAP/HeuristicLab.Analysis/3.3/MultidimensionalScaling/MultidimensionalScaling.cs

    r5723 r5855  
    6161      double epsf = 0;
    6262      double epsx = 0;
    63       int maxits = 1000;
     63      int maxits = 100;
    6464      alglib.mincgstate state = null;
    6565      alglib.mincgreport rep;
     
    6969          double[] c = new double[] { coordinates[i, 0], coordinates[i, 1] };
    7070
    71           if (iterations == 0 && i == 0) {
    72             alglib.mincgcreate(c, out state);
    73             alglib.mincgsetcond(state, epsg, epsf, epsx, maxits);
    74           } else {
    75             alglib.mincgrestartfrom(state, c);
     71          try {
     72            if ((iterations == 0 && i == 0)) {
     73              alglib.mincgcreate(c, out state);
     74              alglib.mincgsetcond(state, epsg, epsf, epsx, maxits);
     75            } else {
     76              alglib.mincgrestartfrom(state, c);
     77            }
     78            alglib.mincgoptimize(state, StressGradient, null, new Info(coordinates, distances, i));
     79            alglib.mincgresults(state, out c, out rep);
     80          } catch (alglib.alglibexception e) { }
     81          if (!double.IsNaN(c[0]) && !double.IsNaN(c[1])) {
     82            coordinates[i, 0] = c[0];
     83            coordinates[i, 1] = c[1];
    7684          }
    77           alglib.mincgoptimize(state, StressGradient, null, new Info(coordinates, distances, i));
    78           alglib.mincgresults(state, out c, out rep);
    79 
    80           coordinates[i, 0] = c[0];
    81           coordinates[i, 1] = c[1];
    8285        }
    8386      }
     
    112115
    113116    public static double CalculateNormalizedStress(int dimension, DoubleMatrix distances, DoubleMatrix coordinates) {
    114       double stress = 0;
     117      double stress = 0, normalization = 0;
    115118      for (int i = 0; i < dimension - 1; i++) {
    116119        for (int j = i + 1; j < dimension; j++) {
    117120          if (distances[i, j] != 0) {
    118             stress += Stress(coordinates[i, 0], coordinates[i, 1], distances[i, j], coordinates[j, 0], coordinates[j, 1])
    119               / (distances[i, j] * distances[i, j]);
     121            stress += Stress(coordinates[i, 0], coordinates[i, 1], distances[i, j], coordinates[j, 0], coordinates[j, 1]);
     122            normalization += (distances[i, j] * distances[i, j]);
    120123          }
    121124        }
    122125      }
    123       return stress;
     126      return Math.Sqrt(stress / normalization); ;
    124127    }
    125128
Note: See TracChangeset for help on using the changeset viewer.