Skip to content

ENH: Improved performance of the ConditionalMNLogit class - #9036

Merged
bashtage merged 19 commits into
statsmodels:mainfrom
quant12345:cmnl
Jul 24, 2026
Merged

bashtage merged 19 commits into
statsmodels:mainfrom
quant12345:cmnl

Conversation

@quant12345

@quant12345 quant12345 commented Oct 22, 2023 •

Copy link
Copy Markdown
Contributor
  • tests added / passed.
  • code/documentation is well formatted.
  • properly formatted commit message. See NumPy's guide.

ENH - ConditionalMNLogit class: in loglike method replaces the nested loop to numpy vector operations. In score method, variable v is calculated at a time for the selected values (exp_sum). The number 'p' is used to access them.
As a result, test_conditional_mnlogit_grad is calculated 2.7 times faster, and test_conditional_mnlogit_2d, test_conditional_mnlogit_3d 1.7 times faster.

Below is a description of how to compare the old and new options.

I separated test_conditional_, conditional_models_ into separate files so that I could run the old and new options locally together for comparison (located them in a common directory). In conditional_models there are two classes ConditionalMNLogit and ConditionalMNLogit_new - in which I made improvements. In tests, the module is connected directly to use both options for tests. n = 90 is passed to gen_mnlogit(n)

Below is the test_conditional_ code. The conditional_models_ code is not posted due to line limitations, I am attaching it as an attachment.

test_conditional_ - code
import numpy as np
from conditional_models_ import ConditionalMNLogit, ConditionalMNLogit_new
from statsmodels.tools.numdiff import approx_fprime
from numpy.testing import assert_allclose
import pandas as pd


def gen_mnlogit(n):
    np.random.seed(235)

    g = np.kron(np.ones(5), np.arange(n // 5))
    x1 = np.random.normal(size=n)
    x2 = np.random.normal(size=n)
    xm = np.concatenate((x1[:, None], x2[:, None]), axis=1)
    pa = np.array([[0, 1, -1], [0, 2, -1]])
    lpr = np.dot(xm, pa)
    pr = np.exp(lpr)
    pr /= pr.sum(1)[:, None]
    cpr = pr.cumsum(1)
    y = 2 * np.ones(n)
    u = np.random.uniform(size=n)
    y[u < cpr[:, 2]] = 2
    y[u < cpr[:, 1]] = 1
    y[u < cpr[:, 0]] = 0

    df = pd.DataFrame({"y": y, "x1": x1,
                       "x2": x2, "g": g})
    return df


def test_conditional_mnlogit_grad_new(n):
    df = gen_mnlogit(n)
    model = ConditionalMNLogit_new.from_formula(
        "y ~ 0 + x1 + x2", groups="g", data=df)

    # Compare the gradients to numeric gradients
    for _ in range(5):
        za = np.random.normal(size=4)
        grad = model.score(za)
        ngrad = approx_fprime(za, model.loglike)
        assert_allclose(grad, ngrad, rtol=1e-5, atol=1e-3)


def test_conditional_mnlogit_grad(n):
    df = gen_mnlogit(n)
    model = ConditionalMNLogit.from_formula(
        "y ~ 0 + x1 + x2", groups="g", data=df)

    # Compare the gradients to numeric gradients
    for _ in range(5):
        za = np.random.normal(size=4)
        grad = model.score(za)
        ngrad = approx_fprime(za, model.loglike)
        assert_allclose(grad, ngrad, rtol=1e-5, atol=1e-3)


def test_conditional_mnlogit_2d_new(n):
    df = gen_mnlogit(n)
    model = ConditionalMNLogit_new.from_formula(
        "y ~ 0 + x1 + x2", groups="g", data=df)
    result = model.fit()

    #"""
    # Regression tests
    assert_allclose(
        result.params,
        np.asarray([[0.75592035, -1.58565494],
                    [1.82919869, -1.32594231]]),
        rtol=1e-5, atol=1e-5)
    assert_allclose(
        result.bse,
        np.asarray([[0.68099698, 0.70142727],
                    [0.65190315, 0.59653771]]),
        rtol=1e-5, atol=1e-5)
    #"""


def test_conditional_mnlogit_2d(n):
    df = gen_mnlogit(n)
    model = ConditionalMNLogit.from_formula(
        "y ~ 0 + x1 + x2", groups="g", data=df)
    result = model.fit()

    # Regression tests
    #"""
    assert_allclose(
        result.params,
        np.asarray([[0.75592035, -1.58565494],
                    [1.82919869, -1.32594231]]),
        rtol=1e-5, atol=1e-5)
    assert_allclose(
        result.bse,
        np.asarray([[0.68099698, 0.70142727],
                    [0.65190315, 0.59653771]]),
        rtol=1e-5, atol=1e-5)
    #"""


def test_conditional_mnlogit_3d_new(n):
    df = gen_mnlogit(n)
    df["x3"] = np.random.normal(size=df.shape[0])
    model = ConditionalMNLogit_new.from_formula(
        "y ~ 0 + x1 + x2 + x3", groups="g", data=df)
    result = model.fit()

    #"""
    # Regression tests
    assert_allclose(
        result.params,
        np.asarray([[0.729629, -1.633673],
                    [1.879019, -1.327163],
                    [-0.114124, -0.109378]]),
        atol=1e-5, rtol=1e-5)

    assert_allclose(
        result.bse,
        np.asarray([[0.682965, 0.60472],
                    [0.672947, 0.42401],
                    [0.722631, 0.33663]]),
        atol=1e-5, rtol=1e-5)

    #"""

    # Smoke test
    result.summary()


def test_conditional_mnlogit_3d(n):
    df = gen_mnlogit(n)
    df["x3"] = np.random.normal(size=df.shape[0])
    model = ConditionalMNLogit.from_formula(
        "y ~ 0 + x1 + x2 + x3", groups="g", data=df)
    result = model.fit()

    #"""
    # Regression tests
    assert_allclose(
        result.params,
        np.asarray([[0.729629, -1.633673],
                    [1.879019, -1.327163],
                    [-0.114124, -0.109378]]),
        atol=1e-5, rtol=1e-5)

    assert_allclose(
        result.bse,
        np.asarray([[0.682965, 0.60472],
                    [0.672947, 0.42401],
                    [0.722631, 0.33663]]),
        atol=1e-5, rtol=1e-5)

    #"""

    # Smoke test
    result.summary()

import datetime

n = 90

arr = [[test_conditional_mnlogit_grad_new,
        test_conditional_mnlogit_grad,
        'test_conditional_mnlogit_grad'],
       [test_conditional_mnlogit_2d_new,
        test_conditional_mnlogit_2d,
        'test_conditional_mnlogit_2d'],
       [test_conditional_mnlogit_3d_new,
        test_conditional_mnlogit_3d,
        'test_conditional_mnlogit_3d']]

for i in arr:
    print(i[2]) # name of the called function

    now = datetime.datetime.now()
    i[1](n)
    time_old = datetime.datetime.now() - now

    now = datetime.datetime.now()
    i[0](n)
    time_new = datetime.datetime.now() - now

    print(f'time_old = {time_old}, time_new = {time_new}, '
          f'time_old/time_new = {time_old/time_new}')

    print()

conditional_models_.py.tar.gz

Output:

n = 90

test_conditional_mnlogit_grad 
time_old = 0:00:00.680232, time_new = 0:00:00.236433, time_old/time_new = 2.8770603088401367
test_conditional_mnlogit_2d
time_old = 0:00:01.908332, time_new = 0:00:01.057139, time_old/time_new = 1.8051855054065737
test_conditional_mnlogit_3d
time_old = 0:00:02.635174, time_new = 0:00:01.468636, time_old/time_new = 1.7943002895203441

n = 2000 # with assert commented 

test_conditional_mnlogit_grad 
time_old = 0:00:16.267467, time_new = 0:00:06.169248, time_old/time_new = 2.636863844669561
test_conditional_mnlogit_2d
time_old = 0:00:45.773023, time_new = 0:00:25.878624, time_old/time_new = 1.768757991151307
test_conditional_mnlogit_3d
time_old = 0:00:57.176253, time_new = 0:00:33.577012, time_old/time_new = 1.7028392222631366
**Notes**
  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in main and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass flake8. If on Linux or OSX, you can
    verify you changes are well formatted by running
    git diff upstream/main -u -- "*.py" | flake8 --diff --isolated
    
    assuming flake8 is installed. This command is also available on Windows
    using the Windows System for Linux once flake8 is installed in the
    local Linux environment. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.

…p with numpy vector operations. In 'score' method, the score of the variable 'v' is calculated at a time for the selected values (exp_sum). The number 'p' is used to access them.
@quant12345 quant12345 changed the title Improved performance of the ConditionalMNLogit class ENH: Improved performance of the ConditionalMNLogit class Dec 1, 2023

@jseabold jseabold left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have recently been using these models. In general this looks good to me, if you could change to logsumexp that would be helpful.

Updated for better stability(sum and exp replaced with scipy.special.logsumexp).
@pep8speaks

pep8speaks commented May 14, 2024 •

Copy link
Copy Markdown

Hello @quant12345! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2025-01-07 19:32:22 UTC

@quant12345

quant12345 commented May 14, 2024 •

Copy link
Copy Markdown
Contributor Author

Below is the test_conditional_new code. The conditional_models_new code is not posted due to line limitations, I am attaching it as an attachment(with using scipy.special.logsumexp).

test_conditional_new - code
import numpy as np
from conditional_models_new import ConditionalMNLogit, ConditionalMNLogit_new
from statsmodels.tools.numdiff import approx_fprime
from numpy.testing import assert_allclose
import pandas as pd


def gen_mnlogit(n):
    np.random.seed(235)

    g = np.kron(np.ones(5), np.arange(n // 5))
    x1 = np.random.normal(size=n)
    x2 = np.random.normal(size=n)
    xm = np.concatenate((x1[:, None], x2[:, None]), axis=1)
    pa = np.array([[0, 1, -1], [0, 2, -1]])
    lpr = np.dot(xm, pa)
    pr = np.exp(lpr)
    pr /= pr.sum(1)[:, None]
    cpr = pr.cumsum(1)
    y = 2 * np.ones(n)
    u = np.random.uniform(size=n)
    y[u < cpr[:, 2]] = 2
    y[u < cpr[:, 1]] = 1
    y[u < cpr[:, 0]] = 0

    df = pd.DataFrame({"y": y, "x1": x1,
                       "x2": x2, "g": g})
    return df


def test_conditional_mnlogit_grad_new(n):
    df = gen_mnlogit(n)
    model = ConditionalMNLogit_new.from_formula(
        "y ~ 0 + x1 + x2", groups="g", data=df)

    # Compare the gradients to numeric gradients
    for _ in range(5):
        za = np.random.normal(size=4)
        grad = model.score(za)
        ngrad = approx_fprime(za, model.loglike)
        assert_allclose(grad, ngrad, rtol=1e-5, atol=1e-3)


def test_conditional_mnlogit_grad(n):
    df = gen_mnlogit(n)
    model = ConditionalMNLogit.from_formula(
        "y ~ 0 + x1 + x2", groups="g", data=df)

    # Compare the gradients to numeric gradients
    for _ in range(5):
        za = np.random.normal(size=4)
        grad = model.score(za)
        ngrad = approx_fprime(za, model.loglike)
        assert_allclose(grad, ngrad, rtol=1e-5, atol=1e-3)


def test_conditional_mnlogit_2d_new(n):
    df = gen_mnlogit(n)
    model = ConditionalMNLogit_new.from_formula(
        "y ~ 0 + x1 + x2", groups="g", data=df)
    result = model.fit()

    #"""
    # Regression tests
    assert_allclose(
        result.params,
        np.asarray([[0.75592035, -1.58565494],
                    [1.82919869, -1.32594231]]),
        rtol=1e-5, atol=1e-5)
    assert_allclose(
        result.bse,
        np.asarray([[0.68099698, 0.70142727],
                    [0.65190315, 0.59653771]]),
        rtol=1e-5, atol=1e-5)
    #"""


def test_conditional_mnlogit_2d(n):
    df = gen_mnlogit(n)
    model = ConditionalMNLogit.from_formula(
        "y ~ 0 + x1 + x2", groups="g", data=df)
    result = model.fit()

    # Regression tests
    #"""
    assert_allclose(
        result.params,
        np.asarray([[0.75592035, -1.58565494],
                    [1.82919869, -1.32594231]]),
        rtol=1e-5, atol=1e-5)
    assert_allclose(
        result.bse,
        np.asarray([[0.68099698, 0.70142727],
                    [0.65190315, 0.59653771]]),
        rtol=1e-5, atol=1e-5)
    #"""


def test_conditional_mnlogit_3d_new(n):
    df = gen_mnlogit(n)
    df["x3"] = np.random.normal(size=df.shape[0])
    model = ConditionalMNLogit_new.from_formula(
        "y ~ 0 + x1 + x2 + x3", groups="g", data=df)
    result = model.fit()

    #"""
    # Regression tests
    assert_allclose(
        result.params,
        np.asarray([[0.729629, -1.633673],
                    [1.879019, -1.327163],
                    [-0.114124, -0.109378]]),
        atol=1e-5, rtol=1e-5)

    assert_allclose(
        result.bse,
        np.asarray([[0.682965, 0.60472],
                    [0.672947, 0.42401],
                    [0.722631, 0.33663]]),
        atol=1e-5, rtol=1e-5)

    #"""

    # Smoke test
    result.summary()


def test_conditional_mnlogit_3d(n):
    df = gen_mnlogit(n)
    df["x3"] = np.random.normal(size=df.shape[0])
    model = ConditionalMNLogit.from_formula(
        "y ~ 0 + x1 + x2 + x3", groups="g", data=df)
    result = model.fit()

    #"""
    # Regression tests
    assert_allclose(
        result.params,
        np.asarray([[0.729629, -1.633673],
                    [1.879019, -1.327163],
                    [-0.114124, -0.109378]]),
        atol=1e-5, rtol=1e-5)

    assert_allclose(
        result.bse,
        np.asarray([[0.682965, 0.60472],
                    [0.672947, 0.42401],
                    [0.722631, 0.33663]]),
        atol=1e-5, rtol=1e-5)

    #"""

    # Smoke test
    result.summary()

import datetime

n = 90

arr = [[test_conditional_mnlogit_grad_new,
        test_conditional_mnlogit_grad,
        'test_conditional_mnlogit_grad'],
       [test_conditional_mnlogit_2d_new,
        test_conditional_mnlogit_2d,
        'test_conditional_mnlogit_2d'],
       [test_conditional_mnlogit_3d_new,
        test_conditional_mnlogit_3d,
        'test_conditional_mnlogit_3d']]

for i in arr:
    print(i[2]) # name of the called function

    now = datetime.datetime.now()
    i[1](n)
    time_old = datetime.datetime.now() - now

    now = datetime.datetime.now()
    i[0](n)
    time_new = datetime.datetime.now() - now

    print(f'time_old = {time_old}, time_new = {time_new}, '
          f'time_old/time_new = {time_old/time_new}')

    print()

The performance is the same as in my previous version.
If you use 'n' not 90 comment out the assert.

conditional_models_new.py.tar.gz

quant12345 and others added 8 commits January 7, 2025 16:21
…p with numpy vector operations. In 'score' method, the score of the variable 'v' is calculated at a time for the selected values (exp_sum). The number 'p' is used to access them.
Updated for better stability(sum and exp replaced with scipy.special.logsumexp).
# Conflicts:
#	statsmodels/discrete/conditional_models.py
@josef-pkt josef-pkt mentioned this pull request Jan 7, 2025
6 tasks
@josef-pkt

Copy link
Copy Markdown
Member

Thanks for the PR

I put it on my list of PRs to look at and merge over the next few weeks. (for soonish 0.15)

@quant12345

quant12345 commented Jan 7, 2025 •

Copy link
Copy Markdown
Contributor Author

I added another improvement and comments (commit 1ee8e71), but the tests do not run. So the PR is quite old, I had to tinker with merges and therefore, due to ignorance, I created many commits. Now a merge conflict has appeared, but before that it was not there (it is not clear what is wrong) Line: from scipy.special import logsumexp?

--------------------------------------------------------------performance------------------------------------------------------------------------------------------
Below is the test_conditional_new code. The conditional_models_new code is not posted due to line limitations, I am attaching it as an attachment(with today's changes 07-01-2025).

test_conditional_new - code
import numpy as np
from conditional_models_new import ConditionalMNLogit, ConditionalMNLogit_new
from statsmodels.tools.numdiff import approx_fprime
from numpy.testing import assert_allclose
import pandas as pd


def gen_mnlogit(n):
    np.random.seed(235)

    g = np.kron(np.ones(5), np.arange(n // 5))
    x1 = np.random.normal(size=n)
    x2 = np.random.normal(size=n)
    xm = np.concatenate((x1[:, None], x2[:, None]), axis=1)
    pa = np.array([[0, 1, -1], [0, 2, -1]])
    lpr = np.dot(xm, pa)
    pr = np.exp(lpr)
    pr /= pr.sum(1)[:, None]
    cpr = pr.cumsum(1)
    y = 2 * np.ones(n)
    u = np.random.uniform(size=n)
    y[u < cpr[:, 2]] = 2
    y[u < cpr[:, 1]] = 1
    y[u < cpr[:, 0]] = 0

    df = pd.DataFrame({"y": y, "x1": x1,
                       "x2": x2, "g": g})
    return df


def test_conditional_mnlogit_grad_new(n):
    df = gen_mnlogit(n)
    model = ConditionalMNLogit_new.from_formula(
        "y ~ 0 + x1 + x2", groups="g", data=df)

    # Compare the gradients to numeric gradients
    for _ in range(5):
        za = np.random.normal(size=4)
        grad = model.score(za)
        ngrad = approx_fprime(za, model.loglike)
        assert_allclose(grad, ngrad, rtol=1e-5, atol=1e-3)


def test_conditional_mnlogit_grad(n):
    df = gen_mnlogit(n)
    model = ConditionalMNLogit.from_formula(
        "y ~ 0 + x1 + x2", groups="g", data=df)

    # Compare the gradients to numeric gradients
    for _ in range(5):
        za = np.random.normal(size=4)
        grad = model.score(za)
        ngrad = approx_fprime(za, model.loglike)
        assert_allclose(grad, ngrad, rtol=1e-5, atol=1e-3)


def test_conditional_mnlogit_2d_new(n):
    df = gen_mnlogit(n)
    model = ConditionalMNLogit_new.from_formula(
        "y ~ 0 + x1 + x2", groups="g", data=df)
    result = model.fit()

    #"""
    # Regression tests
    assert_allclose(
        result.params,
        np.asarray([[0.75592035, -1.58565494],
                    [1.82919869, -1.32594231]]),
        rtol=1e-5, atol=1e-5)
    assert_allclose(
        result.bse,
        np.asarray([[0.68099698, 0.70142727],
                    [0.65190315, 0.59653771]]),
        rtol=1e-5, atol=1e-5)
    #"""


def test_conditional_mnlogit_2d(n):
    df = gen_mnlogit(n)
    model = ConditionalMNLogit.from_formula(
        "y ~ 0 + x1 + x2", groups="g", data=df)
    result = model.fit()

    # Regression tests
    #"""
    assert_allclose(
        result.params,
        np.asarray([[0.75592035, -1.58565494],
                    [1.82919869, -1.32594231]]),
        rtol=1e-5, atol=1e-5)
    assert_allclose(
        result.bse,
        np.asarray([[0.68099698, 0.70142727],
                    [0.65190315, 0.59653771]]),
        rtol=1e-5, atol=1e-5)
    #"""


def test_conditional_mnlogit_3d_new(n):
    df = gen_mnlogit(n)
    df["x3"] = np.random.normal(size=df.shape[0])
    model = ConditionalMNLogit_new.from_formula(
        "y ~ 0 + x1 + x2 + x3", groups="g", data=df)
    result = model.fit()

    #"""
    # Regression tests
    assert_allclose(
        result.params,
        np.asarray([[0.729629, -1.633673],
                    [1.879019, -1.327163],
                    [-0.114124, -0.109378]]),
        atol=1e-5, rtol=1e-5)

    assert_allclose(
        result.bse,
        np.asarray([[0.682965, 0.60472],
                    [0.672947, 0.42401],
                    [0.722631, 0.33663]]),
        atol=1e-5, rtol=1e-5)

    #"""

    # Smoke test
    result.summary()


def test_conditional_mnlogit_3d(n):
    df = gen_mnlogit(n)
    df["x3"] = np.random.normal(size=df.shape[0])
    model = ConditionalMNLogit.from_formula(
        "y ~ 0 + x1 + x2 + x3", groups="g", data=df)
    result = model.fit()

    #"""
    # Regression tests
    assert_allclose(
        result.params,
        np.asarray([[0.729629, -1.633673],
                    [1.879019, -1.327163],
                    [-0.114124, -0.109378]]),
        atol=1e-5, rtol=1e-5)

    assert_allclose(
        result.bse,
        np.asarray([[0.682965, 0.60472],
                    [0.672947, 0.42401],
                    [0.722631, 0.33663]]),
        atol=1e-5, rtol=1e-5)

    #"""

    # Smoke test
    result.summary()

import datetime

n = 90

arr = [[test_conditional_mnlogit_grad_new,
        test_conditional_mnlogit_grad,
        'test_conditional_mnlogit_grad'],
       [test_conditional_mnlogit_2d_new,
        test_conditional_mnlogit_2d,
        'test_conditional_mnlogit_2d'],
       [test_conditional_mnlogit_3d_new,
        test_conditional_mnlogit_3d,
        'test_conditional_mnlogit_3d']]

for i in arr:

    now = datetime.datetime.now()
    i[1](n)
    time_old = datetime.datetime.now() - now

    now = datetime.datetime.now()
    i[0](n)
    time_new = datetime.datetime.now() - now

    print(f'{i[2]}    ', f'time_old = {time_old}, time_new = {time_new}, '
          f'time_old/time_new = {time_old/time_new}')

Performance is better than previous commits.
If you use 'n' not 90 comment out the assert.

comparison results
n = 90

test_conditional_mnlogit_grad   time_old = 0:00:00.722798, time_new = 0:00:00.125969, time_old/time_new = 5.737903769975152
test_conditional_mnlogit_2d     time_old = 0:00:02.027359, time_new = 0:00:00.255898, time_old/time_new = 7.9225277258907845
test_conditional_mnlogit_3d     time_old = 0:00:02.748847, time_new = 0:00:00.359301, time_old/time_new = 7.650540911380709

n = 2000

test_conditional_mnlogit_grad   time_old = 0:00:17.706207, time_new = 0:00:03.517461, time_old/time_new = 5.033803359866677
test_conditional_mnlogit_2d     time_old = 0:00:45.822618, time_new = 0:00:05.897196, time_old/time_new = 7.7702382623877515
test_conditional_mnlogit_3d     time_old = 0:01:02.887811, time_new = 0:00:07.655789, time_old/time_new = 8.214412779662553

if you run the tests themselves before and after the changes.

before:

pytest statsmodels/discrete/tests/test_conditional.py::test_conditional_mnlogit_grad - 1.53s
pytest statsmodels/discrete/tests/test_conditional.py::test_conditional_mnlogit_3d   - 3.50s
pytest statsmodels/discrete/tests/test_conditional.py::test_conditional_mnlogit_2d   - 2.75s

after:

pytest statsmodels/discrete/tests/test_conditional.py::test_conditional_mnlogit_grad - 1.03s
pytest statsmodels/discrete/tests/test_conditional.py::test_conditional_mnlogit_3d   - 1.27s
pytest statsmodels/discrete/tests/test_conditional.py::test_conditional_mnlogit_2d   - 1.16s

conditional_models_new.zip

@josef-pkt

Copy link
Copy Markdown
Member

do you know how to do an interactive rebase in git?

The formatting of the import statements has changed in statsmodels main. So those merge conflicts need to be resolved

@quant12345

Copy link
Copy Markdown
Contributor Author

I haven't worked with interactive rebase in git yet. I couldn't send a push. In PyCharm terminal it said that I need to merge before pushing. I tried several times. Then I tried to merge and after that I was able to send a push).
'The formatting of the import statements has changed in statsmodels main' do I need to do any manipulations in this regard?

@bashtage

bashtage commented Jan 7, 2025

Copy link
Copy Markdown
Member

I fixed your merge problem

You need to pull this change before making more changes.

@quant12345 quant12345 closed this Mar 6, 2025
@Aniketsy

Aniketsy commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

@quant12345 gentle ping, are you planning to open new PR for this, as i can see it was in good direction and in priority as per review from members and @bashtage helped to solve some merge conflicts

I fixed your merge problem

You need to pull this change before making more changes.

Or i can open a new pr and add you co-author so that we can proceed with your work. please let me know

@quant12345 quant12345 reopened this Jun 14, 2026
@quant12345

quant12345 commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor Author

@Aniketsy opened it again, fixed linting, removed merge conflicts.
I also have PR 9264, let me know if you need it.

@Aniketsy

Aniketsy commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor
=========================== short test summary info ============================
FAILED statsmodels/tsa/statespace/tests/test_smoothing.py::test_smoothed_state_autocovariances_backwards_oos[True-False-None]
= 1 failed, 19531 passed, 431 skipped, 140 xfailed, 705 warnings in 1060.54s (0:17:40) =

ci- fail looks unrelated

@quant12345 thanks for re-opening this PR, hoping to moving this forward... i'll review this once from my end

I also have PR 9264, let me know if you need it.

is this separate PR ? if related to this please link


grad = np.zeros((q, c))
for ii in self._grp_ix:
for ii in np.array(self._grp_ix):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how will this behave when group size will be different ?
if this breaks, then we should revert this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aniketsy do I understand correctly that you mean a non-homogeneous array, for example: [[1,3],[4,5,6,7],[1]] ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aniketsy do I understand correctly that you mean a non-homogeneous array, for example: [[1,3],[4,5,6,7],[1]] ?

@quant12345 yes could you please verify

@quant12345 quant12345 Jun 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returned the row to its original state: for ii in self._grp_ix:. I also checked all three tests with the change (all three tests were successful).

@quant12345

Copy link
Copy Markdown
Contributor Author
=========================== short test summary info ============================
FAILED statsmodels/tsa/statespace/tests/test_smoothing.py::test_smoothed_state_autocovariances_backwards_oos[True-False-None]
= 1 failed, 19531 passed, 431 skipped, 140 xfailed, 705 warnings in 1060.54s (0:17:40) =

ci- fail looks unrelated

@quant12345 thanks for re-opening this PR, hoping to moving this forward... i'll review this once from my end

I also have PR 9264, let me know if you need it.

is this separate PR ? if related to this please link

I tried print('!!!!!!!!!!!!!!') the loglike and score functions from ConditionalMNLogit. When running the test:
pytest statsmodels/tsa/statespace/tests/test_smoothing.py::test_smoothed_state_autocovariances_backwards_oos[True-False-None] -s
Nothing is printed, it looks like the changed code is not involved in this test. Local tests are passing successfully.

PR 9264 is independent of this.

@Aniketsy

Copy link
Copy Markdown
Contributor

I tried print('!!!!!!!!!!!!!!') the loglike and score functions from ConditionalMNLogit. When running the test:
pytest statsmodels/tsa/statespace/tests/test_smoothing.py::test_smoothed_state_autocovariances_backwards_oos[True-False-None] -s
Nothing is printed, it looks like the changed code is not involved in this test. Local tests are passing successfully.

hmm, yes 👍

@bashtage
bashtage dismissed jseabold’s stale review July 24, 2026 11:31

This is out-of-date

@bashtage
bashtage merged commit 24d7bf7 into statsmodels:main Jul 24, 2026
8 of 9 checks passed
@bashtage

Copy link
Copy Markdown
Member

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants