Ejemplo n.º 1
0
    def train(self, X, **kw):
        from plastk import rand
        self._mem.append((X, kw))

        N = len(self._mem)
        i = rand.randrange(N)
        self.debug("Training on memory element", i)
        V, training_kw = self._mem[i]
        super(VQTrainingMemory, self).train(V, **training_kw)

        if N > self.memory_size:
            self._mem.pop(0)

        self.present_input(X)
Ejemplo n.º 2
0
    def train(self,X,**kw):
        from plastk import rand
        self._mem.append((X,kw))
        
        N = len(self._mem)
        i = rand.randrange(N)
        self.debug("Training on memory element",i)
        V,training_kw = self._mem[i]
        super(VQTrainingMemory,self).train(V,**training_kw)

        if N > self.memory_size:
            self._mem.pop(0)
            
        self.present_input(X)
Ejemplo n.º 3
0
#				loadTiles loads them into array tiles starting from position startElement
#			if memSizeorCtable is a CollisionTable,
#				hashing collisions are checked for and handled
#				otherwise it must be an integer power of 2 and collisions are ignored
#			floats is a list of real variables to be tiled
#			ints is an optional list of integer variables to be tiled
#		CollisionTable(size,safety) or makeCtable(size,safety)
#			size and safety are optional; size must be a power of 2; makeCtable checks for this

from plastk.rand import random, randrange
from math import floor, log

_maxNumFloats = 200  # maximum number of variables used in one grid
_maxLongint = 2147483647
_maxLongintBy4 = _maxLongint // 4
_randomTable = [randrange(65536) for i in range(2048)]

# The following are temporary variables used by tiles.
_qstate = [0 for i in range(_maxNumFloats)]
_base = [0 for i in range(_maxNumFloats)]
_coordinates = [0 for i in range(1 + 2 * _maxNumFloats)]


class CollisionTable:
    "Structure to handle collisions"

    def __init__(self, size_val=2048, safety_val='safe'):
        # if not power of 2 error
        if not powerOf2(size_val):
            print "error - size should be a power of 2"
        self.size = size_val
Ejemplo n.º 4
0
#				loadTiles loads them into array tiles starting from position startElement
#			if memSizeorCtable is a CollisionTable, 
#				hashing collisions are checked for and handled
#				otherwise it must be an integer power of 2 and collisions are ignored
#			floats is a list of real variables to be tiled
#			ints is an optional list of integer variables to be tiled
#		CollisionTable(size,safety) or makeCtable(size,safety)
#			size and safety are optional; size must be a power of 2; makeCtable checks for this

from plastk.rand import random, randrange
from math import floor, log

_maxNumFloats = 200					# maximum number of variables used in one grid
_maxLongint = 2147483647
_maxLongintBy4 = _maxLongint // 4          
_randomTable = [randrange(65536) for i in range(2048)]

# The following are temporary variables used by tiles.
_qstate = [0 for i in range(_maxNumFloats)]
_base = [0 for i in range(_maxNumFloats)]
_coordinates = [0 for i in range(1 + 2*_maxNumFloats)]

class CollisionTable:
	"Structure to handle collisions"
	def __init__(self, size_val=2048, safety_val='safe'):
		# if not power of 2 error
		if not powerOf2(size_val):
			print "error - size should be a power of 2"
		self.size = size_val				
		self.safety = safety_val			# one of 'safe', 'super safe' or 'unsafe'
		self.calls = 0