N.fit(method='fmin_powell', iterlim=1000, tol=.001):

        Causes the normal approximation object to fit itself.

        method: May be one of the following, from the scipy.optimize package:
            -fmin_l_bfgs_b
            -fmin_ncg
            -fmin_cg
            -fmin_powell
            -fmin

        no_callback: Boolean indicating whether or not to use a callback
        function. If True and a callback keyword is provided in kwargs, then
        the user-supplied callback will be used. Otherwise, if False,
        and verbose > 0, a default callback will print iteration progress.

        The kwargs are passed to the scipy.optimize functions. See there
        for more information.

def fit(self, method='fmin_powell', iterlim=1000, tol=.0001, verbose=0,
            no_callback=False, **kwargs):
        """
        N.fit(method='fmin_powell', iterlim=1000, tol=.001):

        Causes the normal approximation object to fit itself.

        method: May be one of the following, from the scipy.optimize package:
            -fmin_l_bfgs_b
            -fmin_ncg
            -fmin_cg
            -fmin_powell
            -fmin

        no_callback: Boolean indicating whether or not to use a callback
        function. If True and a callback keyword is provided in kwargs, then
        the user-supplied callback will be used. Otherwise, if False,
        and verbose > 0, a default callback will print iteration progress.

        The kwargs are passed to the scipy.optimize functions. See there
        for more information.
        """
        self.tol = tol
        self.method = method
        self.verbose = verbose

        p = zeros(self.len, dtype=float)
        for stochastic in self.stochastics:
            p[self._slices[stochastic]] = ravel(stochastic.value)

        if not self.method == 'newton':
            if not scipy_imported:
                raise ImportError('Scipy is required to use EM and NormApprox')

        default_callback = (verbose > 0 and not no_callback)
        if default_callback and 'callback' in kwargs:
            raise ValueError("For user-provided callback and verbose output"
                             " set use_callback to True")

        if default_callback:
            def callback(p):
                try:
                    print_('Current log-probability : %f' % self.logp)
                except ZeroProbability:
                    print_('Current log-probability : %f' % -Inf)
        elif 'callback' in kwargs:
            callback = kwargs.pop('callback')
        else:
            def callback(p):
                pass

        if self.method == 'fmin_ncg':
            p = fmin_ncg(f=self.func,
                         x0=p,
                         fprime=self.gradfunc,
                         fhess=self.hessfunc,
                         epsilon=self.eps,
                         maxiter=iterlim,
                         callback=callback,
                         avextol=tol,
                         disp=verbose,
                         **kwargs)

        elif self.method == 'fmin':

            p = fmin(func=self.func,
                     x0=p,
                     callback=callback,
                     maxiter=iterlim,
                     ftol=tol,
                     disp=verbose, **kwargs)

        elif self.method == 'fmin_powell':
            p = fmin_powell(func=self.func,
                            x0=p,
                            callback=callback,
                            maxiter=iterlim,
                            ftol=tol,
                            disp=verbose, **kwargs)

        elif self.method == 'fmin_cg':
            p = fmin_cg(f=self.func, x0=p,
                        fprime=self.gradfunc,
                        epsilon=self.eps,
                        callback=callback,
                        maxiter=iterlim,
                        gtol=tol,
                        disp=verbose, **kwargs)

        elif self.method == 'fmin_l_bfgs_b':
            from scipy import __version__ as sp_version
            from distutils.version import LooseVersion
            if LooseVersion(sp_version) >= LooseVersion('0.12.0'):
                p = fmin_l_bfgs_b(func=self.func,
                                  x0=p,
                                  fprime=self.gradfunc,
                                  epsilon=self.eps,
                                  callback=callback,
                                  pgtol=tol,
                                  iprint=verbose - 1,
                                  **kwargs)[0]
            else:
                if verbose > 0:
                    from warnings import warn
                    warn("Callbacks are not available for fmin_l_bfgs_b in "
                         "SciPy < 0.12.0. Optimization progress will not be"
                         "displayed.", UserWarning)
                p = fmin_l_bfgs_b(func=self.func,
                                  x0=p,
                                  fprime=self.gradfunc,
                                  epsilon=self.eps,
                                  pgtol=tol,
                                  iprint=verbose - 1,
                                  **kwargs)[0]
        else:
            raise ValueError('Method unknown.')

        self._set_stochastics(p)
        self._mu = p

        try:
            self.logp_at_max = self.logp
        except:
            raise RuntimeError(
                'Posterior probability optimization converged to value with zero probability.')

        lnL = sum([x.logp for x in self.observed_stochastics]
                  )  # log-likelihood of observed stochastics
        self.lnL = lnL
        try:
            self.AIC = 2. * (self.len - lnL)  # 2k - 2 ln(L)
            self.AICc = self.AIC + ((2 * self.len * (self.len + 1)) / float(self.data_len - self.len - 1))
        except Exception as e:
            print('Cannot calculate AIC:', e)
            self.AICc = self.AIC = -Inf
        try:
            self.BIC = self.len * log(
                self.data_len) - 2. * lnL  # k ln(n) - 2 ln(L)
        except FloatingPointError as e:
            print('Cannot calculate BIC:', e)
            self.BIC = -Inf

        self.fitted = True