Changeset 7416 for trunk/sources/HeuristicLab.Analysis
- Timestamp:
- 01/26/12 16:28:17 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Analysis/3.3/MultidimensionalScaling/MultidimensionalScaling.cs
r7259 r7416 103 103 private static void StressFitness(double[] x, double[] fi, object obj) { 104 104 Info info = (obj as Info); 105 int idx = 0; 105 106 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; 109 111 } 110 112 } … … 114 116 int idx = 0; 115 117 for (int i = 0; i < info.Coordinates.Rows; i++) { 116 if (i != info.Row) {117 118 119 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); ; 122 124 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])); 123 125 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; 125 128 } 129 idx++; 126 130 } 127 131 } … … 153 157 for (int i = 0; i < dimension - 1; i++) { 154 158 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])) { 157 162 stress += Stress(coordinates[i, 0], coordinates[i, 1], dissimilarities[i, j], coordinates[j, 0], coordinates[j, 1]); 158 163 normalization += (dissimilarities[i, j] * dissimilarities[i, j]);
Note: See TracChangeset
for help on using the changeset viewer.