Θεωρία Πληροφορίας - Κώδικες. Γιαννακόπουλος Θεόδωρος

Σχετικά έγγραφα
Θεωρία Πληροφορίας - Κώδικες. Γιαννακόπουλος Θεόδωρος

Θεωρία Πληροφορίας - Κώδικες. Γιαννακόπουλος Θεόδωρος

LESSON 14 (ΜΑΘΗΜΑ ΔΕΚΑΤΕΣΣΕΡΑ) REF : 202/057/34-ADV. 18 February 2014

derivation of the Laplacian from rectangular to spherical coordinates

Θεωρία Πληροφορίας - Κώδικες. Γιαννακόπουλος Θεόδωρος

Phys460.nb Solution for the t-dependent Schrodinger s equation How did we find the solution? (not required)

STARTING STEPS IN GRAMMAR, FINAL TEST C TERM 2012 UNITS 1-18

Οι αδελφοί Montgolfier: Ψηφιακή αφήγηση The Montgolfier Βrothers Digital Story (προτείνεται να διδαχθεί στο Unit 4, Lesson 3, Αγγλικά Στ Δημοτικού)

3.4 SUM AND DIFFERENCE FORMULAS. NOTE: cos(α+β) cos α + cos β cos(α-β) cos α -cos β

7 Present PERFECT Simple. 8 Present PERFECT Continuous. 9 Past PERFECT Simple. 10 Past PERFECT Continuous. 11 Future PERFECT Simple

HOMEWORK 4 = G. In order to plot the stress versus the stretch we define a normalized stretch:

Section 8.3 Trigonometric Equations

Solutions to the Schrodinger equation atomic orbitals. Ψ 1 s Ψ 2 s Ψ 2 px Ψ 2 py Ψ 2 pz

Finite Field Problems: Solutions

ΚΥΠΡΙΑΚΟΣ ΣΥΝΔΕΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY 21 ος ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ Δεύτερος Γύρος - 30 Μαρτίου 2011

9.09. # 1. Area inside the oval limaçon r = cos θ. To graph, start with θ = 0 so r = 6. Compute dr

2 Composition. Invertible Mappings

Οδηγίες Αγοράς Ηλεκτρονικού Βιβλίου Instructions for Buying an ebook

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 19/5/2007

department listing department name αχχουντσ ϕανε βαλικτ δδσϕηασδδη σδηφγ ασκϕηλκ τεχηνιχαλ αλαν ϕουν διξ τεχηνιχαλ ϕοην µαριανι

BECAUSE WE REALLY WANT TO KNOW WHAT YOU THINK ABOUT SCHOOL AND YOUR GARDEN. Fairly true If I decide to learn something hard, I can.

Η αντίσταση στην ανθρωπιστική ψυχοθεραπεία

Right Rear Door. Let's now finish the door hinge saga with the right rear door

FINAL TEST B TERM-JUNIOR B STARTING STEPS IN GRAMMAR UNITS 8-17

Writing for A class. Describe yourself Topic 1: Write your name, your nationality, your hobby, your pet. Write where you live.

Code Breaker. TEACHER s NOTES

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 6/5/2006

Συστήματα Διαχείρισης Βάσεων Δεδομένων

Final Test Grammar. Term C'

The Simply Typed Lambda Calculus

CHAPTER 25 SOLVING EQUATIONS BY ITERATIVE METHODS

Living and Nonliving Created by: Maria Okraska

b. Use the parametrization from (a) to compute the area of S a as S a ds. Be sure to substitute for ds!

Homework 3 Solutions

ΑΛΕΞΑΝΔΡΟΣ ΠΑΛΛΗΣ SCHOOLTIME E-BOOKS

5.4 The Poisson Distribution.

Paper Reference. Paper Reference(s) 1776/04 Edexcel GCSE Modern Greek Paper 4 Writing. Thursday 21 May 2009 Afternoon Time: 1 hour 15 minutes

