void Stats::Impl::computeSums(const Stats::data_type& data) { if (data.size()>0) D_ = data[0].size(); sumData_ = Stats::vector_type(D_); sumOuterProducts_ = Stats::matrix_type(D_, D_); sumData_.clear(); sumOuterProducts_.clear(); for (Stats::data_type::const_iterator it=data.begin(); it!=data.end(); ++it) { if (it->size() != D_) { ostringstream message; message << "[Stats::Impl::computeSums()] " << D_ << "-dimensional data expected: " << *it; throw runtime_error(message.str()); } sumData_ += *it; sumOuterProducts_ += outer_prod(*it, *it); } }
void processTLP(const TruncatedLorentzianParameters& tlp, int trialCount, bool verbose) { if (verbose) cout << tlp << "\n\n\n"; else cout << columnHeader_ << endl; for (double snr=2; snr<=10; snr+=.5) for (double gridOffset=-.5; gridOffset<=.5; gridOffset+=.1) /* double snr = 100; double gridOffset = 0; */ { if (verbose) { cout << fixed; cout << "signal-to-noise ratio: " << snr << endl; cout << "relative grid offset: " << gridOffset << endl; } Stats::data_type data; double crBound = 0; for (int i=0; i<trialCount; i++) { try { Stats::vector_type result = runTrial(tlp, snr, gridOffset, crBound); data.push_back(result); } catch (exception& e) { cerr << e.what() << endl; cerr << "Caught exception, continuing.\n"; } } if (verbose) { cout << endl << setw(13) << "err_f0_pred" << setw(14) << "err_f0" << setw(14) << "err_tau" << setw(14) << "err_magnitude" << setw(14) << "err_phase" << setw(14) << "model_error" << setw(14) << "z-score" << endl; for (Stats::data_type::iterator it=data.begin(); it!=data.end(); ++it) outputVector(*it); } Stats stats(data); double mean_f0 = stats.mean()(F0); double variance_f0 = stats.covariance()(F0,F0); double expectedF0Squared = stats.meanOuterProduct()(F0,F0); if (verbose) { outputStats(stats); cout << endl; cout << fixed << noshowpos; cout << "<err_f0^2>: " << expectedF0Squared << endl; cout << "Cramer-Rao bound: " << crBound << endl << endl; cout << columnHeader_ << endl; } cout << noshowpos << fixed << setprecision(3) << setw(7) << snr << " " << setw(7) << gridOffset << " " << setprecision(10) << setw(14) << mean_f0 << " " << setw(14) << variance_f0 << " " << setw(14) << sqrt(variance_f0) << " " << setw(14) << expectedF0Squared << " " << setw(14) << crBound << endl; if (verbose) cout << "\n\n"; } }