how to make one layer perceptrons learn to show seven segments? - neural-network

I was asked to write an algorithm to make seven one layer perceptrons learn to show seven segments number according to 4 0-1 inputs, for example
-1 -1 -1 -1 ==> 1 1 1 1 1 1 -1 % 0
-1 -1 -1 1 ==> -1 -1 -1 -1 1 1 -1 % 1
...
can any one help me, please

So, if I'm interpreting this correctly, you give your net a binary representation of a digit and you want it to tell you what line segments are needed to display that digit seven-segments style.
Luckily, since there are only 10 digits, you can just hand write a training set where each digit is correctly matched to the segments needed, and then use the standard perceptron training algorithm: the delta rule.
This algorithm will change the weights of the network until every input pattern is associated with the correct output pattern.
Implementation note: make sure all 4 input units are connected to all 7 output units, and that all of the connection weights start out at some small random value.

Related

Choosing which variables to normalize while applying logistic regression

Suppose a dataset comprises independent variables that are continuous and binary variables. Usually the label/outcome column is converted to a one hot vector, whereas continuous variables can be normalized. But what needs to be applied for binary variables.
AGE RACE GENDER NEURO EMOT
15.95346 0 0 3 1
14.57084 1 1 0 0
15.8193 1 0 0 0
15.59754 0 1 0 0
How does this apply for logistic regression and neural networks?
If the range of continuous value is small, encode it into a binary form and use each bit of that binary form as a predictor.
For example, number 2 = 10 in binary.
Therefore
predictor_bit_0 = 0
predictor_bit_1 = 1
Try and see if it works. Just to warn you, this method is very subjective and may or may not yield good results for your data. I'll keep you posted if I find a better solution

How to properly model ANN to find relationship between real value input-output data?

