Ignore:
Timestamp:
Aug 20, 2014, 1:07:11 PM (11 years ago)
Author:
Frederik Heber <heber@…>
Children:
907198
Parents:
39616b
git-author:
Frederik Heber <heber@…> (07/21/14 08:20:10)
git-committer:
Frederik Heber <heber@…> (08/20/14 13:07:11)
Message:

tempcommit: Modified calculateErrorOfMatching() to measure error as deviation from mean rotation angle.

  • distances between points for a equidistantly distributed set of points on a sphere does not sound too sensible. We now calculate the average rotation angle between the two given sets of points and give the L1/L2 error as maximum and squared average difference to this mean.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Exporters/SphericalPointDistribution.cpp

    r39616b r7e45c4  
    471471  std::pair<double, double> errors( std::make_pair( 0., 0. ) );
    472472
    473   if (_Matching.size() > 1) {
    474     LOG(5, "INFO: Matching is " << _Matching);
    475 
    476     // calculate all pair-wise distances
    477     IndexTupleList_t keys(_old.size(), IndexList_t() );
    478     std::generate (keys.begin(), keys.end(), UniqueNumberList);
    479 
    480     const DistanceArray_t firstdistances = calculatePairwiseDistances(_old, keys);
    481     const DistanceArray_t seconddistances = calculatePairwiseDistances(_new, _Matching);
    482 
    483     ASSERT( firstdistances.size() == seconddistances.size(),
    484         "calculateL2ErrorOfMatching() - mismatch in pair-wise distance array sizes.");
    485     DistanceArray_t::const_iterator firstiter = firstdistances.begin();
    486     DistanceArray_t::const_iterator seconditer = seconddistances.begin();
    487     for (;(firstiter != firstdistances.end()) && (seconditer != seconddistances.end());
    488         ++firstiter, ++seconditer) {
    489       const double gap = fabs(*firstiter - *seconditer);
    490       // L1 error
    491       if (errors.first < gap)
    492         errors.first = gap;
    493       // L2 error
    494       errors.second += gap*gap;
    495     }
    496     // there is at least one distance, we've checked that before
    497     errors.second *= 1./(double)firstdistances.size();
    498   } else {
    499     // check whether we have any zero centers: Combining points on new sphere may result
    500     // in zero centers
    501     for (SphericalPointDistribution::IndexTupleList_t::const_iterator iter = _Matching.begin();
    502         iter != _Matching.end(); ++iter) {
    503       if ((iter->size() != 1) && (calculateCenter( _new, *iter).IsZero())) {
    504         errors.first = 2.;
    505         errors.second = 2.;
    506       }
    507     }
    508   }
     473  // the error is the deviation from the mean angle
     474  std::vector<double> distances;
     475  double mean = 0.;
     476  for (IndexTupleList_t::const_iterator matchingiter = _Matching.begin();
     477      matchingiter != _Matching.end(); ++matchingiter) {
     478    // calculate distance on surface as rotation angle
     479    const Vector newcenter = calculateCenter(_new, *matchingiter);
     480    const Vector &oldcenter = _old[std::distance(_Matching.begin(), matchingiter)];
     481    Vector axis = newcenter;
     482    axis.VectorProduct(oldcenter);
     483    axis.Normalize();
     484    const double distance = newcenter.Angle(oldcenter);
     485    distances.push_back(distance);
     486    mean += distance;
     487  }
     488  if (!_Matching.empty())
     489    mean *= 1./(double)_Matching.size();
     490  LOG(5, "DEBUG: Mean distance is " << mean << " for " << _Matching.size() << " points.");
     491
     492  // analyse errors
     493  for (std::vector<double>::const_iterator iter = distances.begin();
     494      iter != distances.end(); ++iter) {
     495    const double difference = fabs(*iter - mean);
     496    if (errors.first < difference) {
     497      errors.first = difference;
     498    }
     499    errors.second += difference*difference;
     500
     501  }
     502  errors.second = sqrt(errors.second);
     503
     504//  if (!_Matching.empty()) {
     505//    // there is at least one distance, we've checked that before
     506//    errors.second *= 1./(double)_Matching.size();
     507//  }
     508
     509//  if (_Matching.size() > 1) {
     510//    LOG(5, "INFO: Matching is " << _Matching);
     511//
     512//    // calculate all pair-wise distances
     513//    IndexTupleList_t keys(_old.size(), IndexList_t() );
     514//    std::generate (keys.begin(), keys.end(), UniqueNumberList);
     515//
     516//    const DistanceArray_t firstdistances = calculatePairwiseDistances(_old, keys);
     517//    const DistanceArray_t seconddistances = calculatePairwiseDistances(_new, _Matching);
     518//
     519//    ASSERT( firstdistances.size() == seconddistances.size(),
     520//        "calculateL2ErrorOfMatching() - mismatch in pair-wise distance array sizes.");
     521//    DistanceArray_t::const_iterator firstiter = firstdistances.begin();
     522//    DistanceArray_t::const_iterator seconditer = seconddistances.begin();
     523//    for (;(firstiter != firstdistances.end()) && (seconditer != seconddistances.end());
     524//        ++firstiter, ++seconditer) {
     525//      const double gap = fabs(*firstiter - *seconditer);
     526//      // L1 error
     527//      if (errors.first < gap)
     528//        errors.first = gap;
     529//      // L2 error
     530//      errors.second += gap*gap;
     531//    }
     532//    // there is at least one distance, we've checked that before
     533//    errors.second *= 1./(double)firstdistances.size();
     534//  } else {
     535//    // check whether we have any zero centers: Combining points on new sphere may result
     536//    // in zero centers
     537//    for (SphericalPointDistribution::IndexTupleList_t::const_iterator iter = _Matching.begin();
     538//        iter != _Matching.end(); ++iter) {
     539//      if ((iter->size() != 1) && (calculateCenter( _new, *iter).IsZero())) {
     540//        errors.first = 2.;
     541//        errors.second = 2.;
     542//      }
     543//    }
     544//  }
    509545  LOG(4, "INFO: Resulting errors for matching (L1, L2): "
    510546      << errors.first << "," << errors.second << ".");
Note: See TracChangeset for help on using the changeset viewer.