Returns a dictonary that associates the integer representation of each candidate with the 
        bayesian losses that we calculate using brute force.

        :ivar Profile profile: A Profile object that represents an election profile.
340833
def getCandScoresMapBruteForce(self, profile):
        
        
        wmg = profile.getWmg(True)
        losses = dict()
        for cand in wmg.keys():
            losses[cand] = 0.0

        # Calculate the denominator.
        denom = 0.0
        for permutation in itertools.permutations(wmg.keys()):
            denom = denom + self.phi ** float(self.kendallTau(permutation, wmg))

        for permutation in itertools.permutations(wmg.keys()):
            prob = self.phi**float(self.kendallTau(permutation, wmg))/denom
            for cand in wmg.keys():
                losses[cand] += self.utilityFunction.getUtility([cand], permutation)* prob
        return losses
233897
def ecc(self, n):
        

        """
        ny, nx = self._profile.shape
        xmax, ymax = self._xymax
        xcm, ycm = self._cm

        # create (X, Y) grids relative to CM
        Y, X = np.mgrid[ymax:-ymax:1j*ny, -xmax:xmax:1j*nx]
        X -= xcm
        Y -= ycm

        # create grid of weights = profile * R^n
        Rsq = X*X + Y*Y
        if n == 1:
            W = np.sqrt(Rsq, out=Rsq)
        elif n == 2:
            W = Rsq
        else:
            if n & 1:  # odd n
                W = np.sqrt(Rsq)
            else:  # even n
                W = np.copy(Rsq)
            # multiply by R^2 until W = R^n
            for _ in range(int((n-1)/2)):
                W *= Rsq
        W *= self._profile

        # create grid of e^{i*n*phi} * W
        i_n_phi = np.zeros_like(X, dtype=complex)
        np.arctan2(Y, X, out=i_n_phi.imag)
        i_n_phi.imag *= n
        exp_phi = np.exp(i_n_phi, out=i_n_phi)
        exp_phi *= W

        return abs(exp_phi.sum()) / W.sum()
794633
def profileMain(self, M, z):
        
        c = self.c_M_z(M, z)
        r200 = self.r200_M(M)
        rho0 = self.rho0_c(c)
        Rs = r200/c
        return r200, rho0, c, Rs
53215
def get_profile_ic(self, profile: List) -> Dict:
        
        sim_response = get_attribute_information_profile(self.url, tuple(profile))

        profile_ic = {}
        try:
            for cls in sim_response['input']:
                profile_ic[cls['id']] = cls['IC']
        except JSONDecodeError as json_exc:
            raise JSONDecodeError(
                "Cannot parse owlsim2 response: {}".format(json_exc.msg),
                json_exc.doc,
                json_exc.pos
            )

        return profile_ic
1102850
def MoV_SNTV(profile, K):
    

    # Currently, we expect the profile to contain complete ordering over candidates.
    elecType = profile.getElecType()
    if elecType != "soc" and elecType != "toc" and elecType != "csv":
        print("ERROR: unsupported profile type")
        exit()

    m = profile.numCands
    candScoresMap = MechanismPlurality().getCandScoresMap(profile)
    if K >= m:
        return float("inf")
    # print(candScoresMap)
    sorted_items = sorted(candScoresMap.items(), key=lambda x: x[1], reverse=True)
    sorted_dict = {key: value for key, value in sorted_items}
    sorted_cand = list(sorted_dict.keys())
    MoV = math.floor((sorted_dict[sorted_cand[K - 1]] - sorted_dict[sorted_cand[K]]) / 2) + 1
    return MoV
449190
def calcDrawingProbs(self):
        

        wmg = self.wmg
        phi = self.phi

        # We say the weight of the candidate in position i is phi^i.
        weights = []
        for i in range(0, len(wmg.keys())):
            weights.append(phi**i)

        # Calculate the probabilty that an item at each weight is drawn.
        totalWeight = sum(weights)
        for i in range(0, len(wmg.keys())):
            weights[i] = weights[i]/totalWeight

        return weights
1036242
def coombs_winners(self, profile):
        
        elecType = profile.getElecType()
        if elecType == "soc" or elecType == "csv":
            return self.coombssoc_winners(profile)
        elif elecType == "toc":
            return self.coombstoc_winners(profile)
        else:
            print("ERROR: unsupported profile type")
            exit()
787316
def parse_profile_from_hcard(hcard: str, handle: str):
    
    from federation.entities.diaspora.entities import DiasporaProfile  # Circulars
    doc = html.fromstring(hcard)
    profile = DiasporaProfile(
        name=_get_element_text_or_none(doc, ".fn"),
        image_urls={
            "small": _get_element_attr_or_none(doc, ".entity_photo_small .photo", "src"),
            "medium": _get_element_attr_or_none(doc, ".entity_photo_medium .photo", "src"),
            "large": _get_element_attr_or_none(doc, ".entity_photo .photo", "src"),
        },
        public=True if _get_element_text_or_none(doc, ".searchable") == "true" else False,
        id=handle,
        handle=handle,
        guid=_get_element_text_or_none(doc, ".uid"),
        public_key=_get_element_text_or_none(doc, ".key"),
    )
    return profile
936062
def profile(length=25):
    

    from werkzeug.contrib.profiler import ProfilerMiddleware
    app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[length])
    app.run()
745643
def AppMoVCopeland(profile, alpha=0.5):
    

    # Currently, we expect the profile to contain complete ordering over candidates.
    elecType = profile.getElecType()
    if elecType != "soc" and elecType != "toc":
        print("ERROR: unsupported profile type")
        exit()

    # Initialization
    n = profile.numVoters
    m = profile.numCands

    # Compute the original winner d
    # Initialize each Copeland score as 0.0.
    copelandscores = {}
    for cand in profile.candMap.keys():
        copelandscores[cand] = 0.0

    # For each pair of candidates, calculate the number of votes in which one beat the other.
    wmgMap = profile.getWmg()
    for cand1, cand2 in itertools.combinations(wmgMap.keys(), 2):
        if cand2 in wmgMap[cand1].keys():
            if wmgMap[cand1][cand2] > 0:
                copelandscores[cand1] += 1.0
            elif wmgMap[cand1][cand2] < 0:
                copelandscores[cand2] += 1.0

            # If a pair of candidates is tied, we add alpha to their score for each vote.
            else:
                copelandscores[cand1] += alpha
                copelandscores[cand2] += alpha
    d = max(copelandscores.items(), key=lambda x: x[1])[0]

    #Compute c* = argmin_c RM(d,c)
    relative_margin = {}
    alter_without_d = delete(range(1, m + 1), d - 1)
    for c in alter_without_d:
        relative_margin[c] = RM(wmgMap, n, m, d, c, alpha)
    c_star = min(relative_margin.items(), key=lambda x: x[1])[0]

    return relative_margin[c_star]*(math.ceil(log(m)) + 1)
230701
def profile(func, stream=None):
    
    def wrapper(*args, **kwargs):
        prof = LineProfiler()
        val = prof(func)(*args, **kwargs)
        show_results(prof, stream=stream)
        return val
    return wrapper
483401
def getMaximinScores(profile):
    

    # Currently, we expect the profile to contain complete ordering over candidates. Ties are
    # allowed however.
    elecType = profile.getElecType()
    if elecType != "soc" and elecType != "toc":
        print("ERROR: unsupported election type")
        exit()

    wmgMap = profile.getWmg()
    # Initialize each Copeland score as infinity.
    maximinscores = {}
    for cand in wmgMap.keys():
        maximinscores[cand] = float("inf")

    # For each pair of candidates, calculate the number of votes in which one beat the other.

    # For each pair of candidates, calculate the number of times each beats the other.
    for cand1, cand2 in itertools.combinations(wmgMap.keys(), 2):
        if cand2 in wmgMap[cand1].keys():
            maximinscores[cand1] = min(maximinscores[cand1], wmgMap[cand1][cand2])
            maximinscores[cand2] = min(maximinscores[cand2], wmgMap[cand2][cand1])

    return maximinscores
474918
def profile(self):
        
        if self._profile is None:
            self._profile = self.build_profile()
        return self._profile
1019915
def profile(func):
    
    def inner(*args, **kwargs):

        pr = cProfile.Profile()
        pr.enable()
        res = func(*args, **kwargs)
        pr.disable()
        s = io.StringIO()
        ps = pstats.Stats(pr, stream=s).sort_stats('cumulative')
        ps.print_stats()
        print(s.getvalue())

        return res
    return inner
264650
def getIncEdgesMap(self):
        

        # We calculate the number of incoming edges for each candidate and store it into a dictionary 
        # that associates the number of incoming edges with the candidates with that number.
        incEdgesMap = dict()
        for cand1 in self.wmgMap.keys():
            incEdgesSum = 0
            for cand2 in self.wmgMap[cand1].keys():
                if self.wmgMap[cand1][cand2] > 0:
                    incEdgesSum += self.wmgMap[cand1][cand2]
            
            # Check if this is the first candidate associated with this number of associated edges.
            if incEdgesSum in incEdgesMap.keys():
                incEdgesMap[incEdgesSum].append(cand1)
            else:
                incEdgesMap[incEdgesSum] = [cand1]  

        return incEdgesMap
247732
def getCandScoresMapBruteForce(self, profile):
        

        wmg = profile.getWmg(True)
        m = len(wmg.keys())
        cands = range(m)
        V = self.createBinaryRelation(m)
        gains = dict()
        for cand in wmg.keys():
            gains[cand] = 0
        graphs = itertools.product(range(2), repeat=m*(m-1)/2)
        for comb in graphs:
            prob = 1
            i = 0
            for a, b in itertools.combinations(cands,2):
                V[a][b] = comb[i]
                V[b][a] = 1-comb[i]
                if comb[i] > 0:
                    prob *= 1/(1+self.phi ** float(wmg[a+1][b+1]))
                else:
                    prob *= 1/(1+self.phi ** float(wmg[b+1][a+1]))
                i += 1
                if i >= m*(m-1)/2:
                    break
            for cand in wmg.keys():
                gains[cand] += self.utilityFunction.getUtility([cand], V)*prob
        return gains
1277461
def get_profile(profile, caller, runner):
    '''
    
    '''
    profiles = profile.split(',')
    data = {}
    for profile in profiles:
        if os.path.basename(profile) == profile:
            profile = profile.split('.')[0]  # Trim extension if someone added it
            profile_path = os.path.join(os.path.dirname(__file__), 'profiles', profile + '.yml')
        else:
            profile_path = profile
        if os.path.exists(profile_path):
            try:
                rendered_template = _render_profile(profile_path, caller, runner)
                line = '-' * 80
                log.debug('\n%s\n%s\n%s\n', line, rendered_template, line)
                data.update(yaml.load(rendered_template))
            except Exception as ex:
                log.debug(ex, exc_info=True)
                raise salt.exceptions.SaltException('Rendering profile failed: {}'.format(ex))
        else:
            raise salt.exceptions.SaltException('Profile "{}" is not found.'.format(profile))

    return data