Monte Carlo Experiment in Huffman
Show older comments
I have an exercise in which I have a random variable X = {1, 2, 3} with probabilities 1/2, 1/4, 1/4.
Apply Huffman coding in x (1..n), where x vector. Repeat for 1000 Monte Carlo experiments. What does the second part of the question mean?
Thanks
Answers (5)
George Karystinos
on 9 Apr 2016
1 vote
Thalia den rotame sto matlab answers gia ta project. kovesai! :)
Walter Roberson
on 8 Apr 2016
for generation = 1 : 1000
X = generate_symbols(N);
H = huffman_compress(X);
HS(generation) = numel(H); %how much space did it take?
end
Roger Stafford
on 8 Apr 2016
In case you don't have access to a huffman compression algorithm, I would expect in your particular case the huffman encoding would be
1 <--> 0
2 <--> 10
3 <--> 110
4 <--> 111
See these websites for further information:
https://en.wikipedia.org/wiki/Huffman_coding
https://en.wikipedia.org/wiki/Variable-length_code#Uniquely_decodable_codes
T
on 9 Apr 2016
0 votes
1 Comment
Roger Stafford
on 9 Apr 2016
Here's how you would produce the values 1, 2, 3, or 4 with probabilities of 1/2, 1/4, 1/8, and 1/8 respectively:
r = rand(n,1); % Generate n random numbers between 0 and 1
x = 1*(r<=1/2) + 2*((r>1/2)&(r<=3/4)) ...
+ 3*((r>3/4)&(r<=7/8)) + 4*(r>7/8);
The values of x will have the given probabilities. Such a procedure is known as a Monte Carlo method.
George Karystinos
on 9 Apr 2016
0 votes
Thalia mono i vandi ekane kariera me allo onoma, kserw oti eisai esu miss T, mn krivesai
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!