def make_basin_from_sets(self, start_state, end_state): # print "start_state: ",start_state # print "end_state: ",end_state start_states = set() sb = self.get_containing_superbasin(start_state) if sb is None: start_states.add(start_state) else: start_states.update(sb.states) end_states = set() sb = self.get_containing_superbasin(end_state) if sb is None: end_states.add(end_state) else: end_states.update(sb.states) # Is there an upper limit for the size of a superbasin? if config.sb_max_size: numstates = len(start_states) + len(end_states) # if number of states in the new superbasin will be larger # than the maximum size, do not proceed if numstates > config.sb_max_size: return # Now start creating the new superbasin. merge_states = [start_state, end_state] new_sb_states = set() for i in merge_states: sb = self.get_containing_superbasin(i) if sb is None: new_sb_states.add(i) else: new_sb_states.update(sb.states) # keep basins to analyze data if True: sb.delete(self.path_storage) else: sb.delete() self.superbasins.remove(sb) new_sb_states = list(new_sb_states) # print "connect_state: before" # self.states.connect_states(new_sb_states) #XXX:This should ensure detailed balance # However, it will likely be very slow. We should be able to do without it. # Also, if confidence is changed and new processes are found, the superbasin # will ignore these new processes. self.states.connect_state_sets(start_states, end_states) # print "connect_state: after" # print "superbasins.append: before" self.superbasins.append( superbasin.Superbasin(self.path, self.next_sb_num, state_list=new_sb_states)) # print "superbasins.append: after" logger.info("Created superbasin with states " + str([i.number for i in new_sb_states])) self.next_sb_num += 1
def __init__(self, superbasin_path, states, kT): self.path = superbasin_path self.path_storage = os.path.join(superbasin_path, "storage") self.states = states self.kT = kT if not os.path.isdir(self.path): logger.warning('Superbasin path does not exist, creating %s' % self.path) os.makedirs(self.path) os.makedirs(self.path_storage) self.superbasins = [] self.next_sb_num = 0 for i in os.listdir(self.path): if i == 'storage': continue self.next_sb_num = max(self.next_sb_num, int(i)) self.superbasins.append( superbasin.Superbasin(self.path, i, get_state=states.get_state)) self.next_sb_num += 1 self.read_data()
def make_basin(self, merge_states): print "ohdeargod make a basin" new_sb_states = [] for i in merge_states: sb = self.get_containing_superbasin(i) if sb is None: if i not in new_sb_states: new_sb_states.append(i) else: for j in sb.states: if j not in new_sb_states: new_sb_states.append(j) self.superbasins.remove(sb) #self.states.connect_states(new_sb_states) #XXX:This should ensure detailed balance #However, it will likely be very slow. We should be able to do without it. #Also, if confidence is changed and new processes are found, the superbasin #will ignore these new processes. self.superbasins.append(superbasin.Superbasin(new_sb_states)) print "Created superbasin with states " #+ str([i.number for i in new_sb_states])