- Timestamp:
- 03/29/11 01:42:41 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/QAP/HeuristicLab.Analysis/3.3/MultidimensionalScaling/MultidimensionalScaling.cs
r5723 r5855 61 61 double epsf = 0; 62 62 double epsx = 0; 63 int maxits = 100 0;63 int maxits = 100; 64 64 alglib.mincgstate state = null; 65 65 alglib.mincgreport rep; … … 69 69 double[] c = new double[] { coordinates[i, 0], coordinates[i, 1] }; 70 70 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]; 76 84 } 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];82 85 } 83 86 } … … 112 115 113 116 public static double CalculateNormalizedStress(int dimension, DoubleMatrix distances, DoubleMatrix coordinates) { 114 double stress = 0 ;117 double stress = 0, normalization = 0; 115 118 for (int i = 0; i < dimension - 1; i++) { 116 119 for (int j = i + 1; j < dimension; j++) { 117 120 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]); 120 123 } 121 124 } 122 125 } 123 return stress;126 return Math.Sqrt(stress / normalization); ; 124 127 } 125 128
Note: See TracChangeset
for help on using the changeset viewer.