def _solve(solver, x0, disp=False, callback=None):
     from copy import deepcopy as _copy
     from mystic.tools import isNull
     if x0 is not None:
         solver.SetInitialPoints(x0)
         if solver._useStrictRange:  #XXX: always, settable, or sync'd ?
             solver.SetStrictRanges(solver._strictMin,
                                    solver._strictMax)
     _term = (solver._live is False) and solver.Terminated()
     if _term is True:
         solver._live = True  #XXX: HACK don't reset _fcalls
     if solver._cost[1] is None:  #XXX: HACK for configured NestedSolver
         solver.SetObjective(cost, ExtraArgs=ExtraArgs)
     solver.Solve(disp=disp, callback=callback)
     if _term is True: solver._live = False
     sm = solver._stepmon
     em = solver._evalmon
     if isNull(sm): sm = ([], [], [], [])
     else:
         sm = _copy(sm)
         sm = (sm._x, sm._y, sm._id, sm._info)
     if isNull(em): em = ([], [], [], [])
     else:
         em = _copy(em)
         em = (em._x, em._y, em._id, em._info)
     return solver, sm, em
 def _step(solver, x0, disp=False, callback=None):
     from copy import deepcopy as _copy
     from mystic.tools import isNull
     #ns = len(solver._stepmon)
     #ne = len(solver._evalmon)
     if x0 is not None:
         solver.SetInitialPoints(x0)
         if solver._useStrictRange:  #XXX: always, settable, or sync'd ?
             solver.SetStrictRanges(solver._strictMin,
                                    solver._strictMax)
     _term = (solver._live is False) and solver.Terminated()
     if _term is True:
         solver._live = True  #XXX: HACK don't reset _fcalls
     solver.Step(cost,
                 ExtraArgs=ExtraArgs,
                 disp=disp,
                 callback=callback)
     if _term is True: solver._live = False
     sm = solver._stepmon
     em = solver._evalmon
     if isNull(sm): sm = ([], [], [], [])
     else:
         sm = _copy(sm)  #[ns:]
         sm = (sm._x, sm._y, sm._id, sm._info)
     if isNull(em): em = ([], [], [], [])
     else:
         em = _copy(em)  #[ne:]
         em = (em._x, em._y, em._id, em._info)
     return solver, sm, em
 def local_optimize(solver, x0, rank=None, disp=False, callback=None):
     from copy import deepcopy as _copy
     from mystic.tools import isNull
     solver.id = rank
     solver.SetInitialPoints(x0)
     if solver._useStrictRange: #XXX: always, settable, or sync'd ?
         solver.SetStrictRanges(min=solver._strictMin, \
                                max=solver._strictMax) # or lower,upper ?
     solver.Solve(cost, disp=disp, callback=callback)
     sm = solver._stepmon
     em = solver._evalmon
     if isNull(sm): sm = ([],[],[],[])
     else: sm = (_copy(sm._x),_copy(sm._y),_copy(sm._id),_copy(sm._info))
     if isNull(em): em = ([],[],[],[])
     else: em = (_copy(em._x),_copy(em._y),_copy(em._id),_copy(em._info))
     return solver, sm, em
Esempio n. 4
0
 def local_optimize(solver, x0, rank=None, disp=False, callback=None):
     from copy import deepcopy as _copy
     from mystic.tools import isNull
     solver.id = rank
     solver.SetInitialPoints(x0)
     if solver._useStrictRange: #XXX: always, settable, or sync'd ?
         solver.SetStrictRanges(min=solver._strictMin, \
                                max=solver._strictMax) # or lower,upper ?
     solver.Solve(cost, disp=disp, callback=callback)
     sm = solver._stepmon
     em = solver._evalmon
     if isNull(sm): sm = ([],[],[],[])
     else: sm = (_copy(sm._x),_copy(sm._y),_copy(sm._id),_copy(sm._info))
     if isNull(em): em = ([],[],[],[])
     else: em = (_copy(em._x),_copy(em._y),_copy(em._id),_copy(em._info))
     return solver, sm, em
Esempio n. 5
0
def write_converge_file(mon,log_file='paramlog.py',**kwds):
  if isNull(mon): return  #XXX: throw error? warning? ???
  monitor = write_monitor( *raw_to_converge( *read_monitor(mon) ) )
  header = "written in 'converge' format"
  if kwds.has_key('header'):
    header += "\n# " + str(kwds.pop('header'))
  write_raw_file(monitor,log_file,header=header,**kwds)
  return
Esempio n. 6
0
def write_support_file(mon, log_file='paramlog.py', **kwds):
    if isNull(mon): return  #XXX: throw error? warning? ???
    monitor = write_monitor(*raw_to_support(*read_monitor(mon)))
    header = "written in 'support' format"
    if kwds.has_key('header'):
        header += "\n# " + str(kwds.pop('header'))
    write_raw_file(monitor, log_file, header=header, **kwds)
    return
Esempio n. 7
0
def write_converge_file(mon,log_file='paramlog.py',**kwds):
  if isNull(mon): return  #XXX: throw error? warning? ???
  monitor = write_monitor( *raw_to_converge( *read_monitor(mon) ) )
  header = "written in 'converge' format"
  if 'header' in kwds:
    header += "\n# " + str(kwds.pop('header'))
  write_raw_file(monitor,log_file,header=header,**kwds)
  return
