2013/den13: gen_data.m

File gen_data.m, 1.4 KB (added by jtapson, 5 years ago)

function to generate a test data set

Line 
1function [ X, W ] = gen_data( channels, length, window, overlap, fraction )
2
3% function to generate test data for SKIM script
4% written by Jonathan Tapson at Telluride, 2/7/2013
5%
6% X is data set, W is the target pattern
7% multiple inputs, one output
8% output is the last column of X
9% channels is number of input neurons
10% length is number of samples in time
11% window is length in samples of pattern
12% overlap is likelihood of patterns overlapping (not real probability)
13% fraction is fraction of samples which are random spikes
14% gen_stp: Generate a spatio-temporal pattern for training or testing
15
16out_block=10;                               % length of output spike
17out_pat=ones(10,1);                         % target pattern
18X = (rand(length, channels+1)<fraction);     % start with random spike noise
19X(:,(channels+1))=zeros(length,1);          % empty output array
20W = zeros(window, channels+1);              % empty pattern block
21
22% make spatio-temporal pattern
23R= round(rand(1,channels)*(window-out_block-1)); % spike indices, not overlapping with target
24for i=1:channels
25   W((R(i)+1),i)=1;                         % make spikes
26end
27W((window-out_block+1):window,channels+1)=out_pat;
28
29% insert spatio-temporal pattern in X (this is a mess)
30T=window/length*overlap;
31I=(rand(length,1)<T);
32for i=1:(length-window)
33    if I(i,1)==1
34        X(i:(i+window-1),:)=W+X(i:(i+window-1),:);
35    end
36
37
38
39
40end
41