Ab Abstra raction Lecturer Michael Ball UC Berkeley | Computer - - PowerPoint PPT Presentation

ab abstra raction
SMART_READER_LITE
LIVE PREVIEW

Ab Abstra raction Lecturer Michael Ball UC Berkeley | Computer - - PowerPoint PPT Presentation

Co Computational Structures in Data Science UC Berkeley EECS Ab Abstra raction Lecturer Michael Ball UC Berkeley | Computer Science 88 | Michael Ball Ab Abstra raction Detail removal The act of leaving out of consideration one or


slide-1
SLIDE 1

Co Computational Structures in Data Science

UC Berkeley EECS Lecturer Michael Ball

UC Berkeley | Computer Science 88 | Michael Ball

Ab Abstra raction

slide-2
SLIDE 2

UC Berkeley | Computer Science 88 | Michael Ball

  • Detail removal

“The act of leaving out of consideration

  • ne or more properties of a complex
  • bject so as to attend to others.”
  • Generalization

“The process of formulating general concepts by abstracting common properties of instances”

  • Technical terms: Compression,

Quantization, Clustering, Unsupervized Learning

Ab Abstra raction

Henri Matisse “Naked Blue IV”

2

slide-3
SLIDE 3

UC Berkeley | Computer Science 88 | Michael Ball

Ex Experime ment

3

slide-4
SLIDE 4

UC Berkeley | Computer Science 88 | Michael Ball

Wh Where re a are re yo you f fro rom?

Possible Answers:

  • Planet Earth
  • Europe
  • California
  • The Bay Area
  • San Mateo
  • 1947 Center Street, Berkeley,

CA

  • 37.8693° N, 122.2696° W

All correct but different levels of abstraction!

4

slide-5
SLIDE 5

UC Berkeley | Computer Science 88 | Michael Ball

Ab Abstra raction g gone w wro rong!

5

slide-6
SLIDE 6

UC Berkeley | Computer Science 88 | Michael Ball

  • You’ll want to look at only the

interesting data, leave out the details, zoom in/out…

  • Abstraction is the idea that

you focus on the essence, the cleanest way to map the messy real world to one you can build

  • Experts are often brought in to

know what to remove and what to keep!

De Detail Re Remo moval (in Da Data Science)

The London Underground 1928 Map & the 1933 map by Harry Beck.

6

01/28/19 UCB CS88 Sp19 L1

slide-7
SLIDE 7

UC Berkeley | Computer Science 88 | Michael Ball

  • Examples:

– Functions (e.g., sin x) – Hiring contractors – Application Programming Interfaces

(APIs)

– Technology (e.g., cars)

  • Amazing things are built when

these layer

– And the abstraction layers are

getting deeper by the day!

Th The Powe wer of Abstraction, Ev Everywh where!

Abstraction Barrier (Interface)

(the interface, or specification, or contract)

Below the abstraction line

This is where / how / when / by whom it is actually built, which is done according to the interface, specification, or contract. We only need to worry about the interface, or specification, or contract NOT how (or by whom) it’s built

Above the abstraction line

01/19/18 UCB CS88 Sp18 L1

7

slide-8
SLIDE 8

UC Berkeley | Computer Science 88 | Michael Ball

  • Abstraction is not universal without loss of information

(mathematically provable). This means, in the end, the complexity can only be “moved around”

  • Abstraction makes us

forget how things actually work and can therefore hide bias. Example: AI and hiring decisions.

  • Abstraction makes things special and that creates dependencies.

Dependencies grow longer and longer over time and can become unmanageable.

Ab Abstra raction: P Pitfalls

01/19/18 UCB CS88 Sp18 L1

8

slide-9
SLIDE 9

UC Berkeley | Computer Science 88 | Michael Ball

Al Algori rithm

  • An algorithm (pronounced AL-go-rith-um) is a procedure or formula to

solve a problem.

  • An algorithm is a sequence of instructions to change the state of a
  • system. For example: A computer’s memory, your brain (math), or the

ingredients to prepare food (cooking recipe). Think Data 8: Change or retrieve the content of a table.

9

slide-10
SLIDE 10

UC Berkeley | Computer Science 88 | Michael Ball

Al Algori rithm: P Pro ropert rties

  • An algorithm is a description that can be expressed within a finite

amount of space and time.

  • Executing the algorithm may take infinite space and/or time, e.g.

``calculate all prime numbers”.

  • In CS and math, we prefer to use well-defined formal languages for

defining an algorithm.

10

slide-11
SLIDE 11

UC Berkeley | Computer Science 88 | Michael Ball

Al Algori rithm: We Well-De Definition

11

slide-12
SLIDE 12

UC Berkeley | Computer Science 88 | Michael Ball

