def get_stim_cw_neighbors(c, o, n_i, rf, r2=2, cw_r2=None): _, s, trs = generate_cc_types((n_i,)*c, (rf,)*c, order=o, excl=True) ind = np.argmin(np.sum(np.abs(s - (n_i/2,)*c), axis=1)) r = np.sqrt(r2) ds = u.euclidean_distance(s, s[ind]) close_stim_mask = ds <= r all_cw = trs(s) ds_cw = u.euclidean_distance(all_cw, all_cw[ind]) if cw_r2 is None: ds_nextmin = ds_cw[ds_cw > 0] md = np.min(ds_nextmin) else: md = np.sqrt(cw_r2) md_mask = ds_cw == md n_md_neigh_close = np.sum(np.logical_and(close_stim_mask, md_mask)) n_md_neigh = np.sum(md_mask) # blah ana_c_cw = volume_nball(r, o) - 1 # if o == 1 or (rf > 1 and o < c): if o < c: ana_c_cw = 2*r*c ana_all_cw = _close_words(c, o, n_i, rf=rf, excl=True) print('close and nn', ana_c_cw, '||', n_md_neigh_close) print(' nn', ana_all_cw, '||', n_md_neigh) print('min dist', md) print('close/all', n_md_neigh_close/n_md_neigh) return md, n_md_neigh_close, n_md_neigh
def obtain_stretchfactor_cent(cent, rad, trans, filt, n_pts=1000): pts = generate_points_on_sphere(n_pts, len(cent), cent=cent, rad=rad) rep_pts, _, _ = simulate_pop_resp(pts, trans, filt, noise_var=0) rep_cent, _, _ = simulate_pop_resp(cent.reshape((1, -1)), trans, filt, noise_var=0) stretches = gu.euclidean_distance(rep_pts, rep_cent)/rad return stretches
def find_distances(trans_types): ind_pairs = list(it.combinations(range(len(trans_types)), 2)) dists = np.zeros(len(ind_pairs)) for i, p in enumerate(ind_pairs): t1 = trans_types[p[0]] t2 = trans_types[p[1]] dists[i] = u.euclidean_distance(t1, t2) return dists
def integ_lattice_in_ball(r, d, eps=.000001): int_size = int(np.ceil(2 * r + 1)) int_size_ind = np.floor(int_size / 2).astype(int) midpt = range(int(int_size))[int(int_size_ind / 2)] pts = np.array(list(it.product(range(int_size), repeat=d))) pts_est = volume_nball(r, d) ds = gu.euclidean_distance(pts, (midpt, ) * d) pts_rea = np.sum(ds <= r + eps) return pts_est, pts_rea
def _ident_close_words(c, o, n_i, rf, cent=True): _, s, trs = generate_cc_types((n_i,)*c, (rf,)*c, order=o, excl=True) ind = np.argmin(np.sum(np.abs(s - (n_i/2,)*c), axis=1)) all_cw = trs(s) ds_cw = u.euclidean_distance(all_cw, all_cw[ind]) ds_nextmin = ds_cw[ds_cw > 0] md = np.min(ds_nextmin) md_mask = ds_cw == md return s[md_mask], s[ind]
def compute_num_neighbors(c, o, n_i, rf, one_feat=False): _, s, trs = generate_cc_types((n_i,)*c, (rf,)*c, order=o, excl=True) ind = np.argmin(np.sum(np.abs(s - (n_i/2,)*c), axis=1)) if one_feat: fv = s[0, 0] mask = s[:, 0] != fv ind = 0 print((n_i-1)*n_i**(c - 1)) else: mask = np.ones(len(s)) cw = trs(s) ds = u.euclidean_distance(cw[mask], cw[ind]) ds = ds[ds > 0] md = np.min(ds) n_neigh = np.sum(ds == md) return md, n_neigh
def get_all_distances(self): dists_all = np.zeros((len(self.rep), len(self.rep))) for i, stim_i in enumerate(self.rep): dists_all[i] = u.euclidean_distance(stim_i, self.rep) return dists_all
def decode_word(word, types): dists = u.euclidean_distance(word, types) ind = np.argmin(dists) return types[ind], ind