Computes the spectral entropy
348905
def stSpectralEntropy(X, n_short_blocks=10):
    """"""
    L = len(X)                         # number of frame samples
    Eol = numpy.sum(X ** 2)            # total spectral energy

    sub_win_len = int(numpy.floor(L / n_short_blocks))   # length of sub-frame
    if L != sub_win_len * n_short_blocks:
        X = X[0:sub_win_len * n_short_blocks]

    sub_wins = X.reshape(sub_win_len, n_short_blocks, order='F').copy()  # define sub-frames (using matrix reshape)
    s = numpy.sum(sub_wins ** 2, axis=0) / (Eol + eps)                      # compute spectral sub-energies
    En = -numpy.sum(s*numpy.log2(s + eps))                                    # compute spectral entropy

    return En
272402
public static EntropyStats entropy(Matrix m) {
        if (m instanceof SparseMatrix)
            return entropy((SparseMatrix) m);

        double sum = 0;
        double[] colSums = new double[m.columns()];
        double[] rowSums = new double[m.rows()];
        for (int r = 0; r < m.rows(); ++r) {
            for (int c = 0; c < m.columns(); ++c) {
                double v = m.get(r, c);
                sum += v;
                colSums[c] += v;
                rowSums[r] += v;
            }
        }

        double entropy = 0;
        double[] colEntropy = new double[m.columns()];
        double[] rowEntropy = new double[m.rows()];
        for (int r = 0; r < m.rows(); ++r) {
            for (int c = 0; c < m.columns(); ++c) {
                double v = m.get(r, c);
                if (v != 0d) {
                    entropy -= entropy(v, sum);
                    colEntropy[c] -= entropy(v, colSums[c]);
                    rowEntropy[r] -= entropy(v, rowSums[r]);
                }
            }
        }
        return new EntropyStats(entropy, colEntropy, rowEntropy);
    }
299203
def entropy(args):
    
    p = OptionParser(entropy.__doc__)
    p.add_option("--threshold", default=0, type="int",
                help="Complexity needs to be above")
    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    kmc_out, = args
    fp = open(kmc_out)
    for row in fp:
        kmer, count = row.split()
        score = entropy_score(kmer)
        if score >= opts.threshold:
            print(" ".join((kmer, count, "{:.2f}".format(score))))
1303801
def get_entropy(self):
        
        dim = self.mu.shape[0]
        entropy = 0.5 * (dim * (numpy.log(2. * numpy.pi) + 1.) + numpy.log(self.det))
        return entropy
402884
def cond_entropy(x, y, bins_y=None, bins_xy=None, method='nearest-neighbors', units='bits'):
    '''
    
    '''
    HXY = entropy(data=np.concatenate([x, y], axis=1), bins=bins_xy, method=method, units=units)
    HY  = entropy(data=y, bins=bins_y, method=method, units=units)

    return HXY - HY
257461
def entropy(string):
    """"""
    p, lns = Counter(string), float(len(string))
    return -sum(count/lns * math.log(count/lns, 2) for count in p.values())
36256
def get_spectral_index(src, egy):
    """"""
    delta = 1E-5
    f0 = src.spectrum()(pyLike.dArg(egy * (1 - delta)))
    f1 = src.spectrum()(pyLike.dArg(egy * (1 + delta)))

    if f0 > 0 and f1 > 0:
        gamma = np.log10(f0 / f1) / np.log10((1 - delta) / (1 + delta))
    else:
        gamma = np.nan

    return gamma
680724
def main():
    
    args = parse_args()

    try:
        s = pyhsm.base.YHSM(device=args.device, debug=args.debug)
        get_entropy(s, args.iterations, args.ratio)
        return 0
    except pyhsm.exception.YHSM_Error as e:
        sys.stderr.write("ERROR: %s" % (e.reason))
        return 1
663559
def entropy_variance(data, class_attr=None,
    method=DEFAULT_CONTINUOUS_METRIC):
    
    assert method in CONTINUOUS_METRICS, "Unknown entropy variance metric: %s" % (method,)
    assert (class_attr is None and isinstance(data, dict)) \
        or (class_attr is not None and isinstance(data, list))
    if isinstance(data, dict):
        lst = data
    else:
        lst = [record.get(class_attr) for record in data]
    return get_variance(lst)
839227
def entropy(self):
    
    if self.k < self.n:
      _, entropy = binaryEntropy(self.dutyCycle)
      return entropy
    else:
      return 0
1311069
def entropy(string):
    """"""
    entropy = 0
    for number in range(256):
        result = float(string.encode('utf-8').count(
            chr(number))) / len(string.encode('utf-8'))
        if result != 0:
            entropy = entropy - result * math.log(result, 2)
    return entropy
1239814
def __entropy(data):
    ''''''
    # normalize and convert to float
    data = data/float(numpy.sum(data))
    # for each grey-value g with a probability p(g) = 0, the entropy is defined as 0, therefore we remove these values and also flatten the histogram
    data = data[numpy.nonzero(data)]
    # compute entropy
    return -1. * numpy.sum(data * numpy.log2(data))
142622
def stSpectralFlux(X, X_prev):
    
    # compute the spectral flux as the sum of square distances:
    sumX = numpy.sum(X + eps)
    sumPrevX = numpy.sum(X_prev + eps)
    F = numpy.sum((X / sumX - X_prev/sumPrevX) ** 2)

    return F
424521
def gtlike_spectrum_to_vectors(spectrum):
    


    parameters = pyLike.ParameterVector()
    spectrum.getParams(parameters)

    npar = max(parameters.size(), 10)
    o = {'param_names': np.zeros(npar, dtype='S32'),
         'param_values': np.empty(npar, dtype=float) * np.nan,
         'param_errors': np.empty(npar, dtype=float) * np.nan,
         }

    for i, p in enumerate(parameters):
        o['param_names'][i] = p.getName()
        o['param_values'][i] = p.getTrueValue()
        perr = abs(p.error() * p.getScale()) if p.isFree() else np.nan
        o['param_errors'][i] = perr

    return o
630587
def _embedding_spectral(matrix, dimensions=3, unit_length=True,
                        affinity_matrix=None, sigma=1):
    
    if affinity_matrix is None:
        aff = rbf(matrix, sigma=sigma)
    else:
        aff = affinity_matrix
    coords = sklearn.manifold.spectral_embedding(aff, dimensions)
    return normalise_rows(coords) if unit_length else coords
653895
def ThermalSpectrum(self):
        
        try:
            # delegate to subclass.
            thom = _ThermalObservationMode(self._obsmode)
            self.pixscale = thom.pixscale
            return thom._getSpectrum()
        except IndexError:   # graph table is broken.
            raise IndexError("Cannot calculate thermal spectrum; graphtable may be broken")
1109380
def _compute_Lp_matrix(self):
        
        self.Lp = sum([1/self.eigen_values[i]
                      * np.outer(self.eigen_basis[:, i], self.eigen_basis[:, i])
                      for i in range(1, self.eigen_values.size)])