Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Who can help in my assignment, please?

Question posted by: dgtal01 (Newbie) on April 22nd, 2008 02:32 PM
Hi every body
I have assignment and i don't understand it
If anyone have the solution for this assignment
please help me
I am sure I will find the answers with you
So please Your Excellency me solved.

1)Source Modeling:
In this exercise you are required to explore the notion of entropy and the amount of bits required to represent a source. You are given a text file containing the United States of America’s Declaration of independence, “DecOfInd.txt”. What is the file size in bytes? Write a program to compute the frequency of the ASCII characters used in the text. Note that the text also used characters such as “full stop”, “space”, “comma”, “semi-colon”, capitals letters, etc. These are to be treated as separate symbols. Report your finding as a probability distribution table. Compute and report
the entropy of this text as the entropy of a source generating these characters. Comment on the probability distribution of the characters used in the text file. Is your expectation on the most frequently used letter of the English alphabet confirmed? On average how many bits/symbol would you expect to use in encoding this text file?

2) Entropy Coding I (Huffman Encoder/Decoder):
Given the source model (i.e. probability distribution) you have generated, write a program to implement binary Huffman encoder that will take your source model and the given text, and generate an encoded file named, “DecOfInd.huf ”. To make life easy, you can represent your binary symbol set as any arbitrary symbols, for example, ”0=a”, ”1=b”, rather than using bitwise operation to write out the encoded file (but this is your choice - you need to write it in your report though, on which choice you have taken). Report on the size of the file generated by counting the total number of symbols written to file and dividing by eight to obtain, ”size in bytes”. What compression factor were you able to achieve?
Write a program to implement the Huffman decoder. Now, use your decoder to decode your encoded file. Name your output, “DecOfInd-1.txt”. The output should be identical to the original file, “DecOfInd.txt”. What is the file size?
To check that is the case, use the UNIX/Linux command, cmp - l DecOfInd.txt DecOfInd-1.txt && ’no changes’ on the original file and decoded file. Report on the output of executing this command. You should “cut and paste” the output and insert it in your report. If your output from executing the command is too long, write it to a file and submit it. Use a reasonable file name.

3) Entropy Coding II (Adaptive Huffman Encoder/Decoder) :
Repeat the previous exercise with the Adaptive Huffman algorithm. You are to implement a binary Adaptive Huffman algorithm that will take the your source model and the given text, and generate an encoded file named, “DecOfInd.ahuf”. Then, you are to implement the Adaptive Huffman decoder as well. Name your output, “DecOfInd-ahuf-1.txt”, and again, compare it with the original file with the cmp command.
Then, cut and paste the output and insert it in your report, and answer the following questions:
 What is the file size of “DecOfInd.ahuf”?
 Compare and contrast the result of Adaptive Huffman and Huffman algorithm from the previous exercise, and comment on it.

4) Channel Modeling :
In the previous exercise (Entropy Coding I) you designed the binary Huffman encoder and decoder suitable for the given text file. This text will now be “transmitted” through a binary channel with a probability of bit error, p. You will simulate this channel by writing a program that inserts error into its input by inverting every bit with a probability, p.Select a value of p = 0:2 and run your program on the file, “DecOfInd.huf ”, generated in the Entropy Coding exercise. Name your output file “DecOfInd.bch1 ”. Now, use your Huffman decoder to decode the file “DecOfInd.bch1 ” into “DecOfInd-bch1.txt”. You can analyse the output by comparing it with the original text.Use the UNIX/Linux command, cmp - l DecOfInd.txt DecOfInd-bch1.txt && ’no changes’ and report the output of your execution. Reflect and comment on the output. Could you read and understand the output text, “DecOfInd-bch1.txt”?

My regards
dgtal_01
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
JosAH's Avatar
JosAH
Chief Editor
6,797 Posts
April 22nd, 2008
03:23 PM
#2

Re: Who can help in my assignment, please?
Start by designing a 'counting' class (or a couple of them). You want to end up
with a collection of character, frequency pairs that form the basis of the Huffman
tree construction.

kind regards,

Jos

Reply
dgtal01's Avatar
dgtal01
Newbie
4 Posts
April 24th, 2008
04:16 AM
#3

Re: Who can help in my assignment, please?
Hi Jos,
thank you for your replay
how i can start?
do you have somthing reday?
how many programs should me write in this assignment?
I have this programe from other member is it usefull for me?

1. import java.io.*;
2. import java.util.*;
3.
4. public class SourceModel
5. {
6.
7.
8. public static void main(String [] Args)
9. {
10.
11. int j;
12. String str;
13.
14. Map<Integer, Integer> m = new HashMap<Integer, Integer>();
15.
16. try
17. {
18. BufferedReader in = new BufferedReader(new FileReader("DecOfInd.txt"));
19.
20. while ((str = in.readLine()) != null)
21. {
22. for(int i = 0; i < str.length(); i++)
23. {
24.
25. if(!m.containsKey((int)str.charAt(i)))
26. {
27. m.put((int)str.charAt(i),1);
28. }
29. else
30. {
31. j = m.get((int)str.charAt(i));
32. j++;
33.
34. m.put((int)str.charAt(i),j);
35.
36. }
37.
38. }
39. }
40.
41. }
42. catch (IOException e)
43. {
44.
45. }
46.
47. System.out.println();
48. System.out.println(m.size() + " distinct letters:");
49. System.out.println(m);
50.
51. int count = 0;
52.
53. for(int i :m.keySet())
54. {
55. System.out.println(i + " = " + m.get(i));
56. count += m.get(i);
57. }
58. System.out.println("Total Number of Characters: "+count);
59.
60. }
61. }

Reply
sukatoa's Avatar
sukatoa
Needs Regular Fix
411 Posts
April 24th, 2008
04:54 AM
#4

