def bitphase(uphase,lphase):
    ubitphase = []
    lbitphase = []
    for yy in range(0,len(uphase)):
        uph = []
        lph = []
        for xx in range(0,199):
            bitstart = xx*6
            sbin = bitstart+1
            ebin = bitstart+5
            ubit = uphase[yy][sbin:ebin]
            lbit = lphase[yy][sbin:ebin]
            upperrange = ptp(ubit)   # ptp Finds the range in the 
            lowerrange = ptp(lbit)   # respective bits

            if upperrange < 0.15:          # This is just 
                meanubit = np.mean(ubit)   # to establish
                uph.extend([meanubit])     # any bits used in the 
            if lowerrange < 0.15:          # overall median calc are locked on (ranges less than 0.15 over bit)
                meanlbit = np.mean(lbit)   # This means there are a different amount of valid 
                lph.extend([meanlbit])     # bits for the upper and lower sideband frequencies
        ubitphase.extend([uph])
        lbitphase.extend([lph])            
    ubitphase = np.array(ubitphase)
    lbitphase = np.array(lbitphase)    
    return ubitphase, lbitphase
示例#2
0
def medxbin(x, y, binsize, minpts=20, xmin=None, xmax=None):
    """
    Compute the median (and other statistics) in fixed bins along the x-axis.
    """
    import numpy as np
    from scipy import ptp

    # Need an exception if there are fewer than three arguments.

    if xmin == None:
        xmin = x.min()
    if xmax == None:
        xmax = x.max()
    #print(xmin,xmax)

    nbin = int(ptp(x) / binsize)
    bins = np.linspace(xmin, xmax, nbin)
    idx = np.digitize(x, bins)
    #print(nbin, bins, xmin, xmax)

    stats = np.zeros(nbin, [('median', 'f8'), ('sigma', 'f8'), ('iqr', 'f8')])
    for kk in np.arange(nbin):
        npts = len(y[idx == kk])
        if npts > minpts:
            stats['median'][kk] = np.median(y[idx == kk])
            stats['sigma'][kk] = np.std(y[idx == kk])
            stats['iqr'][kk] = np.subtract(
                *np.percentile(y[idx == kk], [75, 25]))

    # Remove bins with too few points.
    good = np.nonzero(stats['median'])
    stats = stats[good]

    return bins[good], stats
示例#3
0
def distribution_stat(val_list):
    """(distribution_stat):
        Takes a list and returns some distribution statistics in form of a dictionary. 
    """
    n_vals = len(val_list)
    
    if n_vals == 0:
        stat = {'n': 0, 'av': None, 'median': None, 'min': None, 'max': None, 'mad': None, 'rmsd': None, 'spread': None}
    else:
        average = sp.average(val_list) 

        median = median_func(val_list)

        spread = sp.ptp(val_list)

        mad = 0.0
        for val in val_list:
            mad += abs(val-average)
        mad = mad/n_vals

        rmsd = 0.0
        for val in val_list:
            rmsd += (val-average)**2
        rmsd = sqrt(rmsd/n_vals)

        stat = {'n': n_vals, 'av': average, 'median': median, 'min': min, 'max': max, 'mad': mad, 'rmsd': rmsd, 'spread': spread}
    return stat
示例#4
0
文件: util.py 项目: desihub/desisim
def medxbin(x,y,binsize,minpts=20,xmin=None,xmax=None):
    """
    Compute the median (and other statistics) in fixed bins along the x-axis.
    """
    import numpy as np
    from scipy import ptp

    # Need an exception if there are fewer than three arguments.

    if xmin==None:
        xmin = x.min()
    if xmax==None:
        xmax = x.max()
    #print(xmin,xmax)

    nbin = int(ptp(x)/binsize)
    bins = np.linspace(xmin,xmax,nbin)
    idx  = np.digitize(x,bins)
    #print(nbin, bins, xmin, xmax)

    stats = np.zeros(nbin,[('median','f8'),('sigma','f8'),('iqr','f8')])
    for kk in np.arange(nbin):
        npts = len(y[idx==kk])
        if npts>minpts:
            stats['median'][kk] = np.median(y[idx==kk])
            stats['sigma'][kk] = np.std(y[idx==kk])
            stats['iqr'][kk] = np.subtract(*np.percentile(y[idx==kk],[75, 25]))

    # Remove bins with too few points.
    good = np.nonzero(stats['median'])
    stats = stats[good]

    return bins[good], stats
