I have this code:   def normalize_dictionary(self, d):         """"""           values = d.values()         x = float(sum(values))         n = {}         for k in d:             n[k] = (d[k]/x)         return n       def smallest_value(self, nd1, nd2):         """"""           valuesnd1 = nd1.values()         valuesnd2 = nd2.values()           x = min(valuesnd1)         y = min(valuesnd2)           if x < y:             return x         else:             return y         def compare_dictionaries(self, d, nd1, nd2):         """"""         nd1 = self.normalize_dictionary(nd1)         nd2 = self.normalize_dictionary(nd2)         epsilon = self.smallest_value(nd1, nd2) / 2         log1, log2 = 0.0, 0.0         for key in d:             if key in nd1:                 log1 += d[key] * math.log2(nd1[key])             else:                 log1 += d[key] * math.log2(epsilon)             if key in nd2:                 log2 += d[key] * math.log2(nd2[key])             else:                 log2 += d[key] * math.log2(epsilon)         return [log1, log2]   d = {'a': 5, 'b': 1, 'c': 2} d1 = {'a': 5, 'b': 1, 'c': 2} nd1 = tm.normalize_dictionary(d1) assert nd1 == {'a': 0.625, 'b': 0.125, 'c': 0.25} d2 = {'a': 15, 'd': 1} nd2 = tm.normalize_dictionary(d2) assert nd2 == {'a': 0.9375, 'd': 0.0625} list_of_log_probs = tm.compare_dictionaries(d, nd1, nd2) print(list_of_log_probs)   #assert list_of_log_probs[0] == -16.356143810225277 #assert list_of_log_probs[1] == -19.18621880878296   with this given the asserts list_of_log_probs gives me [-10.390359525563188, -15.465547021957407] in stead of the assertions answers.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I have this code:

 

def normalize_dictionary(self, d):

        """"""


 

        values = d.values()

        x = float(sum(values))

        n = {}

        for k in d:

            n[k] = (d[k]/x)

        return n


 

    def smallest_value(self, nd1, nd2):

        """"""


 

        valuesnd1 = nd1.values()

        valuesnd2 = nd2.values()


 

        x = min(valuesnd1)

        y = min(valuesnd2)


 

        if x < y:

            return x

        else:

            return y

   

    def compare_dictionaries(self, d, nd1, nd2):

        """"""

        nd1 = self.normalize_dictionary(nd1)

        nd2 = self.normalize_dictionary(nd2)

        epsilon = self.smallest_value(nd1, nd2) / 2

        log1, log2 = 0.0, 0.0

        for key in d:

            if key in nd1:

                log1 += d[key] * math.log2(nd1[key])

            else:

                log1 += d[key] * math.log2(epsilon)

            if key in nd2:

                log2 += d[key] * math.log2(nd2[key])

            else:

                log2 += d[key] * math.log2(epsilon)

        return [log1, log2]

 

d = {'a': 5, 'b': 1, 'c': 2}

d1 = {'a': 5, 'b': 1, 'c': 2}

nd1 = tm.normalize_dictionary(d1)

assert nd1 == {'a': 0.625, 'b': 0.125, 'c': 0.25}

d2 = {'a': 15, 'd': 1}

nd2 = tm.normalize_dictionary(d2)

assert nd2 == {'a': 0.9375, 'd': 0.0625}

list_of_log_probs = tm.compare_dictionaries(d, nd1, nd2)

print(list_of_log_probs)


 

#assert list_of_log_probs[0] == -16.356143810225277

#assert list_of_log_probs[1] == -19.18621880878296

 

with this given the asserts list_of_log_probs gives me [-10.390359525563188, -15.465547021957407] in stead of the assertions answers.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Dictionary
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education