Return the average Adamic/Adar similarity between a brand's followers
    and the followers of each exemplar. We approximate the number of followed
    accounts per user by only considering those in our brand set.
430810
def adamic(brands, exemplars):
    
    print('adamic deprecated...requires loading all brands in memory.')
    return
    degrees = compute_log_degrees(brands, exemplars)
    scores = {}
    exemplar_sums = dict([(exemplar, sum(degrees[z] for z in exemplars[exemplar])) for exemplar in exemplars])

    for brand in sorted(brands):
        brand_sum = sum(degrees[z] for z in brands[brand])
        total = 0.
        for exemplar in exemplars:
            total += sum(degrees[z] for z in brands[brand] & exemplars[exemplar]) / (brand_sum + exemplar_sums[exemplar])
        scores[brand] = total / len(exemplars)
    return scores
81660
def admirers(options = {})
      options = options.merge(:access_token => token, :access_secret => secret) if (token && secret)
      favorite_listings = FavoriteListing.find_all_listings_favored_by(id, options)
      user_ids  = favorite_listings.map {|f| f.user_id }.uniq
      (user_ids.size > 0) ? Array(Etsy::User.find(user_ids, options)) : []
    end
1083353
def similarity(color)
      distance({ :r => @red, :g => @green, :b => @blue}, { :r => color.red, :g => color.green, :b => color.blue}) / sqrt(3 * (255 ** 2))
    end
1085880
def similarity(self, other: 'Trigram') -> float:
        
        if not len(self._trigrams) or not len(other._trigrams):
            return 0

        count = float(len(self._trigrams & other._trigrams))
        len1 = float(len(self._trigrams))
        len2 = float(len(other._trigrams))

        return count / (len1 + len2 - count)
739592
def similarity1DdiffShapedArrays(arr1, arr2, normalize=False):
    
    # assign longer and shorter here, because jit cannot do it
    if len(arr1) < len(arr2):
        arr1, arr2 = arr2, arr1
    if not len(arr2):
        out = sum(arr1)
    else:
        out = _calc(arr1, arr2)

    if normalize:
        if not len(arr2):
            mn = arr1[0]
            mx = arr1[-1]
        else:
            mn = min(arr1[0], arr2[0])
            mx = max(arr1[-1], arr2[-1])
        out = out/ (mx - mn)

    return out
1370218
def followers(self, actor, flag=''):
        
        return [follow.user for follow in self.followers_qs(actor, flag=flag)]
812007
def get_followers_following(username)
      {
        following: @octokit.following(username).length,
        followers: @octokit.followers(username).length
      }
    end
644462
def fit(self, weighted, show_progress=True):
        
        self.similarity = all_pairs_knn(weighted, self.K,
                                        show_progress=show_progress,
                                        num_threads=self.num_threads).tocsr()
        self.scorer = NearestNeighboursScorer(self.similarity)
821658
def _calculate_similarity(c):
    
    ma = {}
    for idc in c:
        set1 = _get_seqs(c[idc])
        [ma.update({(idc, idc2): _common(set1, _get_seqs(c[idc2]), idc, idc2)}) for idc2 in c if idc != idc2 and (idc2, idc) not in ma]
    # logger.debug("_calculate_similarity_ %s" % ma)
    return ma
1235343
def similarities(self, rank):
        
        self._check_rank(rank)
        return [result.similarity for result in self.results[rank]]
51832
def _similarity_matrix(self, concepts):
        
        n_cons = len(concepts)
        sim_mat = np.zeros((n_cons, n_cons))
        for i, c1 in enumerate(concepts):
            for j, c2 in enumerate(concepts):
                # Just build the lower triangle
                if i >= j:
                    sim_mat[i,j] = self._semsim(c1, c2) if i != j else 1.
        return sim_mat + sim_mat.T - np.diag(sim_mat.diagonal())
1019544
public void similar(IMatrix U, IMatrix result) {
        if ((result.rows != U.columns) || (result.columns != U.columns)) result.reshape(U.columns, U.columns);

        double realsum, imagsum, realinnersum, imaginnersum;
        for (int i = 0; i < U.columns; i++)
            for (int j = 0; j < U.columns; j++) {
                realsum = 0d;
                imagsum = 0d;
                for (int k = 0; k < U.columns; k++) {
                    realinnersum = 0d;
                    imaginnersum = 0d;
                    for (int l = 0; l < U.columns; l++) {
                        realinnersum += realmatrix[k][l] * U.realmatrix[l][j] - imagmatrix[k][l] * U.imagmatrix[l][j];
                        imaginnersum += realmatrix[k][l] * U.imagmatrix[l][j] + imagmatrix[k][l] * U.realmatrix[l][j];
                    }
                    realsum += U.realmatrix[k][i] * realinnersum - U.imagmatrix[k][i] * imaginnersum;
                    imagsum += U.realmatrix[k][i] * imaginnersum + U.imagmatrix[k][i] * realinnersum;
                }
                result.realmatrix[i][j] = realsum;
                result.imagmatrix[i][j] = imagsum;
            }
    }
97909
def get_similar_entries(context, number=5,
                        template='zinnia/tags/entries_similar.html'):
    
    entry = context.get('entry')
    if not entry:
        return {'template': template, 'entries': []}

    vectors = EntryPublishedVectorBuilder()
    entries = vectors.get_related(entry, number)

    return {'template': template,
            'entries': entries}
123774
def follower_ids(self, user):
        
        user = str(user)
        user = user.lstrip('@')
        url = 'https://api.twitter.com/1.1/followers/ids.json'

        if re.match(r'^\d+$', user):
            params = {'user_id': user, 'cursor': -1}
        else:
            params = {'screen_name': user, 'cursor': -1}

        while params['cursor'] != 0:
            try:
                resp = self.get(url, params=params, allow_404=True)
            except requests.exceptions.HTTPError as e:
                if e.response.status_code == 404:
                    log.info("no users matching %s", screen_name)
                raise e
            user_ids = resp.json()
            for user_id in user_ids['ids']:
                yield str_type(user_id)
            params['cursor'] = user_ids['next_cursor']
1198286
def followers(self):
        
        if self._followers is None:
            self.assert_bind_client()
            if self.follower_count > 0:
                self._followers = self.bind_client.get_athlete_followers(self.id)
            else:
                # Shortcut if we know there aren't any
                self._followers = []
        return self._followers
446435
def similarity(self, other):
        """"""
        ratio = 1.0 if (str(self).lower() == str(other).lower()) else 0.0
        similarity = self.Similarity(ratio)
        return similarity
324659
def correlation_by_exemplar(brands, exemplars, validation_scores, analyze_fn_str, outf):
    
    analyze_fn = getattr(analyze, analyze_fn_str)
    keys = sorted(k for k in validation_scores.keys() if k in set(x[0] for x in brands))
    truth = [validation_scores[k] for k in keys]
    result = {}
    outf.write('exemplar\tcorr\tn_followers\n')
    outf.flush()
    for exemplar in exemplars:
        single_exemplar = {exemplar: exemplars[exemplar]}
        social_scores = analyze_fn(brands, single_exemplar)
        predicted = [social_scores[k] for k in keys]
        outf.write('%s\t%g\t%d\n' % (exemplar, scistat.pearsonr(predicted, truth)[0], len(exemplars[exemplar])))
        outf.flush()
        result[exemplar] = scistat.pearsonr(predicted, truth)[0]
    outf.close()
    return result