def stellingwerf_pdm_theta(times, mags, errs, frequency, binsize=0.05, minbin=9): ''' This calculates the Stellingwerf PDM theta value at a test frequency. ''' period = 1.0/frequency fold_time = times[0] phased = phase_magseries(times, mags, period, fold_time, wrap=False, sort=True) phases = phased['phase'] pmags = phased['mags'] bins = np.arange(0.0, 1.0, binsize) nbins = bins.size binnedphaseinds = npdigitize(phases, bins) binvariances = [] binndets = [] goodbins = 0 for x in npunique(binnedphaseinds): thisbin_inds = binnedphaseinds == x thisbin_phases = phases[thisbin_inds] thisbin_mags = pmags[thisbin_inds] if thisbin_mags.size > minbin: thisbin_variance = npvar(thisbin_mags,ddof=1) binvariances.append(thisbin_variance) binndets.append(thisbin_mags.size) goodbins = goodbins + 1 # now calculate theta binvariances = nparray(binvariances) binndets = nparray(binndets) theta_top = npsum(binvariances*(binndets - 1)) / (npsum(binndets) - goodbins) theta_bot = npvar(pmags,ddof=1) theta = theta_top/theta_bot return theta
def variance(numbers): if numpy: return npvar(numbers) elif py3statistics: return p3var(numbers) mn = mean(numbers) variance = old_div(sum([(e - mn)**2 for e in numbers]), len(numbers))
def decomp(self): r""" Get the fixed and random effects. Returns ------- fixed_effects : Fixed effects. random_effects : Random effects. """ from numpy import var as npvar decomp = dict(fixed_effects={}, random_effects={}) for fe in self.fixed_effects: if hasattr(fe, "offset"): continue decomp["fixed_effects"][fe.name] = npvar(fe.value()) for re in self.covariance_matrices: decomp["random_effects"][re.name] = re.scale total = 0 for _, v in iter(decomp.items()): for _, vi in iter(v.items()): total += vi for k0, v in iter(decomp.items()): for k1, vi in iter(v.items()): decomp[k0][k1] = vi / total return decomp
def variance(numbers): if numpy: return npvar(numbers) elif py3statistics: return p3var(numbers) mn = mean(numbers) variance = sum([(e - mn) ** 2 for e in numbers]) / float(len(numbers)) return variance
def var(self, price_list): """ This calculates the variance of a time series over the last self._nvar days """ self._check_list_input('var', self._nvar, price_list) tmp_list = price_list[-self._nvar:] result = npvar(tmp_list) return result
def demo_analysis(wavfilepaht): # オーディオロード sig = SignalData().load_wav(wavfilepaht, 'M') # スペクトログラム spgram = sig.slice_time_ms(80, 120).gwt() # スペクトル(インパクト音) spec_impact = spgram.slice_time_ms(20, 23).time_average() # .plot().show() # ガワ感 from numpy import var as npvar g = spec_impact.liftering(lifter=5, mode="low").slice_freq_hz(1000, 4500).info().get_data() gawa = npvar(g) print gawa # 硬さ katasa = spec_impact.liftering(lifter=15, mode="low").slice_freq_khz(1, 4.5).cof() # .plot().show() print katasa return katasa, gawa
def lightcurve_ptp_measures(ftimes, fmags, ferrs): '''This calculates various point-to-point measures (`eta` in Kim+ 2014). Parameters ---------- ftimes,fmags,ferrs : np.array The input mag/flux time-series with all non-finite elements removed. Returns ------- dict A dict with values of the point-to-point measures, including the `eta` variability index (often used as its inverse `inveta` to have the same sense as increasing variability index -> more likely a variable star). ''' ndet = len(fmags) if ndet > 9: timediffs = npdiff(ftimes) # get rid of stuff with time diff = 0.0 nzind = npnonzero(timediffs) ftimes, fmags, ferrs = ftimes[nzind], fmags[nzind], ferrs[nzind] # recalculate ndet and diffs ndet = ftimes.size timediffs = npdiff(ftimes) # calculate the point to point measures p2p_abs_magdiffs = npabs(npdiff(fmags)) p2p_squared_magdiffs = npdiff(fmags) * npdiff(fmags) robstd = npmedian(npabs(fmags - npmedian(fmags))) * 1.483 robvar = robstd * robstd # these are eta from the Kim+ 2014 paper - ratio of point-to-point # difference to the variance of the entire series # this is the robust version eta_robust = npmedian(p2p_abs_magdiffs) / robvar eta_robust = eta_robust / (ndet - 1.0) # this is the usual version eta_normal = npsum(p2p_squared_magdiffs) / npvar(fmags) eta_normal = eta_normal / (ndet - 1.0) timeweights = 1.0 / (timediffs * timediffs) # this is eta_e modified for uneven sampling from the Kim+ 2014 paper eta_uneven_normal = ((npsum(timeweights * p2p_squared_magdiffs) / (npvar(fmags) * npsum(timeweights))) * npmean(timeweights) * (ftimes.max() - ftimes.min()) * (ftimes.max() - ftimes.min())) # this is robust eta_e modified for uneven sampling from the Kim+ 2014 # paper eta_uneven_robust = ((npsum(timeweights * p2p_abs_magdiffs) / (robvar * npsum(timeweights))) * npmedian(timeweights) * (ftimes[-1] - ftimes[0]) * (ftimes[-1] - ftimes[0])) return { 'eta_normal': eta_normal, 'eta_robust': eta_robust, 'eta_uneven_normal': eta_uneven_normal, 'eta_uneven_robust': eta_uneven_robust } else: return None
def stellingwerf_pdm_theta(times, mags, errs, frequency, binsize=0.05, minbin=9): ''' This calculates the Stellingwerf PDM theta value at a test frequency. Parameters ---------- times,mags,errs : np.array The input time-series and associated errors. frequency : float The test frequency to calculate the theta statistic at. binsize : float The phase bin size to use. minbin : int The minimum number of items in a phase bin to consider in the calculation of the statistic. Returns ------- theta_pdm : float The value of the theta statistic at the specified `frequency`. ''' period = 1.0 / frequency fold_time = times[0] phased = phase_magseries(times, mags, period, fold_time, wrap=False, sort=True) phases = phased['phase'] pmags = phased['mags'] bins = nparange(0.0, 1.0, binsize) binnedphaseinds = npdigitize(phases, bins) binvariances = [] binndets = [] goodbins = 0 for x in npunique(binnedphaseinds): thisbin_inds = binnedphaseinds == x thisbin_mags = pmags[thisbin_inds] if thisbin_mags.size > minbin: thisbin_variance = npvar(thisbin_mags, ddof=1) binvariances.append(thisbin_variance) binndets.append(thisbin_mags.size) goodbins = goodbins + 1 # now calculate theta binvariances = nparray(binvariances) binndets = nparray(binndets) theta_top = npsum(binvariances * (binndets - 1)) / (npsum(binndets) - goodbins) theta_bot = npvar(pmags, ddof=1) theta = theta_top / theta_bot return theta
def lightcurve_ptp_measures(ftimes, fmags, ferrs): ''' This calculates various point-to-point measures (eta in Kim+ 2014). ''' ndet = len(fmags) if ndet > 9: timediffs = npdiff(ftimes) # get rid of stuff with time diff = 0.0 nzind = npnonzero(timediffs) ftimes, fmags, ferrs = ftimes[nzind], fmags[nzind], ferrs[nzind] # recalculate ndet and diffs ndet = ftimes.size timediffs = npdiff(ftimes) # calculate the point to point measures p2p_abs_magdiffs = npabs(npdiff(fmags)) p2p_squared_magdiffs = npdiff(fmags) * npdiff(fmags) robstd = npmedian(npabs(fmags - npmedian(fmags))) * 1.483 robvar = robstd * robstd # these are eta from the Kim+ 2014 paper - ratio of point-to-point # difference to the variance of the entire series # this is the robust version eta_robust = npmedian(p2p_abs_magdiffs) / robvar eta_robust = eta_robust / (ndet - 1.0) # this is the usual version eta_normal = npsum(p2p_squared_magdiffs) / npvar(fmags) eta_normal = eta_normal / (ndet - 1.0) timeweights = 1.0 / (timediffs * timediffs) # this is eta_e modified for uneven sampling from the Kim+ 2014 paper eta_uneven_normal = ((npsum(timeweights * p2p_squared_magdiffs) / (npvar(fmags) * npsum(timeweights))) * npmean(timeweights) * (ftimes.max() - ftimes.min()) * (ftimes.max() - ftimes.min())) # this is robust eta_e modified for uneven sampling from the Kim+ 2014 # paper eta_uneven_robust = ((npsum(timeweights * p2p_abs_magdiffs) / (robvar * npsum(timeweights))) * npmedian(timeweights) * (ftimes[-1] - ftimes[0]) * (ftimes[-1] - ftimes[0])) return { 'eta_normal': eta_normal, 'eta_robust': eta_robust, 'eta_uneven_normal': eta_uneven_normal, 'eta_uneven_robust': eta_uneven_robust } else: return None