Solutions to Exercise Sheet 5

Problem Set 3: Solutions

LESSON 12 (ΜΑΘΗΜΑ ΔΩΔΕΚΑ) REF : 202/055/32-ADV. 4 February 2014

Στο εστιατόριο «ToDokimasesPrinToBgaleisStonKosmo?» έξω από τους δακτυλίους του Κρόνου, οι παραγγελίες γίνονται ηλεκτρονικά.

Chapter 2 * * * * * * * Introduction to Verbs * * * * * * *

Fractional Colorings and Zykov Products of graphs

TMA4115 Matematikk 3

2. THEORY OF EQUATIONS. PREVIOUS EAMCET Bits.

Μηχανική Μάθηση Hypothesis Testing

ΕΠΙΧΕΙΡΗΣΙΑΚΗ ΑΛΛΗΛΟΓΡΑΦΙΑ ΚΑΙ ΕΠΙΚΟΙΝΩΝΙΑ ΣΤΗΝ ΑΓΓΛΙΚΗ ΓΛΩΣΣΑ

Exercises 10. Find a fundamental matrix of the given system of equations. Also find the fundamental matrix Φ(t) satisfying Φ(0) = I. 1.

ΧΡΗΣΗ ΣΩΜΑΤΩΝ ΚΕΜΕΝΩΝ ΩΣ ΛΕΞΙΚΟΓΡΑΦΙΚΗ ΕΛΛΗΝΟ ΑΓΓΛΙΚΟ ΣΩΜΑ ΚΕΙΜΕΝΩΝ ΣΟΦΙΑ ΤΡΥΠΑΝΑΓΝΩΣΤΟΠΟΥΛΟΥ

ΣΧΟΛΙΚΟ ΕΤΟΣ

1999 MODERN GREEK 2 UNIT Z

C.S. 430 Assignment 6, Sample Solutions

ΑΓΓΛΙΚΑ ΙΙΙ. Ενότητα 12b: The Little Prince. Ζωή Κανταρίδου Τμήμα Εφαρμοσμένης Πληροφορικής

Υλοποίηση Πληροφοριακών Συστημάτων - Προγραμματισμός σε Java (robocode) - know your enemy - Βασίλειος Καρακόιδας

Εγκατάσταση λογισμικού και αναβάθμιση συσκευής Device software installation and software upgrade

«ΨΥΧΙΚΗ ΥΓΕΙΑ ΚΑΙ ΣΕΞΟΥΑΛΙΚΗ» ΠΑΝΕΥΡΩΠΑΪΚΗ ΕΡΕΥΝΑ ΤΗΣ GAMIAN- EUROPE

Ordinal Arithmetic: Addition, Multiplication, Exponentiation and Limit

Econ 2110: Fall 2008 Suggested Solutions to Problem Set 8 questions or comments to Dan Fetter 1

Math 6 SL Probability Distributions Practice Test Mark Scheme

EE512: Error Control Coding

coho the coworking home

Section 7.6 Double and Half Angle Formulas

Verklarte Nacht, Op.4 (Εξαϋλωμένη Νύχτα, Έργο 4) Arnold Schoenberg ( )

Στεγαστική δήλωση: Σχετικά με τις στεγαστικές υπηρεσίες που λαμβάνετε (Residential statement: About the residential services you get)

Matrices and Determinants

ΕΠΙΧΕΙΡΗΣΙΑΚΗ ΑΛΛΗΛΟΓΡΑΦΙΑ ΚΑΙ ΕΠΙΚΟΙΝΩΝΙΑ ΣΤΗΝ ΑΓΓΛΙΚΗ ΓΛΩΣΣΑ

ΕΡΕΥΝΗΤΙΚΗ ΕΡΓΑΣΙΑ ΑΓΓΛΟΦΩΝΗ ΜΟΥΣΙΚΗ

Adjectives. Describing the Qualities of Things. A lesson for the Paideia web-app Ian W. Scott, 2015

