def load_histogram(self, infn_hist): loader = Loader() shape, ticks, hist_arr = loader.load_histogram(infn_hist) self._hcel = hist_arr[:, :-1] self._count = hist_arr[:, -1] n_cel, n_dim = self._hcel.shape if n_dim != self.mode: raise ValueError( "Input histogram dimension does match with the initial dimension." ) self._total = n_cel self.shape = shape
def describe_view(ins_hist, ins_desc, desc_voc, xlab, ylab, outs): assert desc_voc in VALID_DESCVOCS loader = Loader() desc = DTMNormDescribe if desc_voc == 'dtmnorm' else GaussianDescribe desc_parms = loader.load_describes_parms(ins_desc, desc, mode=2) h_shape, ticks_vec, hist_arr = loader.load_histogram(ins_hist) csr_mat = csr_matrix((hist_arr[:, -1], (hist_arr[:, 0], hist_arr[:, 1])), shape=h_shape, dtype=int) # plot_heatmap(ticks_vec[1], ticks_vec[0], csr_mat.toarray(), xlabel=xlabel, ylabel=ylabel, outfn=outfn) plot_heatmap_ellipse_covs(ticks_vec[1], ticks_vec[0], csr_mat.toarray(), desc_parms, base=10, scales=(1.5, 3), xlabel=xlab, ylabel=ylab, outfn=outs)
def load_hcel_weights(in_hist, in_hcel2avgfeat, mode=2, wtcol_index=1, sep=','): loader = Loader() _, _, hist_arr = loader.load_histogram(in_hist) nhcubes = len(hist_arr) hcube2index = dict(zip(map(tuple, hist_arr[:, :2]), range(nhcubes))) hcube_weight = np.zeros(nhcubes) #np.empty((nhcubes, nfeat)) with open(in_hcel2avgfeat, 'r') as fp: for line in fp.readlines(): if line.startswith('#'): continue tok = line.strip().split(sep) pos = tuple(map(int, tok[:mode])) hcube_weight[hcube2index[pos]] = float(tok[wtcol_index + mode - 1]) fp.close() return hcube_weight