I'm trying to make an ANN which could tell me if there is causality between my input and output data. Data is following:
My input are measured values of pesticides (19 total) in an area eg:
-1.031413662 -0.156086316 -1.079232918 -0.659174849 -0.734577317 -0.944137546 -0.596917991 -0.282641072 -0.023508282 3.405638835 -1.008434997 -0.102330305 -0.65961995 -0.687140701 -0.167400684 -0.4387984 -0.855708613 -0.775964435 1.283238514
And the output is the measured value of plant-somthing in the same area (55 total) eg:
0.00 0.00 0.00 13.56 0 13.56 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13.56 0 0 0 1.69 0 0 0 0 0 0 0 0 0 0 1.69 0 0 0 0 13.56 0 0 0 0 13.56 0 0 0 0 0 0
Values for input are in range from -2.5 to 10, and for output from 0 to 100.
So the question I'm trying to answer is: in what measure does pesticide A affect plant-somthings.
What are good ways to model (represent) input/output neurons to be able to process the mentioned input/output data? And how to scale/convert input/output data to be useful for NN?
Is there a book/paper that I should look at?
First, a neural network cannot find the causality between output and input, but only the correlation (just like every other probabilistic methods). Causality can only be derived logically from reasoning (and even then, it's not always clear, it all depends on your axioms).
Secondly, about how to design a neural network to model your data, here is a pretty simple rule that can be generally applied to make a first working draft:
set the number of input neurons = the number of input variables for one sample
set the number of output neurons = the number of output variables for one sample
then play with the number of hidden layers and the number of hidden neurons per hidden layer. In practice, you want to use the fewest number of hidden layers/neurons to model your data correctly, but enough so that the function approximated by your neural network fits correctly the data (else the error in output will be huge compared to the real output dataset).
Why do you need to use just enough neurons but not too much? This is because if you use a lot of hidden neurons, you are sure to overfit your data, and thus you will make a perfect prediction on your training dataset, but not in the general case when you will use real datasets. Theoretically, this is because a neural network is a function approximator, thus it can approximate any function, but using a too high order function will lead to overfitting. See PAC learning for more info on this.
So, in your precise case, the first thing to do is to clarify how many variables you have in input and in output for each sample. If it's 19 in input, then create 19 input nodes, and if you have 55 output variables, then create 55 output neurons.
About scaling and pre-processing, yes you should normalize your data between the range 0 and 1 (or -1 and 1 it's up to you and it depends on the activation function). A very good place to start is to watch the videos at the machine learning course by Andrew Ng at Coursera, this should get you kickstarted quickly and correctly (you'll be taught the tools to check that your neural network is working correctly, and this is immensely important and useful).
Note: you should check your output variables, from the sample you gave it seems they use discrete values: if the values are discrete, then you can use discrete output variables which will be a lot more precise and predictive than using real, floating values (eg, instead of having [0, 1.69, 13.56] as the possible output values, you'll have [0,1,2], this is called "binning" or multi-class categorization). In practice, this means you have to change the way your network works, by using a classification neural network (using activation functions such as sigmoid) instead of a regressive neural network (using activation functions such as logistic regression or rectified linear unit).

How to encode packet information by XOR in matlab

I am working in channel coding part. My major is encoding with bit information. For example, given a input bit is x=[1 0 1] and G matrix is
G =
1 0 0 1
0 0 1 0
1 1 0 1
then encoding symbol will be y=mod(x*G,2)% mod to convert to binary bit
y =
0 1 0 0
It is very simple idea for bits encoding processing in channel coding. Now I want to do map this work to packet encoding. Some paper mentioned that we can do this way for packet encoding if we consider each packet is n bytes. For example, I have a text file that size is 3000bytes. Now I will divide the file into 1000 packet. Hence, each packet has size is that 3 bytes. My problem is that I done with bit encoding. However, I don't have any idea to work with packet encoding. Please let me know if you worked with this problem. I hear that bit encoding we only has two level 0 and 1, so we can use GF=2. If we work for packet level, we must consider GF>2. I am not sure it
Second question is that how about if packet size equals 50 bytes instead of 3 bytes?
First, when you talk about GF(p^m), you mean Galois Field, where p is a prime number that indicates the degree of the polynomial. Hence, it is possible to define a field with pm elements. In your case, p=2 and m=3. Once, you have the polynomial, you can apply it using two different encoding schemes:
Block coding. You can split the packet into several blocks of 3 bits and encode each block independently. Use zero-padding in case they are not multiples.
Convolutional coding. You apply the polynomial as a sliding algorithm.
The second approach is more robust and has lower delays.
The GF terminology is used to work with polynomials, the concepts of extended Galois Fields and polynomials are not very complicated, but it takes time to understand it. However, in practice, if you have a polynomial expression you just apply it to the bit sequence in the fashion that you want, block or convolutional (or fountain).
You matrix G is actually defining 4 polynomials for the input X=[1 x x^2], namely Y1=1+x^2, Y2=x^2 and Y3=x, Y4=1+x^2

How to calculate a Laplacian mask or any size [duplicate]

This question already has an answer here:
Laplacian kernels of higher order in image processing
(1 answer)
Closed 3 years ago.
I would like to know how to calculate a Laplacian mask of an arbitrary odd size kernel (2nd derivative). For example, I know a 3x3 would be:
1 1 1
1 -8 1
1 1 1
And a 5x5 mask would be:
1 1 1 1 1
1 1 1 1 1
1 1 -24 1 1
1 1 1 1 1
1 1 1 1 1
However, this is all I know. I don't know how these were calculated. I believe that all 2nd derivative masks always have a different center number surrounded by 1s. My question is, how would I calculate the center number for nxn where n is odd? (e.g. 7x7, 15x15, etc.) I am planning on implementing this in Matlab. I appreciate any help I can get.
The Laplacian function looks like this:
and is described by:
σ here determines the spread of the inverted bell. The digital mask is a discrete approximation of this function. And therefore for smaller values of window size (n) and σ, you get a large negative number surrounded by 1s all over. But as you increase the window size and σ, that's not going to be the case.
To calculate the digital mask correctly, you should use the function given above. The center pixel of your odd sized square (nxn) will be your origin.
For reference: http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm
Here's a simple way:
function mask = LapMask(n)
mask = ones(n);
mask(ceil((n^2)/2)) = 1 - n^2;
end
I'll leave it to you to add the error checking making certain that n is odd

Input format explanation for TOH

Today i came across this Tower of Hanoi problem from Facebook and here is the question and solution for this - Facebook sample puzzle: Towers of Hanoi
But the problem i am facing is i am not able to understand the inputs given here . i know the basics of tower of Hanoi. i am not able to understand this part
Constraints:
1<= N<=8
3<= K<=5
Input Format:
N K
2nd line contains N integers.
Each integer in the second line is in the range 1 to K where the i-th integer denotes the peg to which disc of radius i is present in the initial configuration.
3rd line denotes the final configuration in a format similar to the initial configuration.
N and K are inputs where N is the number of disks and K is the number of pegs. But what is the initial configuration and final configuration here is an example.
Sample Input #00:
2 3
1 1
2 2
where 2 is the Number of disks and 3 is the number of pegs what the next line 1 1 and 2 2. can anyone please help me in understanding this problem and correct me if my understanding is wrong.
This sample input denotes: Both disks are on the first peg, and you should move them to the second peg.
Another sample input:
6 4
4 2 4 3 1 1
1 1 1 1 1 1
describes this placement:
5 1
6 2 4 3
_ _ _ _