Skip to content

Commit

Permalink
Added CrossEntropy
Browse files Browse the repository at this point in the history
  • Loading branch information
sharnam19 committed Oct 23, 2017
1 parent 58b7f55 commit 5d6dc6c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
16 changes: 14 additions & 2 deletions networks/layers/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ def loss_reg(self):

def backprop(self,dOut=None):
return self.dx


def accuracy(self,scores,y):
return 1.0*np.sum(np.argmax(scores,axis=1)==y)/y.shape[0]

class SVM():

def __init__(self):
Expand All @@ -222,6 +225,9 @@ def loss_reg(self):

def backprop(self,dOut=None):
return self.dx

def accuracy(self,scores,y):
return 1.0*np.sum(np.argmax(scores,axis=1)==y)/y.shape[0]

def MSE():

Expand All @@ -241,6 +247,9 @@ def loss_reg(self):

def backprop(self,dOut=None):
return self.dx

def accuracy(self,scores,y):
return rel_error(scores,y)

class CrossEntropy():

Expand All @@ -260,7 +269,10 @@ def loss_reg(self):

def backprop(self,dOut=None):
return self.dx


def accuracy(self,scores,y):
return 1.0*np.sum(round(scores,0)==y)/y.shape[0]

class BatchNormalization(object):

def __init__(self,gamma,beta,params,update_params):
Expand Down
5 changes: 1 addition & 4 deletions networks/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ def batch_test(self,X,y):
loss += layer.loss_reg()

scores,inp = self.layers[-1].forward(inp,y)
return self.accuracy(scores,y),inp+loss

def accuracy(self,scores,y):
return 1.0*np.sum(np.argmax(scores,axis=1)==y)/y.shape[0]
return self.layers[-1].accuracy(scores,y),inp+loss

def predict(self,X):
inp = X
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
setup(
name = 'networks',
packages = ['networks','networks/layers','networks/layers/util/','networks/layers/descent/'],
version = '0.3.5', # Ideally should be same as your GitHub release tag varsion
version = '0.3.6', # Ideally should be same as your GitHub release tag varsion
description = 'Allows to create NN models',
author = 'Shharrnam Chhatpar',
author_email = '[email protected]',
url = 'https://github.com/sharnam19/Networks',
download_url = 'https://github.com/sharnam19/Networks/archive/v0.3.5.tar.gz',
download_url = 'https://github.com/sharnam19/Networks/archive/v0.3.6.tar.gz',
keywords = ['machine-learning', 'deep-learning','neural-networks','linear regression',
'logistic regression'],
classifiers = [],
Expand Down

0 comments on commit 5d6dc6c

Please sign in to comment.