/* * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
float AdaptiveWeightedAverage::compute_adaptive_average(float new_sample, float average) { // We smooth the samples by not using weight() directly until we've // had enough data to make it meaningful. We'd like the first weight // used to be 1, the second to be 1/2, etc until we have // OLD_THRESHOLD/weight samples. unsigned count_weight = 0;
// Avoid division by zero if the counter wraps (7158457) if (!is_old()) {
count_weight = OLD_THRESHOLD/count();
}
void AdaptivePaddedAverage::sample(float new_sample) { // Compute new adaptive weighted average based on new sample.
AdaptiveWeightedAverage::sample(new_sample);
// Now update the deviation and the padded average. float new_avg = average(); float new_dev = compute_adaptive_average(fabsd(new_sample - new_avg),
deviation());
set_deviation(new_dev);
set_padded_average(new_avg + padding() * new_dev);
_last_sample = new_sample;
}
float new_avg = average(); if (new_sample != 0) { // We only create a new deviation if the sample is non-zero float new_dev = compute_adaptive_average(fabsd(new_sample - new_avg),
deviation());
// The _mean_y and _mean_x are decaying averages and can // be used to discount earlier data. If they are used, // first consider whether all the quantities should be // kept as decaying averages. // _intercept = _mean_y.average() - _slope * _mean_x.average();
_intercept = (_sum_y - _slope * _sum_x) / ((double) _mean_x.count());
}
}
}
// Both decrement_will_decrease() and increment_will_decrease() return // true for a slope of 0. That is because a change is necessary before // a slope can be calculated and a 0 slope will, in general, indicate // that no calculation of the slope has yet been done. Returning true // for a slope equal to 0 reflects the intuitive expectation of the // dependence on the slope. Don't use the complement of these functions // since that intuitive expectation is not built into the complement. bool LinearLeastSquareFit::decrement_will_decrease() { return (_slope >= 0.00);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.