numenta / nupic-legacy

Numenta Platform for Intelligent Computing is an implementation of Hierarchical Temporal Memory (HTM), a theory of intelligence based strictly on the neuroscience of the neocortex.
http://numenta.org/
GNU Affero General Public License v3.0
6.33k stars 1.56k forks source link

KNNClassifier test fails: getPartitionId #2927

Closed breznak closed 8 years ago

breznak commented 8 years ago

A report... fails on Ubuntu with core and nupic installed from offic. binaries.

tests/unit/nupic/support/object_json_test.py:75: TestObjectJson.testTuple PASSED
tests/unit/nupic/support/consoleprinter_test/consoleprinter_test.py:48: ConsolePrinterTest.testPrint PASSED

================================================================================== FAILURES ===================================================================================
____________________________________________________________________ KNNClassifierTest.testGetPartitionId _____________________________________________________________________
self = <tests.unit.nupic.algorithms.knn_classifier_test.KNNClassifierTest testMethod=testGetPartitionId>

    def testGetPartitionId(self):
      """
        Test a sequence of calls to KNN to ensure we can retrieve partition Id:
            - We first learn on some patterns (including one pattern with no
              partitionId in the middle) and test that we can retrieve Ids.
            - We then invoke inference and then check partitionId again.
            - We check incorrect indices to ensure we get an exception.
            - We check the case where the partitionId to be ignored is not in
              the list.
            - We learn on one more pattern and check partitionIds again
            - We remove rows and ensure partitionIds still work
        """
      params = {"distanceMethod": "rawOverlap"}
      classifier = KNNClassifier(**params)

      dimensionality = 40
      a = np.array([1, 3, 7, 11, 13, 17, 19, 23, 29], dtype=np.int32)
      b = np.array([2, 4, 8, 12, 14, 18, 20, 28, 30], dtype=np.int32)
      c = np.array([1, 2, 3, 14, 16, 19, 22, 24, 33], dtype=np.int32)
      d = np.array([2, 4, 8, 12, 14, 19, 22, 24, 33], dtype=np.int32)
      e = np.array([1, 3, 7, 12, 14, 19, 22, 24, 33], dtype=np.int32)

      denseA = np.zeros(dimensionality)
      denseA[a] = 1.0

      classifier.learn(a, 0, isSparse=dimensionality, partitionId=433)
      classifier.learn(b, 1, isSparse=dimensionality, partitionId=213)
      classifier.learn(c, 1, isSparse=dimensionality, partitionId=None)
      classifier.learn(d, 1, isSparse=dimensionality, partitionId=433)

>     self.assertEquals(classifier.getPartitionId(0), 433)
E     AttributeError: 'KNNClassifier' object has no attribute 'getPartitionId'

tests/unit/nupic/algorithms/knn_classifier_test.py:230: AttributeError
____________________________________________________________ KNNClassifierTest.testGetPartitionIdWithNoIdsAtFirst _____________________________________________________________
self = <tests.unit.nupic.algorithms.knn_classifier_test.KNNClassifierTest testMethod=testGetPartitionIdWithNoIdsAtFirst>

    def testGetPartitionIdWithNoIdsAtFirst(self):
      """
        Tests that we can correctly retrieve partition Id even if the first few
        vectors do not have Ids
        """
      params = {"distanceMethod": "rawOverlap"}
      classifier = KNNClassifier(**params)

      dimensionality = 40
      a = np.array([1, 3, 7, 11, 13, 17, 19, 23, 29], dtype=np.int32)
      b = np.array([2, 4, 8, 12, 14, 18, 20, 28, 30], dtype=np.int32)
      c = np.array([1, 2, 3, 14, 16, 19, 22, 24, 33], dtype=np.int32)
      d = np.array([2, 4, 8, 12, 14, 19, 22, 24, 33], dtype=np.int32)

      denseA = np.zeros(dimensionality)
      denseA[a] = 1.0

      denseD = np.zeros(dimensionality)
      denseD[d] = 1.0

      classifier.learn(a, 0, isSparse=dimensionality, partitionId=None)
      classifier.learn(b, 1, isSparse=dimensionality, partitionId=None)
      classifier.learn(c, 2, isSparse=dimensionality, partitionId=211)
      classifier.learn(d, 1, isSparse=dimensionality, partitionId=405)

      cat, _, _, _ = classifier.infer(denseA, partitionId=405)
      self.assertEquals(cat, 0)

      cat, _, _, _ = classifier.infer(denseD, partitionId=405)