Re: Who can help in my assignment, please?
Quote:
Originally Posted by dgtal01
Hi Jos,
thank you for your replay
how i can start?
do you have somthing reday?
how many programs should me write in this assignment?
I have this programe from other member is it usefull for me?

1. import java.io.*;
2. import java.util.*;
3.
4. public class SourceModel
5. {
6.
7.
8. public static void main(String [] Args)
9. {
10.
11. int j;
12. String str;
13.
14. Map<Integer, Integer> m = new HashMap<Integer, Integer>();
15.
16. try
17. {
18. BufferedReader in = new BufferedReader(new FileReader("DecOfInd.txt"));
19.
20. while ((str = in.readLine()) != null)
21. {
22. for(int i = 0; i < str.length(); i++)
23. {
24.
25. if(!m.containsKey((int)str.charAt(i)))
26. {
27. m.put((int)str.charAt(i),1);
28. }
29. else
30. {
31. j = m.get((int)str.charAt(i));
32. j++;
33.
34. m.put((int)str.charAt(i),j);
35.
36. }
37.
38. }
39. }
40.
41. }
42. catch (IOException e)
43. {
44.
45. }
46.
47. System.out.println();
48. System.out.println(m.size() + " distinct letters:");
49. System.out.println(m);
50.
51. int count = 0;
52.
53. for(int i :m.keySet())
54. {
55. System.out.println(i + " = " + m.get(i));
56. count += m.get(i);
57. }
58. System.out.println("Total Number of Characters: "+count);
59.
60. }
61. }


Please inclose your codes with a codetag soon.

Just reminding, :)
sukatoa

Reply
dgtal01's Avatar
dgtal01
Newbie
4 Posts
April 26th, 2008
01:20 AM
#5

Re: Who can help in my assignment, please?
Quote:
Originally Posted by sukatoa
Please inclose your codes with a codetag soon.

Just reminding, :)
sukatoa


I don't understand to you
what you want?

Reply
sukatoa's Avatar
sukatoa
Needs Regular Fix
411 Posts
April 26th, 2008
01:26 AM
#6

Re: Who can help in my assignment, please?
Quote:
Originally Posted by dgtal01
I don't understand to you
what you want?



Make use of the available formatting tags in the forum Use CODE tags around your code unless you are posting a single line of code in which case it is acceptable to omit them:
Code: ( text )
  1. ..code goes here..

Code: ( text )
  1. ..php code goes here..

Code: ( text )
  1. ..C like code goes here..

Code: ( text )
  1. ..html code goes here..

This will preserve white space and use a mono-spaced font making the code easier to read.

:)

Reply
Laharl's Avatar
Laharl
Expert
595 Posts
April 26th, 2008
01:28 AM
#7

Re: Who can help in my assignment, please?
CODE tags are the # button on the posting interface. They keep your code formatted the way you input, rather than having the whitespace stripped. The idea is to make the code easier for everyone to read.

Compare:
Code: ( text )
  1. public static void main(String[] args){
  2.       blah();
  3. }

to
public static void main(String[] args){
blah();
}

As to your original question, what code have you written? We're not going to do your homework for you.

Reply
dgtal01's Avatar
dgtal01
Newbie
4 Posts
April 26th, 2008
05:05 AM
#8

Re: Who can help in my assignment, please?
Quote:
Originally Posted by Laharl
CODE tags are the # button on the posting interface. They keep your code formatted the way you input, rather than having the whitespace stripped. The idea is to make the code easier for everyone to read.

Compare:
Code: ( text )
  1. public static void main(String[] args){
  2.       blah();
  3. }

to
public static void main(String[] args){
blah();
}

As to your original question, what code have you written? We're not going to do your homework for you.


Thank you for your replay
Can you help me to start

Reply
JosAH's Avatar
JosAH
Chief Editor
6,797 Posts
April 26th, 2008
07:56 AM
#9

Re: Who can help in my assignment, please?
Quote:
Originally Posted by dgtal01
Thank you for your replay
Can you help me to start


You better start thinking a bit more OO: you have to deal with nodes in a tree:

Code: ( text )
  1. public abstract class HuffmanNode implements Comparable<HuffmanNode> {
  2.     protected int freq; // the frequency of this node
  3.     protected int code; // the Huffman code of this node
  4.     ...
  5. }


There are two types of those nodes: the leaf nodes that contain a simple character
and their corresponding Huffman code and internal nodes that just point to their
children which both are Huffman nodes again:

Code: ( text )
  1. public class LeafNode extends HuffmanNode {
  2.     private char chr; // the character itself
  3.     private int len; // the bit length of the code
  4.     ...
  5. }
  6. public class InternalNode extends HuffmanNode {
  7.     private HuffmanNode lft; // the left child
  8.     private HuffmanNode rgt; // the right child
  9.     ...
  10. }


I just did the class organization for you; you have to supply the methods and build
a tree out of these nodes. A TreeSet comes to mind that does all the sorting for
you given an appropriate compareTo() method in the nodes themselves. For the
collection phase of the algorithm (reading in all the chars) a simple hash map of
type Map<Character, HuffmanNode> will do fine.

kind regards,

Jos

Reply
SiAnZ's Avatar
SiAnZ
Newbie
1 Posts
May 14th, 2008
06:21 PM
#10

Re: Who can help in my assignment, please?
yo dgtal01... if u can find this code online... that means other people in ur course can also get it.. if all of you hand up this copy of code together, this means you are copying from one another or otherwise. so i recommend you to do it out yourself instead of getting risked getting 0 marks for your assignment. this is just a piece of advice for you. up to you if you wanna listen or not...

Reply
Reply
Not the answer you were looking for? Post your question . . .
170,099 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top Java Forum Contributors