Home > TNNT_1_07 > @theta_neuron_network > relate_q_to_k.m

relate_q_to_k

PURPOSE ^

RELATE_Q_TO_K relates spiking and synaptic indices

SYNOPSIS ^

function K2Q=relate_q_to_k(ThNN,ts,varargin)

DESCRIPTION ^

RELATE_Q_TO_K relates spiking and synaptic indices

Description:
If Neuron1 and Neuron2 are provided, returns an array that contains q
values for Neuron 2 on the synapse between Neuron 1 and Neuron 2. The
indices of the array are the k values.  This array can then be used to
relate the synaptic indices (k) with the spiking indices (q).
For SISO networks, k=q. If Neuron1 and Neuron2 are not provided, a cell
array is returned with K2Q arrays for all connected neuron pairs.  This
second method of calling is more efficient than repeatedly calling the
first method since it reduces redundant function calling.

Syntax:
K2Q=RELATE_Q_TO_K(ThNN,ts,[Verbose]);
K2Q=RELATE_Q_TO_K(ThNN,ts,Neuron1,Neuron2,[Verbose]);
K2Q=RELATE_Q_TO_K(ThNN,ts,Neuron1,Neuron2,InputNeurons,Verbose);

Input Parameters:
o ThNN: An object of the theta neuron network class
o ts: A cell array of length NumNeurons containing in each cell an array
    of length r_j of neuron j's output spike times.
o Neuron1: Neuron index for the input neuron
o Neuron2: Neuron index for the output neuron
o InputNeurons: Optional input array containing the input neuron indices
    for Neuron1, used to reduce redundant computation. Verbose must be
    specified if InputNeurons is specified.
o Verbose: Optional flag to indicate if extra information will be
    displayed on the screen. A value of 0 displays no additional
    information (this is the default value), while a value of 1 displays
    all information.  Values greater than 1 display partial information.
    See Verbose for more details.

Output Parameters:
o K2Q: Either an array that contains q values for Neuron 2 on the synapse
    between Neuron 1 and Neuron 2 (the indices of the array are the k
    values) or a cell array with K2Q arrays for all connected neuron
    pairs.

Examples:
>> %SISO Example
>> ThNN=theta_neuron_network('ReferenceTime',-1,'StructureFormat',...
     {'LayerArray', [2 1]});
>> ts=run_network(ThNN, [1 5; 2 7]);
>> K2Q=relate_q_to_k(ThNN,ts,2,3,1);
>> K2Q=relate_q_to_k(ThNN,ts,2,3,[1 2],0);
>> K2QAll=relate_q_to_k(ThNN,ts)

>> %MIMO Example
>> ThNN=theta_neuron_network('ReferenceTime',-1,'StructureFormat',...
     {'LayerArray', [2 1]});
>> ts=run_network(ThNN, [2 3; 1 5; 2 7]);
>> K2Q=relate_q_to_k(ThNN,ts,2,3,1);
>> K2QAll=relate_q_to_k(ThNN,ts)

