Fortran 和电子表格算出来都是 0.0300。Matlab 给出的数更大,而且会随权重变化。全是 1 的时候没问题。cfg.weights 看起来也对。为什么?
% config.m
cfg.weights = [1 1 2 2 4 4];
% run_calibration.m
data = load_readings(cfg.data_file);
pred = model_predict(data.t, cfg);
score = weighted_rms(data.v, pred, cfg.weights);
% weighted_rms.m
function s = weighted_rms(obs, pred, w)
res = (obs - pred) .* w;
wss = sum(res.^2);
% mean() in case we pass several channels later
s = sqrt(mean(wss) / sum(w));
end
obs 和 pred 分别检查过,都和参考值一致。没有报错,也没有警告。在 Fortran 里这就是一个循环。
从英语翻译·查看原文Fortran and spreadsheet give 0.0300. Matlab gives bigger number and it changes with weights. All ones is fine. cfg.weights looks right. Why?
% config.m
cfg.weights = [1 1 2 2 4 4];
% run_calibration.m
data = load_readings(cfg.data_file);
pred = model_predict(data.t, cfg);
score = weighted_rms(data.v, pred, cfg.weights);
% weighted_rms.m
function s = weighted_rms(obs, pred, w)
res = (obs - pred) .* w;
wss = sum(res.^2);
% mean() in case we pass several channels later
s = sqrt(mean(wss) / sum(w));
end
obs and pred checked separately, both match reference. No error, no warning. In Fortran this is one loop.