Compression
AI 101
Background
Connections
In lecture we have now shown the ability to classify without looking at all of the data.
- We differentiate odds from evens looking at a single dot.
- We differentiate 2s/3s from 4s/5s looking at only two dots.
This raises the question: Do we really need to consider all 9 dots?
Definitions
- Today, we will work with code cells of Colab to create a multi-layer perceptron that classifies dice while only looking at some of the dots.
- Five, to be precise.
Setup
The Dice
- You will need a code cell that includes at least the following:
- Same as last time but we now add
owtandrht- which aretwoandthrbackwards, spectively.
- Same as last time but we now add
- We will take just the first 5 values - the full top row, and the first two values in the middle row - only.
- To do so, we will use the location or indexing notation we used previously with
enumerate.- Include some numerical value within box brackets
[]after the name of the vector. - Here we will be much more complex, using ranges that include multiple values in multiple dimensions.
- You don’t need to know how to write this yourself, but I want to show it to you in case you see it from e.g. Gemini.
- Include some numerical value within box brackets
- To do so, we will use the location or indexing notation we used previously with
[[0 0 0 0 1]
[0 0 1 0 0]
[1 0 0 0 0]
[0 0 1 0 1]
[1 0 0 0 1]
[1 0 1 0 0]
[1 0 1 0 1]
[1 0 1 1 0]]
- What this does is takes a sub-matrix
[:,:6]:is used to give a range, like from position 4 until position 7 as4:7- When given with no leading or trailing value, the minimum or maximum location in a matrix is used.
- So
[:,:]would mean all rows, all columns. [:,:5]means “all rows” and “first five columns”.- So this is just the first five values of every row.
The Neural Network
- We previously made a neural network with random “edge weights”.
- This martix is the wrong size and shape.
- It would need to be transposed, and…
- Is not configured to see only 5 dots per row.
[[0.29884947 0.3144994 0.76388236 0.9727125 0.79230589 0.31494447]
[0.61333102 0.04722925 0.02491468 0.74922503 0.29564891 0.88536523]
[0.49378738 0.16377066 0.40014686 0.18179832 0.058686 0.85960791]
[0.70291002 0.4480385 0.68653965 0.89904509 0.00763921 0.4539155 ]
[0.58468916 0.34388308 0.13938706 0.52802477 0.86118817 0.03931347]]
- Also, while it is the case that the last layer should produce a vector of length six, it is not not neccesarily the case the the first layer should produce a vector of length six.
- Though it must accept a vector of length five.
[[0.53586084 0.52996526 0.93852926 0.46319658]
[0.18591283 0.36240707 0.02616822 0.03204079]
[0.04390665 0.13184045 0.12620412 0.46739894]
[0.32014103 0.32382582 0.78328115 0.6487318 ]
[0.61042119 0.14217155 0.34123971 0.58671807]]
- Then the next (presumably final) layer must accept whatever the output size of the previous layer was, and produce a vector of length 6.
[[0.19002589 0.70990041 0.34847719 0.02513219 0.97794254 0.27009436]
[0.92262211 0.21533637 0.221479 0.70821292 0.75846892 0.57699114]
[0.22601844 0.51359476 0.84351458 0.30148299 0.0130723 0.08584287]
[0.21908189 0.44984581 0.87534262 0.27773684 0.85478421 0.71669635]]
- These can be amicably multiplied.
[False False False False False False]
[False False False False False False]
[False False False False False False]
[False False False False False False]
[False True True False True True]
[False False False False False False]
[False True True False True True]
[False False True False False False]
You do not need to make or use a random matrix (training a multi-layer perceptron is out-of-scope for this term, but not too bad), rather we will have you work to create one yourself.
It should look like this:
- Basically the same as last week, but…
- Now we have two each of two-encoding and three-encoding die.
- Eight die in total.
key = np.array([
[ True, False, False, False, False, False],
[False, True, False, False, False, False],
[False, True, False, False, False, False],
[False, False, True, False, False, False],
[False, False, True, False, False, False],
[False, False, False, True, False, False],
[False, False, False, False, True, False],
[False, False, False, False, False, True]
])Your Task
Steps
- Construct two matrices.
- One top layer
- One bot layer
- The top layer must be of size 5 by \(x\)
- The bot layer must be of size \(x\) by 6.
- You may use any \(x\) value you like.
- Ensure that when multiplied, you correctly classify all die in
compress.
Final Product
- You should have a Colab document which, when run:
- Contains the compressed die.
- Contains top and bot layers that you wrote.
- Performs the multiplications to classify each of the compressed die.
- Either is correct in all cases (same as
key), or - Has a note of 1000 words explaining what you tried, why, and why it didn’t work.
- I plan to show my solution Monday.