See also theta_neuron_network, verbose

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function K2Q=relate_q_to_k(ThNN,ts,varargin)
0002 %RELATE_Q_TO_K relates spiking and synaptic indices
0003 %
0004 %Description:
0005 %If Neuron1 and Neuron2 are provided, returns an array that contains q
0006 %values for Neuron 2 on the synapse between Neuron 1 and Neuron 2. The
0007 %indices of the array are the k values.  This array can then be used to
0008 %relate the synaptic indices (k) with the spiking indices (q).
0009 %For SISO networks, k=q. If Neuron1 and Neuron2 are not provided, a cell
0010 %array is returned with K2Q arrays for all connected neuron pairs.  This
0011 %second method of calling is more efficient than repeatedly calling the
0012 %first method since it reduces redundant function calling.
0013 %
0014 %Syntax:
0015 %K2Q=RELATE_Q_TO_K(ThNN,ts,[Verbose]);
0016 %K2Q=RELATE_Q_TO_K(ThNN,ts,Neuron1,Neuron2,[Verbose]);
0017 %K2Q=RELATE_Q_TO_K(ThNN,ts,Neuron1,Neuron2,InputNeurons,Verbose);
0018 %
0019 %Input Parameters:
0020 %o ThNN: An object of the theta neuron network class
0021 %o ts: A cell array of length NumNeurons containing in each cell an array
0022 %    of length r_j of neuron j's output spike times.
0023 %o Neuron1: Neuron index for the input neuron
0024 %o Neuron2: Neuron index for the output neuron
0025 %o InputNeurons: Optional input array containing the input neuron indices
0026 %    for Neuron1, used to reduce redundant computation. Verbose must be
0027 %    specified if InputNeurons is specified.
0028 %o Verbose: Optional flag to indicate if extra information will be
0029 %    displayed on the screen. A value of 0 displays no additional
0030 %    information (this is the default value), while a value of 1 displays
0031 %    all information.  Values greater than 1 display partial information.
0032 %    See Verbose for more details.
0033 %
0034 %Output Parameters:
0035 %o K2Q: Either an array that contains q values for Neuron 2 on the synapse
0036 %    between Neuron 1 and Neuron 2 (the indices of the array are the k
0037 %    values) or a cell array with K2Q arrays for all connected neuron
0038 %    pairs.
0039 %
0040 %Examples:
0041 %>> %SISO Example
0042 %>> ThNN=theta_neuron_network('ReferenceTime',-1,'StructureFormat',...
0043 %     {'LayerArray', [2 1]});
0044 %>> ts=run_network(ThNN, [1 5; 2 7]);
0045 %>> K2Q=relate_q_to_k(ThNN,ts,2,3,1);
0046 %>> K2Q=relate_q_to_k(ThNN,ts,2,3,[1 2],0);
0047 %>> K2QAll=relate_q_to_k(ThNN,ts)
0048 %
0049 %>> %MIMO Example
0050 %>> ThNN=theta_neuron_network('ReferenceTime',-1,'StructureFormat',...
0051 %     {'LayerArray', [2 1]});
0052 %>> ts=run_network(ThNN, [2 3; 1 5; 2 7]);
0053 %>> K2Q=relate_q_to_k(ThNN,ts,2,3,1);
0054 %>> K2QAll=relate_q_to_k(ThNN,ts)
0055 %
0056 %See also theta_neuron_network, verbose
0057 
0058 %Copyright (C) 2008 Sam McKennoch <Samuel.McKennoch@loria.fr>
0059 
0060 
0061 if nargin<2
0062     disp('Error in relate_q_to_k: Not enough input arguments');
0063     K2Q=-1;
0064     return;
0065 elseif nargin==2
0066     Verbose=0;
0067 elseif nargin==3
0068     Verbose=varargin{1};
0069 elseif nargin==4
0070     Neuron1=varargin{1};
0071     Neuron2=varargin{2};
0072     Verbose=0;
0073     InputNeurons=ThNN.RelativeInputNeurons{Neuron2};%get_input_neurons(ThNN,Neuron2);
0074 elseif nargin==5
0075     Neuron1=varargin{1};
0076     Neuron2=varargin{2};
0077     Verbose=varargin{3};
0078     InputNeurons=ThNN.RelativeInputNeurons{Neuron2};%get_input_neurons(ThNN,Neuron2);
0079 elseif nargin==6
0080     Neuron1=varargin{1};
0081     Neuron2=varargin{2};
0082     InputNeurons=varargin{3};
0083     Verbose=varargin{4};
0084 end
0085 
0086 %Recursively call this function in single neuron mode
0087 if nargin==2 || nargin==3
0088     Weights=ThNN.Weights;
0089     Conn=(Weights~=0);
0090     K2Q=cell(size(Conn));
0091 
0092     if ThNN.RecursionFlag
0093         %Inline setdiff
0094         %NeuronQueue=setdiff(1:size(Conn,1),ThNN.InputNeurons');%CompletedNeurons);
0095         NeuronQueue=1:size(Conn,1);
0096         for n=1:length(ThNN.InputNeurons)
0097             NeuronQueue=NeuronQueue(~(NeuronQueue==ThNN.InputNeurons(n)));
0098         end
0099     else
0100         NeuronQueue=ThNN.NeuronQueue;
0101     end
0102 
0103     Pos=1;
0104     while Pos<=length(NeuronQueue) && ~isempty(NeuronQueue)
0105         %[NeuronQueue,CurrentNeuron]=pop(NeuronQueue);
0106         CurrentNeuron=NeuronQueue(Pos);
0107         if ThNN.RecursionFlag
0108             NeuronQueue=NeuronQueue(2:end);
0109         else
0110             Pos=Pos+1;
0111         end
0112         CurrentInputNeurons=ThNN.RelativeInputNeurons{CurrentNeuron}';%get_input_neurons(ThNN,CurrentNeuron)';
0113         for j=CurrentInputNeurons
0114             K2Q{j,CurrentNeuron}=relate_q_to_k(ThNN,ts,j,CurrentNeuron,CurrentInputNeurons,Verbose);
0115         end
0116         %Find Similarly connected Neurons
0117         for m=NeuronQueue(Pos:end)'
0118             if min(Conn(m,:)==Conn(CurrentNeuron,:))==1
0119                 K2Q(:,m)=K2Q(:,CurrentNeuron);
0120 
0121                 %Inline setdiff
0122                 %NeuronQueue=setdiff(NeuronQueue,m)
0123                 NeuronQueue=NeuronQueue(~(NeuronQueue==m)); %Short because m is a scalar
0124 
0125             end
0126         end
0127     end
0128 
0129     %Single neuron mode
0130 else
0131 
0132     Indices=[]; K2Q=[];
0133 
0134     try
0135         for j=1:length(InputNeurons)
0136             Indices=[Indices; [InputNeurons(j)*ones(1,length(ts{InputNeurons(j)})); ts{InputNeurons(j)}]'];
0137         end
0138 
0139         %Inline sortrows
0140         %Indices=sortrows(Indices,2);
0141         [Temp1,Temp2]=sort(Indices(:,2));
0142         Indices=[Indices(Temp2,1) Temp1];
0143 
0144         K2Q=[K2Q; find(Indices(:,1)==Neuron1)];
0145 
0146         if (Verbose==1)
0147             disp(['Calculating the index relationship between neurons ', num2str(Neuron1), ' and ' num2str(Neuron2)]);
0148             disp('Indices contains the input neuron index in row 1 and the input spike time in row 2');
0149             Indices
0150             disp('K2Q is an array that contains the q values for the second neuron on the synapse between the two neurons');
0151             K2Q
0152         end
0153 
0154         return;
0155     catch
0156         if ~ismember(Neuron1,InputNeurons)
0157             disp('Error in K2Q: Neuron1 is not an input neuron to Neuron2');
0158             K2Q=-1;
0159             return;
0160         end
0161     end
0162 end

Generated on Wed 02-Apr-2008 15:16:32 by m2html © 2003