Exemplo n.º 1
0
def kojima_solve(lcp,**kwargs):
    thresh   = kwargs.get('thresh',1e-12)
    max_iter = kwargs.get('max_iter',2)
    reg  = kwargs.get('reg',1e-7)
    
    (N,) = lcp.q.shape
    D = np.random.rand(N)
    #lcp.M += reg * sps.diags(D)
    x0 = kwargs.get('x0',np.ones(N))
    y0 = kwargs.get('y0',np.ones(N))

    iterator = KojimaIPIterator(lcp,x0=x0,y0=y0)
    solver = IterativeSolver(iterator)

    term_conds = [InnerProductTerminationCondition(thresh),
                  MaxIterTerminationCondition(max_iter),                  
                  SteplenTerminationCondition(1e-20)]
    announce = [IterAnnounce(),
                PotentialAnnounce(),
                PotentialDiffAnnounce()]
    solver.termination_conditions.extend(term_conds)
    solver.notifications.extend(announce)    

    solver.solve()
    (p,d) = (iterator.get_primal_vector(),iterator.get_dual_vector())

    return (p,d,iterator.data)
Exemplo n.º 2
0
def projective_solve(plcp,**kwargs):
    thresh   = kwargs.get('thresh',1e-15)
    max_iter = kwargs.get('max_iter',1000)
    reg  = kwargs.get('reg',1e-7)
    
    (N,K) = plcp.Phi.shape
    x0 = kwargs.get('x0',np.ones(N))
    y0 = kwargs.get('y0',np.ones(N))
    w0 = kwargs.get('w0',plcp.Phi.T.dot(plcp.q))

    iterator = ProjectiveIPIterator(plcp,x0=x0,y0=y0,w0=w0)
    solver = IterativeSolver(iterator)

    term_conds = [InnerProductTerminationCondition(thresh),
                  MaxIterTerminationCondition(max_iter),                  
                  SteplenTerminationCondition(1e-20)]
    announce = [IterAnnounce(),
                PotentialAnnounce(),
                PotentialDiffAnnounce()]
    solver.termination_conditions.extend(term_conds)
    solver.notifications.extend(announce)    

    solver.solve()
    (p,d) = (iterator.get_primal_vector(),iterator.get_dual_vector())

    return (p,d,iterator.data)