>     self.assertEquals(cat, 2)
E     AssertionError: 1 != 2

tests/unit/nupic/algorithms/knn_classifier_test.py:310: AssertionError
============================================================== 2 failed, 817 passed, 45 skipped in 82.06 seconds =
rhyolight commented 8 years ago

@breznak Is this using the newest binaries?

nupic 0.3.6
nupic.bindings 0.2.7
cogmission commented 8 years ago

I'm currently porting this to Java and all tests run fine for me (I'm compiling from source [with @rhyolight's help]). So this must be a binary packaging thing...?

breznak commented 8 years ago

I'm now having 0.3.7 from source as well and the problem is not occurring. So I believe it was the binary package as well

rhyolight commented 8 years ago

Thanks for checking guys.

cogmission commented 8 years ago

👊🏽

dai-dao commented 8 years ago

@breznak I'm getting the same errors as you did when running the tests. Could you tell me how you solved the issue?

app-genesis commented 8 years ago

Same here @breznak

cogmission commented 8 years ago

@dai-dao @app-genesis I mentioned earlier that you have to make sure you have the latest versions (it runs fine for me - I have a source installation not binaries). When @breznak updated, he stopped getting these errors.

(You can tell its ok in the latest version because the build (which runs all the tests), passes. ;-)

app-genesis commented 8 years ago

@cogmission Personally I use nupic.bindings 0.2.7 I'm not sure which version of NuPic I have installed because I installed it by pip install nupic. Could you please inform us how to check which version we have installed (nupic --version doesn't work) and how to update it to the newest version? Thank you!!!

cogmission commented 8 years ago

I'm afraid I don't pip very well, you should probably post to the mailing list

app-genesis commented 8 years ago

My version file in NuPic says 0.3.7.dev0 and the nupic.bindings I've installed was nupic.bindings-0.2.7-cp27-none-linux_x86_64.whl. So, I think I have the latest versions but I get these two failures. Could you please suggest me to try anything else?

cogmission commented 8 years ago

Hi @app-genesis,

I suggest you try asking this question on the "NuPIC-hackers" mailing list if you don't get a response here from someone who can help you? Here's the link to help get you started: http://numenta.org/lists/

rhyolight commented 8 years ago

boom

app-genesis commented 8 years ago

@cogmission Thank you for your polite answer. I have indeed the latest versions which I found by typing in console:

python import pkg_resources nupicBindings = pkg_resources.get_distribution("nupic.bindings") print nupicBindings.project_name, nupicBindings.version nupic = pkg_resources.get_distribution("nupic") print nupic.project_name, nupic.version

I confused with nupic and nupic.core, the guides are not exactly the same. I reinstalled everything according to Compiling NuPIC on Ubuntu 14 LTS video and everything works fine now. Thank you! @rhyolight nice gif, not so helpful though.

rhyolight commented 8 years ago

@app-genesis Yes, sorry. Perhaps this helps? http://lists.numenta.org/pipermail/nupic_lists.numenta.org/2016-January/012622.html

rhyolight commented 8 years ago

@app-genesis It is possible you have some other versions of nupic or nupic.core installed. Try uninstalling them all before restarting the installation process:

pip uninstall nupic -y
pip uninstall nupic.bindings -y

Run those commands several times until pip tells you nothing is installed.

app-genesis commented 8 years ago

@rhyolight everything works fine now. Thank you very much!

rhyolight commented 8 years ago

@app-genesis Can you share what you did to fix the problem?

app-genesis commented 8 years ago

@rhyolight As I wrote yesterday I reinstalled everything according to Compiling NuPIC on Ubuntu 14 LTS YouTube video, which I think is yours. So, thank you again!