diff options
author | justanothercatgirl <sotov@twistea.su> | 2025-04-17 12:48:23 +0300 |
---|---|---|
committer | justanothercatgirl <sotov@twistea.su> | 2025-04-17 12:48:23 +0300 |
commit | 0bd2ab4d1f9e8fdbf55ed11d61fe2e75720a334a (patch) | |
tree | 59f91bead63e9f68f74dafd73b68491286eabcf7 /libprakpp/include/prakmath.hpp | |
parent | 45f12ba19761024d335407793ffb8d4823b28149 (diff) |
finished 206, 207
Diffstat (limited to 'libprakpp/include/prakmath.hpp')
-rw-r--r-- | libprakpp/include/prakmath.hpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/libprakpp/include/prakmath.hpp b/libprakpp/include/prakmath.hpp index bb09e74..d43c11f 100644 --- a/libprakpp/include/prakmath.hpp +++ b/libprakpp/include/prakmath.hpp @@ -321,7 +321,6 @@ void least_squares_linear( << ", s.size() = " << ss.size() << std::endl; return; } - [[assume(xs.size() == ys.size() && ys.size() == ss.size())]]; size_t sz = xs.size(); prak::vector<T> ones(sz); @@ -364,6 +363,27 @@ void least_squares_linear( b.err = sqrt(d1 / D); } +template <std::floating_point T> +void least_squares_prop( + const prak::vector<T> &xs, + const prak::vector<T> &ys, + const prak::vector<T> &ss, + struct pvalue<T> &a) { + assert("Different-sized vectors passed to least squares method" && xs.size() == ys.size()); + size_t s = xs.size(); + prak::vector<T> buf(s), si(s); + vmul(ss.data(), ss.data(), si.data(), s); + + vmul(xs.data(), ys.data(), buf.data(), s); + vdiv(buf.data(), ss.data(), buf.data(), s); + T D1 = vsum(buf.data(), s); + + vmul(xs.data(), xs.data(), buf.data(), s); + vdiv(buf.data(), ss.data(), buf.data(), s); + T D2 = vsum(buf.data(), s); + a.val = D1/D2; + a.err = 1/D2; +} /// May throw std::bad_optional_access template <typename T> |