def _get_output_features_constant(self, neighs_info, k, typefeats=(0, 0)): """Get 'output' features. Get the features of the elements in the neighbourhood of the elements we want to study. That case is under assumption of the constant selection of features. Parameters ---------- neighs_info: pst.Neighs_Info the container of all the information of the neighbourhood. k: list or np.ndarray perturbations indices we want to get. typefeats: tuple or list the selectors for the features of the neighs of elements `i`. Returns ------- feats_neighs: np.ndarray or list the features of the neighs of the elements `i`. """ ## Neighs info as an object neighs_info = ensuring_neighs_info(neighs_info, k) ## Input mapping neighs_info = self._maps_input[typefeats[0]](neighs_info) ## Features retrieve feats_neighs = self.features[typefeats[1]].compute((neighs_info, k)) ## Outformat feats_neighs = self._maps_output(self, feats_neighs) return feats_neighs
def compute_descriptors(self, i, neighs_info, k=None, feat_selectors=None): """General compute descriptors for descriptormodel class. Parameters ---------- i: np.ndarray or list the indices of the elements `i`. neighs_info: pst.Neighs_Info the container of all the information of the neighbourhood. k: int or list (default=None) the perturbations indices we wantto get. feat_selectors: list, tuple or pst.BaseSelector (default=None) the selection information. Returns ------- descriptors: list the descriptors for each perturbation and element. vals_i: list or np.ndarray the store information index of each element `i`. """ ## 0. Prepare list of k ks = list(range(self.k_perturb + 1)) if k is None else k ks = [ks] if type(ks) == int else ks i_input = [i] if type(i) == int else i # if type(feat_selectors) == tuple: # feat_selectors = [feat_selectors] neighs_info = ensuring_neighs_info(neighs_info, k) # sh = neighs_info.shape # print sh, len(i_input), len(ks), ks, i_input # assert(len(i_input) == sh[1]) # assert(len(ks) == sh[0]) ## 1. Prepare selectors t_feat_in, t_feat_out, t_feat_des = self.get_type_feats(i, feat_selectors) # print t_feat_in, t_feat_out, t_feat_des ## 2. Get pfeats (pfeats 2dim array (krein, jvars)) desc_i = self._get_input_features(i_input, ks, t_feat_in) print i_input, ks, self._get_input_features, type(t_feat_in) print "." * 20, desc_i desc_neigh = self._get_output_features(neighs_info, ks, t_feat_out) # print i, ks, i_input, neighs_info, neighs_info.ks, neighs_info.idxs ## 3. Map vals_i vals_i = self._get_vals_i(i, ks) # print '+'*10, vals_i, desc_neigh, desc_i ## 4. Complete descriptors (TODO) descriptors = self._complete_desc_i(i, neighs_info, desc_i, desc_neigh, vals_i, t_feat_des) # descriptors =\ # self.descriptormodel.complete_desc_i(i, neighs_info, desc_i, # desc_neigh, vals_i) ## 5. Join descriptors descriptors = self._join_descriptors(descriptors) return descriptors, vals_i
def _get_output_features_variable(self, neighs_info, k, typefeats=(0, 0)): """Get 'output' features. Get the features of the elements in the neighbourhood of the elements we want to study. That case is under assumption of the variable selection of features. Parameters ---------- neighs_info: pst.Neighs_Info the container of all the information of the neighbourhood. k: list or np.ndarray perturbations indices we want to get. typefeats: tuple or list the selectors for the features of the neighs of elements `i`. Returns ------- feats_neighs: np.ndarray or list the features of the neighs of the elements `i`. """ ## Neighs info as an object neighs_info = ensuring_neighs_info(neighs_info, k) ## Loop for all typefeats i_l = len(neighs_info.iss) # print i_l, neighs_info.iss, neighs_info.idxs k_l = 1 if type(k) == int else len(k) typefeats = [typefeats] * i_l if type(typefeats) == tuple else typefeats feats_neighs = [[] for kl in range(k_l)] for j in range(i_l): ## Input mapping neighs_info_j = neighs_info.get_copy_iss_by_ind(j) neighs_info_j = self._maps_input[typefeats[j][0]](neighs_info_j) ## Features retrieve feats_neighs_j = self.features[typefeats[j][1]].compute((neighs_info_j, k)) ## Outformat feats_neighs_j = self._maps_output(self, feats_neighs_j) ## Store for k_j in range(len(feats_neighs_j)): feats_neighs[k_j].append(feats_neighs_j[k_j][0]) assert len(feats_neighs) == k_l assert len(feats_neighs[0]) == i_l return feats_neighs