'Fit the unconditional maximum likelihood of an AR(p) process.
Parameters
start_params : array-like, optional
A first guess on the parameters.  Defaults is a vector of zeros.
method : str, optional
Unconstrained solvers:
Default is \'bfgs\', \'newton\' (newton-raphson), \'ncg\'
(Note that previous 3 are not recommended at the moment.)
and \'powell\'
Constrained solvers:
\'bfgs-b\', \'tnc\'
See notes.
maxiter : int, optional
The maximum number of function evaluations. Default is 35.
tol = float
The convergence tolerance.  Default is 1e-08.
penalty : bool
Whether or not to use a penalty function.  Default is False,
though this is ignored at the moment and the penalty is always
used if appropriate.  See notes.
Notes
The unconstrained solvers use a quadratic penalty (regardless if
penalty kwd is True or False) in order to ensure that the solution
stays within (-1,1).  The constrained solvers default to using a bound
of (-.999,.999).'

def fit(self, start_params=None, method='bfgs', maxiter=35, tol=1e-08, penalty=False):

    self.penalty = penalty
    method = method.lower()
    minfunc = (lambda params: (- self.loglike(params)))
    if (method in ['newton', 'bfgs', 'ncg']):
        super(AR, self).fit(start_params=start_params, method=method, maxiter=maxiter, tol=tol)
    else:
        bounds = [((-0.999), 0.999)]
        if (start_params == None):
            start_params = np.array([0])
        if (method == 'bfgs-b'):
            retval = optimize.fmin_l_bfgs_b(minfunc, start_params, approx_grad=True, bounds=bounds)
            (self.params, self.llf) = retval[0:2]
        if (method == 'tnc'):
            retval = optimize.fmin_tnc(minfunc, start_params, approx_grad=True, bounds=bounds)
            self.params = retval[0]
        if (method == 'powell'):
            retval = optimize.fmin_powell(minfunc, start_params)
            self.params = retval[None]
