Example #1
0
    def optimize(
        init_params=init_params,
        f=f,
        df=df,
        barrier=barrier,
        callback=callback,
        gtol=gtol,
        maxiter=maxiter,
        full_output=full_output,
        **options
    ):
        init_params = flat(init_params)
        print "Starting optimization:"
        sys.stdout.flush()
        t0 = time.time()
        x, fx, dfx, _, _, _ = fmin_barrier_bfgs(
            f,
            init_params,
            fprime=df,
            gtol=gtol,
            maxiter=maxiter,
            callback=callback,
            barrier=barrier,
            disp=disp,
            full_output=True,
            **options
        )
        objective.callback(x, force=True)
        print "... done optimizing in", time.time() - t0, "sec."

        if full_output:
            return (x, fx, dfx)
        else:
            return x
Example #2
0
def _sum_objectives( objectives, global_objective, attribute, X ):
    x = global_objective.unflat(X)
    indices = global_objective.indices
    result  = kb.zeros_like(x)
    for i,obj in enumerate(objectives):
        flat = getattr(obj,attribute)(split_params(x,i,indices))
        try:
            param = obj.unflat(flat)
        except:
            param = {attribute:flat}
        result = fuse_params( result , param , i , indices )
    return kb.flat( result )
Example #3
0
    def optimize(init_params=init_params, f=f, 
                 df=df, barrier=barrier, callback=callback, gtol=gtol, 
                 maxiter=maxiter , full_output=full_output , **options):
        init_params = flat(init_params)
#        x, fx, dfx, _, _, _, _ = fmin_bfgs(f,init_params,fprime=df,
#                                                   gtol=gtol,maxiter=maxiter,
#                                                   callback=callback,
#                                                   barrier=barrier, disp=disp,
#                                                   full_output=True, **options)                                                   
        x , fx , d = fmin_l_bfgs_barrier(f, init_params, fprime=df, args=(),
                                         approx_grad=0, barrier=barrier,
                                         callback = callback,
                                         bounds=None, m=10, factr=1e0, 
                                         pgtol=1e-5, epsilon=1e-8,
                                         iprint=-1, maxfun=15000, disp=disp)
        if full_output:
            return (x,fx,d)
        else:
            return x
Example #4
0
 def packaged_function(params): return some_function(kb.flat(params),*t.ArgValues)
 return packaged_function
Example #5
0
 def flat(self,X): return kb.flat(X)
 def unflat(self,X): return kb.unflat(self.Example_Params,X)
Example #6
0
 def flat(self,X): return kb.flat(X)
 def unflat(self,X): return kb.unflat(self.init_params,X)
Example #7
0
 def packaged_function(params): return some_function(kb.flat(params),*t.args)
 return packaged_function