aboutsummaryrefslogtreecommitdiffstats
path: root/libprakpp/include/prakmath.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'libprakpp/include/prakmath.hpp')
-rw-r--r--libprakpp/include/prakmath.hpp22
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>