I need to create a perceptron which has two target values(0,1) and 21 input vectors. Each vector is 110592 in size. How do I call the "newp" function for this?
p=[I1,I2,I3,P1,P2,P3,Q1,Q2,Q3,R1,R2,R3,Z1,Z2,Z3,A1,A2,A3,B1,B2,B3];
t=[0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
each vector I1,I2. etc are of size 1*110592.
if the perceptron has only two inputs, i can call the function as below.
newp([0 1;0 2],1); // which says 1st input is of range 0 to 1 and 2nd input is of range 0 2
SO the problem is how do i format my first argument when i have such a large vector input?
Related
I hope you can help with a little problem I am having.
I want to upsample and downsample a vector with zeros and ones. We have the functions upsample and downsample for that, however, the upsample function in Matlab only adds zeros to the vector. I would like to repeat the value, instead of just putting in zeros.
Unfortunately the upsample function does not do that. Thus, I tried to use repmat (in the third dimension) and then reshape to get back to the old format. I know it must be possible with these functions, but if I simply use them, the vector just gets duplicated and added to the end.
An example:
The input vector is: [1 0 0 1 0 1 0 1 1 1 0 0] (these should be random).
Now I want to upsample (say) by a factor of 2. Then I want to get:
[1 1 0 0 0 0 1 1 0 0 1 1 0 0 1 1 1 1 1 1 0 0 0 0].
Thanks in advance for any help!
You can use repelem:
>> repelem([1 0 1],2)
ans =
1 1 0 0 1 1
Or using repmat and reshape when input is a column vector:
>> input = [1 0 1];
>> reshape(repmat(input, 2, 1), 1, [])
ans =
1 1 0 0 1 1
How can I count the number of values that are contiguous in an matrix? For example, if
A= [ 1 0 1 0 0 0 0 \
1 1 1 0 0 0 1\
1 1 0 1 1 1 1]
is a 7 by 3 matrix then the result should indicate that there are 12 contiguous values that are "1" (highlighted in bold), that there are 8 contiguous 0 values (highlighted in italics) and one lone 0 value. Code in IDL is preferred but MATLAB would also be helpful.
This is what you can do in MATLAB using the bwconncomp function. This is a function in the Image Processing Toolbox. I don't know a whole lot about IDL, it might have a similar function.
bwconncomp returns a struct with some information, one of the fields is PixelIdxList, which is a cell array with one element per connected component. Each of these elements is a vector with the indices to one of the array elements in the connected component. For the case of the 1 elements in your example, this cell array will have one vector with 12 values. For the case of the 0 elements, it will have two vectors, one with 1 value and one with 8:
>> A = [ 1 0 1 0 0 0 0 ; 1 1 1 0 0 0 1 ; 1 1 0 1 1 1 1 ];
>> CC = bwconncomp(A==1, 8);
>> cellfun(#numel, CC.PixelIdxList)
ans =
12
>> CC = bwconncomp(A==0, 8);
>> cellfun(#numel, CC.PixelIdxList)
ans =
1 8
The bwconncomp takes 4 or 8 as the second argument. This specifies what are considered connected elements (contiguous values, neighbors). 4 means only the 4 elements N,S,E,W are connected; 8 means also diagonal connections exist (8 neighbors).
I used selforgmap for pattern recognition. After training finished i calculated the network's output of the whole data and I got a logical matrix.
I want know how selforgmap:
1- numbers the neurons (i mean from 1 to N, while N equals the total number of neurons)
2-
Here is my map
1 O------O
/ /
0 O------O
0 0.5 1 1.5
the output looks like this (after transpose)
1 0 0 0
0 1 0 0
1 0 0 0
1 0 0 0
0 0 1 0
0 1 0 0
0 0 1 0
0 0 1 0
i want know which column in output corresponds to which neuron of the map
Selforgmap in MATLAB starts the numbering from the bottom left. For your example, the neurons are labeled:
3 - 4
/ /
1 2
You can use the
vec2ind(output)
command to associate the output with the neuron to which the corresponding input has been assigned.
I want to find the index of all linear columns in matrix. The output is a vector in which gives 1 for independent columns and -1 for all linear dependency columns. For example, I have a matrix A that is
A =
1 0 0 0 0 1 1
1 0 0 1 0 1 1
1 1 1 0 1 1 1
1 1 1 0 1 1 0
We can see that column dependency are 1,2,3,5,6. Hence my expected result are
output=[-1 -1 -1 1 -1 -1 1];
And the independent matrix remains
A =
0 1
1 1
0 1
0 0
How to implement it by matlab ?
How about with linear rows?
I think you are looking for something like this -
out = ones(1,size(A,2))
out(sum(all(bsxfun(#eq,A,permute(A,[1 3 2])),1),2)>=2)=-1
So, basically for each column, it finds if there are any other matching columns and if there are, it identifies that as a "dependent" (from what I could gather as the definition for this problem) column.
Output -
out =
-1 -1 -1 1 -1 -1 1
For finding "dependency" across rows, use this -
out = ones(1,size(A,1))
out(sum(all(bsxfun(#eq,A,permute(A,[3 2 1])),2),1)>=2)=-1
In nntool, the sample data is formatted as: [0 1 -1; 2 3 1]
I have ~8000 data points in a text file.
How do I format those points for use here? What does the semicolon signify?
From this example, that would mean each column of the input data would be separated by a ;. The Target data would be a vector like [1 2 3 4] corresponding to each row of the input data.
E.g. if you want to learn the XOR truth table:
X Y XOR
0 0 0
0 1 1
1 0 1
1 1 0
Then the Input matrix is
X Y
0 0
0 1
1 0
1 1
And the Target is
XOR
0
1
1
0
And therefore, your data should be formatted as [0 0 1 1;0 1 0 1] for the input (each column is separated by a ;) and the target data would be [0 1 1 0].
As far as your 8000 point data file is concerned, you can load it into a variable in your workspace and let nntool read the input matrix from your workspace or a .mat file (after you've saved the variable into it).