aboutsummaryrefslogtreecommitdiffstats
path: root/libprakpp/include/praktable.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'libprakpp/include/praktable.hpp')
-rw-r--r--libprakpp/include/praktable.hpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/libprakpp/include/praktable.hpp b/libprakpp/include/praktable.hpp
index f00e7b9..1870ec6 100644
--- a/libprakpp/include/praktable.hpp
+++ b/libprakpp/include/praktable.hpp
@@ -222,6 +222,14 @@ public:
return data.at(names.size() * row + column);
}
+ const dtype & SUBSCR_OPRTR (const std::string &column, size_t row) const noexcept(false) {
+ size_t i = index(column);
+ return data.at(names.size() * row + index(column));
+ }
+
+ const dtype & SUBSCR_OPRTR (size_t column, size_t row) const {
+ return data.at(names.size() * row + column);
+ }
// prints a table. defaults to using std::cout, but any std::ostream can be passed in it.
void print(std::ostream &stream = std::cout) const {
stream << "columns: " << columns << ", rows: " << rows << std::endl;
@@ -493,7 +501,7 @@ public:
// returns an std::pair with coefficients A and B in that order
std::pair<prak::pvalue<dtype>, prak::pvalue<dtype>>
- least_squares_linear(std::string x, std::string y, std::optional<std::string> sigma, std::optional<dtype> sigma_fixed)
+ least_squares_linear(std::string x, std::string y, std::optional<std::string> sigma, std::optional<dtype> sigma_fixed) const
noexcept(false) {
if (sigma.has_value() == sigma_fixed.has_value())
throw std::invalid_argument("sigma and sigma_fixed can't both have (no) value");
@@ -501,9 +509,9 @@ public:
prak::vector<dtype> _y(rows);
prak::vector<dtype> _s(rows);
- std::copy(begin(x), end(x), _x.begin());
- std::copy(begin(y), end(y), _y.begin());
- if (sigma.has_value()) std::copy(begin(*sigma), end(*sigma), _s.begin());
+ std::copy(cbegin(x), cend(x), _x.begin());
+ std::copy(cbegin(y), cend(y), _y.begin());
+ if (sigma.has_value()) std::copy(cbegin(*sigma), cend(*sigma), _s.begin());
else _s = prak::vector<dtype>(rows, static_cast<dtype>(*sigma_fixed));
std::pair<prak::pvalue<dtype>, prak::pvalue<dtype>> ret;
@@ -512,31 +520,31 @@ public:
}
// calculate an average of the column
- dtype col_avg(const std::string &column) {
+ dtype col_avg(const std::string &column) const {
dtype accum = dtype{};
- for (auto it = begin(column); it != end(column); ++it)
+ for (auto it = cbegin(column); it != cend(column); ++it)
accum += *it;
return accum / rows;
}
- dtype col_max(const std::string &column) {
+ dtype col_max(const std::string &column) const {
dtype max = dtype{};
- for (auto it = begin(column); it != end(column); ++it)
+ for (auto it = cbegin(column); it != cend(column); ++it)
max = max < *it ? *it : max;
return max;
}
- dtype col_min(const std::string &column) {
+ dtype col_min(const std::string &column) const {
dtype min = dtype{};
- for (auto it = begin(column); it != end(column); ++it)
+ for (auto it = cbegin(column); it != cend(column); ++it)
min = min > *it ? *it : min;
return min;
}
// calculate standard deviation of the column
- dtype col_stddev(const std::string &column) {
+ dtype col_stddev(const std::string &column) const {
dtype accum = dtype{};
dtype avg = col_avg(column);
- for (auto it = begin(column); it != end(column); ++it)
+ for (auto it = cbegin(column); it != cend(column); ++it)
accum += (*it - avg)*(*it - avg);
return std::sqrt(accum / rows);
}