コード例 #1
0
    def hessian_compute_fit_old(self, lm_lambda=None):
        "take one Hessian fitting step  if lm_lambda undefined, otherwise make Levenberg-Marquardt adjustment"

        if hasattr(self, 'fitmat'):
            del self.fitmat
            # if we are recycing, thoroughly clean up possibly huge objects
            self.collect()

        n = self.pointcount
        fxarray = self.derivs()

        self.set_weights()
        fxwarray = self.weights_multiply(Numeric.transpose(fxarray))
        self.fitmat = dot(fxwarray, fxarray)

        # make Levenberg-Marquardt correction to inverse-covariance matrix
        if lm_lambda is not None:
            for i in range(self.param_count):
                self.fitmat[i, i] *= (1.0 + lm_lambda)

        for i in range(self.param_count):  # handle frozen parameters
            if self.frozen[i]:
                self.fitmat[i, :] = 0.0
                self.fitmat[:, i] = 0.0
                self.fitmat[i, i] = 1.0

        if (self.firstpass):
            self.funcvals = self.compute_funcvals()
            self.firstpass = 0

        self.fitvector = solve_linear_equations(
            self.fitmat, dot(fxwarray, self.yarray[:n] - self.funcvals))
        self.funcparams = self.funcparams + self.fitvector * (1 - self.frozen)
        self.funcvals = self.compute_funcvals()
        self.compute_chi2()
コード例 #2
0
	def hessian_compute_fit(self, lm_lambda=None): 
		"take one Hessian fitting step  if lm_lambda undefined, otherwise make Levenberg-Marquardt adjustment"
		
		if hasattr(self, 'fitmat'):
			del self.fitmat
			self.collect() #if we are recycing, thoroughly clean up possibly huge objects
			
		n=self.pointcount		
		fxarray=self.derivs()

		self.set_weights()
		fxwarray=self.weights_multiply(Numeric.transpose(fxarray))
		self.fitmat=dot(fxwarray, fxarray)
		
		if lm_lambda is not None: #make Levenberg-Marquardt correction to inverse-covariance matrix
			for i in range(self.param_count):
				self.fitmat[i,i]*=(1.0+lm_lambda)
				
		for i in range(self.param_count): #handle frozen parameters
			if self.frozen[i]:
				self.fitmat[i,:]=0.0
				self.fitmat[:,i]=0.0
				self.fitmat[i,i]=1.0

		if(self.firstpass):
			self.funcvals=self.compute_funcvals()
			self.firstpass=0

		self.fitvector=solve_linear_equations(self.fitmat, dot(fxwarray, self.yarray[:n]-self.funcvals) )
		self.funcparams=self.funcparams+self.fitvector*(1-self.frozen)
		self.funcvals=self.compute_funcvals()
		self.compute_chi2()			
コード例 #3
0
def lowess(x, y, f=2./3., iter=3):
  """lowess(x, y, f=2./3., iter=3) -> yest

Lowess smoother: Robust locally weighted regression.
The lowess function fits a nonparametric regression curve to a scatterplot.
The arrays x and y contain an equal number of elements; each pair
(x[i], y[i]) defines a data point in the scatterplot. The function returns
the estimated (smooth) values of y.

The smoothing span is given by f. A larger value for f will result in a
smoother curve. The number of robustifying iterations is given by iter. The
function will run faster with a smaller number of iterations."""
  n = len(x)
  r = int(ceil(f*n))
  h = [sort(abs(x-x[i]))[r] for i in range(n)]
  w = clip(abs(([x]-transpose([x]))/h),0.0,1.0)
  w = 1-w*w*w
  w = w*w*w
  yest = zeros(n,'d')
  delta = ones(n,'d')
  for iteration in range(iter):
    for i in range(n):
      weights = delta * w[:,i]
      b = array([sum(weights*y), sum(weights*y*x)])
      A = array([[sum(weights),   sum(weights*x)],
                 [sum(weights*x), sum(weights*x*x)]])
      beta = solve_linear_equations(A,b)
      yest[i] = beta[0] + beta[1]*x[i]
    residuals = y-yest
    s = median(abs(residuals))
    delta = clip(residuals/(6*s),-1,1)
    delta = 1-delta*delta
    delta = delta*delta
  return yest
