How to increase iterations for scipy.optimize.linprog function in python?
Asked Answered
J

1

6

I am trying to check if the train data is linearly separable or not. For that I am using the following code.

try:
        import os
        import random
        import traceback
        import numpy as np
        import scipy.io as sio
        from scipy.optimize import linprog
        os.system('cls')
        dicA  = sio.loadmat('A.mat')
        A = dicA.get('A')
        lengthA = int(len(A)/1000)
        aRange = range(0,lengthA)
        selectedIndexes = random.sample(aRange,lengthA)
        A1 = A[selectedIndexes]
        del A
        b = -1*np.ones(len(A1),np.int64)
        c = np.zeros(11,np.int64)
        del dicA
        res = linprog(c, A_ub=A1, b_ub=b, bounds=(-float('inf'), float('inf')),options={"disp": True})
        print(res)
except:
        print('exception')
        tb = traceback.format_exc()
        print(tb)
finally:

        print('reached finally')

I am using the equation mentioned at this link. I get following output when I run the script.

Iteration limit reached.
     fun: -0.0
 message: 'Iteration limit reached.'
     nit: 1000
  status: 1
 success: False
       x: nan
reached finally

So, does the iteration limit reached means that data is not linearly separable, if not then how do I increase the limit.

Jylland answered 24/8, 2017 at 4:8 Comment(0)
R
6

I think you can add maxiter to options.

options = {"disp": True, "maxiter": 5000}
res = linprog(c, A_ub=A1, b_ub=b, bounds=(None, None), options=options)

According with documentation you can use None in bounds to specify no bounds in the given direction.

Roden answered 24/8, 2017 at 4:15 Comment(1)
"maxiter": 5000 did not work for me and when I increase 5000 to 50000, it worked well.Clachan

© 2022 - 2024 — McMap. All rights reserved.