Skip to content

Convergence issue when running on another computer #557

@pipobingo

Description

@pipobingo

Dear all,

I have recently bought a new computer and moved my project to it. Unfortuntly, whether it used to work perfectly on my older computer (it converged at each iteration) the fitting method doeas not converge properly anymore. Here is a small project that shows the issue. This project fits a GMMHMM on the the historic quotes of the S&P 500 index.

import yfinance as yf
import numpy as np

from hmmlearn import hmm

train_size = 320

data = yf.download(['ES=F'], '2018-08-01', '2020-12-31')
data["Close_log_change"] = np.log(data["Close"]) - np.log(data["Close"].shift())
data.dropna(inplace=True)

train_X = data[["Close_log_change"]].values
sub_X = train_X[0:train_size]

best_model = None
best_score = None

for i in range(20):
    print(i)
    model = hmm.GMMHMM(n_components=2, n_mix=3, n_iter=200, covariance_type="full", tol=1e0, verbose=True)
    try:
        model.fit(sub_X)
        train_score = model.score(sub_X)
        if not best_score or train_score > best_score:
            best_model = model
            best_score = train_score
    except:
        print("Model fit failed")

predictions = best_model.predict(sub_X)

This is what I get with my older computer:

[100%%*] 1 of 1 completed
0
1 713.70922034 +nan
2 952.18758237 +238.47836203
3 1046.89245242 +94.70487005
4 1056.92409225 +10.03163983
5 1059.28461180 +2.36051955
6 1059.86363858 +0.57902678
1
1 714.17865533 +nan
2 978.69374078 +264.51508545
3 1050.31653266 +71.62279188
4 1056.84363373 +6.52710108
5 1058.21041521 +1.36678147
6 1058.57464713 +0.36423192
2
1 713.98811884 +nan
2 979.34027161 +265.35215276
3 1050.34166207 +71.00139047
4 1056.81325537 +6.47159330
5 1058.15052814 +1.33727277
6 1058.50423967 +0.35371153
3
1 713.59847535 +nan
2 982.58666138 +268.98818603
3 1060.02659599 +77.43993461
4 1073.56376370 +13.53716771
5 1079.43327297 +5.86950927
6 1081.66235743 +2.22908446
7 1082.54154451 +0.87918708
4
1 713.85631130 +nan
2 955.68071132 +241.82440002
3 1047.39602064 +91.71530931
4 1056.85081071 +9.45479007
5 1058.99599600 +2.14518528
6 1059.48154928 +0.48555329

And this is what I get with my new computer:

[100%%*] 1 of 1 completed
0
1 886.84498330 +nan
2 979.75280368 +92.90782038
3 1027.39715089 +47.64434722
4 1050.72201834 +23.32486745
5 1056.02595111 +5.30393277
6 1058.80254364 +2.77659253
7 1060.00543734 +1.20289370
1
8 1060.53869195 +0.53325461
1 926.02168446 +nan
2 976.03917042 +50.01748597
3 1072.03070284 +95.99153242
4 1064.62916788 -7.40153496
Model is not converging. Current: 1064.6291678790426 is not greater than 1072.0307028413386. Delta is -7.401534962295955
2
1 919.09287400 +nan
2 976.03917042 +56.94629642
3 1072.03070284 +95.99153242
4 1064.62916788 -7.40153496
Model is not converging. Current: 1064.6291678790408 is not greater than 1072.030702841333. Delta is -7.401534962292317
3
1 916.16007344 +nan
2 976.03917042 +59.87909698
3 1072.03070284 +95.99153242
4 1064.62916788 -7.40153496
Model is not converging. Current: 1064.6291678790428 is not greater than 1072.030702841338. Delta is -7.401534962295273
4
1 -1229.69145284 +nan
2 979.75280368 +2209.44425652
3 1027.39715089 +47.64434722
4 1050.72201834 +23.32486745
5 1056.02595111 +5.30393277
6 1058.80254364 +2.77659253
7 1060.00543734 +1.20289370
8 1060.53869195 +0.53325461

Process finished with exit code 0

When it is converging on any try on my old computer, it is not converging all the time on my new one and it does not converge to the the same result.

Does anyone has an idea on why this occurs ?

Thank you very much in advance for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions