Skip to content

Commit

Permalink
fixed bug in newton
Browse files Browse the repository at this point in the history
  • Loading branch information
teseoch committed Oct 12, 2023
1 parent edb5cd7 commit 02d2627
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/polysolve/nonlinear/BFGS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace polysolve::nonlinear
std::string name() const override { return "BFGS"; }

protected:
virtual int default_descent_strategy() override { return 1; }
virtual void set_default_descent_strategy() override { descent_strategy = 1; }

using Superclass::descent_strategy_name;
std::string descent_strategy_name(int descent_strategy) const override;
Expand Down
2 changes: 1 addition & 1 deletion src/polysolve/nonlinear/GradientDescent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace polysolve::nonlinear
std::string name() const override { return "GradientDescent"; }

protected:
virtual int default_descent_strategy() override { return 1; }
virtual void set_default_descent_strategy() override { descent_strategy = 1; }

using Superclass::descent_strategy_name;
std::string descent_strategy_name(int descent_strategy_) const override;
Expand Down
2 changes: 1 addition & 1 deletion src/polysolve/nonlinear/LBFGS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace polysolve::nonlinear
std::string name() const override { return "L-BFGS"; }

protected:
virtual int default_descent_strategy() override { return 1; }
void set_default_descent_strategy() override { descent_strategy = 1; }

using Superclass::descent_strategy_name;
std::string descent_strategy_name(int descent_strategy) const override;
Expand Down
2 changes: 1 addition & 1 deletion src/polysolve/nonlinear/LBFGSB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace polysolve::nonlinear
std::string name() const override { return "L-BFGS-B"; }

protected:
virtual int default_descent_strategy() override { return 1; }
virtual void set_default_descent_strategy() override { descent_strategy = 1; }

using Superclass::descent_strategy_name;
std::string descent_strategy_name(int descent_strategy) const override;
Expand Down
2 changes: 1 addition & 1 deletion src/polysolve/nonlinear/MMA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace polysolve::nonlinear
std::string name() const override { return "MMA"; }

protected:
virtual int default_descent_strategy() override { return 1; }
virtual void set_default_descent_strategy() override { descent_strategy = 1; }

using Superclass::descent_strategy_name;
std::string descent_strategy_name(int descent_strategy) const override;
Expand Down
6 changes: 3 additions & 3 deletions src/polysolve/nonlinear/Newton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ namespace polysolve::nonlinear
// check_direction will increase descent_strategy if needed
return compute_update_direction(objFunc, x, grad, direction);

reg_weight /= reg_weight_dec;
if (reg_weight < reg_weight_min)
reg_weight = 0;
// reg_weight /= reg_weight_dec;
// if (reg_weight < reg_weight_min)
// reg_weight = 0;

return true;
}
Expand Down
6 changes: 5 additions & 1 deletion src/polysolve/nonlinear/Newton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ namespace polysolve::nonlinear

void reset(const int ndof) override;

virtual int default_descent_strategy() override { return force_psd_projection ? 1 : 0; }
virtual void set_default_descent_strategy() override
{
reg_weight = 0;
descent_strategy = force_psd_projection ? 1 : 0;
}
void increase_descent_strategy() override;

using Superclass::descent_strategy_name;
Expand Down
4 changes: 2 additions & 2 deletions src/polysolve/nonlinear/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ namespace polysolve::nonlinear
// Post update
// -----------

descent_strategy = default_descent_strategy(); // Reset this for the next iterations
set_default_descent_strategy(); // Reset this for the next iterations

const double step = (rate * delta_x).norm();

Expand Down Expand Up @@ -344,7 +344,7 @@ namespace polysolve::nonlinear
void Solver::reset(const int ndof)
{
this->m_current.reset();
descent_strategy = default_descent_strategy();
set_default_descent_strategy();
m_error_code = ErrorCode::SUCCESS;

const std::string line_search_name = solver_info["line_search"];
Expand Down
2 changes: 1 addition & 1 deletion src/polysolve/nonlinear/Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace polysolve::nonlinear
// Compute the search/update direction
virtual bool compute_update_direction(Problem &objFunc, const TVector &x_vec, const TVector &grad, TVector &direction) = 0;

virtual int default_descent_strategy() = 0;
virtual void set_default_descent_strategy() = 0;
virtual void increase_descent_strategy() = 0;

virtual bool is_direction_descent() { return true; }
Expand Down
2 changes: 1 addition & 1 deletion src/polysolve/nonlinear/line_search/LineSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace polysolve::nonlinear::line_search
objFunc.gradient(x, grad);

if (grad.norm() < 1e-30)
return 1;
return step_size;

const bool use_grad_norm = grad.norm() < use_grad_norm_tol;
if (use_grad_norm)
Expand Down

0 comments on commit 02d2627

Please sign in to comment.