Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7416


Ignore:
Timestamp:
01/26/12 16:28:17 (12 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
Location:
trunk/sources
Files:
3 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]);
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QAPVisualizationControl.cs

    r7259 r7416  
    205205        Bitmap newBitmap = null;
    206206        stressLabel.Text = "-";
     207        stressLabel.ForeColor = Color.Black;
    207208        if (distancesRadioButton.Checked && Distances != null && Distances.Rows > 0
    208209          && Distances.Rows == Distances.Columns) {
    209           if (Distances.Rows > 35) {
     210          if (Distances.Rows > 50) {
    210211            newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    211212            WriteCenteredTextToBitmap(ref newBitmap, "Problem dimension is too large for visualization.");
     
    214215        } else if (weightsRadioButton.Checked && Weights != null && Weights.Rows > 0
    215216          && Weights.Rows == Weights.Columns) {
    216           if (Weights.Rows > 35) {
     217          if (Weights.Rows > 50) {
    217218            newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    218219            WriteCenteredTextToBitmap(ref newBitmap, "Problem dimension is too large for visualization.");
     
    228229          && Assignment.Length == Distances.Rows
    229230          && Assignment.Validate()) {
    230           if (Assignment.Length > 35) {
     231          if (Assignment.Length > 50) {
    231232            newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    232233            WriteCenteredTextToBitmap(ref newBitmap, "Problem dimension is too large for visualization.");
     
    249250        Bitmap newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    250251        stressLabel.Text = "-";
     252        stressLabel.ForeColor = Color.Black;
    251253        WriteCenteredTextToBitmap(ref newBitmap, "Please refresh view.");
    252254        showingMessage = false; // we're showing a message, but we should be showing the visualization, so this is false
     
    270272          stress = MultidimensionalScaling.CalculateNormalizedStress(distances, coordinates);
    271273          stressLabel.Text = stress.ToString("0.00", CultureInfo.CurrentCulture.NumberFormat);
     274          if (stress < 0.1) stressLabel.ForeColor = Color.DarkGreen;
     275          else if (stress < 0.2) stressLabel.ForeColor = Color.DarkOrange;
     276          else stressLabel.ForeColor = Color.DarkRed;
    272277        } catch {
    273278          WriteCenteredTextToBitmap(ref newBitmap, "Distance matrix is not symmetric");
    274279          showingMessage = true;
    275280          stressLabel.Text = "-";
     281          stressLabel.ForeColor = Color.Black;
    276282          return newBitmap;
    277283        }
     
    349355        for (int i = 0; i < weights.Rows; i++)
    350356          for (int j = i + 1; j < weights.Rows; j++) {
    351             if (weights[i, j] > maxWeight)
    352               maxWeight = weights[i, j] + weights[j, i];
     357            if (weights[i, j] > maxWeight) maxWeight = weights[i, j];
     358            if (weights[j, i] > maxWeight) maxWeight = weights[j, i];
    353359          }
    354360
     
    356362        for (int i = 0; i < distances.Rows; i++)
    357363          for (int j = 0; j < distances.Columns; j++) {
    358             distances[i, j] = maxWeight + 1 - weights[i, j];
     364            if (weights[i, j] == 0) distances[i, j] = double.NaN;
     365            else distances[i, j] = maxWeight / weights[i, j];
    359366          }
    360367
     
    365372          stress = MultidimensionalScaling.CalculateNormalizedStress(distances, coordinates);
    366373          stressLabel.Text = stress.ToString("0.00", CultureInfo.CurrentCulture.NumberFormat);
     374          if (stress < 0.1) stressLabel.ForeColor = Color.DarkGreen;
     375          else if (stress < 0.2) stressLabel.ForeColor = Color.DarkOrange;
     376          else stressLabel.ForeColor = Color.DarkRed;
    367377        } catch {
    368378          WriteCenteredTextToBitmap(ref newBitmap, "Weights matrix is not symmetric");
    369379          showingMessage = true;
    370380          stressLabel.Text = "-";
     381          stressLabel.ForeColor = Color.Black;
    371382          return newBitmap;
    372383        }
     
    454465          stress = MultidimensionalScaling.CalculateNormalizedStress(distances, coordinates);
    455466          stressLabel.Text = stress.ToString("0.00", CultureInfo.CurrentCulture.NumberFormat);
     467          if (stress < 0.1) stressLabel.ForeColor = Color.DarkGreen;
     468          else if (stress < 0.2) stressLabel.ForeColor = Color.DarkOrange;
     469          else stressLabel.ForeColor = Color.DarkRed;
    456470        } catch {
    457471          WriteCenteredTextToBitmap(ref newBitmap, "Unknown error");
    458472          showingMessage = true;
    459473          stressLabel.Text = "-";
     474          stressLabel.ForeColor = Color.Black;
    460475          return newBitmap;
    461476        }
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/Data/els19.dat

    r5562 r7416  
    1119
    2 
    3   0  12  36  28  52  44 110 126  94  63 130 102  65  98 132 132 126 120 126
    4  12   0  24  75  82  75 108  70 124  86  93 106  58 124 161 161  70  64  70
    5  36  24   0  47  71  47 110  73 126  71  95 110  46 127 163 163  73  67  73
    6  28  75  47   0  42  34 148 111 160  52  94 148  49 117 104 109 111 105 111
    7  52  82  71  42   0  42 125 136 102  22  73 125  32  94 130 130 136 130 136
    8  44  75  47  34  42   0 148 111 162  52  96 148  49 117 152 152 111 105 111
    9 110 108 110 148 125 148   0  46  46 136  47  30 108  51  79  79  46  47  41
    10 126  70  73 111 136 111  46   0  69 141  63  46 119  68 121 121  27  24  36
    11  94 124 126 160 102 162  46  69   0 102  34  45  84  23  80  80  69  64  51
    12  63  86  71  52  22  52 136 141 102   0  64 118  29  95 131 131 141 135 141
    13 130  93  95  94  73  96  47  63  34  64   0  47  56  54  94  94  63  46  24
    14 102 106 110 148 125 148  30  46  45 118  47   0 100  51  89  89  46  40  36
    15  65  58  46  49  32  49 108 119  84  29  56 100   0  77 113 113 119 113 119
    16  98 124 127 117  94 117  51  68  23  95  54  51  77   0  79  79  68  62  51
    17 132 161 163 104 130 152  79 121  80 131  94  89 113  79   0  10 113 107 119
    18 132 161 163 109 130 152  79 121  80 131  94  89 113  79  10   0 113 107 119
    19 126  70  73 111 136 111  46  27  69 141  63  46 119  68 113 113   0   6  24
    20 120  64  67 105 130 105  47  24  64 135  46  40 113  62 107 107   6   0  12
    21 126  70  73 111 136 111  41  36  51 141  24  36 119  51 119 119  24  12   0
    222
    233    0 76687     0   415   545   819   135  1368   819  5630
     
    5939 1783     0     0     0     0     0     0     0     0     0
    6040    0     0     0     0     0     0     0     0     0
     41
     42  0  12  36  28  52  44 110 126  94  63 130 102  65  98 132 132 126 120 126
     43 12   0  24  75  82  75 108  70 124  86  93 106  58 124 161 161  70  64  70
     44 36  24   0  47  71  47 110  73 126  71  95 110  46 127 163 163  73  67  73
     45 28  75  47   0  42  34 148 111 160  52  94 148  49 117 104 109 111 105 111
     46 52  82  71  42   0  42 125 136 102  22  73 125  32  94 130 130 136 130 136
     47 44  75  47  34  42   0 148 111 162  52  96 148  49 117 152 152 111 105 111
     48110 108 110 148 125 148   0  46  46 136  47  30 108  51  79  79  46  47  41
     49126  70  73 111 136 111  46   0  69 141  63  46 119  68 121 121  27  24  36
     50 94 124 126 160 102 162  46  69   0 102  34  45  84  23  80  80  69  64  51
     51 63  86  71  52  22  52 136 141 102   0  64 118  29  95 131 131 141 135 141
     52130  93  95  94  73  96  47  63  34  64   0  47  56  54  94  94  63  46  24
     53102 106 110 148 125 148  30  46  45 118  47   0 100  51  89  89  46  40  36
     54 65  58  46  49  32  49 108 119  84  29  56 100   0  77 113 113 119 113 119
     55 98 124 127 117  94 117  51  68  23  95  54  51  77   0  79  79  68  62  51
     56132 161 163 104 130 152  79 121  80 131  94  89 113  79   0  10 113 107 119
     57132 161 163 109 130 152  79 121  80 131  94  89 113  79  10   0 113 107 119
     58126  70  73 111 136 111  46  27  69 141  63  46 119  68 113 113   0   6  24
     59120  64  67 105 130 105  47  24  64 135  46  40 113  62 107 107   6   0  12
     60126  70  73 111 136 111  41  36  51 141  24  36 119  51 119 119  24  12   0
Note: See TracChangeset for help on using the changeset viewer.