Esempio n. 8
0
def write_support_file(mon,log_file='paramlog.py',**kwds):
  if isNull(mon): return  #XXX: throw error? warning? ???
  monitor = write_monitor( *raw_to_support( *read_monitor(mon) ) )
  header = "written in 'support' format"
  if 'header' in kwds:
    header += "\n# " + str(kwds.pop('header'))
  write_raw_file(monitor,log_file,header=header,**kwds)
  return
 def _solve(solver, x0, disp=False, callback=None):
     from copy import deepcopy as _copy
     from mystic.tools import isNull
     if x0 is not None:
         solver.SetInitialPoints(x0)
         if solver._useStrictRange: #XXX: always, settable, or sync'd ?
             solver.SetStrictRanges(solver._strictMin,solver._strictMax)
     solver.Solve(cost,ExtraArgs=ExtraArgs,disp=disp,callback=callback)
     sm = solver._stepmon
     em = solver._evalmon
     if isNull(sm): sm = ([],[],[],[])
     else:
         sm = _copy(sm)
         sm = (sm._x,sm._y,sm._id,sm._info)
     if isNull(em): em = ([],[],[],[])
     else:
         em = _copy(em)
         em = (em._x,em._y,em._id,em._info)
     return solver, sm, em
Esempio n. 10
0
def __orig_write_support_file(mon, log_file='paramlog.py'):
    if isNull(mon): return  #XXX: throw error? warning? ???
    steps, energy = read_monitor(mon)
    log = []
    if len(steps) > 0:
        for p in range(len(steps[0])):
            q = []
            for s in range(len(steps)):
                q.append(steps[s][p])
            log.append(q)
    monitor = write_monitor(log, energy)
    write_raw_file(monitor, log_file)
    return
Esempio n. 11
0
def __orig_write_support_file(mon,log_file='paramlog.py'):
  if isNull(mon): return  #XXX: throw error? warning? ???
  steps, energy = read_monitor(mon)
  log = []
  if len(steps) > 0:
    for p in range(len(steps[0])):
      q = []
      for s in range(len(steps)):
        q.append(steps[s][p])
      log.append(q)  
  monitor = write_monitor(log, energy)
  write_raw_file(monitor,log_file)
  return
Esempio n. 12
0
def write_raw_file(mon,log_file='paramlog.py',**kwds):
  if isNull(mon): return  #XXX: throw error? warning? ???
  steps, energy = read_monitor(mon)
  f = open(log_file,'w')
  if 'header' in kwds:
    f.write('# %s\n' % kwds.pop('header'))
  for variable,value in kwds.items(): # write remaining kwds as variables
    f.write('%s = %s\n' % (variable,value))
 #f.write('# %s\n' % energy[-1])
  f.write('params = %s\n' % steps)
  f.write('cost = %s\n' % energy)
  f.close()
  return
Esempio n. 13
0
def write_raw_file(mon,log_file='paramlog.py',**kwds):
  if isNull(mon): return  #XXX: throw error? warning? ???
  steps, energy = read_monitor(mon)
  f = open(log_file,'w')
  if 'header' in kwds:
    f.write('# %s\n' % kwds.pop('header'))
  for variable,value in kwds.items(): # write remaining kwds as variables
    f.write('%s = %s\n' % (variable,value))
 #f.write('# %s\n' % energy[-1])
  f.write('params = %s\n' % steps)
  f.write('cost = %s\n' % energy)
  f.close()
  return
 def _solve(solver, x0, disp=False, callback=None):
     from copy import deepcopy as _copy
     from mystic.tools import isNull
     if x0 is not None:
         solver.SetInitialPoints(x0)
         if solver._useStrictRange:  #XXX: always, settable, or sync'd ?
             solver.SetStrictRanges(solver._strictMin,
                                    solver._strictMax)
     solver.Solve(cost,
                  ExtraArgs=ExtraArgs,
                  disp=disp,
                  callback=callback)
     sm = solver._stepmon
     em = solver._evalmon
     if isNull(sm): sm = ([], [], [], [])
     else:
         sm = _copy(sm)
         sm = (sm._x, sm._y, sm._id, sm._info)
     if isNull(em): em = ([], [], [], [])
     else:
         em = _copy(em)
         em = (em._x, em._y, em._id, em._info)
     return solver, sm, em
Esempio n. 15
0
def write_raw_file(mon,log_file='paramlog.py',**kwds):
  if isNull(mon): return  #XXX: throw error? warning? ???
  steps, energy = read_monitor(mon)
  f = open(log_file,'w')
  if 'header' in kwds:
    f.write('# %s\n' % kwds['header'])
    del kwds['header']
  f.write("inf = float('inf')\n") # define special values
  f.write("nan = float('nan')\n") # define special values
  for variable,value in getattr(kwds, 'iteritems', kwds.items)():
    f.write('%s = %s\n' % (variable,value))# write remaining kwds as variables
 #f.write('# %s\n' % energy[-1])
  f.write('params = %s\n' % steps)
  f.write('cost = %s\n' % energy)
  f.close()
  return