def experiment(alpha=alpha_default, sd0=sd0_default, sd=sd_default, N=N_default, distance=distance_default): np.random.seed(1) _model = WorldModel(CRP(alpha), Gauss(sigma_0=sd0)) _animal = Animal(worldModel=_model) experiences = np.nan * np.ones((N * nPresentations * 2)) partition1 = np.array([]) partition2 = np.array([]) partitionN = np.array([]) lps = np.nan * np.empty((N, 3)) posts = np.nan * np.empty((N * nPresentations * 2, 3)) similarity = np.nan * np.empty((N, 1)) for i in range(N): c1 = stats.norm(loc=np.array([-distance / 2]), scale=sd * np.ones((1, K))) c2 = stats.norm(loc=np.array([+distance / 2]), scale=sd * np.ones((1, K))) for _i in range(nPresentations): experience1 = c1.rvs() experiences[i * nPresentations * 2 + _i * 2] = experience1 post1 = _animal.experience(experience1) if i + _i == 0: partition1 = np.array([[0]]) partition2 = np.array([[0]]) partitionN = np.array([[0]]) else: partition1 = np.vstack((partition1, 0)) partition2 = np.vstack((partition2, 0)) partitionN = np.vstack( (partitionN, 2 * i * nPresentations + _i)) if i > 0: posts[i * nPresentations * 2 + _i, :] = post1.squeeze() _animal.clusterAssignments = partition2 for _i in range(nPresentations): experience2 = c2.rvs() experiences[i * nPresentations * 2 + _i * 2 + 1] = experience2 post2 = _animal.experience(experience2) partition1 = np.vstack((partition1, 0)) partition2 = np.vstack((partition2, 1)) partitionN = np.vstack( (partitionN, (2 * i + 1) * nPresentations + _i)) if i > 0: posts[i * nPresentations * 2 + nPresentations + _i, :] = post2.squeeze() _animal.clusterAssignments = partition2 #TODO: look over this for what to do about partitions2activity ret = partitions2activity(_animal, experience1, [partition1, partition2], [zeta0, zeta1A, zeta1B]) activity1 = ret[0] tmp_lps = ret[1] ret = partitions2activity(_animal, experience2, [partition1, partition2], [zeta0, zeta1A, zeta1B]) activity2 = ret[0] tmp_lps_2 = ret[1] np.testing.assert_array_equal(tmp_lps, tmp_lps_2) lps[i, 0:2] = tmp_lps lps[i, 0] = _animal.partition_prob(partition1) lps[i, 1] = _animal.partition_prob(partition2) lps[i, 2] = _animal.partition_prob(partitionN) similarity[i] = np.corrcoef(activity1, activity2)[0, 1] return similarity, lps, _animal, partition1, partition2, c1, c2, experiences, posts
#%% np.random.seed(params['seed']) sd = 0.2 c1 = stats.norm(loc=np.zeros((1, 4)), scale=sd * np.ones((1, 4))) alpha = params['alpha'] worldModel = WorldModel(CRP(alpha), Gauss()) animal1 = Animal(worldModel=worldModel) nExperiences = 20 for i in range(nExperiences): animal1.experience(c1.rvs()) animal1.clusterAssignments = np.zeros((nExperiences, 1)) distance_default = 1 # distance between different features a = 0 b = distance_default post = np.vstack((animal1.belief(np.array([a, a, a, a])).transpose(), animal1.belief(np.array([b, a, a, a])).transpose(), animal1.belief(np.array([b, a, a, b])).transpose(), animal1.belief(np.array([b, b, b, b])).transpose())) #%% figInd = 0 figInd += 1 f = plt.figure(figInd) f.clear() bar_width = 0.2