(self)
return plus_vars, minus_vars
Solve the optimization problem associated with each point
Solve the optimization problem associated with each point
Solve the optimization problem associated with each point
def __solve__(self):
    """ Solve the optimization problem associated with each point """
    
    # Cones on the plus and minus side
    sup_plus_vars = cvx.Variable(shape=(len(self.points), self.dim))
    inf_plus_vars = cvx.Variable(shape=(len(self.points), self.dim))
    sup_minus_vars = cvx.Variable(shape=(len(self.points), self.dim))
    inf_minus_vars = cvx.Variable(shape=(len(self.points), self.dim))
    constraints = [sup_plus_vars >= 0, inf_plus_vars >= 0, sup_minus_vars >= 0, sup_plus_vars >= 0]

    # inf/sup relational constraints
    constraints += [sup_plus_vars >= inf_plus_vars]
    constraints += [sup_minus_vars <= inf_minus_vars]

    # Cone constraints
    for (i,(pone,vone)) in enumerate(self.points.items()):
      # point i has to be able to project into point j
      for (j,(ptwo,vtwo)) in enumerate(self.points.items()):
        if i==j: continue
        lhs_sup = 0.0
        lhs_inf = 0.0
        for (di,(poned,ptwod)) in enumerate(zip(pone,ptwo)):
          run = ptwod - poned
          supvar = 0.0
          infvar = 0.0
          if ptwod > poned:
            supvar = sup_plus_vars[i,di]
            infvar = inf_plus_vars[i,di]
          elif ptwod < poned:
            supvar = sup_minus_vars[i,di]
            infvar = inf_minus_vars[i,di]
          lhs_sup += run*supvar
          lhs_inf += run*infvar
        constraints += [lhs_sup >= vtwo-vone, lhs_inf <= vtwo-vone]

    # Optimization : minimize cone width
    objective = cvx.Minimize(cvx.norm(sup_plus_vars-inf_plus_vars)+cvx.norm(inf_minus_vars-sup_minus_vars))
    p = cvx.Problem(objective, constraints)
    # Run it!
    p.solve(verbose=False, solver=cvx.CVXOPT, kktsolver='robust', refinement=5)
    # Post-mortem...
    if p.status != 'optimal' and p.status != 'optimal_inaccurate':
      raise ScoreCreationError("Could not create scoring function: Optimization Failed")
      return None
    # Pull out the coefficients from the variables
    plus_vars = [[(sup_plus_vars[i,j].value,inf_plus_vars[i,j].value) for j in range(self.dim)] for i in range(len(self.points))]
    minus_vars = [[(sup_minus_vars[i,j].value,inf_minus_vars[i,j].value) for j in range(self.dim)] for i in range(len(self.points))]
    return plus_vars, minus_vars
def __solve__ ( self ) : # Cones on the plus and minus side sup_plus_vars = cvx . Variable ( shape = ( len ( self . points ) , self . dim ) ) inf_plus_vars = cvx . Variable ( shape = ( len ( self . points ) , self . dim ) ) sup_minus_vars = cvx . Variable ( shape = ( len ( self . points ) , self . dim ) ) inf_minus_vars = cvx . Variable ( shape = ( len ( self . points ) , self . dim ) ) constraints = [ sup_plus_vars >= 0 , inf_plus_vars >= 0 , sup_minus_vars >= 0 , sup_plus_vars >= 0 ] # inf/sup relational constraints constraints += [ sup_plus_vars >= inf_plus_vars ] constraints += [ sup_minus_vars <= inf_minus_vars ] # Cone constraints for ( i , ( pone , vone ) ) in enumerate ( self . points . items ( ) ) : # point i has to be able to project into point j for ( j , ( ptwo , vtwo ) ) in enumerate ( self . points . items ( ) ) : if i == j : continue lhs_sup = 0.0 lhs_inf = 0.0 for ( di , ( poned , ptwod ) ) in enumerate ( zip ( pone , ptwo ) ) : run = ptwod - poned supvar = 0.0 infvar = 0.0 if ptwod > poned : supvar = sup_plus_vars [ i , di ] infvar = inf_plus_vars [ i , di ] elif ptwod < poned : supvar = sup_minus_vars [ i , di ] infvar = inf_minus_vars [ i , di ] lhs_sup += run * supvar lhs_inf += run * infvar constraints += [ lhs_sup >= vtwo - vone , lhs_inf <= vtwo - vone ] # Optimization : minimize cone width objective = cvx . Minimize ( cvx . norm ( sup_plus_vars - inf_plus_vars ) + cvx . norm ( inf_minus_vars - sup_minus_vars ) ) p = cvx . Problem ( objective , constraints ) # Run it! p . solve ( verbose = False , solver = cvx . CVXOPT , kktsolver = 'robust' , refinement = 5 ) # Post-mortem... if p . status != 'optimal' and p . status != 'optimal_inaccurate' : raise ScoreCreationError ( "Could not create scoring function: Optimization Failed" ) return None # Pull out the coefficients from the variables plus_vars = [ [ ( sup_plus_vars [ i , j ] . value , inf_plus_vars [ i , j ] . value ) for j in range ( self . dim ) ] for i in range ( len ( self . points ) ) ] minus_vars = [ [ ( sup_minus_vars [ i , j ] . value , inf_minus_vars [ i , j ] . value ) for j in range ( self . dim ) ] for i in range ( len ( self . points ) ) ] return plus_vars , minus_vars