我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用scipy.median()。
def get_html(self, base_file_name: str, h_level: int) -> str: sp = None # type: SingleProperty columns = [ BOTableColumn("n", "{:5d}", lambda sp, _: sp.observations(), first), BOTableColumn("mean", "{:10.5f}", lambda sp, _: sp.mean(), first), BOTableColumn("mean / best mean", "{:5.5%}", lambda sp, means: sp.mean() / min(means), first), BOTableColumn("mean / mean of first impl", "{:5.5%}", lambda sp, means: sp.mean() / means[0], first), BOTableColumn("std / mean", "{:5.5%}", lambda sp, _: sp.std_dev_per_mean(), first), BOTableColumn("std / best mean", "{:5.5%}", lambda sp, means: sp.std_dev() / min(means), first), BOTableColumn("std / mean of first impl", "{:5.5%}", lambda sp, means: sp.std_dev() / means[0], first), BOTableColumn("median", "{:5.5f}", lambda sp, _: sp.median(), first) ] html = """ <h{h}>Input: {input}</h{h}> The following plot shows the actual distribution of the measurements for each implementation. {box_plot} """.format(h=h_level, input=repr(self.input), box_plot=self.get_box_plot_html(base_file_name)) html += self.table_html_for_vals_per_impl(columns, base_file_name) return html
def alt_results(self, samples, kplanets): titles = sp.array(["Amplitude","Period","Longitude", "Phase","Eccentricity", 'Acceleration', 'Jitter', 'Offset', 'MACoefficient', 'MATimescale', 'Stellar Activity']) namen = sp.array([]) ndim = kplanets * 5 + self.nins*2*(self.MOAV+1) + self.totcornum + 1 RESU = sp.zeros((ndim, 5)) for k in range(kplanets): namen = sp.append(namen, [titles[i] + '_'+str(k) for i in range(5)]) namen = sp.append(namen, titles[5]) # for acc for i in range(self.nins): namen = sp.append(namen, [titles[ii] + '_'+str(i+1) for ii in sp.arange(2)+6]) for c in range(self.MOAV): namen = sp.append(namen, [titles[ii] + '_'+str(i+1) + '_'+str(c+1) for ii in sp.arange(2)+8]) for h in range(self.totcornum): namen = sp.append(namen, titles[-1]+'_'+str(h+1)) alt_res = map(lambda v: (v[2], v[3]-v[2], v[2]-v[1], v[4]-v[2], v[2]-v[0]), zip(*np.percentile(samples, [2, 16, 50, 84, 98], axis=0))) logdat = '\nAlternative results with uncertainties based on the 2nd, 16th, 50th, 84th and 98th percentiles of the samples in the marginalized distributions' logdat = '\nFormat is like median +- 1-sigma, +- 2-sigma' for res in range(ndim): logdat += '\n'+namen[res]+' : '+str(alt_res[res][0])+' +- '+str(alt_res[res][1:3]) +' 2% +- '+str(alt_res[res][3:5]) RESU[res] = sp.percentile(samples, [2, 16, 50, 84, 98], axis=0)[:, res] print(logdat) return RESU
def _getMedianVals(self): ''' @return: A scipy matrix representing the gray-scale median values of the image stack. If you want a pyvision image, just wrap the result in pv.Image(result). ''' self._imageStack = self._imageBuffer.asStackBW() medians = sp.median(self._imageStack, axis=0) #median of each pixel jet in stack return medians
def _updateMedian(self): curImg = self._imageBuffer.getLast() curMat = curImg.asMatrix2D() median = self._medians up = (curMat > median)*1.0 down = (curMat < median)*1.0 self._medians = self._medians + up - down
def property_filter_half(cur_index: int, all: t.List[Program], property_func: t.Callable[[Program], float], remove_upper_half: bool) -> bool: """ Note: if the number of programs is uneven, then one program will belong to the upper and the lower half. """ vals = [property_func(p) for p in all] cur_val = vals[cur_index] median = sp.median(vals) if (remove_upper_half and cur_val > median) or (not remove_upper_half and cur_val < median): return False return True
def initialize(self, sample_from_prior, distance_to_ground_truth_function): super().initialize(sample_from_prior, distance_to_ground_truth_function) eps_logger.debug("calc initial epsilon") # calculate initial epsilon if not given if self._initial_epsilon == 'from_sample': distances = sp.asarray([distance_to_ground_truth_function(x) for x in sample_from_prior]) eps_t0 = sp.median(distances) * self.median_multiplier self._look_up = {0: eps_t0} else: self._look_up = {0: self._initial_epsilon} eps_logger.info("initial epsilon is {}".format(self._look_up[0]))
def __call__(self, t, history): try: return self._look_up[t] except KeyError: df_weighted = history.get_weighted_distances(None) median = weighted_median( df_weighted.distance.as_matrix(), df_weighted.w.as_matrix()) self._look_up[t] = median * self.median_multiplier eps_logger.debug("new eps, t={}, eps={}" .format(t, self._look_up[t])) return self._look_up[t]
def __MR_final_saliency(self,integrated_sal, labels, aff): # get binary image if self.binary_thre == None: thre = sp.median(integrated_sal.astype(float)) mask = integrated_sal > thre # get indicator ind = self.__MR_second_stage_indictor(mask,labels) return self.__MR_saliency(aff,ind) # read image