Float calDiscreteErrorLinf(const arrayList &ao, const arrayList &ap) { assert(ao.size() == ap.size()); int n = ao.size(); arrayList aabs(n); for (int i = 0; i < n; i++) { aabs[i] = ABS(ap[i] - ao[i]); } return aabs.max(); }
Float calDiscreteErrorL1(const arrayList &ao, const arrayList &ap) { assert(ao.size() == ap.size()); int n = ao.size(); Float errsum = 0.0; for (int i = 0; i < n; i++) { errsum += abs(ap[i] - ao[i]); } return errsum; }
Float cal_weighted_arithmetic_mean(const arrayList &a, const arrayList &w) { assert(a.size() == w.size()); int len = a.size(); double sumup = 0.0; double sumdown = 0.0; for (int i = 0; i < len; i++) { sumup += w[i] * a[i]; sumdown += w[i]; } return sumup / sumdown; }
/** * Create an arrayBuffer from a list. * This is the reverse of arrayBuffer2list. * <b>Notice</b> it is up to the caller to free the memory allocated in the returned buffer. * * @param lst A list to convert. * @param &argLen Write the length to this argument. * @return A pointer that is managed by the caller. */ array_buffer::arrayBuffer array_buffer::list2arrayBuffer(const arrayList lst, unsigned int &argLen) { argLen = static_cast<unsigned int>(lst.size()); arrayBuffer arrayBuffer = new arrayBufferItem[argLen]; arrayList::const_iterator it = lst.begin(); int i; for (i=0;it!=lst.end();++it,i++) { std::wstring::size_type alen = (*it).size(); arrayBuffer[i] = new wchar_t[alen+2]; wcsncpy(arrayBuffer[i], (*it).c_str(), alen+1); } if (i != argLen) throw ArrayBufferException("Invalid length!"); return arrayBuffer; }