def movMF(<EOL>X,<EOL>n_clusters,<EOL>posterior_type="<STR_LIT>",<EOL>force_weights=None,<EOL>n_init=<NUM_LIT:10>,<EOL>n_jobs=<NUM_LIT:1>,<EOL>max_iter=<NUM_LIT>,<EOL>verbose=False,<EOL>init="<STR_LIT>",<EOL>random_state=None,<EOL>tol=<NUM_LIT>,<EOL>copy_x=True,<EOL>):
if n_init <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % n_init<EOL>)<EOL><DEDENT>random_state = check_random_state(random_state)<EOL>if max_iter <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % max_iter<EOL>)<EOL><DEDENT>best_inertia = np.infty<EOL>X = as_float_array(X, copy=copy_x)<EOL>tol = _tolerance(X, tol)<EOL>if hasattr(init, "<STR_LIT>"):<EOL><INDENT>init = check_array(init, dtype=X.dtype.type, copy=True)<EOL>_validate_center_shape(X, n_clusters, init)<EOL>if n_init != <NUM_LIT:1>:<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % n_init,<EOL>RuntimeWarning,<EOL>stacklevel=<NUM_LIT:2>,<EOL>)<EOL>n_init = <NUM_LIT:1><EOL><DEDENT><DEDENT>best_centers = None<EOL>best_labels = None<EOL>best_weights = None<EOL>best_concentrations = None<EOL>best_posterior = None<EOL>best_inertia = None<EOL>if n_jobs == <NUM_LIT:1>:<EOL><INDENT>for it in range(n_init):<EOL><INDENT>(centers, weights, concentrations, posterior, labels, inertia) = _movMF(<EOL>X,<EOL>n_clusters,<EOL>posterior_type=posterior_type,<EOL>force_weights=force_weights,<EOL>max_iter=max_iter,<EOL>verbose=verbose,<EOL>init=init,<EOL>random_state=random_state,<EOL>tol=tol,<EOL>)<EOL>if best_inertia is None or inertia < best_inertia:<EOL><INDENT>best_centers = centers.copy()<EOL>best_labels = labels.copy()<EOL>best_weights = weights.copy()<EOL>best_concentrations = concentrations.copy()<EOL>best_posterior = posterior.copy()<EOL>best_inertia = inertia<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>seeds = random_state.randint(np.iinfo(np.int32).max, size=n_init)<EOL>results = Parallel(n_jobs=n_jobs, verbose=<NUM_LIT:0>)(<EOL>delayed(_movMF)(<EOL>X,<EOL>n_clusters,<EOL>posterior_type=posterior_type,<EOL>force_weights=force_weights,<EOL>max_iter=max_iter,<EOL>verbose=verbose,<EOL>init=init,<EOL>random_state=random_state,<EOL>tol=tol,<EOL>)<EOL>for seed in seeds<EOL>)<EOL>centers, weights, concentrations, posteriors, labels, inertia = zip(*results)<EOL>best = np.argmin(inertia)<EOL>best_labels = labels[best]<EOL>best_inertia = inertia[best]<EOL>best_centers = centers[best]<EOL>best_concentrations = concentrations[best]<EOL>best_posterior = posteriors[best]<EOL>best_weights = weights[best]<EOL><DEDENT>return (<EOL>best_centers,<EOL>best_labels,<EOL>best_inertia,<EOL>best_weights,<EOL>best_concentrations,<EOL>best_posterior,<EOL>)<EOL>
Wrapper for parallelization of _movMF and running n_init times.