LESSON 28 (ΜΑΘΗΜΑ ΕΙΚΟΣΙ ΟΚΤΩ) REF : 201/033/28. 2 December 2014

Elements of Information Theory

Chapter 29. Adjectival Participle

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 11/3/2006

VBA ΣΤΟ WORD. 1. Συχνά, όταν ήθελα να δώσω ένα φυλλάδιο εργασίας με ασκήσεις στους μαθητές έκανα το εξής: Version ΗΜΙΤΕΛΗΣ!!!!

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 24/3/2007

Πρόβλημα 1: Αναζήτηση Ελάχιστης/Μέγιστης Τιμής

( ) 2 and compare to M.

LESSON 26 (ΜΑΘΗΜΑ ΕΙΚΟΣΙ ΕΞΙ) REF : 102/030/ November 2014

PARTIAL NOTES for 6.1 Trigonometric Identities

Concrete Mathematics Exercises from 30 September 2016

Please be sure that your kid memorized the song. Students homework -Pg.2: Read the song and the translation 3 times.

LESSON 6 (ΜΑΘΗΜΑ ΕΞΙ) REF : 201/045/26-ADV. 10 December 2013

LESSON 16 (ΜΑΘΗΜΑ ΔΕΚΑΕΞΙ) REF : 102/018/16-BEG. 4 March 2014

1) Formulation of the Problem as a Linear Programming Model

Q1a. HeavisideTheta x. Plot f, x, Pi, Pi. Simplify, n Integers

Durbin-Levinson recursive method

(a,b) Let s review the general definitions of trig functions first. (See back cover of your book) sin θ = b/r cos θ = a/r tan θ = b/a, a 0

Newborn Upfront Payment & Newborn Supplement

ST5224: Advanced Statistical Theory II

Math221: HW# 1 solutions

How to register an account with the Hellenic Community of Sheffield.

Προγραμματισμός Υπολογιστών με C++

Partial Trace and Partial Transpose

Numerical Analysis FMN011

Objectives-Στόχοι: -Helping your Child become a fantastic language learner «Βοηθώντας το παιδί σας να γίνει εξαιρετικό στην εκμάθηση γλωσσών» 6/2/2014

SUPERPOSITION, MEASUREMENT, NORMALIZATION, EXPECTATION VALUES. Reading: QM course packet Ch 5 up to 5.6

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Ψηφιακή Οικονομία. Διάλεξη 10η: Basics of Game Theory part 2 Mαρίνα Μπιτσάκη Τμήμα Επιστήμης Υπολογιστών

Other Test Constructions: Likelihood Ratio & Bayes Tests

IIT JEE (2013) (Trigonomtery 1) Solutions

Dynamic types, Lambda calculus machines Section and Practice Problems Apr 21 22, 2016

Transcript:

Θεωρία Πληροφορίας - Κώδικες Γιαννακόπουλος Θεόδωρος 1

Θεωρία Πληροφορίας - Κώδικες Εργαστήριο 3 Παραδείγματα Python για Θεωρία Πληροφορίας (1, 2 και 5) 2

inf_teiste_info_theory_lab - διαθέσιμο στο github github.com/tyiannak/inf_teiste_info_theory_lab - βασικές λειτουργίες και παραδείγματα example1.py import ITlib ITlib.py βασικές συναρτήσεις (υπολογισμός εντροπίας, οριακών πιθανοτήτων, χωρητικότητας καναλιού κτλ) example2.py import ITlib example3.py import ITlib import ITlib 3

