You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
also, shouldn't scale / absxi; instead be absxi/scale? Looking at the spec, section 16.9.2.7:
Constraints: For all i in the domain of v, and for f and ssq of type T, the expression ssq = ssq + (abs(x[i]) / f)*(abs(x[i]) / f) is well formed.
It says abs(x[i])/f should be well-formed, but not f/abs(x[i]).
also, if things are correct, in theory one should have that:
scaling_factor * scaling_factor * scaled_sum_of_squares = sum of squares of abs(x[i]) plus init.scaling_factor *
init.scaling_factor * init.scaled_sum_of_squares.
see dlassq. But that does not work for the impl above.
So i tried something on my end:
{
using std::abs;
using std::max;
T scale = init.scaling_factor;
for (std::size_t i = 0; i < x.extent(0); ++i) {
scale = max(scale, abs(x(i)));
}
T ssq = (init.scaling_factor*init.scaling_factor*init.scaled_sum_of_squares)/(scale*scale);
T s= {};
for (std::size_t i = 0; i < x.extent(0); ++i) {
constauto absxi = abs(x(i));
constauto quotient = absxi/scale;
ssq = ssq + quotient * quotient;
s += absxi*absxi;
}
std::experimental::linalg::sum_of_squares_result<T> result;
result.scaled_sum_of_squares = ssq;
result.scaling_factor = scale;
// verify that things are consistent according to definitionconstauto lhs = scale*scale*ssq;
constauto rhs = s+init.scaling_factor*init.scaling_factor*init.scaled_sum_of_squares;
std::cout << lhs << "" << rhs << '\n';
EXPECT_NEAR(lhs, rhs, 1e-9);
}
and this works, in the sense that it satisfies:
scaling_factor * scaling_factor * scaled_sum_of_squares = sum of squares of abs(x[i]) plus init.scaling_factor *
init.scaling_factor * init.scaled_sum_of_squares.
The text was updated successfully, but these errors were encountered:
fnrizzi
changed the title
vector_sum_of_squares: Rescaling algorithm may not be correct
P1673: vector_sum_of_squares: Rescaling algorithm may not be correct
Mar 14, 2022
@mhoemmen
I was looking at this and it seems to me this is wrong?
why does scale change along the way?
also, shouldn't
scale / absxi;
instead beabsxi/scale
? Looking at the spec, section 16.9.2.7:It says
abs(x[i])/f
should be well-formed, but notf/abs(x[i])
.also, if things are correct, in theory one should have that:
scaling_factor * scaling_factor * scaled_sum_of_squares = sum of squares of abs(x[i]) plus init.scaling_factor * init.scaling_factor * init.scaled_sum_of_squares.
see dlassq. But that does not work for the impl above.
So i tried something on my end:
and this works, in the sense that it satisfies:
The text was updated successfully, but these errors were encountered: