Beispiel #1
0
    def __init__(self, r=None, j=None, M=None, N=None, x=None, v=None, pred=None, 
                 Avv=None, lam = 0.0, dtd = None, 
                 atol = 1e-6, rtol = 1e-6, callback=None, parameterspacenorm=False,
                 pids=None, in_logp=False):
        '''
        Initiate variables for calculating the geodesic 
        inputs:
            r - residual function
            j - jacobian function
            Avv - second directional derivative function
            M - data space dimension
            N - parameter space dimension
            x - starting position
            v - starting direction
            lam - parameter which scales the addition to g (ie g = j^T j + lam *dtd, addition helps with small singular values)
            dtd - identity matrix of size N
            atol - absolute tolerance
            rtol - relative tolerance
            callback - optional function to determine whether to stop geodesic
            parameterspacenorm - whether to restrict a to be perpendicular to v (ie. no acceleration along v, |v|=1)
        outputs:
            set state of ode for finding the geodesic
        '''
        if pred:
            r, j, M, N, pids = pred.f, pred.Df, len(pred.dids), len(pred.pids), pred.pids
            if x is None:
                x = pred.p0
            if v is None:
                v = pred.get_sloppyv(x)
            
        if Avv is None:
            Avv = lambda x, v: (r(x+0.1*v) + r(x-0.1*v) - 2.0*r(x))/0.01

        self.r, self.j, self.Avv = r, j, Avv
        self.M, self.N = M, N
        self.lam = lam
        if dtd is None:
            self.dtd = np.eye(N)
        else:
            self.dtd = dtd
        self.atol = atol
        self.rtol = rtol
        ode.__init__(self, self.geodesic_rhs, jac = None)
        self.set_initial_value(x, v)
        ode.set_integrator(self, 'vode', atol = atol, rtol = rtol)
        if callback is None:
            self.callback = callback_func
        elif callback == 'volume':
            self.callback = lambda t,x,v: self.vols[-1] > self.vols[0] * 0.01**N
        else:
            self.callback = callback
        self.parameterspacenorm = parameterspacenorm
        self.pids = pids
        self.in_logp = in_logp
Beispiel #2
0
 def __init__(self,
              r,
              j,
              Avv,
              M,
              N,
              x,
              v,
              lam=0.0,
              dtd=None,
              atol=1e-6,
              rtol=1e-6,
              callback=None,
              parameterspacenorm=False,
              invSVD=False):
     """
     Construct an instance of the geodesic object
     r = function for calculating the model.  This is not needed for the geodesic, but is used to save the geodesic path in data space.  Called as r(x)
     j = function for calculating the jacobian of the model with respect to parameters.  Called as j(x)
     Avv = function for calculating the second directional derivative of the model in a direction v.  Called as Avv(x,v)
     M = Number of model predictions
     N = Number of model parameters
     x = vector of initial parameter values
     v = vector of initial velocity
     lam = set to nonzero to calculate geodesic on the model graph.
     dtd = metric for the parameter space contribution to the model graph
     atol = absolute tolerance for solving the geodesic
     rtol = relative tolerance for solving geodesic
     callback = function called after each geodesic step.  Called as callback(geo) where geo is the current instance of the geodesic class.
     parameterspacenorm = Set to True to reparameterize the geodesic to have a constant parameter space norm.  (Default is to have a constant data space norm.)
     invSVD = Set to true to use the singular value decomposition to calculate the inverse metric.  This is slower, but can help with nearly singular FIM.
     """
     self.r, self.j, self.Avv = r, j, Avv
     self.M, self.N = M, N
     self.lam = lam
     if dtd is None:
         self.dtd = np.eye(N)
     else:
         self.dtd = dtd
     self.atol = atol
     self.rtol = rtol
     ode.__init__(self, self.geodesic_rhs, jac=None)
     self.set_initial_value(x, v)
     ode.set_integrator(self, 'vode', atol=atol, rtol=rtol)
     if callback is None:
         self.callback = callback_func
     else:
         self.callback = callback
     self.parameterspacenorm = parameterspacenorm
     self.invSVD = False
Beispiel #3
0
 def __init__(self, r, j, Avv, M, N, x, v, lam = 0.0, dtd = None, atol = 1e-6, rtol = 1e-6, callback = None, parameterspacenorm = False):
     self.r, self.j, self.Avv = r, j, Avv
     self.M, self.N = M, N
     self.lam = lam
     if dtd is None:
         self.dtd = np.eye(N)
     else:
         self.dtd = dtd
     self.atol = atol
     self.rtol = rtol
     ode.__init__(self, self.geodesic_rhs, jac = None)
     self.set_initial_value(x, v)
     ode.set_integrator(self, 'vode', atol = atol, rtol = rtol)
     if callback is None:
         self.callback = callback_func
     else:
         self.callback = callback
     self.parameterspacenorm = parameterspacenorm
Beispiel #4
0
 def __init__(self, f, jac=None):
     w = lambda t, y, args: array(f(t, self.cint, *args), 'float32')
     ode.__init__(self, w, jac)
     self.set_f_params(())