diff --git a/src/solvers/logit/nfglogit.cc b/src/solvers/logit/nfglogit.cc index 1273cb9d3..0187887bd 100644 --- a/src/solvers/logit/nfglogit.cc +++ b/src/solvers/logit/nfglogit.cc @@ -38,6 +38,13 @@ void PointToProfile(MixedStrategyProfile &p_profile, const Vector &p_profile, const Vector &p_point) +{ + for (size_t i = 1; i < p_point.size(); i++) { + p_profile[i] = p_point[i]; + } +} + Vector ProfileToPoint(const LogitQREMixedStrategyProfile &p_profile) { Vector point(p_profile.size() + 1); @@ -75,6 +82,7 @@ class Equation { virtual ~Equation() = default; virtual double Value(const MixedStrategyProfile &p_profile, + const MixedStrategyProfile &p_logProfile, const Vector &p_strategyValues, double p_lambda) const = 0; virtual void Gradient(const MixedStrategyProfile &p_profile, const Vector &p_strategyValues, @@ -105,6 +113,7 @@ class SumToOneEquation final : public Equation { ~SumToOneEquation() override = default; double Value(const MixedStrategyProfile &p_profile, + const MixedStrategyProfile &p_logProfile, const Vector &p_strategyValues, double p_lambda) const override; void Gradient(const MixedStrategyProfile &p_profile, const Vector &p_strategyValues, const Matrix &p_strategyDerivs, @@ -112,6 +121,7 @@ class SumToOneEquation final : public Equation { }; double SumToOneEquation::Value(const MixedStrategyProfile &p_profile, + const MixedStrategyProfile &p_logProfile, const Vector &p_strategyValues, double p_lambda) const { double value = -1.0; @@ -157,6 +167,7 @@ class RatioEquation final : public Equation { ~RatioEquation() override = default; double Value(const MixedStrategyProfile &p_profile, + const MixedStrategyProfile &p_logProfile, const Vector &p_strategyValues, double p_lambda) const override; void Gradient(const MixedStrategyProfile &p_profile, const Vector &p_strategyValues, const Matrix &p_strategyDerivs, @@ -164,10 +175,11 @@ class RatioEquation final : public Equation { }; double RatioEquation::Value(const MixedStrategyProfile &p_profile, + const MixedStrategyProfile &p_logProfile, const Vector &p_strategyValues, double p_lambda) const { - return (std::log(p_profile[m_strategyIndex]) - std::log(p_profile[m_refStrategyIndex]) - - p_lambda * (p_strategyValues[m_strategyIndex] - p_strategyValues[m_refStrategyIndex])); + return p_logProfile[m_strategyIndex] - p_logProfile[m_refStrategyIndex] - + p_lambda * (p_strategyValues[m_strategyIndex] - p_strategyValues[m_refStrategyIndex]); } void RatioEquation::Gradient(const MixedStrategyProfile &p_profile, @@ -209,13 +221,14 @@ class EquationSystem { private: std::vector> m_equations; const Game &m_game; - mutable MixedStrategyProfile m_profile; + mutable MixedStrategyProfile m_profile, m_logProfile; mutable Vector m_strategyValues; mutable Matrix m_strategyDerivs; }; EquationSystem::EquationSystem(const Game &p_game) : m_game(p_game), m_profile(p_game->NewMixedStrategyProfile(0.0)), + m_logProfile(p_game->NewMixedStrategyProfile(0.0)), m_strategyValues(m_profile.MixedProfileLength()), m_strategyDerivs(m_profile.MixedProfileLength(), m_profile.MixedProfileLength()) { @@ -232,13 +245,15 @@ EquationSystem::EquationSystem(const Game &p_game) void EquationSystem::GetValue(const Vector &p_point, Vector &p_lhs) const { PointToProfile(m_profile, p_point); + PointToLogProfile(m_logProfile, p_point); const double lambda = p_point.back(); int col = 1; for (const auto &strategy : m_game->GetStrategies()) { m_strategyValues[col++] = m_profile.GetPayoff(strategy); } - std::transform(m_equations.begin(), m_equations.end(), p_lhs.begin(), - [this, lambda](auto e) { return e->Value(m_profile, m_strategyValues, lambda); }); + std::transform(m_equations.begin(), m_equations.end(), p_lhs.begin(), [this, lambda](auto e) { + return e->Value(m_profile, m_logProfile, m_strategyValues, lambda); + }); } void EquationSystem::GetJacobian(const Vector &p_point, Matrix &p_jac) const