Fits the mean and variance parameters to the data
324341
private void fitParameters(Map<Long, Double> metricData) {
        mean = getMetricMean(metricData);
        variance = getMetricVariance(metricData);
    }
76415
def zip_fit_params(data):
    
    genes, cells = data.shape
    m = data.mean(1)
    v = data.var(1)
    M = (v-m)/(m**2+v-m)
    #M = v/(v+m**2)
    #M[np.isnan(M)] = 0.0
    M = np.array([min(1.0, max(0.0, x)) for x in M])
    L = m + v/m - 1.0
    #L = (v + m**2)/m
    L[np.isnan(L)] = 0.0
    L = np.array([max(0.0, x) for x in L])
    return L, M
1048914
def stats():
    ''''''
    import re
    import sys
    import math
    values = []
    for line in sys.stdin:
        values.extend(map(float, re.findall(r'\d+\.?\d+', line)))

    mean = sum(values) / len(values)
    variance = sum((val - mean) ** 2 for val in values) / len(values)
    print '%3i items; mean: %10.5f; std-dev: %10.5f' % (
        len(values), mean, math.sqrt(variance))
1282312
def fit_mle(self, data, b=None):
        
        # Take mean of data as MLE of distribution mean, then calculate p
        mu = np.mean(data)
        if not b:
            b = np.sum(data)
        lam = _expon_solve_lam_from_mu_vect(mu, b)

        # Just return float, not len 1 array
        if len(np.atleast_1d(lam)) == 1:
            return float(lam), b
        else:
            return lam, b
155020
def fit(self, X):
        
        params_dict = _fit_gmm_params(X=X, n_mixtures=self.n_clusters, \
                        n_init=self.n_trials, init_method=self.init_method, \
                        n_iter=self.max_iter, tol=self.tol)
        self.priors_ = params_dict['priors']
        self.means_  = params_dict['means']
        self.covars_ = params_dict['covars']

        self.converged = True
        self.labels_ = self.predict(X)
1222742
def moments_match_ep(self, data_i, tau_i, v_i, Y_metadata_i=None):
        
        sigma2_hat = 1./(1./self.variance + tau_i)
        mu_hat = sigma2_hat*(data_i/self.variance + v_i)
        sum_var = self.variance + 1./tau_i
        Z_hat = 1./np.sqrt(2.*np.pi*sum_var)*np.exp(-.5*(data_i - v_i/tau_i)**2./sum_var)
        return Z_hat, mu_hat, sigma2_hat
461994
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        mean = self._get_mean(sites, rup, dists, imt, stddev_types)
        stddevs = [np.ones(len(dists.rrup))*get_sigma(imt)]
        return mean, stddevs
904517
def fit(self, X):
        
        LOGGER.debug('Fitting Gaussian Copula')
        column_names = self.get_column_names(X)
        distribution_class = import_object(self.distribution)

        for column_name in column_names:
            self.distribs[column_name] = distribution_class()
            column = self.get_column(X, column_name)
            self.distribs[column_name].fit(column)

        self.covariance = self._get_covariance(X)
        self.fitted = True
28995
def fit(self, X, y, **fit_params):
        
        return default_client().sync(self._fit, X, y, **fit_params)
669635
def fit(self):
        
        # the objective function that will be minimized in the least square
        # fitting
        objective_func = lambda pars, x, y: y - self._func(x, pars)
        self._params = self._initial_guess()
        self.eos_params, ierr = leastsq(
            objective_func, self._params, args=(self.volumes, self.energies))
        # e0, b0, b1, v0
        self._params = self.eos_params
        if ierr not in [1, 2, 3, 4]:
            raise EOSError("Optimal parameters not found")
492323
def fit_predict(self, X, y=None, **kwargs):
        
        return self.fit(X, **kwargs).predict(X, **kwargs)
168856
def fit(self, X, y=None):
        
        if self.normalize:
            X = normalize(X)

        self._check_force_weights()
        random_state = check_random_state(self.random_state)
        X = self._check_fit_data(X)

        (
            self.cluster_centers_,
            self.labels_,
            self.inertia_,
            self.weights_,
            self.concentrations_,
            self.posterior_,
        ) = movMF(
            X,
            self.n_clusters,
            posterior_type=self.posterior_type,
            force_weights=self.force_weights,
            n_init=self.n_init,
            n_jobs=self.n_jobs,
            max_iter=self.max_iter,
            verbose=self.verbose,
            init=self.init,
            random_state=random_state,
            tol=self.tol,
            copy_x=self.copy_x,
        )

        return self
1074001
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        

        # get mean and std using the superclass
        mean, stddevs = super().get_mean_and_stddevs(
            sites, rup, dists, imt, stddev_types)

        # correction factor (see Atkinson and Boore, 2011; equation 5 at
        # page 1126 and nga08_gm_tmr.for line 508
        corr_fact = 10.0**(np.max([0, 3.888 - 0.674 * rup.mag]) -
                           (np.max([0, 2.933 - 0.510 * rup.mag]) *
                            np.log10(dists.rjb + 10.)))

        return np.log(np.exp(mean)*corr_fact), stddevs
378216
def get_means_and_scales(self):
        
        return self.optim.parameters[::2], np.exp(self.optim.parameters[1::2])
1035235
def fit(self, X, y, n_iter=None):
        """"""
        self.n_iter = self.n_iter if n_iter is None else n_iter
        X = getattr(X, 'values', X).reshape(len(X), 1)
        X_1 = self.homogenize(X)
        for i in range(self.n_iter):
            for i in range(0, len(X), 10):  # minibatch learning for numerical stability
                batch = slice(i, min(i + 10, len(X)))
                Xbatch, ybatch = X[batch, :], y[batch]
                X_1_batch = X_1[batch, :]
                self.W += (self.alpha / len(X) ** 1.5) * (
                    self.delta(Xbatch, ybatch).reshape((len(Xbatch), 1)).T.dot(X_1_batch))
        return self
384844
def fit(self, X):
        
        self.centers_, self.labels_, self.sse_arr_, self.n_iter_ = \
              _kmeans(X, self.n_clusters, self.max_iter, self.n_trials, self.tol)
542179
def fit(self, X, *args, **kwargs):
        

        self.constant_value = self._get_constant_value(X)

        if self.constant_value is None:
            if self.unfittable_model:
                self.model = getattr(scipy.stats, self.model_class)(*args, **kwargs)
            else:
                self.model = getattr(scipy.stats, self.model_class)(X, *args, **kwargs)

            for name in self.METHOD_NAMES:
                attribute = getattr(self.__class__, name)
                if isinstance(attribute, str):
                    setattr(self, name, getattr(self.model, attribute))

                elif attribute is None:
                    setattr(self, name, missing_method_scipy_wrapper(lambda x: x))

        else:
            self._replace_constant_methods()

        self.fitted = True