18#include <errhandlingapi.h>
19#include <libloaderapi.h>
21#include <processthreadsapi.h>
34#include <initializer_list>
40#include <system_error>
44#if defined(__linux__) && !defined(__ANDROID__)
49#include <TargetConditionals.h>
64extern "C" char **environ;
68#include "fastlowess.h"
97inline bool hasOutput(
const std::vector<std::string> &outputs,
99 return std::find(outputs.begin(), outputs.end(), name) != outputs.end();
108 : std::runtime_error(message) {}
112 std::initializer_list<const char *> supported,
113 const char *adapter) {
114 for (
const auto &output : outputs) {
115 const auto *
const found =
116 std::find_if(supported.begin(), supported.end(),
117 [&output](
const char *name) { return output == name; });
118 if (found == supported.end()) {
119 throw LowessError(
"Unknown output '" + output +
"' for " + adapter);
125 if (
const char *message = fastlowess_last_error_message()) {
138 explicit Expected(T val) : val_(std::move(val)), has_val_(true) {}
148 explicit operator bool()
const {
return has_val_; }
168 return std::move(val_);
173 throw LowessError(
"Bad expected access: has value");
179 Expected(std::string err, ErrorTag error_tag)
180 : err_(std::move(err)), has_val_(false) {
181 static_cast<void>(error_tag);
288 if (has_value == 1) {
316 double y()
const {
return y_; }
353 explicit OnlineOutput(
const fastlowess_CppOnlineOutput &raw)
364 double y_ = std::numeric_limits<double>::quiet_NaN();
365 double standard_error_ = std::numeric_limits<double>::quiet_NaN();
366 double residual_ = std::numeric_limits<double>::quiet_NaN();
367 double robustness_weight_ = std::numeric_limits<double>::quiet_NaN();
368 int iterations_used_ = -1;
369 double derivative_ = std::numeric_limits<double>::quiet_NaN();
370 double confidence_lower_ = std::numeric_limits<double>::quiet_NaN();
371 double confidence_upper_ = std::numeric_limits<double>::quiet_NaN();
372 double prediction_lower_ = std::numeric_limits<double>::quiet_NaN();
373 double prediction_upper_ = std::numeric_limits<double>::quiet_NaN();
385 aic_(std::isnan(result.
aic) ? std::nullopt
386 : std::optional<double>(result.
aic)),
387 aicc_(std::isnan(result.
aicc) ? std::nullopt
388 : std::optional<double>(result.
aicc)),
396 double rmse()
const {
return rmse_; }
397 double mae()
const {
return mae_; }
403 std::optional<double>
aic()
const {
return aic_; }
405 std::optional<double>
aicc()
const {
return aicc_; }
412 double r_squared_ = NAN;
413 std::optional<double> aic_;
414 std::optional<double> aicc_;
415 std::optional<double> effective_df_;
416 double residual_sd_ = NAN;
450 : result_(c_result) {}
459 other.result_ = fastlowess_CppPredictResult{};
463 if (
this != &other) {
464 fastlowess_predict_free_result(&result_);
465 result_ = other.result_;
466 other.result_ = fastlowess_CppPredictResult{};
472 size_t size()
const {
return static_cast<size_t>(result_.n); }
475 bool valid()
const {
return result_.n > 0 && result_.error ==
nullptr; }
479 return result_.error !=
nullptr ? std::string(result_.error) :
"";
483 std::vector<double>
y()
const {
484 if (result_.n == 0 || result_.y ==
nullptr) {
487 return std::vector<double>(result_.y, result_.y + result_.n);
492 if (result_.standard_errors !=
nullptr) {
493 return std::vector<double>(result_.standard_errors,
494 result_.standard_errors + result_.n);
501 if (result_.confidence_lower !=
nullptr) {
502 return std::vector<double>(result_.confidence_lower,
503 result_.confidence_lower + result_.n);
510 if (result_.confidence_upper !=
nullptr) {
511 return std::vector<double>(result_.confidence_upper,
512 result_.confidence_upper + result_.n);
519 if (result_.prediction_lower !=
nullptr) {
520 return std::vector<double>(result_.prediction_lower,
521 result_.prediction_lower + result_.n);
528 if (result_.prediction_upper !=
nullptr) {
529 return std::vector<double>(result_.prediction_upper,
530 result_.prediction_upper + result_.n);
538 if (result_.derivative !=
nullptr) {
539 return std::vector<double>(result_.derivative,
540 result_.derivative + result_.n);
546 fastlowess_CppPredictResult result_ = {};
559 explicit PredictModel(fastlowess_CppPredictHandle *handle) : ptr_(handle) {}
562 if (ptr_ !=
nullptr) {
563 fastlowess_predict_handle_free(ptr_);
573 other.ptr_ =
nullptr;
577 if (
this != &other) {
578 if (ptr_ !=
nullptr) {
579 fastlowess_predict_handle_free(ptr_);
582 other.ptr_ =
nullptr;
588 bool valid()
const {
return ptr_ !=
nullptr; }
595 const auto result = fastlowess_predict(
596 ptr_, new_x.data(),
static_cast<size_t>(new_x.size()),
597 hasOutput(options.outputs,
"se") ? 1 : 0, options.intervals.confidence,
598 options.intervals.prediction,
599 hasOutput(options.outputs,
"derivative") ? 1 : 0,
600 options.extrapolation.c_str(), options.max_extrapolation_distance,
601 options.max_neighbor_distance, options.intervals.bootstrap,
602 options.seed.value_or(0), options.seed.has_value() ? 1 : 0);
607 fastlowess_CppPredictHandle *ptr_ =
nullptr;
620 : result_(c_result) {}
629 other.result_ = empty_result();
633 if (
this != &other) {
635 result_ = other.result_;
636 other.result_ = empty_result();
642 size_t size()
const {
return static_cast<size_t>(result_.n); }
645 bool valid()
const {
return result_.n > 0 && result_.error ==
nullptr; }
649 return result_.error !=
nullptr ? std::string(result_.error) :
"";
654 if (result_.x ==
nullptr || index >=
size()) {
655 throw std::out_of_range(
"LOWESS x index out of range");
657 return result_.x[index];
662 if (result_.y ==
nullptr || index >=
size()) {
663 throw std::out_of_range(
"LOWESS y index out of range");
665 return result_.y[index];
670 if (result_.n == 0 || result_.x ==
nullptr) {
673 return std::vector<double>(result_.x, result_.x + result_.n);
678 if (result_.n == 0 || result_.y ==
nullptr) {
681 return std::vector<double>(result_.y, result_.y + result_.n);
686 if (result_.residuals !=
nullptr) {
687 return std::vector<double>(result_.residuals,
688 result_.residuals + result_.n);
695 if (result_.standard_errors !=
nullptr) {
696 return std::vector<double>(result_.standard_errors,
697 result_.standard_errors + result_.n);
704 if (result_.confidence_lower !=
nullptr) {
705 return std::vector<double>(result_.confidence_lower,
706 result_.confidence_lower + result_.n);
713 if (result_.confidence_upper !=
nullptr) {
714 return std::vector<double>(result_.confidence_upper,
715 result_.confidence_upper + result_.n);
722 if (result_.prediction_lower !=
nullptr) {
723 return std::vector<double>(result_.prediction_lower,
724 result_.prediction_lower + result_.n);
731 if (result_.prediction_upper !=
nullptr) {
732 return std::vector<double>(result_.prediction_upper,
733 result_.prediction_upper + result_.n);
740 if (result_.robustness_weights !=
nullptr) {
741 return std::vector<double>(result_.robustness_weights,
742 result_.robustness_weights + result_.n);
749 if (result_.derivative !=
nullptr) {
750 return std::vector<double>(result_.derivative,
751 result_.derivative + result_.n);
758 if (result_.cv_scores !=
nullptr) {
759 return std::vector<double>(result_.cv_scores,
760 result_.cv_scores + result_.cv_scores_len);
779 return PredictModel(fastlowess_lowess_take_predict_handle(&result_));
783 static fastlowess_CppLowessResult empty_result() {
784 fastlowess_CppLowessResult result{};
785 result.iterations_used = -1;
788 result.r_squared = NAN;
791 result.effective_df = NAN;
792 result.residual_sd = NAN;
796 void release() noexcept { fastlowess_lowess_free_result(&result_); }
798 fastlowess_CppLowessResult result_ = {};
809 {
"diagnostics",
"residuals",
"weights",
"derivative",
"se",
"sorted"},
811 custom_weights_ = options.custom_weights;
812 ptr_ = fastlowess_lowess_new(
813 options.fraction, options.iterations, options.delta,
814 options.weight_function.c_str(), options.robustness_method.c_str(),
815 options.scaling_method.c_str(), options.boundary_policy.c_str(),
816 options.intervals.confidence, options.intervals.prediction,
817 hasOutput(options.outputs,
"diagnostics") ? 1 : 0,
818 hasOutput(options.outputs,
"residuals") ? 1 : 0,
819 hasOutput(options.outputs,
"weights") ? 1 : 0,
820 hasOutput(options.outputs,
"derivative") ? 1 : 0,
821 options.zero_weight_fallback.c_str(), options.auto_converge,
822 options.cv.fractions.empty() ? nullptr : options.cv.fractions.data(),
823 static_cast<size_t>(options.cv.fractions.size()),
824 options.cv.method.c_str(), options.cv.k, options.parallel ? 1 : 0,
825 hasOutput(options.outputs,
"se") ? 1 : 0,
826 hasOutput(options.outputs,
"sorted") ? 1 : 0, options.backend.c_str(),
827 options.missing.c_str(), options.retain_model ? 1 : 0);
828 if (ptr_ ==
nullptr) {
831 if (options.seed.has_value()) {
832 fastlowess_lowess_set_seed(ptr_, *options.seed);
834 if (options.intervals.bootstrap > 0) {
835 fastlowess_lowess_set_bootstrap(ptr_, options.intervals.bootstrap);
840 if (ptr_ !=
nullptr) {
841 fastlowess_lowess_free(ptr_);
850 Lowess(
Lowess &&other) noexcept : ptr_(other.ptr_) { other.ptr_ =
nullptr; }
853 if (
this != &other) {
854 if (ptr_ !=
nullptr) {
855 fastlowess_lowess_free(ptr_);
858 other.ptr_ =
nullptr;
866 const std::vector<double> &y_values,
867 const std::vector<double> &custom_weights = {}) {
869 if (x_values.size() != y_values.size()) {
871 "x and y must have the same length");
873 if (x_values.empty()) {
875 "Input arrays must not be empty");
877 const std::vector<double> &weights =
878 custom_weights.empty() ? custom_weights_ : custom_weights;
879 if (!weights.empty() && weights.size() != y_values.size()) {
881 "custom_weights length must match y length");
885 fastlowess_lowess_fit(ptr_, x_values.data(), y_values.data(),
886 static_cast<size_t>(x_values.size()),
887 weights.empty() ?
nullptr : weights.data(),
888 static_cast<size_t>(weights.size()));
890 if (result.error !=
nullptr) {
891 const std::string error_msg(result.error);
892 fastlowess_lowess_free_result(&result);
896 return Expected<LowessResult>(LowessResult(result));
900 fastlowess_CppLowess *ptr_ =
nullptr;
901 std::vector<double> custom_weights_;
913 options.weight_function.c_str(),
options.robustness_method.c_str(),
925 if (ptr_ ==
nullptr) {
931 if (ptr_ !=
nullptr) {
939 other.ptr_ =
nullptr;
942 if (
this != &
other) {
943 if (ptr_ !=
nullptr) {
947 other.ptr_ =
nullptr;
953 const std::vector<double> &
y_values) {
954 if (expect_finalized_) {
963 static_cast<size_t>(
x_values.size()));
974 if (expect_finalized_) {
977 expect_finalized_ =
true;
991 {
"diagnostics",
"residuals",
"weights",
"derivative",
"se"},
994 !
options.custom_weights.empty() ||
997 "StreamingLowess does not support Batch-only options: cv, backend, "
998 "custom_weights, outputs containing 'sorted', or retain_model");
1002 fastlowess_CppStreamingLowess *ptr_ =
nullptr;
1003 bool expect_finalized_ =
false;
1016 options.weight_function.c_str(),
options.robustness_method.c_str(),
1026 if (ptr_ ==
nullptr) {
1032 if (ptr_ !=
nullptr) {
1040 other.ptr_ =
nullptr;
1043 if (
this != &
other) {
1044 if (ptr_ !=
nullptr) {
1048 other.ptr_ =
nullptr;
1078inline std::optional<std::string> platformTag() {
1081#elif defined(__APPLE__) && TARGET_OS_OSX
1083#elif defined(__ANDROID__)
1084 return std::nullopt;
1085#elif defined(__linux__) && defined(__GLIBC__)
1088 return std::nullopt;
1092inline std::optional<std::string> archTag() {
1093#if defined(__aarch64__) || defined(_M_ARM64)
1095#elif defined(__x86_64__) || defined(_M_X64)
1098 return std::nullopt;
1102inline std::string libraryExt() {
1105#elif defined(__APPLE__)
1112inline bool stdinIsInteractive() {
1120inline std::string cacheDir() {
1128 const char *
home = std::getenv(
"HOME");
1129 const std::string
base = (
home !=
nullptr) ?
home :
".";
1131 return base +
"/.fastlowess/gpu";
1134inline bool makeDir(
const std::string &
dir) {
1135 std::error_code error;
1136 std::filesystem::create_directories(
dir, error);
1137 return !error && std::filesystem::is_directory(
dir, error) && !error;
1140inline bool fileExists(
const std::string &
path) {
1145inline bool copyFile(
const std::string &
src,
const std::string &
dst) {
1146 std::error_code error;
1147 return std::filesystem::copy_file(
1148 src,
dst, std::filesystem::copy_options::overwrite_existing, error);
1151inline bool gpuLibraryEnabled(
const std::string &
path) {
1182inline std::string stagingPath(
const std::string &
destination) {
1183 static std::atomic<unsigned long long>
sequence{0};
1190 std::to_string(
sequence.fetch_add(1, std::memory_order_relaxed));
1193inline void removeFile(
const std::string &
path) {
1194 std::error_code error;
1195 std::filesystem::remove(
path, error);
1198inline bool promoteFile(
const std::string &
staging,
1204 std::error_code error;
1210inline bool installLocalGpuFile(
const std::filesystem::path &
source,
1228inline bool runProcess(
const std::vector<std::string> &
arguments) {
1234 std::vector<const char *>
argv;
1239 argv.push_back(
nullptr);
1242 std::vector<char *>
argv;
1247 argv.push_back(
nullptr);
1292inline bool install(
bool yes =
false,
const std::string &
local_path =
"") {
1294 std::cout <<
"GPU backend is already active.\n";
1298 const std::string dir = detail::cacheDir();
1299 if (!detail::makeDir(dir)) {
1300 std::cerr <<
"Failed to create GPU cache directory: " << dir <<
"\n";
1304 if (!local_path.empty()) {
1305 if (!detail::fileExists(local_path)) {
1306 std::cerr <<
"No such file: " << local_path <<
"\n";
1309 if (!detail::gpuLibraryEnabled(local_path)) {
1310 std::cerr <<
"The library at " << local_path
1311 <<
" does not report GPU support.\n";
1315 if (!detail::stdinIsInteractive()) {
1316 std::cerr <<
"install_gpu() requires confirmation; pass yes=true to "
1317 "proceed non-interactively."
1321 std::cout <<
"Install " << local_path
1322 <<
" in place of the current build? [y/N] ";
1324 std::getline(std::cin, answer);
1325 if (answer !=
"y" && answer !=
"Y" && answer !=
"yes") {
1326 std::cout <<
"Aborted.\n";
1331 const std::string dest = (std::filesystem::path(dir) /
1332 std::filesystem::path(local_path).filename())
1334 std::cout <<
"Installing " << local_path <<
" ...\n";
1335 if (!detail::installLocalGpuFile(local_path, dest)) {
1336 std::cerr <<
"Failed to validate/install " << local_path <<
" to " << dest
1340 std::cout <<
"Installed to " << dest <<
"\n";
1341 std::cout <<
"Relink your application against this library (or "
1342 "dlopen/LoadLibrary it) and restart to use the GPU backend."
1347 const auto platform = detail::platformTag();
1348 const auto architecture = detail::archTag();
1349 if (!platform || !architecture) {
1350 std::cerr <<
"No prebuilt GPU library is available for this platform and "
1356 const std::string version = fastlowess_version();
1357 const std::string asset =
"libfastlowess_cpp-gpu-v" + version +
"-" +
1358 *platform +
"-" + *architecture +
"." +
1359 detail::libraryExt();
1363 const std::string url =
1364 "https://github.com/thisisamirv/lowess-project/releases/download/"
1369 if (!detail::stdinIsInteractive()) {
1370 std::cerr <<
"install_gpu() requires confirmation; pass yes=true to "
1371 "proceed non-interactively."
1375 std::cout <<
"Download and install " << asset
1376 <<
" from github.com/thisisamirv/lowess-project? [y/N] ";
1378 std::getline(std::cin, answer);
1379 if (answer !=
"y" && answer !=
"Y" && answer !=
"yes") {
1380 std::cout <<
"Aborted.\n";
1385 const std::string dest = (std::filesystem::path(dir) / asset).
string();
1386 const std::string staging = detail::stagingPath(dest);
1388 std::cout <<
"Downloading " << url <<
" ...\n";
1389 if (!detail::runProcess(
1390 {
"curl",
"-fL",
"--progress-bar",
"-o", staging, url})) {
1391 detail::removeFile(staging);
1392 std::cerr <<
"Download failed. A matching GPU build may not exist for "
1393 "this platform/version yet, or `curl` is not installed."
1397 if (!detail::gpuLibraryEnabled(staging)) {
1398 detail::removeFile(staging);
1399 std::cerr <<
"Downloaded library does not report GPU support.\n";
1402 if (!detail::promoteFile(staging, dest)) {
1403 detail::removeFile(staging);
1404 std::cerr <<
"Failed to install downloaded library to " << dest <<
"\n";
1408 std::cout <<
"Downloaded to " << dest <<
"\n";
1409 std::cout <<
"Relink your application against this library (or "
1410 "dlopen/LoadLibrary it) and restart to use the GPU backend."
Diagnostics from LOWESS fitting.
Definition fastlowess.hpp:379
std::optional< double > aic() const
Akaike Information Criterion, if computed.
Definition fastlowess.hpp:403
std::optional< double > aicc() const
Corrected AIC, if computed.
Definition fastlowess.hpp:405
bool has_value() const
Definition fastlowess.hpp:394
Diagnostics(const fastlowess_CppLowessResult &result)
Definition fastlowess.hpp:383
double rmse() const
Definition fastlowess.hpp:396
double mae() const
Definition fastlowess.hpp:397
double r_squared() const
Definition fastlowess.hpp:398
double residual_sd() const
Batch: robust residual scale estimate (1.4826 * MAD); Streaming: cumulative sample SD of emitted resi...
Definition fastlowess.hpp:401
std::optional< double > effective_df() const
Effective degrees of freedom, if computed.
Definition fastlowess.hpp:407
A result type that holds either a value or an error.
Definition fastlowess.hpp:135
static Expected make_error(std::string msg)
Definition fastlowess.hpp:142
const std::string & error() const
Definition fastlowess.hpp:171
bool has_value() const
Definition fastlowess.hpp:146
T && value() &&
Definition fastlowess.hpp:164
Expected(T val)
Definition fastlowess.hpp:138
const T & value() const &
Definition fastlowess.hpp:157
T & value() &
Definition fastlowess.hpp:150
Exception thrown when LOWESS operation fails.
Definition fastlowess.hpp:105
LowessError(const std::string &message)
Definition fastlowess.hpp:107
Result of LOWESS smoothing operation.
Definition fastlowess.hpp:615
LowessResult & operator=(const LowessResult &)=delete
LowessResult(LowessResult &&other) noexcept
Definition fastlowess.hpp:628
std::vector< double > confidence_lower() const
Get confidence interval lower bounds.
Definition fastlowess.hpp:703
bool valid() const
Check if result is valid.
Definition fastlowess.hpp:645
std::vector< double > residuals() const
Get residuals (empty if not computed)
Definition fastlowess.hpp:685
double y_value(size_t index) const
Access smoothed y value at index.
Definition fastlowess.hpp:661
double x_value(size_t index) const
Access x value at index.
Definition fastlowess.hpp:653
std::vector< double > cv_scores() const
Get cross-validation scores (empty if not computed)
Definition fastlowess.hpp:757
std::vector< double > confidence_upper() const
Get confidence interval upper bounds.
Definition fastlowess.hpp:712
std::vector< double > prediction_lower() const
Get prediction interval lower bounds.
Definition fastlowess.hpp:721
std::vector< double > standard_errors() const
Get standard errors (empty if not computed)
Definition fastlowess.hpp:694
std::vector< double > y_vector() const
Get smoothed y values as vector.
Definition fastlowess.hpp:677
double fraction_used() const
Fraction used for smoothing.
Definition fastlowess.hpp:766
int iterations_used() const
Number of iterations performed (-1 if not available)
Definition fastlowess.hpp:769
Diagnostics diagnostics() const
Get diagnostics.
Definition fastlowess.hpp:772
LowessResult(const LowessResult &)=delete
std::string error() const
Get error message (empty if no error)
Definition fastlowess.hpp:648
size_t size() const
Number of data points.
Definition fastlowess.hpp:642
std::vector< double > derivative() const
Get the per-point local fit derivative (slope) (empty if not computed)
Definition fastlowess.hpp:748
std::vector< double > prediction_upper() const
Get prediction interval upper bounds.
Definition fastlowess.hpp:730
std::vector< double > robustness_weights() const
Get robustness weights (empty if not computed)
Definition fastlowess.hpp:739
LowessResult(const fastlowess_CppLowessResult &c_result)
Definition fastlowess.hpp:619
std::vector< double > x_vector() const
Get x values as vector.
Definition fastlowess.hpp:669
LowessResult()
Definition fastlowess.hpp:617
LowessResult & operator=(LowessResult &&other) noexcept
Definition fastlowess.hpp:632
~LowessResult()
Definition fastlowess.hpp:622
PredictModel predict_model()
Extract the retained predict model (only available when LowessOptions::retain_model was set to true b...
Definition fastlowess.hpp:778
Batch LOWESS model.
Definition fastlowess.hpp:804
Lowess & operator=(Lowess &&other) noexcept
Definition fastlowess.hpp:852
Expected< LowessResult > fit(const std::vector< double > &x_values, const std::vector< double > &y_values, const std::vector< double > &custom_weights={})
Definition fastlowess.hpp:865
Lowess(const Lowess &)=delete
~Lowess()
Definition fastlowess.hpp:839
Lowess & operator=(const Lowess &)=delete
Lowess(const LowessOptions &options={})
Definition fastlowess.hpp:806
Lowess(Lowess &&other) noexcept
Definition fastlowess.hpp:850
Online LOWESS model.
Definition fastlowess.hpp:1009
OnlineLowess(const OnlineOptions &options={})
Definition fastlowess.hpp:1011
OnlineLowess(const OnlineLowess &)=delete
Expected< OnlineOutput > add_point(double x, double y)
Add a single point and return the smoothed value.
Definition fastlowess.hpp:1060
OnlineLowess(OnlineLowess &&other) noexcept
Definition fastlowess.hpp:1039
~OnlineLowess()
Definition fastlowess.hpp:1031
OnlineLowess & operator=(const OnlineLowess &)=delete
OnlineLowess & operator=(OnlineLowess &&other) noexcept
Definition fastlowess.hpp:1042
Result of a single online update step.
Definition fastlowess.hpp:304
OnlinePointStatus status() const
Detailed outcome of the latest add_point call.
Definition fastlowess.hpp:313
double confidence_upper() const
Upper confidence interval bound for the latest point (NaN if not computed).
Definition fastlowess.hpp:339
bool dropped() const
True when missing = "drop" ignored a non-finite point.
Definition fastlowess.hpp:310
double derivative() const
Local fit derivative (slope) for the latest point (NaN if not computed).
Definition fastlowess.hpp:331
double standard_error() const
Standard error (NaN if not computed).
Definition fastlowess.hpp:319
double prediction_upper() const
Upper prediction interval bound for the latest point (NaN if not computed).
Definition fastlowess.hpp:347
double confidence_lower() const
Lower confidence interval bound for the latest point (NaN if not computed).
Definition fastlowess.hpp:335
double prediction_lower() const
Lower prediction interval bound for the latest point (NaN if not computed).
Definition fastlowess.hpp:343
double robustness_weight() const
Robustness weight for the latest point (NaN if not computed).
Definition fastlowess.hpp:325
double y() const
Smoothed value for the latest point (valid only when has_value() == true).
Definition fastlowess.hpp:316
int iterations_used() const
Number of robustness iterations performed (−1 if not applicable).
Definition fastlowess.hpp:328
double residual() const
Residual y − smoothed (NaN if not computed).
Definition fastlowess.hpp:322
bool has_value() const
True when the window has enough points to produce a smoothed estimate.
Definition fastlowess.hpp:307
Retained fitted-model state enabling out-of-sample predict().
Definition fastlowess.hpp:555
PredictModel(const PredictModel &)=delete
PredictModel & operator=(const PredictModel &)=delete
PredictModel(fastlowess_CppPredictHandle *handle)
Definition fastlowess.hpp:559
PredictResult predict(const std::vector< double > &new_x, const PredictOptions &options={}) const
Evaluate the fitted model at out-of-sample query points not in the training set.
Definition fastlowess.hpp:592
PredictModel & operator=(PredictModel &&other) noexcept
Definition fastlowess.hpp:576
bool valid() const
True if this model was actually retained (retain_model was set).
Definition fastlowess.hpp:588
PredictModel(PredictModel &&other) noexcept
Definition fastlowess.hpp:572
~PredictModel()
Definition fastlowess.hpp:561
Result of PredictModel::predict().
Definition fastlowess.hpp:445
std::vector< double > y() const
Predicted y values, one per query point.
Definition fastlowess.hpp:483
std::vector< double > prediction_lower() const
Lower prediction interval bounds (empty if not requested)
Definition fastlowess.hpp:518
std::vector< double > standard_errors() const
Standard errors (empty if not requested)
Definition fastlowess.hpp:491
std::vector< double > confidence_lower() const
Lower confidence interval bounds (empty if not requested)
Definition fastlowess.hpp:500
PredictResult(const fastlowess_CppPredictResult &c_result)
Definition fastlowess.hpp:449
PredictResult(const PredictResult &)=delete
PredictResult & operator=(PredictResult &&other) noexcept
Definition fastlowess.hpp:462
bool valid() const
Check if result is valid.
Definition fastlowess.hpp:475
std::string error() const
Get error message (empty if no error)
Definition fastlowess.hpp:478
~PredictResult()
Definition fastlowess.hpp:452
std::vector< double > confidence_upper() const
Upper confidence interval bounds (empty if not requested)
Definition fastlowess.hpp:509
std::vector< double > derivative() const
Local fit's derivative (slope) at each query point (empty if not requested)
Definition fastlowess.hpp:537
PredictResult(PredictResult &&other) noexcept
Definition fastlowess.hpp:458
std::vector< double > prediction_upper() const
Upper prediction interval bounds (empty if not requested)
Definition fastlowess.hpp:527
PredictResult & operator=(const PredictResult &)=delete
size_t size() const
Number of query points.
Definition fastlowess.hpp:472
Streaming LOWESS model.
Definition fastlowess.hpp:907
StreamingLowess & operator=(StreamingLowess &&other) noexcept
Definition fastlowess.hpp:941
StreamingLowess & operator=(const StreamingLowess &)=delete
Expected< LowessResult > finalize()
Definition fastlowess.hpp:973
StreamingLowess(StreamingLowess &&other) noexcept
Definition fastlowess.hpp:938
StreamingLowess(const StreamingLowess &)=delete
Expected< LowessResult > process_chunk(const std::vector< double > &x_values, const std::vector< double > &y_values)
Definition fastlowess.hpp:952
StreamingLowess(const StreamingOptions &options={})
Definition fastlowess.hpp:909
~StreamingLowess()
Definition fastlowess.hpp:930
constexpr int k_default_min_points
Definition fastlowess.hpp:81
constexpr int k_default_overlap
Sentinel meaning "use the library default" (chunk_size / 10, clamped to [1, chunk_size - 10]); negati...
Definition fastlowess.hpp:79
constexpr int k_default_chunk_size
Definition fastlowess.hpp:76
constexpr int k_default_cv_k
Definition fastlowess.hpp:75
constexpr double k_default_fraction
Definition fastlowess.hpp:74
constexpr int k_default_window_capacity
Definition fastlowess.hpp:80
Definition fastlowess.hpp:71
void throwInitializationError(const char *fallback)
Definition fastlowess.hpp:124
OnlinePointStatus
Outcome of OnlineLowess::add_point.
Definition fastlowess.hpp:281
@ Dropped
Point ignored under missing = "drop".
@ Filling
Window still has fewer than min_points finite observations.
@ Ready
Smoothed fields are valid for the latest point.
OnlinePointStatus onlinePointStatusFromRaw(int has_value)
Definition fastlowess.hpp:287
bool hasOutput(const std::vector< std::string > &outputs, const char *name)
Definition fastlowess.hpp:97
void validateOutputs(const std::vector< std::string > &outputs, std::initializer_list< const char * > supported, const char *adapter)
Definition fastlowess.hpp:111
Definition fastlowess.hpp:84
std::string method
Definition fastlowess.hpp:86
int k
Definition fastlowess.hpp:87
std::vector< double > fractions
Definition fastlowess.hpp:85
Definition fastlowess.hpp:141
Definition fastlowess.hpp:90
size_t bootstrap
Zero disables bootstrap refits.
Definition fastlowess.hpp:94
double confidence
Definition fastlowess.hpp:91
double prediction
Definition fastlowess.hpp:92
Options for configuring LOWESS smoothing.
Definition fastlowess.hpp:194
double delta
Interpolation threshold (NaN = auto)
Definition fastlowess.hpp:197
std::string scaling_method
Definition fastlowess.hpp:201
IntervalsOptions intervals
Definition fastlowess.hpp:205
std::vector< double > custom_weights
Per-observation case weights.
Definition fastlowess.hpp:225
std::string missing
Policy for non-finite (NaN/Inf) values in input data: "error" (default) or "drop".
Definition fastlowess.hpp:218
int iterations
Robustness iterations.
Definition fastlowess.hpp:196
std::string robustness_method
Definition fastlowess.hpp:200
bool parallel
Definition fastlowess.hpp:212
std::string boundary_policy
Definition fastlowess.hpp:202
std::string weight_function
Definition fastlowess.hpp:199
std::string backend
Execution backend: "cpu" (default) or "gpu" (requires the library to be built with the gpu Cargo feat...
Definition fastlowess.hpp:215
std::string zero_weight_fallback
Definition fastlowess.hpp:203
bool retain_model
Retain the fitted model's training data, enabling LowessResult::predict_model().
Definition fastlowess.hpp:229
std::optional< uint64_t > seed
Definition fastlowess.hpp:206
CVOptions cv
Cross-validation configuration. Empty fractions disable CV.
Definition fastlowess.hpp:221
double auto_converge
Auto-convergence threshold.
Definition fastlowess.hpp:207
double fraction
Smoothing fraction (0, 1].
Definition fastlowess.hpp:195
std::vector< std::string > outputs
Optional result components: diagnostics, residuals, weights, derivative, se, and sorted.
Definition fastlowess.hpp:211
Options for online LOWESS.
Definition fastlowess.hpp:252
int iterations
Robustness iterations (requires update_mode = "full")
Definition fastlowess.hpp:254
std::vector< std::string > outputs
Optional result components: "weights", "derivative", and/or "se".
Definition fastlowess.hpp:267
std::optional< uint64_t > seed
Definition fastlowess.hpp:269
double auto_converge
Auto-convergence threshold.
Definition fastlowess.hpp:263
double fraction
Smoothing fraction (0, 1].
Definition fastlowess.hpp:253
std::string update_mode
Definition fastlowess.hpp:277
int min_points
Definition fastlowess.hpp:276
std::string weight_function
Definition fastlowess.hpp:257
double delta
Interpolation threshold (NaN = auto)
Definition fastlowess.hpp:255
std::string boundary_policy
Definition fastlowess.hpp:260
std::string robustness_method
Definition fastlowess.hpp:258
std::string missing
Policy for non-finite (NaN/Inf) x/y values passed to add_point(): "error" (default) or "drop".
Definition fastlowess.hpp:273
int window_capacity
Definition fastlowess.hpp:275
std::string scaling_method
Definition fastlowess.hpp:259
IntervalsOptions intervals
Definition fastlowess.hpp:268
std::string zero_weight_fallback
Definition fastlowess.hpp:261
Options for PredictModel::predict().
Definition fastlowess.hpp:422
IntervalsOptions intervals
Definition fastlowess.hpp:425
std::vector< std::string > outputs
Optional prediction components: "se" and/or "derivative".
Definition fastlowess.hpp:424
std::optional< uint64_t > seed
Definition fastlowess.hpp:426
double max_extrapolation_distance
Under "linear" extrapolation, the maximum allowed distance beyond the training boundary before predic...
Definition fastlowess.hpp:433
std::string extrapolation
Behavior for query points outside the training range ("clamp", "linear", "error").
Definition fastlowess.hpp:429
double max_neighbor_distance
Maximum allowed distance to the farthest point in a query's local window before predict() errors,...
Definition fastlowess.hpp:437
Options for streaming LOWESS.
Definition fastlowess.hpp:235
int overlap
Negative (the default) means "use the library default" (chunk_size / 10, clamped to [1,...
Definition fastlowess.hpp:239
std::string merge_strategy
weighted_average, average, take_first, take_last
Definition fastlowess.hpp:240
int chunk_size
Definition fastlowess.hpp:236