-
Notifications
You must be signed in to change notification settings - Fork 1
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
Sourcery Starbot ⭐ refactored manncodes/xeno #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ def forward(self, input): | |
return np.maximum(0.0, input) | ||
|
||
def derivative(self, input=None): | ||
last_forward = input if input else self.last_forward | ||
last_forward = input or self.last_forward | ||
res = np.zeros(last_forward.shape, dtype=get_dtype()) | ||
res[last_forward > 0] = 1. | ||
return res | ||
|
@@ -76,7 +76,7 @@ def forward(self, input): | |
return input | ||
|
||
def derivative(self, input=None): | ||
last_forward = input if input else self.last_forward | ||
last_forward = input or self.last_forward | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return np.ones(last_forward.shape, dtype=get_dtype()) | ||
|
||
|
||
|
@@ -93,11 +93,10 @@ def forward(self, input): | |
self.last_forward = input | ||
x = input - np.max(input, axis=1, keepdims=True) | ||
exp_x = np.exp(x) | ||
s = exp_x / np.sum(exp_x, axis=1, keepdims=True) | ||
return s | ||
return exp_x / np.sum(exp_x, axis=1, keepdims=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def derivative(self, input=None): | ||
last_forward = input if input else self.last_forward | ||
last_forward = input or self.last_forward | ||
Comment on lines
-100
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return np.ones(last_forward.shape, dtype=get_dtype()) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ def decompose_size(size): | |
fan_in = size[0] | ||
fan_out = size[1] | ||
|
||
elif len(size) == 4 or len(size) == 5: | ||
elif len(size) in [4, 5]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
respective_field_size = np.prod(size[2:]) | ||
fan_in = size[1] * respective_field_size | ||
fan_out = size[0] * respective_field_size | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,8 +86,7 @@ def forward(self, input, *args, **kwargs): | |
|
||
self.last_input = input | ||
linear_out = np.dot(input, self.W) + self.b | ||
act_out = self.act_layer.forward(linear_out) | ||
return act_out | ||
return self.act_layer.forward(linear_out) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def backward(self, pre_grad, *args, **kwargs): | ||
|
||
|
@@ -128,11 +127,10 @@ def connect_to(self, prev_layer): | |
def forward(self, input, train=True, *args, **kwargs): | ||
|
||
if 0. < self.p < 1.: | ||
if train: | ||
self.last_mask = get_rng().binomial(1, 1 - self.p, input.shape) / (1 - self.p) | ||
return input * self.last_mask | ||
else: | ||
if not train: | ||
return input * (1 - self.p) | ||
self.last_mask = get_rng().binomial(1, 1 - self.p, input.shape) / (1 - self.p) | ||
return input * self.last_mask | ||
Comment on lines
-131
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
else: | ||
return input | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,10 +92,7 @@ def backward(self, pre_grad, *args, **kwargs): | |
dmu = -1 * np.sum(dxmu1 + dxmu2, axis=0) | ||
dx2 = 1. / N * np.ones((N, D)) * dmu | ||
|
||
# step0 done! | ||
dx = dx1 + dx2 | ||
|
||
return dx | ||
return dx1 + dx2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
|
||
@property | ||
def params(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,10 +64,7 @@ def fit(self, X, Y, max_iter=100, batch_size=64, shuffle=True, | |
else: | ||
valid_X, valid_Y = None, None | ||
|
||
iter_idx = 0 | ||
while iter_idx < max_iter: | ||
iter_idx += 1 | ||
|
||
for iter_idx in range(1, max_iter + 1): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
# shuffle | ||
if shuffle: | ||
seed = get_rng().randint(111, 1111111) | ||
|
@@ -142,8 +139,7 @@ def predict(self, X): | |
x_next = X | ||
for layer in self.layers[:]: | ||
x_next = layer.forward(x_next) | ||
y_pred = x_next | ||
return y_pred | ||
return x_next | ||
Comment on lines
-145
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def accuracy(self, outputs, targets): | ||
y_predicts = np.argmax(outputs, axis=1) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
ReLU.derivative
refactored with the following changes:or-if-exp-identity
)