Exemple #1
0
    def text(self,v,threshold=0.1,minimum_count=1,include_pairs=True,join='+',maximum_count=5,terms=None,normalize=False):
        if isinstance(v,HRR): v=v.v
        if v is None or self.vectors is None: return ''        
        if normalize:
            nrm=norm(v)
            if nrm>0: v/=nrm
        
        m=numeric.dot(self.vectors,v)
        matches=[(m[i],self.keys[i]) for i in range(len(m))]
        if include_pairs:
            if self.vector_pairs is None: self.generate_pairs()
            # vector_pairs may still be none after generate_pairs (if there is only 1 vector)
            if self.vector_pairs is not None:
                m2=numeric.dot(self.vector_pairs,v)
                matches.extend([(m2[i],self.key_pairs[i]) for i in range(len(m2))])
        if terms is not None:
            matches=[m for m in matches if m[1] in terms]
        matches.sort()
        matches.reverse()

        r=[]        
        for m in matches:
            if threshold is None or (m[0]>threshold and len(r)<maximum_count): r.append(m)
            elif len(r)<minimum_count: r.append(m)
            else: break
            
        return join.join(['%0.2f%s'%(c,k) for (c,k) in r])
    def __init__(self,name,dims,trials_per_block=40,block_rewards=[[0.21,0.63],[0.63,0.21],[0.12,0.72],[0.72,0.12]]):
        # parameters
        self.dims = dims
        self.trials_per_block = trials_per_block
        if len(block_rewards[0]) != dims:
            raise Exception('block_reward dimensionality must match dims')
        self.block_rewards = block_rewards
        
        # vars and constants
        self.trial_num = 0
        self.delay_t = 0.0
        self.approach_t = 0.0
        self.reward_t = 0.0
        self.reward = [0.0] * dims
        self.thalamus_sum = [0.0] * dims
        self.thalamus_choice = 0
        self.rewarded = 0
        self.reward_val = 1.0
        self.gate_val = [0.9]
        self.vstr_gate_val = [1.0]
        self.data_log = []
        
        # generate random state_d-d unit vector
        self.ctx_val = array([random.gauss(0,1) for i in range(state_d)])
        self.ctx_val /= norm(self.ctx_val)   
        
        self.state = 'delay'

        nef.SimpleNode.__init__(self,name)
Exemple #3
0
    def __init__(self,
                 name,
                 dims,
                 learners,
                 trials_per_block=10,
                 environments=[0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1],
                 learn=[
                     True, True, True, True, True, True, True, True, False,
                     False, False, False, False, False, False, False
                 ],
                 block_rewards=[[0.12, 0.72], [0.72, 0.12], [0.12, 0.72],
                                [0.72, 0.12], [0.12, 0.72], [0.72, 0.12],
                                [0.12, 0.72], [0.72, 0.12], [1.0, 0.0],
                                [1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [0.0, 1.0],
                                [0.0, 1.0], [0.0, 1.0], [0.0, 1.0]]):
        # parameters
        self.dims = dims
        self.trials_per_block = trials_per_block
        if len(block_rewards[0]) != dims:
            raise Exception('block_reward dimensionality must match dims')
        if len(environments) != len(block_rewards):
            raise Exception('must specify environment for each block')
        self.block_rewards = block_rewards

        # vars and constants
        self.trial_num = 0
        self.delay_t = 0.0
        self.approach_t = 0.0
        self.reward_t = 0.0
        self.reward = [0.0] * dims
        self.thalamus_sum = [0.0] * dims
        self.thalamus_choice = 0
        self.rewarded = 0
        self.reward_val = 1.0
        self.gate_val = [0.9]
        self.vstr_gate_val = [0.9]
        self.data_log = []
        self.learners = learners
        self.learn = learn

        # generate random cortical states
        self.environments = environments
        self.ctx_states = []
        for i in range(max(self.environments) + 1):
            state = array([random.gauss(0, 1) for i in range(state_d)])
            state /= norm(state)
            self.ctx_states.append(state)

        self.ctx_state = self.ctx_states[self.environments[0]]

        self.state = 'delay'

        nef.SimpleNode.__init__(self, name)
Exemple #4
0
 def tick(self):
     length = numeric.norm(self.input)
     if length > self.input_threshold:
         self.x = [xx / length for xx in self.input]
     self.input = numeric.zeros(self.dimension)
Exemple #5
0
 def limit(x):
     a=numeric.array(x)
     norm=numeric.norm(a)
     if norm>radius: a=a/(norm/radius)
     return a
Input: Randomly chosen D-dimensional value
Ouput: the same value as the input
"""

D = 1       # number of dimensions
L = 2       # number of layers
N = 50      # number of neurons per layer
pstc = 0.01 # synaptic time constant

import nef
import numeric as np

net = nef.Network('Benchmark-1 Communication', seed=1)

import random
value = np.array([random.gauss(0,1) for i in range(D)])
value /= np.norm(value)

net.make_input('input', value)

for i in range(L):
    net.make('layer%d'%i, N, D)

net.connect('input', 'layer0', pstc=pstc)
for i in range(L-1):
    net.connect('layer%d'%i, 'layer%d'%(i+1), pstc=pstc)

net.view()

Exemple #7
0
 def tick(self):
     length=numeric.norm(self.input)
     if length>self.input_threshold:
         self.x=[xx/length for xx in self.input]
     self.input=numeric.zeros(self.dimension)
Exemple #8
0
 def limit(x):
     a = numeric.array(x)
     norm = numeric.norm(a)
     if norm > radius: a = a / (norm / radius)
     return a
Exemple #9
0
 def compare(self, other):
     scale = norm(self.v) * norm(other.v)
     if scale == 0: return 0
     return dot(self.v, other.v) / (scale)
Exemple #10
0
 def normalize(self):
     nrm = norm(self.v)
     if nrm > 0: self.v /= nrm
Exemple #11
0
 def length(self):
     return norm(self.v)
Exemple #12
0
 def compare(self,other):
     scale=norm(self.v)*norm(other.v)
     if scale==0: return 0
     return dot(self.v,other.v)/(scale)
Exemple #13
0
 def normalize(self):
     nrm=norm(self.v)
     if nrm>0: self.v/=nrm
Exemple #14
0
 def length(self):
     return norm(self.v)