Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layer dimensions in NeuralNetMLP (page 348) #23

Closed
labdmitriy opened this issue Mar 16, 2022 · 1 comment · Fixed by #48
Closed

Layer dimensions in NeuralNetMLP (page 348) #23

labdmitriy opened this issue Mar 16, 2022 · 1 comment · Fixed by #48

Comments

@labdmitriy
Copy link

labdmitriy commented Mar 16, 2022

Hi Sebastian,

There are comments about dimensions for hidden and output layers for MLP on the page 348 and in the repository:

# input dim: [n_hidden, n_features] dot [n_features, n_examples] .T
# output dim: [n_examples, n_hidden]
z_h = np.dot(x, self.weight_h.T) + self.bias_h

# input dim: [n_classes, n_hidden] dot [n_hidden, n_examples] .T
# output dim: [n_examples, n_classes]
z_out = np.dot(a_h, self.weight_out.T) + self.bias_out

Based on the description on the same section above (page 342), it seems that:

  • For hidden layer:
    • x has dimension [n_examples, n_features] (but [n_hidden, n_features] is specified)
    • self.weight_h.T has dimension [n_hidden, n_features].T (but [n_features, n_examples] .T is specified)

So z_h = np.dot(x, self.weight_h.T) + self.bias_h will have specified dimension ([n_examples, n_hidden])

  • For output layer:
    a_h has dimension [n_examples, n_hidden] (but [n_classes, n_hidden] is specified)
    self.weight_h.T has dimension [n_classes, n_hidden].T (but [n_hidden, n_examples] .T is specified)

So z_out = np.dot(a_h, self.weight_out.T) + self.bias_out will have specified dimension ([n_examples, n_classes])

Is it correct, or I am wrong in comments interpretation?

Thank you.

@rasbt
Copy link
Owner

rasbt commented Mar 30, 2022

Oh, good call. think the code comments are still the old ones (arg, that's what I hate about code comments, sometimes it is easy to forget updating them). I initially had it as

z_h = np.dot(self.weight_h, x.T).T + self.bias_h

instead of

z_h = np.dot(x, self.weight_h.T) + self.bias_h

Both are equivalent, though. I will update this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants