简体   繁体   中英

scipy.optimize.linprog not able to find solution

I am trying to check if data is linearly separable or not. I am using the equations mentioned at this link for the purpose. I am using the linprg function of the Scipy package in python. The sizes of arrays are as follows:

A = [12137810,11]
A1 = [12137,11]
b = 12137
c = 11

Here is the code that I am using:

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]
        print('a = [',len(A),',',len(A[0]),']')
        print('a1 = [',len(A1),',',len(A1[0]),']')
        del A
        b = -1*np.ones(len(A1),np.int64)
        c = np.zeros(11,np.int64)
        print('c = ',len(c))
        print('b =',len(b))
        del dicA
        res = linprog(c, A_ub=A1, b_ub=b, bounds=(None,None),options={"disp": True,"maxiter": 25000})
        print(res)
except:
        print('exception')
        tb = traceback.format_exc()
        print(tb)
finally:

        print('reached finally')

Here is the output that I am getting:

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

So, even after 2500 iteration, it was not able to find a solution, nor did it say that solution does not exist.So, does that mean solution does not exist? Or should I increase the iteration limit, if so then by how much?

If you trust the solver (= quality of implementation), increase iteration-limit until some other exit-status occurs.

A good implementation will always end in finite time, meaning: the exit-status will change at some iteration-size . There will be a solution or some certificate for unboundedness or infeasibility.

Edit: Above consequences are limited to implementations of the simplex-method (quality implementation)! Interior-point methods behave differently and do not have an underlying theory in general to provide these certificates robustly (theory in general assumes that the problem is feasible), the exception beeing the ones using a homogeneous self-dual embedding ( An O(√nL)-Iteration Homogeneous and Self-Dual Linear Programming Algorithm ).

The Simplex-algorithm in general is known to use quite a lot of iterations in general (at least compared to Interior-point methods; i'm not judging about your example).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM