Returns KTensor factors for models with specified rank.
176879
def factors(self, rank):
        
        self._check_rank(rank)
        return [result.factors for result in self.results[rank]]
548666
def variance_inflation_factors(df):
    '''
    
    '''
    corr = np.corrcoef(df, rowvar=0)
    corr_inv = np.linalg.inv(corr)
    vifs = np.diagonal(corr_inv)
    return pd.Series(vifs, df.columns, name='VIF')
894576
def getFactors(self, aLocation, axisOnly=False, allFactors=False):
        
        deltas = []
        aLocation.expand(self.getAxisNames())
        limits = getLimits(self._allLocations(), aLocation)
        for deltaLocationTuple, (mathItem, deltaName) in sorted(self.items()):
            deltaLocation = Location(deltaLocationTuple)
            deltaLocation.expand( self.getAxisNames())
            factor = self._accumulateFactors(aLocation, deltaLocation, limits, axisOnly)
            if not (factor-_EPSILON < 0 < factor+_EPSILON) or allFactors:
                # only add non-zero deltas.
                deltas.append((factor, mathItem, deltaName))
        deltas = sorted(deltas, key=itemgetter(0), reverse=True)
        return deltas
303137
def rank(self, n, mu, sigma, crit=.5, upper=10000, xtol=1):
        

        return _make_rank(self, n, mu, sigma, crit=crit, upper=upper,
                                                                    xtol=xtol)
1269652
def get_factor_list(self):
        
        factors = self.get_factor_from_api()
        if not factors:
            return []
        ml = [[int(x)] * y for x, y in factors]
        return [y for x in ml for y in x]
489804
def top_k_accuracy(input:Tensor, targs:Tensor, k:int=5)->Rank0Tensor:
    ""
    input = input.topk(k=k, dim=-1)[1]
    targs = targs.unsqueeze(dim=-1).expand_as(input)
    return (input == targs).max(dim=-1)[0].float().mean()
558910
def priorfactors(self):
        
        priorfactors = {}
        for pop in self.poplist:
            for f in pop.priorfactors:
                if f in priorfactors:
                    if pop.priorfactors[f] != priorfactors[f]:
                        raise ValueError('prior factor %s is inconsistent!' % f)
                else:
                    priorfactors[f] = pop.priorfactors[f]
        return priorfactors
934126
def get_moments(model,x):
    '''
    

    '''
    input_dim = model.X.shape[1]
    x = reshape(x,input_dim)
    fmin = min(model.predict(model.X)[0])
    m, v = model.predict(x)
    s = np.sqrt(np.clip(v, 0, np.inf))
    return (m,s, fmin)
388266
def indexes_to_fix_for_low_rank(rank, size):
    
    #first we'll work out what to keep, and the do the set difference.

    #here are the indexes of the first column, which are the triangular numbers
    n = np.arange(size)
    triangulars = (n**2 + n) / 2
    keep = []
    for i in range(rank):
        keep.append(triangulars[i:] + i)
    #add the diagonal
    keep.append(triangulars[1:]-1)
    keep.append((size**2 + size)/2 -1)# the very last element
    keep = np.hstack(keep)

    return np.setdiff1d(np.arange((size**2+size)/2), keep)
1022664
def available_parameters_subset(self, mx_params):
        
        from copy import copy
        from collections import OrderedDict
        subset_params = copy(mx_params)
        subset_params._params = OrderedDict([
            (k, v) for k, v in mx_params.items() if k in self.weight_names
        ])
        return subset_params
882706
def get_factors_iterative1(n):
    

    todo, res = [(n, 2, [])], []
    while todo:
        n, i, combi = todo.pop()
        while i * i <= n:
            if n % i == 0:
                res += combi + [i, n//i],
                todo.append((n//i, i, combi+[i])),
            i += 1
    return res
930006
def _rank(self, ranking, n):
    
    return nlargest(n, ranking, key=ranking.get)
209378
def factors(self):
        
        if self._factors is None:
            self._factors = FactorList(
                self._version,
                service_sid=self._solution['service_sid'],
                identity=self._solution['identity'],
            )
        return self._factors
1101441
def klm(p, q):
    """"""
    p, q = flatten(p), flatten(q)
    return max(abs(p * np.nan_to_num(np.log(p / q))))
346292
def _mm_rankings(n_items, data, params):
    """"""
    weights = exp_transform(params)
    wins = np.zeros(n_items, dtype=float)
    denoms = np.zeros(n_items, dtype=float)
    for ranking in data:
        sum_ = weights.take(ranking).sum()
        for i, winner in enumerate(ranking[:-1]):
            wins[winner] += 1
            val = 1.0 / sum_
            for item in ranking[i:]:
                denoms[item] += val
            sum_ -= weights[winner]
    return wins, denoms
851675
def ranked_attributes(self):
        
        matrix = javabridge.call(self.jobject, "rankedAttributes", "()[[D")
        if matrix is None:
            return None
        else:
            return arrays.double_matrix_to_ndarray(matrix)
1348579
public Set<Integer> getAdjacentFactors(int factorNum) {
    Set<Integer> adjacentFactors = Sets.newHashSet();
    for (Integer variableNum : factorVariableMap.get(factorNum)) {
      adjacentFactors.addAll(variableFactorMap.get(variableNum));
    }
    return adjacentFactors;
  }