Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/26/12 16:28:17 (13 years ago)
Author:
abeham
Message:

#1767

  • added NaN check to MultidimensionalScaling
  • fixed a bug in StressFitness and now ignore distance to self
  • changed transformation of the weights matrix to a dissimiliarity matrix (set entries to NaN when weight was 0)
  • swapped weights and distance matrix for the els19
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis/3.3/MultidimensionalScaling/MultidimensionalScaling.cs

    r7259 r7416  
    103103    private static void StressFitness(double[] x, double[] fi, object obj) {
    104104      Info info = (obj as Info);
     105      int idx = 0;
    105106      for (int i = 0; i < info.Coordinates.Rows; i++) {
    106         double f = Stress(x, info.Dissimilarities[info.Row, i], info.Coordinates[i, 0], info.Coordinates[i, 1]);
    107         if (i < info.Row) fi[i] = f;
    108         else if (i > info.Row) fi[i - 1] = f;
     107        if (i == info.Row) continue;
     108        if (!double.IsNaN(info.Dissimilarities[info.Row, i]))
     109          fi[idx++] = Stress(x, info.Dissimilarities[info.Row, i], info.Coordinates[i, 0], info.Coordinates[i, 1]);
     110        else fi[idx++] = 0.0;
    109111      }
    110112    }
     
    114116      int idx = 0;
    115117      for (int i = 0; i < info.Coordinates.Rows; i++) {
    116         if (i != info.Row) {
    117           double c = info.Dissimilarities[info.Row, i];
    118           double a = info.Coordinates[i, 0];
    119           double b = info.Coordinates[i, 1];
    120           double f = Stress(x, c, a, b);
    121           fi[idx] = f;
     118        if (i == info.Row) continue;
     119        double c = info.Dissimilarities[info.Row, i];
     120        double a = info.Coordinates[i, 0];
     121        double b = info.Coordinates[i, 1];
     122        if (!double.IsNaN(c)) {
     123          fi[idx] = Stress(x, c, a, b); ;
    122124          jac[idx, 0] = 2 * (x[0] - a) * (Math.Sqrt((a - x[0]) * (a - x[0]) + (b - x[1]) * (b - x[1])) - c) / Math.Sqrt((a - x[0]) * (a - x[0]) + (b - x[1]) * (b - x[1]));
    123125          jac[idx, 1] = 2 * (x[1] - b) * (Math.Sqrt((a - x[0]) * (a - x[0]) + (b - x[1]) * (b - x[1])) - c) / Math.Sqrt((a - x[0]) * (a - x[0]) + (b - x[1]) * (b - x[1]));
    124           idx++;
     126        } else {
     127          fi[idx] = jac[idx, 0] = jac[idx, 1] = 0;
    125128        }
     129        idx++;
    126130      }
    127131    }
     
    153157      for (int i = 0; i < dimension - 1; i++) {
    154158        for (int j = i + 1; j < dimension; j++) {
    155           if (dissimilarities[i, j] != dissimilarities[j, i]) throw new ArgumentException("Dissimilarities is not a symmetric matrix.", "dissimilarities");
    156           if (dissimilarities[i, j] != 0) {
     159          if (dissimilarities[i, j] != dissimilarities[j, i] && !(double.IsNaN(dissimilarities[i, j]) && double.IsNaN(dissimilarities[j, i])))
     160            throw new ArgumentException("Dissimilarities is not a symmetric matrix.", "dissimilarities");
     161          if (!double.IsNaN(dissimilarities[i, j])) {
    157162            stress += Stress(coordinates[i, 0], coordinates[i, 1], dissimilarities[i, j], coordinates[j, 0], coordinates[j, 1]);
    158163            normalization += (dissimilarities[i, j] * dissimilarities[i, j]);
Note: See TracChangeset for help on using the changeset viewer.