<commit_before>import time

import numpy as np
import numpy.random as rnd

from pymanopt.solvers.solver import Solver


class ParticleSwarm(Solver):
    """Particle swarm optimization method."""

    def __init__(self, maxcostevals=None, maxiter=None, populationsize=None,
                 nostalgia=1.4, social=1.4, *args, **kwargs):
        """
        Instantiate Particle Swarm Optimization (PSO) solver class.
        Variable attributes (defaults in brackets):
            - maxcostevals (max(5000, 2 * dim))
                Maximum number of allowed cost evaluations
            - maxiter (max(500, 4 * dim))
                Maximum number of allowed iterations
            - populationsize (min(40, 10 * dim))
                Size of the considered swarm population
            - nostalgia (1.4)
                Quantifies performance relative to past performances
            - social (1.4)
                Quantifies performance relative to neighbors
        """
        super().__init__(*args, **kwargs)

        self._maxcostevals = maxcostevals
        self._maxiter = maxiter
        self._populationsize = populationsize
        self._nostalgia = nostalgia
        self._social = social

    def solve(self, problem, x=None):
        """
        Perform optimization using the particle swarm optimization algorithm.
        Arguments:
            - problem
                Pymanopt problem setup using the Problem class, this must
                have a .manifold attribute specifying the manifold to optimize
                over, as well as a cost (specified using a theano graph
                or as a python function).
            - x=None
                Optional parameter. Initial population of elements on the
                manifold. If None then an initial population will be randomly
                generated
        Returns:
            - x
                Local minimum of obj, or if algorithm terminated before
                convergence x will be the point at which it terminated
        """
        man = problem.manifold
        verbosity = problem.verbosity
        objective = problem.cost

        # Choose proper default algorithm parameters. We need to know about the
        # dimension of the manifold to limit the parameter range, so we have to
        # defer proper initialization until this point.<commit_msg>Fix sphinx warnings for PSO algorithm<commit_after>import time

import numpy as np
import numpy.random as rnd

from pymanopt.solvers.solver import Solver


class ParticleSwarm(Solver):
    """Particle swarm optimization (PSO) method.

    Perform optimization using the derivative-free particle swarm optimization
    algorithm.

    Args:
        maxcostevals: Maximum number of allowed cost evaluations.
        maxiter: Maximum number of allowed iterations.
        populationsize: Size of the considered swarm population.
        nostalgia: Quantifies performance relative to past performances.
        social: Quantifies performance relative to neighbors.
    """

    def __init__(self, maxcostevals=None, maxiter=None, populationsize=None,
                 nostalgia=1.4, social=1.4, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self._maxcostevals = maxcostevals
        self._maxiter = maxiter
        self._populationsize = populationsize
        self._nostalgia = nostalgia
        self._social = social

    def solve(self, problem, x=None):
        """Run PSO algorithm.

        Args:
            problem: Pymanopt problem class instance exposing the cost function
                and the manifold to optimize over.
            x: Initial point on the manifold.
                If no value is provided then a starting point will be randomly
                generated.
        Returns:
            Local minimum of the cost function, or the most recent iterate if
            algorithm terminated before convergence.
        """
        man = problem.manifold
        verbosity = problem.verbosity
        objective = problem.cost

        # Choose proper default algorithm parameters. We need to know about the
        # dimension of the manifold to limit the parameter range, so we have to
        # defer proper initialization until this point.
{'fraction_non_alphanumeric': 0.056617126680820945, 'fraction_numerical': 0.005897617362585515, 'mean_word_length': 2.136094674556213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3085029', 'n_tokens_mistral': 1038, 'n_tokens_neox': 953, 'n_words': 406}