コード例 #4
0
    def hessian_compute_fit(self, lm_lambda=None):
        "take one Hessian fitting step  if lm_lambda undefined, otherwise make Levenberg-Marquardt adjustment"

        if hasattr(self, 'fitmat'):
            del self.fitmat
            # if we are recycing, thoroughly clean up possibly huge objects
            self.collect()

        n = self.pointcount
        fxarray = self.derivs()

        self.set_weights()
        fxwarray = self.weights_multiply(Numeric.transpose(fxarray))
        self.fitmat = dot(fxwarray, fxarray)

        # make Levenberg-Marquardt correction to inverse-covariance matrix
        if lm_lambda is not None:
            for i in range(self.param_count):
                self.fitmat[i, i] *= (1.0 + lm_lambda)

        for i in range(self.param_count):  # handle frozen parameters
            if self.frozen[i]:
                self.fitmat[i, :] = 0.0
                self.fitmat[:, i] = 0.0
                self.fitmat[i, i] = 1.0

        mask = 1 - self.frozen

        # compress out rows & columns of frozen parameters, to make fit much faster
        if numpy.any(self.frozen):
            fitmat = self.fitmat.compress(mask, 0).compress(mask, 1)
        else:
            fitmat = self.fitmat

        if self.firstpass:
            self.funcvals = self.compute_funcvals()
            self.firstpass = 0

        # compress corresponding elements out of the 'y' array
        yarray = dot(fxwarray, self.yarray[:n] - self.funcvals).compress(mask)

        fitvector = solve_linear_equations(fitmat, yarray)

        fullfit = Numeric.zeros_like(self.funcparams)

        # uncompress fit vector
        idx = 0
        for i in xrange(self.param_count):
            if mask[i]:
                fullfit[i] = fitvector[idx]
                idx += 1

        self.funcparams = self.funcparams + fullfit * (1 - self.frozen)
        self.funcvals = self.compute_funcvals()
        self.compute_chi2()
コード例 #5
0
  def hessian_compute_fit(self, lm_lambda=None):
    "take one Hessian fitting step  if lm_lambda undefined, otherwise make Levenberg-Marquardt adjustment"

    if hasattr(self, 'fitmat'):
      del self.fitmat
      # if we are recycing, thoroughly clean up possibly huge objects
      self.collect()

    n = self.pointcount
    fxarray = self.derivs()

    self.set_weights()
    fxwarray = self.weights_multiply(Numeric.transpose(fxarray))
    self.fitmat = dot(fxwarray, fxarray)

    # make Levenberg-Marquardt correction to inverse-covariance matrix
    if lm_lambda is not None:
      for i in range(self.param_count):
        self.fitmat[i, i] *= (1.0 + lm_lambda)

    for i in range(self.param_count):  # handle frozen parameters
      if self.frozen[i]:
        self.fitmat[i, :] = 0.0
        self.fitmat[:, i] = 0.0
        self.fitmat[i, i] = 1.0

    mask = 1 - self.frozen

    # compress out rows & columns of frozen parameters, to make fit much faster
    if numpy.any(self.frozen):
      fitmat = self.fitmat.compress(mask, 0).compress(mask, 1)
    else:
      fitmat = self.fitmat

    if self.firstpass:
      self.funcvals = self.compute_funcvals()
      self.firstpass = 0

    # compress corresponding elements out of the 'y' array
    yarray = dot(fxwarray, self.yarray[:n] - self.funcvals).compress(mask)

    fitvector = solve_linear_equations(fitmat, yarray)

    fullfit = Numeric.zeros_like(self.funcparams)

    # uncompress fit vector
    idx = 0
    for i in xrange(self.param_count):
      if mask[i]:
        fullfit[i] = fitvector[idx]
        idx += 1

    self.funcparams = self.funcparams + fullfit * (1 - self.frozen)
    self.funcvals = self.compute_funcvals()
    self.compute_chi2()
コード例 #6
0
def planepoint(v, i, j, k):
    mat = V(polyMat[i], polyMat[j], polyMat[k])
    vec = V(v[i], v[j], v[k])
    return solve_linear_equations(mat, vec)
コード例 #7
0
 def CoordinatesFromCartesianCoordinates(self, coordinates):
     from LinearAlgebra import solve_linear_equations
     return solve_linear_equations(transpose(self.GetBasis()),
                                   asarray(coordinates))
コード例 #8
0
def planepoint(v,i,j,k):
    mat = V(polyMat[i],polyMat[j],polyMat[k])
    vec = V(v[i],v[j],v[k])
    return solve_linear_equations(mat, vec)
コード例 #9
0
    def CoordinatesFromCartesianCoordinates(self,coordinates):
	from LinearAlgebra import solve_linear_equations
	return solve_linear_equations(transpose(self.GetBasis()),asarray(coordinates))