Al Algori rithms E Earl rly I y In L Life ( (1st

st Gr

Grade)

12

7 8 + 5 1

  • perands
  • perator

least significant digit of result carry (MSD)

slide-13
SLIDE 13

UC Berkeley | Computer Science 88 | Michael Ball

Al Algori rithms E Earl rly I y In L Life ( (In B Binary) ry)

13

+

  • perands
  • perator

LSB result carry (MSD) 1 1 1 1 1 1 1 1 1 1 12 14 26 +

slide-14
SLIDE 14

UC Berkeley | Computer Science 88 | Michael Ball

Mo More re Term rminology gy (Intuitive ve)

Code A sequence of symbols used for communication between systems (brains, computers, brain-to-computer) Data Observations Information Reduction of uncertainty in a model (measured in bits)

14

slide-15
SLIDE 15

UC Berkeley | Computer Science 88 | Michael Ball

Da Data or Co Code?

15

slide-16
SLIDE 16

UC Berkeley | Computer Science 88 | Michael Ball

Da Data or Co Code?

16

slide-17
SLIDE 17

UC Berkeley | Computer Science 88 | Michael Ball

Da Data or Co Code?

17

Here is some information!

slide-18
SLIDE 18

UC Berkeley | Computer Science 88 | Michael Ball

Da Data or Co Code? Abs bstraction!

18

Compiler or Interpreter Here: Python Human-readable code (programming language) Machine-executable instructions (byte code)

slide-19
SLIDE 19

UC Berkeley | Computer Science 88 | Michael Ball

Co Code or GU GUI: More Abs bstraction!

  • Big Idea: Layers of Abstraction

– The GUI look and feel is built out of files, directories, system code, etc.

19

slide-20
SLIDE 20

UC Berkeley | Computer Science 88 | Michael Ball

Re Review: w:

  • Abstraction:

– Detail Removal or Generalizations

  • Code:

– Is an abstraction! – Can be instructions or information

Computer Science is the study of abstraction

20

slide-21
SLIDE 21

UC Berkeley | Computer Science 88 | Michael Ball

21

slide-22
SLIDE 22

Co Computational Structures in Data Science

UC Berkeley EECS Lecturer Michael Ball

UC Berkeley | Computer Science 88 | Michael Ball

Py Python: Statements and Functions

slide-23
SLIDE 23

UC Berkeley | Computer Science 88 | Michael Ball

Le Learning g Obj bjectives

  • Evaluate Python Expressions
  • Call Functions in Python
  • Assign data to Variables

23

slide-24
SLIDE 24

UC Berkeley | Computer Science 88 | Michael Ball

Le Let’s talk Py Python

  • Expression

3.1 * 2.6

  • Call expression

max(0, x)

  • Variables

my_name

  • Assignment Statement

x = <expression>

  • Define Statement:
  • Control Statements: if …

for … while … list comprehension

24

def <function name> (<argument list>) :

slide-25
SLIDE 25

Co Computational Structures in Data Science

UC Berkeley EECS Lecturer Michael Ball

UC Berkeley | Computer Science 88 | Michael Ball

Py Python: De Definitions and Co Control

slide-26
SLIDE 26

UC Berkeley | Computer Science 88 | Michael Ball

Le Learning g Obj bjectives

  • Create your own functions.
  • Use if and else to control the flow of code.

26

slide-27
SLIDE 27

UC Berkeley | Computer Science 88 | Michael Ball

Co Conditional Stateme ment

  • Do some statements, conditional on a predicate expression
  • Example:

27

if <predicate>: <true statements> else: <false statements> if (temperature>37.2): print(“fever!”) else: print(“no fever”)

slide-28
SLIDE 28

UC Berkeley | Computer Science 88 | Michael Ball

De Defining Functions

  • Abstracts an expression or set of statements to apply to lots of instances
  • f the problem
  • A function should do one thing well

28

expression

def <function name> (<argument list>) : return

slide-29
SLIDE 29

UC Berkeley | Computer Science 88 | Michael Ball

Func Functi tions: ns: Exam ampl ple

29

slide-30
SLIDE 30

UC Berkeley | Computer Science 88 | Michael Ball

Ho How w to Write a Good Function

  • Give a descriptive name

– Function names should be lowercase. If necessary, separate words by underscores

to improve readability. Names are extremely suggestive!

  • Chose meaningful parameter names

– Again, names are extremely suggestive.

  • Write the docstring to explain what it does

– What does the function return? What are corner cases for parameters?

  • Write doctest to show what it should do

– Before you write the implementation.

30

Python Style Guide: https://www.python.org/dev/peps/pep-0008

slide-31
SLIDE 31

Co Computational Structures in Data Science

UC Berkeley EECS Lecturer Michael Ball

UC Berkeley | Computer Science 88 | Michael Ball

Func Functi tions ns and and Env nvironm nments ents

slide-32
SLIDE 32

UC Berkeley | Computer Science 88 | Michael Ball

Func Functi tions: ns: Cal alling ng and and Retur eturni ning ng Resul esults ts

32

Python Tutor def max(x, y): return x if x > y else y x = 3 y = 4 + max(17, x + 6) * 0.1 z = x / y

slide-33
SLIDE 33

Co Computational Structures in Data Science

UC Berkeley EECS Lecturer Michael Ball

UC Berkeley | Computer Science 88 | Michael Ball

It Iteration W n With W While le L Loops

slide-34
SLIDE 34

UC Berkeley | Computer Science 88 | Michael Ball

Le Learning g Obj bjectives

  • Write functions that call functions
  • Learn How to use while loops.

34

slide-35
SLIDE 35

UC Berkeley | Computer Science 88 | Michael Ball

while St Statem ement ent – It Iteration C n Cont ntrol

  • Repeat a block of statements until a predicate expression is satisfied

35

<initialization statements>

while <predicate expression>:

<body statements> <rest of the program>