示例#5
0
    def run(self):

        logger.info("Running TED method #" + str(self.method))

        numDesigns = self.designs.getNumDesigns()
        numTEDSamples = self.numSamples

        self.sampledIndexes = np.empty(0, dtype=np.uint64)

        # Operate on the whole design space
        remainingIndexes = np.arange(numDesigns, dtype=np.uint64)

        # Use knob settings as the input X matrix
        tedInput = self.designs.getKnobSettings()

        if self.method == TED.TED_AND_HINT_PARETO:
            hints = self.designs.getHints()
            _, paretoIndexes, paretoScores = Distances.prpt(hints)
            paretoIndexes = paretoIndexes.astype(np.uint64)
            numPareto = paretoIndexes.size

            numPareto = int(
                min(numPareto, self.numSamples * (1 - self.minTEDRatio)))
            numTEDSamples -= numPareto

            # Choose some Pareto designs from the hint space
            self.sampledIndexes = paretoIndexes[np.argsort(paretoScores)
                                                [::-1]][:numPareto]

            # Remove these designs from the TED input matrix
            remainingIndexes = np.setdiff1d(remainingIndexes,
                                            self.sampledIndexes)
            tedInput = self.designs.getKnobSettings()[remainingIndexes]

        elif self.method == TED.TED_HINT_OUTPUT:
            # Set the hint output (objective values) as the TED input matrix
            hints = self.designs.getHints()
            tedInput = hints

        elif self.method == TED.TED_ALL_HINT_OUTPUT:
            tedInput = self.designs.getHints(allPerfTypes=True)

        if self.sigma == 0:
            # A reasonable choice of sigma is on the order of the total range.
            self.sigma = np.sqrt(
                np.max(scipy.ptp(self.designs.getKnobSettings(), 0)))

        # Run TED
        tedIndexes = self.transdesign_sq(tedInput, numTEDSamples, self.sigma,
                                         self.lamb)

        self.sampledIndexes = np.r_[self.sampledIndexes,
                                    remainingIndexes[tedIndexes]]

        if self.enableStats:
            stats = []
            for i in range(1, self.sampledIndexes.size + 1):
                if self.method == TED.TED_AND_HINT_PARETO:
                    numPareto_i = int(
                        min(paretoIndexes.size, i * (1 - self.minTEDRatio)))
                    numTEDSamples_i = i - numPareto_i
                    sampledIdx = np.r_[
                        self.sampledIndexes[:numPareto_i],
                        self.sampledIndexes[numPareto:numPareto +
                                            numTEDSamples_i]]
                else:
                    sampledIdx = self.sampledIndexes[:i]
                adrs = Distances.adrs(self.designs.getGroundTruth(),
                                      sampledIdx)
                stats.append([i, i / self.designs.getNumDesigns(), adrs])
            self.stats = np.array(stats)
示例#6
0
            freq_table[a] += 1

    values = list(freq_table.values())
    keys = list(freq_table.keys())
    return keys[values.index(max(values))]


def describe(*args):
    """
    Given multiple descriptive statistical values, print them out.
    """
    fmt = """
    Mean: {}
    Median: {}
    Mode: {}
    Range: {}
    Standard Deviation: {}
    """
    return print(fmt.format(*args))


if __name__ == '__main__':
    data = [1, 2, 3, 4, 5]
    describe(mean(data), median(data), mode(data), xrange(data), std(data))

    describe(np.mean(data), np.median(data),
             scipy.stats.mode(data)[0], np.ptp(data), np.std(data))

    describe(scipy.mean(data), scipy.median(data),
             scipy.stats.mode(data)[0], scipy.ptp(data), scipy.std(data))