コード例 #1
0
ファイル: LNNet.py プロジェクト: nagyistge/NN-Dropout
 def check_loss(self, X, Y, Ws=[]):
     """Check loss at output layer for observations X/Y."""
     if (len(Ws) == 0):
         Ws = self.layer_weights()
     obs_count = X.shape[0]
     M = self.get_drop_masks(obs_count, 0, 0)
     A = self.feedforward(X, M)
     O = self.out_loss(A[-1], Y)
     Yc = lnf.class_cats(Y)
     Yhc = lnf.class_cats(A[-1])
     hits = sum([(int(a) == int(b)) for (a, b) in zip(Yhc, Yc)])
     acc = float(hits) / float(obs_count)
     return {'loss': O['L'], 'acc': acc, 'grad': O['dL']}
コード例 #2
0
ファイル: LNNet.py プロジェクト: nagyistge/NN-Dropout
    def check_acc(self, X, Y, Ws=[]):
        """Check classification accuracy using inputs X with classes Y.

        Classes should be represented in Y as a +/- 1 indicator matrix.
        """
        if (len(Ws) == 0):
            Ws = self.layer_weights()
        obs_count = X.shape[0]
        Yc = lnf.class_cats(Y)
        M = self.get_drop_masks(obs_count, 0, 0)
        A = self.feedforward(X, M, Ws)
        Yh = A[-1]
        Yhc = lnf.class_cats(Yh)
        hits = sum([(int(a) == int(b)) for (a, b) in zip(Yhc, Yc)])
        return (float(hits) / float(obs_count))