SafeMDP icon indicating copy to clipboard operation
SafeMDP copied to clipboard

Question about the function `update_sets`?

Open SChrisLin opened this issue 4 years ago • 3 comments

Hi, sorry to bother you

I am very confused about the function update_sets, especially the expression self.S |= self.l >= self.h. Theoretically, the self.graph needs to be updated after this expression using the expression such as link_graph_and_safe_set(self.graph, self.S). But, I found self.S |= self.l >= self.h magically updates self.graph, and the function update_sets works very well without link_graph_and_safe_set.

I am new to the package NetworkX, could you tell me how expression self.S |= self.l >= self.h updates the self.graph ?

def update_sets(self):
  """
  Update the sets S, S_hat and G taking with the available observation
  """
  self.update_confidence_interval()
  # self.S[:] = self.l >= self.h
  self.S |= self.l >= self.h
  # link_graph_and_safe_set(self.graph, self.S)  # it should be here

  self.compute_S_hat()
  self.compute_expanders()

SChrisLin avatar Jan 20 '21 16:01 SChrisLin

I think I have found the answer. The key is edge['safe'] = safe_set[node:node + 1, edge['action']], which means it is a reference (^_^).

SChrisLin avatar Jan 20 '21 17:01 SChrisLin

You're absolutely right. The problem was that for efficiency we want to work in batch on numpy arrays, but at the same time we needed the safety feature to be attached to a graph. So the trick was to link the two via this indexing, so that the graph is a pointer/reference to a specific part of the array. That way, as long as we update the safe_set inplace, the corresponding references in the graph get updated automatically too.

On Wed, 20 Jan 2021 at 18:04, SChrisLin [email protected] wrote:

I think I have found the answer. The key is edge['safe'] = safe_set[node:node + 1, edge['action']], which means it is a reference ( ^_^).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/befelix/SafeMDP/issues/5#issuecomment-763790672, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKGGKAZ4A6MQVOR7TT2KX3S24EI5ANCNFSM4WK6MC4A .

befelix avatar Jan 21 '21 22:01 befelix

Thanks for your reply!

SChrisLin avatar Jan 22 '21 08:01 SChrisLin