Correlation Matrix Memories' Orthogonal Key Tests






#!/usr/bin/env python3
"""This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

Based on the paper "Correlation Matrix Memories" by TEUVO KOHONEN.
"""
__author__ = 'Mārtiņš Avots'
import unittest
from completeCorrelationMatrixMemories import CompleteCorrelationMatrixMemory
from testingArtifacts import floatTuple, difference, images3x3
from random import uniform, sample
class OrthogonalKeyTests(unittest.TestCase):
	def testAssymetricOrthogonalKeys(self):
		self.__testOrthogonalKeys({
			(3,0) : (3,1,4.5),
			(0,-7) : (-3,-1,99)
		})
	def testSimpleOrthogonalKeys1(self):
		self.__testOrthogonalKeys({
			(1,0) : (3,1,4.5),
			(0,1) : (-3,-1,99)
		})
	def testSimpleOrthogonalKeys2(self):
		self.__testOrthogonalKeys({
			(2,0) : (3,1,4.5),
			(0,2) : (-3,-1,99)
		})
	def testSimpleOrthogonalKeys4(self):
		self.__testOrthogonalKeys({
			(4,0) : (3,1,4.5),
			(0,4) : (-3,-1,99)
		})
	def testSimpleOrthogonalKeys8(self):
		self.__testOrthogonalKeys({
			(8,0) : (3,1,4.5),
			(0,8) : (-3,-1,99)
		})
	def testSimpleOrthogonalKeysRandom(self):
		self.__testOrthogonalKeys({
			(uniform(-1000, 1000),0) : (3,1,4.5), # TODO Random chosen magic constants
			(0,uniform(-1000, 1000)) : (-3,-1,99) # TODO Random chosen magic constants
		})
	def testSimpleOrthogonalKeys9ZeroTwo(self):
		values = sample(list(images3x3.values()), 9)
		mapping = {}
		for i in range(9):
			orthogonalKey = [0]*9
			orthogonalKey[i] = 2
			orthogonalKey = tuple(orthogonalKey)
			mapping[orthogonalKey] = values[i]
		self.__testOrthogonalKeys(mapping)
	def testSimpleOrthogonalKeys9uniform(self):
		values = sample(list(images3x3.values()), 9)
		mapping = {}
		for i in range(9):
			orthogonalKey = [0]*9
			orthogonalKey[i] = uniform(-1000, 1000) # TODO Random chosen magic constants
			orthogonalKey = tuple(orthogonalKey)
			mapping[orthogonalKey] = values[i]
		self.__testOrthogonalKeys(mapping)
	def __testOrthogonalKeys(self, mapping):
		testSubject = CompleteCorrelationMatrixMemory(mapping)
		for key in mapping:
			recall = testSubject.recall(key)
			expectedRecall = floatTuple(mapping[key])
			for i in range(len(recall)):
				self.assertAlmostEqual(recall[i], expectedRecall[i])
wide screen
  1. archive
    1. academic-publishers-of-research-papers-etc-with-open-accessin-computer-science.html
    2. blogs-related-to-computer-science.html
    3. calculus-languages.html
    4. complete-correlation-matrix-memories-orthogonal-key.tests.html
    5. complete-correlation-matrix-memories.html
    6. html-to-image-conversion-via-wkhtmltopdf.html
    7. information-related-to-managment.html
    8. operation-system-state-interface.html
    9. optimization-software.html
    10. programming-language-concepts.html
    11. publications-defining-optimization-problems.html
    12. publications-related-to-optimization-algorithms.html
    13. publications-related-to-optimization-software.html
    14. test.html
    15. visibility-problem.html
    16. vnc-client.html
    17. writings-related-to-complexities-relevant-to-optimization.html
    18. xml-based-blog-framework-for-splitcells-net.html
  1. archive
    1. academic-publishers-of-research-papers-etc-with-open-accessin-computer-science.html
    2. blogs-related-to-computer-science.html
    3. calculus-languages.html
    4. complete-correlation-matrix-memories-orthogonal-key.tests.html
    5. complete-correlation-matrix-memories.html
    6. html-to-image-conversion-via-wkhtmltopdf.html
    7. information-related-to-managment.html
    8. operation-system-state-interface.html
    9. optimization-software.html
    10. programming-language-concepts.html
    11. publications-defining-optimization-problems.html
    12. publications-related-to-optimization-algorithms.html
    13. publications-related-to-optimization-software.html
    14. test.html
    15. visibility-problem.html
    16. vnc-client.html
    17. writings-related-to-complexities-relevant-to-optimization.html
    18. xml-based-blog-framework-for-splitcells-net.html