Skip to content

Commit

Permalink
NUP-2504: Add test to softmax overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lscheinkman committed Apr 12, 2018
1 parent 669874c commit 9475ec8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/unit/nupic/algorithms/sdr_classifier_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import cPickle as pickle
import random
import sys
import tempfile
import types
import unittest2 as unittest
Expand Down Expand Up @@ -788,6 +789,16 @@ def testMultiStepPredictions(self):
self.assertAlmostEqual(result2[0][1], 1.0, places=1)


def testSoftMaxOverflow(self):
"""
Test if the softmax normalization overflows
"""
c = SDRClassifier([1], 1.0, 0.1, 0)
weight = numpy.array([[sys.float_info.max_exp + 1]])
res = c.inferSingleStep([0], weight)
self.assertFalse(numpy.isnan(res), "SoftMax overflow")


def _doWriteReadChecks(self, computeBeforeSerializing):
c1 = SDRClassifier([0], 0.1, 0.1, 0)

Expand Down

0 comments on commit 9475ec8

Please sign in to comment.