titu1994 / neural-architecture-search

Basic implementation of [Neural Architecture Search with Reinforcement Learning](https://arxiv.org/abs/1611.01578).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

about class StateSpace

gzpan opened this issue · comments

commented

At class StateSpace in Controller.py, many functions e.g. embedding_encode(self, id, value) use state = self[id], I am confused that if it is legal in python ? how could we index self?
another question: why the variable state here is a Dictionary? shouldn't it be a StateSpace object?

I've declared the getitem method inside of StateSpace. After this, the entire class can behave as an array, and therefore be indexed just as above. This is just a convenience function, you can of course simply uses the expanded version as below.

def __getitem__(self, id):
        return self.states[id % self.size]

The benefit is that when the id is being received by the caller, it can be from multiple cells in a loop, so I don't need to worry about which cyclic index this is when I use self[id]. It's a somewhat roundabout way to do something safely without having the client worry about checks.

As to the second question, the StateSpace is a wrapper over all of the states it holds. It internally uses a dictionary. Therefore the client only needs one StateSpace, register all the states to it and then use it to get the states ready for use by the RNNs or for viewing.

Can you list the line where you feel it should be replaced?

commented

Thanks for your fast reply! I make a mistake that I ignore the getitem method. Now the two questions are solved. Thanks again

commented

I forgot another question.
At StateSpace.embedding_encode(self, id, value) function, line 85 in controller.py,
:one_hot[np.arange(1), value_idx] = value_idx + 1,
I think the expression should be : one_hot[np.arange(1), value_idx] = 1 because one hot vector should be
binary. what do you think so

Ah ordinarily you would be correct. Originally, the code did one hot the data, and then passed it to the RNN without an embedding step, as in the data was passed as a one hot over time.

The paper suggests using embedding matrices to simplify learning and make it correct.

Now that "one hot" function actually returns an integer to index the embedding matrix instead.

I should rename that function. It's not a one hot anymore after all.