Εντροπία - Μέγιστη Εν. - Οριακές πιθανότητες (1) ITlib.py (part) import numpy eps = 0.000000000001 Υπολογισμός εντροπίας από array πιθανοτήτων συμβόλων def computeentropy(probs): if numpy.abs(probs.sum()-1.0)<eps: # if sum of probabilities is almost equal to 1 ProbsNonZero = Probs[Probs>eps] # remove zero probabilities return -numpy.sum(probsnonzero * numpy.log2(probsnonzero)) # compute entropy else: raise ValueError("Probabilities must sum to unity!") # raise an error if probabilities do not sum to 1 def computemaxentropy(n): return numpy.math.log(n, 2) Υπολογισμός μέγιστης εντροπίας def computepriorsfromjointp(jointp): if numpy.abs(jointp.sum()-1.0) < eps: Υπολογισμός marginal Px = jointp.sum(axis = 1) πιθανοτήτων P(x), P(y) από τις Py = jointp.sum(axis = 0) από κοινού πιθανότητες P(x,y) return Px, Py else: raise ValueError("Probabilities must sum to unity!") # raise an error if probabilities do not sum to 1 4

example1.py: εντροπία και υπό συνθήκη εντροπία import ITlib, numpy import matplotlib.pyplot as plt def computechannelentropies(jointprobmatrix): [Px, Py] = ITlib.computePriorsFromJointP(jP) print "P(x)", Px print "P(y)", Py Hx = ITlib.computeEntropy(Px) Hy = ITlib.computeEntropy(Py) Hjoint = ITlib.computeEntropy(jP.flatten()) Hcond = Hjoint - Hy print "H(x) = %.4f" % Hx print "H(y) = %.4f" % Hy print "H(x,y) = %.4f" % Hjoint print "H(x y) = %.4f" % Hcond jp = numpy.array([[1.0/4, 1.0/16, 0],[1.0/4, 1.0/8, 0],[0.0, 1.0/16, 1.0/4.0]]) print "Joint probability matrix is " print jp computechannelentropies(jp) Παράδειγμα χρήσης της computeentropy(), computepriorsfromentropy() για τον υπολογισμό εντροπίας και δεσμευμένης εντροπίας από πίνακα αποκοινου πιθανοτήτων Joint probability matrix is [[ 0.25 0.0625 0. ] [ 0.25 0.125 0. ] [ 0. 0.0625 0.25 ]] P(x) [ 0.3125 0.375 0.3125] P(y) [ 0.5 0.25 0.25] H(x) = 1.5794 H(y) = 1.5000 H(x,y) = 2.3750 H(x y) = 0.8750 5

example2.py: εντροπία δυαδικής πηγής Παράδειγμα υπολογισμού και plotting της εντροπίας για μία πηγή με 2 σύμβολα, με πιθανότητες p και 1-p import ITlib import numpy import matplotlib.pyplot as plt step = 0.001 p1 = numpy.arange(0,1+step,step) p2 = 1 - p1 H = numpy.zeros(p1.shape) for i in range(p1.shape[0]): Probs = numpy.array([p1[i], p2[i]]) H[i] = ITlib.computeEntropy(Probs) plt.plot(p1, H) plt.xlabel("p1") plt.ylabel("entropy") plt.show() 6

