Changeset 36290
- Timestamp:
- Nov 20, 2013, 3:21:02 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psStats.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psStats.c
r36238 r36290 1049 1049 1050 1050 #if (CZW) 1051 printf("CZW: bad sigma?: %f %f %f %f %f %f %f %f %f %f\n",1052 binH2F32,binL2F32,binHiF32,binLoF32,binH4F32,binL4F32,1053 sigma1,sigma2,sigma4,sigma);1051 // printf("CZW: bad sigma?: %f %f %f %f %f %f %f %f %f %f\n", 1052 // binH2F32,binL2F32,binHiF32,binLoF32,binH4F32,binL4F32, 1053 // sigma1,sigma2,sigma4,sigma); 1054 1054 1055 printf("CZW (%d): median %f sigma %f delta: %f \n\t %f %f %f %f %f %f %f \n\t %f %f %f %f %f %f %f\n",1055 printf("CZW Robust (%d): median %f sigma %f delta: %f \n\t %f %f %f %f %f %f %f \n\t %f %f %f %f %f %f %f\n", 1056 1056 iterate, 1057 stats->robustMedian,stats->robustStdev,1058 fabs(cumulative->bounds->data.F32[binMedian] - cumulative->bounds->data.F32[binMedian + 1]),1059 1060 cumulative->bounds->data.F32[binMedian-3],cumulative->bounds->data.F32[binMedian-2],1061 cumulative->bounds->data.F32[binMedian-1],1062 cumulative->bounds->data.F32[binMedian],1063 cumulative->bounds->data.F32[binMedian+1],1064 cumulative->bounds->data.F32[binMedian+2],cumulative->bounds->data.F32[binMedian+3],1065 1066 cumulative->nums->data.F32[binMedian-3],cumulative->nums->data.F32[binMedian-2],1067 cumulative->nums->data.F32[binMedian-1],1068 cumulative->nums->data.F32[binMedian],1069 cumulative->nums->data.F32[binMedian+1],1070 cumulative->nums->data.F32[binMedian+2],cumulative->nums->data.F32[binMedian+3]);1057 stats->robustMedian,stats->robustStdev, 1058 fabs(cumulative->bounds->data.F32[binMedian] - cumulative->bounds->data.F32[binMedian + 1]), 1059 1060 cumulative->bounds->data.F32[binMedian-3],cumulative->bounds->data.F32[binMedian-2], 1061 cumulative->bounds->data.F32[binMedian-1], 1062 cumulative->bounds->data.F32[binMedian], 1063 cumulative->bounds->data.F32[binMedian+1], 1064 cumulative->bounds->data.F32[binMedian+2],cumulative->bounds->data.F32[binMedian+3], 1065 1066 cumulative->nums->data.F32[binMedian-3],cumulative->nums->data.F32[binMedian-2], 1067 cumulative->nums->data.F32[binMedian-1], 1068 cumulative->nums->data.F32[binMedian], 1069 cumulative->nums->data.F32[binMedian+1], 1070 cumulative->nums->data.F32[binMedian+2],cumulative->nums->data.F32[binMedian+3]); 1071 1071 // PS_VECTOR_PRINT_F32(histogram->bounds); 1072 1072 // PS_VECTOR_PRINT_F32(histogram->nums); … … 1262 1262 // set roughly so that the lowest bins have about 2 cnts 1263 1263 // Nsmallest ~ N50 / (4*dN)) 1264 psF32 dN = PS_MAX (1, PS_MIN (4, stats->robustN50 / 8)); 1265 binSize = guessStdev / dN; 1264 // psF32 dN = PS_MAX (1, PS_MIN (4, stats->robustN50 / 8)); 1265 1266 // CZW 2013-11-20: We know that the histogram is going to be basically Gaussian. 1267 // Furthermore, we only use the inner +/- 2 sigma parts. Therefore, define the 1268 // binsize such that the bin at 2 sigma contains ~50 points (S/N ~ 7). robustN50 1269 // contains half the total points, so 2 * robustN50 / 50 is the fraction of all 1270 // points in the 2 sigma bin. Dance the erf() relations around, and it looks like 1271 // there's a factor of about 1/20 to include. Keep the PS_MAX to ensure we never bin 1272 // wider than 1 sigma when the number of points is small. 1273 psF32 dN = PS_MAX(1, (stats->robustN50 / 500.0)); 1274 binSize = guessStdev / dN; 1266 1275 } 1267 1276 … … 1291 1300 // We no longer want to reset the binSize here, as it can cause odd things. Better to select 1292 1301 // a number of bins, and then set the min/max values to put those bins sanely around the mean. 1293 long numBins = PS_MAX (50, PS_MIN (10000, (max - min) / binSize));1302 // long numBins = PS_MAX (50, PS_MIN (10000, (max - min) / binSize)); 1294 1303 // binSize = (max - min) / (float) numBins; 1295 1304 psTrace(TRACE, 6, "The new min/max values are (%f, %f).\n", min, max); 1296 1305 psTrace(TRACE, 6, "The new bin size is %f.\n", binSize); 1297 psTrace(TRACE, 6, "The numBins is %ld\n", numBins);1306 // psTrace(TRACE, 6, "The numBins is %ld\n", numBins); 1298 1307 1299 1308 … … 1305 1314 max = guessMean + FITTED_CLIPPING_NUM * guessStdev; 1306 1315 } 1307 1316 long numBins = PS_MAX (50, PS_MIN (10000, (max - min) / binSize)); 1317 if (CZW) { printf("I've clipped: %f %f => %f %f ; %f %ld\n",guessMean,guessStdev,min,max,binSize,stats->robustN50); } 1308 1318 psHistogram *histogram = psHistogramAlloc(min, max, numBins); // A new histogram (without outliers) 1309 1319 if (!psVectorHistogram(histogram, myVector, errors, mask, maskVal)) { … … 1357 1367 } 1358 1368 psTrace (TRACE, 6, "(%f = %.0f) ", histogram->bounds->data.F32[i], histogram->nums->data.F32[i]); 1369 if (CZW) { printf("CENTERED_HISTOGRAM: %f %f\n", 1370 PS_BIN_MIDPOINT(histogram,i), 1371 histogram->nums->data.F32[i]); } 1359 1372 } 1360 1373 psTrace (TRACE, 6, "\n"); 1361 1374 1375 if (CZW) { printf("Bin selection done: %ld %f %f %ld %f %f %ld %f %f\n", 1376 binMin,PS_BIN_MIDPOINT(histogram,binMin),histogram->nums->data.F32[binMin], 1377 binMax,PS_BIN_MIDPOINT(histogram,binMax),histogram->nums->data.F32[binMax], 1378 binPeak,PS_BIN_MIDPOINT(histogram,binPeak),histogram->nums->data.F32[binPeak]); 1379 } 1380 1362 1381 // assume a reasonably well-defined gaussian-like population; run from peak out until val < 0.25*peak 1363 1382 psTrace(TRACE, 6, "The clipped numBins is %ld\n", binMax - binMin); … … 1411 1430 psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 2); 1412 1431 bool status = psVectorFitPolynomial1D (poly, NULL, 0, y, NULL, x); 1432 #if (CZW && 1) 1433 printf("CZW: LowfitPoly: %f %f %f\n",poly->coeff[0],poly->coeff[1],poly->coeff[2]); 1434 for (long i = 0; i < x->n; i++) { 1435 printf("CZW: Lowfit: %d %ld %f %f %f\n", 1436 status,i,x->data.F32[i],y->data.F32[i], 1437 poly->coeff[0] + poly->coeff[1] * x->data.F32[i] + 1438 poly->coeff[2] * pow(x->data.F32[i],2)); 1439 } 1440 #endif 1413 1441 psFree(x); 1414 1442 psFree(y); … … 1417 1445 psErrorClear(); 1418 1446 COUNT_WARNING(10, 100, "Failed to fit a gaussian to the robust histogram.\n"); 1419 1420 1447 psFree(poly); 1421 1448 psFree(histogram); … … 1426 1453 if (poly->coeff[2] >= 0.0) { 1427 1454 COUNT_WARNING(10, 100, "Failed parabolic fit: %f + %f x + %f x^2\n", poly->coeff[0], poly->coeff[1], poly->coeff[2]); 1455 1428 1456 psFree(poly); 1429 1457 psFree(histogram); … … 1478 1506 } 1479 1507 } 1508 1480 1509 psTrace(TRACE, 6, "Lower bound for symmetric range: %f (%ld)\n", 1481 1510 PS_BIN_MIDPOINT(histogram, binS), binS); … … 1499 1528 psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 2); 1500 1529 bool status = psVectorFitPolynomial1D (poly, NULL, 0, y, NULL, x); 1501 #if (CZW && 0) 1530 #if (CZW && 1) 1531 printf("CZW: FullfitPoly: %f %f %f\n",poly->coeff[0],poly->coeff[1],poly->coeff[2]); 1502 1532 for (long i = 0; i < x->n; i++) { 1503 printf("CZW: Dcheck:%ld %f %f %f\n",1504 i,x->data.F32[i],y->data.F32[i],1533 printf("CZW: Fullfit: %d %ld %f %f %f\n", 1534 status,i,x->data.F32[i],y->data.F32[i], 1505 1535 poly->coeff[0] + poly->coeff[1] * x->data.F32[i] + 1506 1536 poly->coeff[2] * pow(x->data.F32[i],2));
Note:
See TracChangeset
for help on using the changeset viewer.
