Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: migrate theta to c++ #955

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
python-version: "3.10"

- name: Install the library
run: pip install uv && uv pip install --system ".[dev]"
run: pip install uv && uv pip install --system ".[dev]" "datasetsforecast<1"

- name: Run M3 experiment
run: |
Expand Down
17 changes: 9 additions & 8 deletions include/statsforecast/nelder_mead.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ using Eigen::VectorXd;
using RowMajorMatrixXd =
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;

auto Clamp(const VectorXd &x, const VectorXd &lower, const VectorXd &upper) {
inline auto Clamp(const VectorXd &x, const VectorXd &lower,
const VectorXd &upper) {
return x.cwiseMax(lower).cwiseMin(upper);
}

double StandardDeviation(const VectorXd &x) {
inline double StandardDeviation(const VectorXd &x) {
return std::sqrt((x.array() - x.mean()).square().mean());
}

Eigen::VectorX<Eigen::Index> ArgSort(const VectorXd &v) {
inline Eigen::VectorX<Eigen::Index> ArgSort(const VectorXd &v) {
Eigen::VectorX<Eigen::Index> indices(v.size());
std::iota(indices.begin(), indices.end(), 0);
std::sort(indices.begin(), indices.end(),
Expand All @@ -25,11 +26,11 @@ Eigen::VectorX<Eigen::Index> ArgSort(const VectorXd &v) {
}

template <typename Func, typename... Args>
std::tuple<VectorXd, double, int> NelderMead(Func F, const VectorXd &x, const VectorXd &lower,
const VectorXd upper, double init_step,
double zero_pert, double alpha, double gamma,
double rho, double sigma, int max_iter, double tol_std,
bool adaptive, Args &&...args) {
std::tuple<VectorXd, double, int>
NelderMead(Func F, const VectorXd &x, const VectorXd &lower,
const VectorXd upper, double init_step, double zero_pert,
double alpha, double gamma, double rho, double sigma, int max_iter,
double tol_std, bool adaptive, Args &&...args) {
auto x0 = Clamp(x, lower, upper);
auto n = x0.size();
if (adaptive) {
Expand Down
Loading
Loading