example5.py: υπολογισμός εντροπίας σε κείμενα H = ; Hmax = ; Π = ; Pink Floyd - Time Ticking away the moments that make up a dull day Fritter and waste the hours in an offhand way. Kicking around on a piece of ground in your home town Waiting for someone or something to show you the way. Tired of lying in the sunshine staying home to watch the rain. You are young and life is long and there is time to kill today. And then one day you find ten years have got behind you. No one told you when to run, you missed the starting gun. Lady Gaga - Bad Romance Beatles - Love me do Love, love me do You know I love you I'll always be true So please, love me do Whoa, love me do Love, love me do You know I love you I'll always be true So please, love me do Whoa, love me do Beatles - Love me do Love, love me do You know I love you I'll always be true So please, love me do Whoa, love me do Love, love me do You know I love you I'll always be true So please, love me do Whoa, love me do Eminem - Rap God Look, I was gonna go easy on you and not to hurt your feelings But I'm only going to get this one chance Something's wrong, I can feel it (Six minutes, Slim Shady, you're on) Just a feeling I've got, like something's about to happen, but I don't know what If that means, what I think it means, we're in trouble, big trouble, And if he is as bananas as you say, I'm not taking any chances You were just what the doctor ordered I'm beginning to feel like a Rap God, Rap God All my people from the front to the back nod, back nod Now who thinks their arms are long enough to slap box, slap box? They said I rap like a robot, so call me Rapbot Mos def - Mathematic Ha ha You know the deal It's just me yo Beats by Su-Primo for all of my peoples, Negros and Latinos And even the gringos Yo, check it one for Charlie Hustle, two for Steady Rock Three for the fourth coming live, future shock It's five dimensions, six senses 7

example5.py Βασικά βήματα ανάλυσης κειμένου document Ticking away the moments that make up a dull day Fritter and waste the hours in an offhand way. Kicking around on a piece of ground in your home town Waiting for someone or something to show you the way. Tired of lying in the sunshine staying home to watch the rain. You are young and life is long and there is time to kill today. And then one day you find ten years have got behind you. No one told you when to run, you missed the starting gun. tokenization and lower case ticking away the moments that make up a dull day fritter and waste the hours in reduced list of words ticking away moments make up dull day fritter waste hours stop word removal list of words counting words+counts words+frequencies Term # way 4 run 3 day 3 come 3 tired 2 sun 2 something 2 shorter 2 find 2 behind 2 away 2 around 2 again 2 young 1 years 1 year 1 watch 1 waste 1 warm 1 waiting 1 normalize Term Freq way 0.035 run 0.026 day 0.026 come 0.026 tired 0.018 sun 0.018 something 0.018 shorter 0.018 find 0.018 behind 0.018 away 0.018 around 0.018 again 0.018 young 0.009 years 0.009 year 0.009 watch 0.009 waste 0.009 warm 0.009 waiting 0.009 entropy H 6.48 Hmax 6.58 Π 1.60% 8

example5.py import ITlib, numpy, re stopwords = ["i'm","don't","it's","i'll","you're","the","of" ] def readtxtandcomputeentropy(filename): print "filename: " + filename f = open(filename, "r") text = f.read() f.close() words = re.findall(r"[\w']+", text) # split to words (tokenization) words2 = [w.lower() for w in words] # convert to lower words3 = [word for word in words2 if word not in stopwords] # remove stopwords terms = []; weights = [] for w in words3: # for each word in the list if w in terms: # if it is already included in the list of terms weights[terms.index(w.lower())] += 1 # increase its count by 1 else: # else terms.append(w.lower()) # add it to the list of terms and weights.append(1) # initalize its counter to 1 terms2 = [t for (w, t) in sorted(zip(weights, terms), reverse = True)] # sort terms by their weights (counts) weights2 = numpy.array(sorted(weights, reverse = True)).astype(float) # and the weights (as float) weights = numpy.array(sorted(weights, reverse = True)) # and the initial weights (as integers) weights2 = weights2 / weights2.sum() # normalize weights2 by the sum (to convert to prob) H = ITlib.computeEntropy(weights2) # compute entropy Hmax = ITlib.computeMaxEntropy(float(len(terms2))) # compute max entropy P = 1 - H/Hmax # compute redundancy print "H=%.2f\tHmax=%.2f\tRed.=%.1f%%" % (H, Hmax, 100*P) readtxtandcomputeentropy("data/lyrics/pinkfloyd_time"); print

example5.py Example 5 Parse the lyrics from 5 songs and compute the entropies (after removing stopwords) filename: data/lyrics/pinkfloyd_time H=6.48 Hmax=6.58 Red.=1.6% filename: data/lyrics/eminem_rapgod H=8.74 Hmax=9.08 Red.=3.8% filename: data/lyrics/ladygaga_badromance H=4.43 Hmax=5.70 Red.=22.2% filename: data/lyrics/beatles_lovemedo H=2.57 Hmax=3.32 Red.=22.7% filename: data/lyrics/mosdef_mathematic H=8.15 Hmax=8.32 Red.=2.0%