Package gmisclib :: Module opt
[frames] | no frames]

Module opt

source code

This module is a Levenberg-Marquardt optimizer with stem-size control for numeric differentiation. It just needs a function that produces residuals. It is multi-threaded, so calculations of residuals can be farmed out to many processors.

UPDATED 12/2009 GPK: NOT TESTED!

Classes
  OptError
  NoDownhill
  NoDerivative
  BadParamError
Raised when you give and opt instance some invalid control parameter.
  BadResult
The function to be optimized returns some illegal result.
  mysem
This is a semaphore that is automatically released when it is de-allocated.
  semclass
This is a semaphore to control the number of simultaneous computations.
  prms
This class records parameters and caches function evaluations.
  LockedList
  opt
A class that implements a optimizer.
Functions
 
vec_equal(a, b)
Check that two Numeric vectors are exactly equal.
source code
 
sumsq(a)
This is the overall error measure.
source code
 
maxabs(a)
This is used as a measure of how much the function changed as a result of a parameter change.
source code
 
wtf(r_dz, delta, quantum)
This shows how important different measurements are to the final derivitive estimate.
source code
 
near_duplicate(guess, tmp, quantum) source code
 
symmetry_point(tmp, T, quantum)
Given a list of (delta, z) in a differentiation, pick one more point that makes the differentiation more symmetric.
source code
 
scale_est(tmp, T) source code
 
explored_region(tmp) source code
 
clz_point(qq, T, quantum)
Given a list of (delta, z) tuples in a differentiation attempt, find another delta that (a) fills a gap in the sequence, (b) is preferably has a sign opposite most of the {delta} values, and (c) has a large wtf().
source code
 
deriv_estimate(tmp, T, quantum) source code
 
need_more_diff_pts(tmp, T, quantum) source code
 
diff_one(x, i, sem)
Differentiate z with respect to parameter i.
source code
 
eval_lambda(processor, a, b, startp, lamb, out, opt) source code
 
lamb_correct(newscale, scale) source code
 
anneal_guts(p, rv, T, lamb, sem, opt) source code
 
test1_fcn(p, args, *d) source code
 
test1()
Linear.
source code
 
test1a_fcn(p, args, *d) source code
 
test1a()
Linear.
source code
 
test2_fcn(p, args, *d) source code
 
test2()
Nonlinear
source code
 
test3_fcn(p, args, *d) source code
 
test3()
Linear, but correlated
source code
 
test4_fcn(p, args, *d) source code
 
test4()
Linear, but with a constraint
source code
 
test5_fcn(p, args, *d) source code
 
test5()
Very Nonlinear
source code
 
test6_fcn(p, args, *d) source code
 
test6()
Curved valley.
source code
 
linconst_min(nparam, param, min)
Generate a linear constraint to be added onto a list and passed to linear_constraint().
source code
 
linconst_max(nparam, param, max)
Generate a linear constraint to be added onto a list and passed to linear_constraint().
source code
 
linear_constraint(op, np, list_of_constraints)
This constrains a step to lie inside a region bounded by a list_of_constraints.
source code
 
test7()
Constraint.
source code
Variables
  __package__ = 'gmisclib'

Imports: os, sys, math, random, traceback, threading, die, avio, gpkmisc, Num, RA, LA


Function Details

wtf(r_dz, delta, quantum)

source code 

This shows how important different measurements are to the final derivitive estimate. The weight must be small when the change of a parameter is smaller than the quantum (i.e. when r_delta < quantum). It must also be small when the change in z is much larger than T (r_dz>>1). It is largest when r_dz is about 1.

symmetry_point(tmp, T, quantum)

source code 

Given a list of (delta, z) in a differentiation, pick one more point that makes the differentiation more symmetric. This is done by picking a new delta that brings sum{delta_i * wtf()} closer to zero, where wtf() is the weight given to each point in the differentiation.

clz_point(qq, T, quantum)

source code 

Given a list of (delta, z) tuples in a differentiation attempt, find another delta that (a) fills a gap in the sequence, (b) is preferably has a sign opposite most of the {delta} values, and (c) has a large wtf(). Points outside the sequence are also considered.

diff_one(x, i, sem)

source code 

Differentiate z with respect to parameter i. We enter this function with the semaphore 'sem' already acquired.

linconst_min(nparam, param, min)

source code 

Generate a linear constraint to be added onto a list and passed to linear_constraint(). This constraint expresses that p[param]>=min.

linconst_max(nparam, param, max)

source code 

Generate a linear constraint to be added onto a list and passed to linear_constraint(). This constraint expresses that p[param]<=max.

linear_constraint(op, np, list_of_constraints)

source code 

This constrains a step to lie inside a region bounded by a list_of_constraints.

Parameters:
  • op - parameters at the beginning of the step.
  • np - target parameters.
  • list_of_constraints - [ (vector, shift), ... ] where the allowable region of each constraint is defined by Num.dot(x, vector)+shift >= 0 . Vector is a numpy array.