def vertex_weights(self): ## first need to pick a simplex to sample from ## vols = [] n_verts = [] for ii in range(self.n_simplex): vols.append(complex_volume(self, ii)) n_verts.append(len(self.simplicial_complex[ii])) norm = sum(vols) # print(norm.item()) ## error catch for 0 volume simplexes if norm == 0: simp_ind = np.random.randint(self.n_simplex) else: vol_cumsum = np.cumsum([vv/norm for vv in vols]) # print(vol_cumsum) simp_ind = np.min(np.where(np.random.rand(1) < vol_cumsum)[0]) ## sample weights for simplex exps = [-(torch.rand(1)).log().item() for _ in range(n_verts[simp_ind])] total = sum(exps) exps = [exp/total for exp in exps] ## now assign vertex weights out vert_weights = [0] * self.n_vert for ii, vert in enumerate(self.simplicial_complex[simp_ind]): vert_weights[vert] = exps[ii] return vert_weights
def forward(self, complex_modex): ## first need to pick a simplex to sample from ## vols = [] n_verts = [] for ii in range(self.n_simplex): vols.append(complex_volume(complex_model, ii)) n_verts.append(len(complex_model.simplexes[ii])) norm = sum(vols) vol_cumsum = np.cumsum([vv/norm for vv in vols]) simp_ind = np.min(np.where(np.random.rand(1) < vol_cumsum)[0]) ## sample weights for simplex exps = [-(torch.rand(1)).log().item() for _ in range(n_verts[simp_ind])] total = sum(exps) exps = [exp/total for exp in exps] ## now assign vertex weights out vert_weights = [0] * complex_model.n_vert for ii, vert in enumerate(complex_model.simplexes[simp_ind]): vert_weights[vert] = exps[ii] return vert_weights
def total_volume(self, vol_function=complex_volume): vol = 0 # for simp in range(self.n_simplex): # vol += complex_volume(self, simp) vol = complex_volume(self, 0) return vol