Disposable<Array> PenaltyFunction<Curve>::values(const Array& x) const { Array::const_iterator guessIt = x.begin(); Size i = initialIndex_; while (guessIt != x.end()) { Traits::updateGuess(curve_->data_, *guessIt, i); ++guessIt; ++i; } curve_->interpolation_.update(); Array penalties(localisation_); helper_iterator instIt = rateHelpersStart_; Array::iterator penIt = penalties.begin(); while (instIt != rateHelpersEnd_) { Real quoteError = (*instIt)->quoteError(); *penIt = std::fabs(quoteError); ++instIt; ++penIt; } return penalties; }
GuidedLocalSearch::Candidate GuidedLocalSearch::search(const std::vector<std::pair<float, float>>& cities, const int kIterLimit, const int kNoImproveLimit, const float kLambda) { srand(static_cast<unsigned>(time(nullptr))); std::vector<std::vector<float>> penalties(cities.size(), std::vector<float>(cities.size(), 0.0f)); GuidedLocalSearch::Candidate current, best; current.permutation = randomPermutation(cities); for (int iter = 0; iter < kIterLimit; ++iter) { localSearch(current, cities, penalties, kNoImproveLimit, kLambda); std::vector<float> utilities = calcualateFeaturesUtilities(cities, current.permutation, penalties); updatePenalties(penalties, cities, current.permutation, utilities); if (!iter || current.ordinaryCost < best.ordinaryCost) { best.permutation = current.permutation; best.ordinaryCost = current.ordinaryCost; best.augmentedCost = current.augmentedCost; } } return best; }
int calc_noise( const lame_internal_flags * const gfc, const int ix [576], const gr_info * const cod_info, const III_psy_xmin * const l3_xmin, const III_scalefac_t * const scalefac, III_psy_xmin * xfsf, calc_noise_result * const res ) { int sfb, l, i, over=0; FLOAT8 over_noise_db = 0; FLOAT8 tot_noise_db = 0; /* 0 dB relative to masking */ FLOAT8 max_noise = 1E-20; /* -200 dB relative to masking */ double klemm_noise = 1E-37; int j = 0; for (sfb = 0; sfb < cod_info->psy_lmax; sfb++) { int s = cod_info->global_gain - ((scalefac->l[sfb] + (cod_info->preflag ? pretab[sfb] : 0)) << (cod_info->scalefac_scale + 1)); FLOAT8 step; FLOAT8 noise = 0.0; if (s<0) { step = pow(2.0, (double)(s - 210) * 0.25); }else{ /* use table lookup. allegedly faster */ step = POW20(s); } l = gfc->scalefac_band.l[sfb+1] - gfc->scalefac_band.l[sfb]; do { FLOAT8 temp = fabs(cod_info->xr[j]) - pow43[ix[j]] * step; noise += temp * temp; j++; } while (--l > 0); noise = xfsf->l[sfb] = noise / l3_xmin->l[sfb]; max_noise=Max(max_noise,noise); klemm_noise += penalties (noise); noise = FAST_LOG10(Max(noise,1E-20)); /* multiplying here is adding in dB, but can overflow */ //tot_noise *= Max(noise, 1E-20); tot_noise_db += noise; if (noise > 0.0) { over++; /* multiplying here is adding in dB -but can overflow */ //over_noise *= noise; over_noise_db += noise; } } for (sfb = cod_info->sfb_smin; sfb < cod_info->psy_smax; sfb++) { int width = gfc->scalefac_band.s[sfb+1] - gfc->scalefac_band.s[sfb]; for ( i = 0; i < 3; i++ ) { int s = cod_info->global_gain - (scalefac->s[sfb][i] << (cod_info->scalefac_scale + 1)) - cod_info->subblock_gain[i] * 8; FLOAT8 step = POW20(s); FLOAT8 noise = 0.0; l = width; do { FLOAT8 temp; temp = pow43[ix[j]] * step - fabs(cod_info->xr[j]); noise += temp * temp; j++; } while (--l > 0); noise = xfsf->s[sfb][i] = noise / l3_xmin->s[sfb][i]; max_noise = Max(max_noise,noise); klemm_noise += penalties (noise); noise = FAST_LOG10(Max(noise,1E-20)); tot_noise_db += noise; if (noise > 0.0) { over++; over_noise_db += noise; } } } res->over_count = over; res->tot_noise = 10.*tot_noise_db; res->over_noise = 10.*over_noise_db; res->max_noise = 10.*FAST_LOG10(max_noise); res->klemm_noise = klemm_noise; return over; }