def optobjective(f,trans,sign=1.0,**kwargs):
    """Wrapper for f to turn it into a minimization objective.
    
    The objective is: 
        obj(x) = sign*f(*trans(x),**kwargs) 
    where f can take multiple inputs and has a scalar output. 
    The input x is a vector.
    
    Both f(...,deriv=True) and trans(...) return backpropagation 
    handles, but obj(x) immediately returns value, gradient.  
    
       
    """
    def obj(x):
        *args, back1 = trans(x, deriv=True)
        y, back2 = f(*args,deriv=True,**kwargs)
        g = back1(*back2(sign))
        return sign*y, g
    
    return obj