1 2
play

1 2 Ex Experiment Where ar Wh are you from? Possible Answers: - PDF document

Ab Abstr stracti ction Co Computatio ional S Structures in in D Data S Scie ience Detail removal The act of leaving out of consideration one or more properties of a complex object so as to attend to others. Generalization


  1. Ab Abstr stracti ction Co Computatio ional S Structures in in D Data S Scie ience • Detail removal “The act of leaving out of consideration one or more properties of a complex object so as to attend to others.” • Generalization UC Berkeley EECS Abstr Ab stracti ction “The process of formulating general Lecturer concepts by abstracting common Michael Ball properties of instances” • Technical terms: Compression, Quantization, Clustering, Unsupervized Learning Henri Matisse “Naked Blue IV” UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 2 1 2 Ex Experiment Where ar Wh are you from? 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! UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 3 4 3 4 Ab Abstr stracti ction gone e wrong! De Detail l Re Remo mova val l (in Da Data Science) • 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! The London Underground 1928 Map & the 1933 map by Harry Beck. UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 5 6 01/28/19 UCB CS88 Sp19 L1 5 6 1

  2. Th The P Power o of A Abs bstraction, Ev Everywhere! Ab Abstr stracti ction: Pitfa tfalls • Abstraction is not universal without loss of information (mathematically provable). This means, in the end, the complexity • Examples: We only need to worry about the can only be “moved around” – Functions (e.g., sin x) interface, or specification, or contract NOT how (or by whom) it’s built – Hiring contractors • Abstraction makes us – Application Programming Interfaces Above the abstraction line (APIs) forget how things actually – Technology (e.g., cars) work and can therefore Abstraction Barrier (Interface) (the interface, or specification, or contract) hide bias. Example: AI and hiring decisions. Below the abstraction line • Amazing things are built when these layer This is where / how / when / by whom it is – And the abstraction layers are actually built, which is done according to getting deeper by the day! the interface, specification, or contract. • Abstraction makes things special and that creates dependencies. Dependencies grow longer and longer over time and can become unmanageable. UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 7 8 01/19/18 UCB CS88 Sp18 L1 01/19/18 UCB CS88 Sp18 L1 7 8 Al Algorith thm Al Algorith thm: Proper erti ties es • An algorithm (pronounced AL-go-rith-um) is a procedure or formula to • An algorithm is a description that can be expressed within a finite solve a problem. amount of space and time. • An algorithm is a sequence of instructions to change the state of a • Executing the algorithm may take infinite space and/or time, e.g. system. For example: A computer’s memory, your brain (math), or the ``calculate all prime numbers”. ingredients to prepare food (cooking recipe). • In CS and math, we prefer to use well-defined formal languages for defining an algorithm. Think Data 8: Change or retrieve the content of a table. UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 9 10 9 10 st Gra Al Algorith thm: Wel ell-De Definition Algorith Al thms s Early In Life fe (1 st Grade) 1 carry (MSD) 7 operands 8 operator + 5 least significant digit of result UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 11 12 11 12 2

  3. Al Algorith thms s Early In Life fe (In Binary) Mo More Termino nology (Int ntui uitive) Code A sequence of symbols used for communication between systems (brains, computers, brain-to-computer) 1 1 0 0 carry (MSD) 1 1 1 0 14 operands 0 0 Data 1 1 + 12 operator + Observations 26 1 1 0 1 0 LSB result Information Reduction of uncertainty in a model (measured in bits) UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 13 14 13 14 Da Data or r Co Code? Data or Da r Co Code? UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 15 16 15 16 Data or Da r Co Code? Data or Da r Co Code? Abstra raction! Here is some information! Human-readable code Machine-executable (programming language) instructions (byte code) Compiler or Interpreter Here: Python UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 17 18 17 18 3

  4. Co Code o or G r GUI: M More re A Abs bstra raction! Re Revi view: w: • Abstraction: – Detail Removal or Generalizations • Code: – Is an abstraction! – Can be instructions or information Computer Science is the study of abstraction • Big Idea: Layers of Abstraction – The GUI look and feel is built out of files, directories, system code, etc. UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 19 20 19 20 Co Computatio ional S Structures in in D Data S Scie ience UC Berkeley EECS Python: S Pyt Stateme ments a and F Functions Lecturer Michael Ball UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 21 21 22 Le Learn rning O g Obj bjective ves Le Let’s t talk Pyt Python • Evaluate Python Expressions • Expression 3.1 * 2.6 • Call Functions in Python • Call expression max(0, x) • Assign data to Variables • Variables my_name • Assignment Statement x = <expression> • Define Statement: def <function name> ( <argument list> ) : • Control Statements: if … for … while … list comprehension UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 23 24 23 24 4

  5. Learn Le rning O g Obj bjective ves Computatio Co ional S Structures in in D Data S Scie ience • Create your own functions. • Use if and else to control the flow of code. UC Berkeley EECS Pyt Python: De Definitions a and Co Contro rol Lecturer Michael Ball UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 26 25 26 Co Conditional S Stateme ment Defining De g Functions • Do some statements, conditional on a predicate expression def <function name> ( <argument list> ) : if <predicate> : <true statements> else: expression return <false statements> • Example: • Abstracts an expression or set of statements to apply to lots of instances if (temperature>37.2) : of the problem print(“fever!”) else: • A function should do one thing well print(“no fever”) UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 27 28 27 28 Fu Function ions: : Exam ampl ple How Ho w to Wri rite a Go 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? Python Style Guide: https://www.python.org/dev/peps/pep-0008 • Write doctest to show what it should do – Before you write the implementation. UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 29 30 29 30 5

  6. Function Fu ions: : Cal allin ing an and d Returnin ing Results Computatio Co ional S Structures in in D Data S Scie ience Python Tutor def max(x, y): UC Berkeley EECS Fu Function ions an and d Envir iron onments Lecturer return x if x > y else y Michael Ball x = 3 y = 4 + max(17, x + 6) * 0.1 z = x / y UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 32 31 32 Learn Le rning O g Obj bjective ves Co Computatio ional S Structures in in D Data S Scie ience • Write functions that call functions • Learn How to use while loops. UC Berkeley EECS Ite Itera rati tion With th While le Loops Lecturer Michael Ball UC Berkeley | Computer Science 88 | Michael Ball UC Berkeley | Computer Science 88 | Michael Ball 34 33 34 while Sta Statem tement ent – Ite Itera rati tion Contro trol • Repeat a block of statements until a predicate expression is satisfied <initialization statements> while <predicate expression> : <body statements> <rest of the program> UC Berkeley | Computer Science 88 | Michael Ball 35 35 6

Recommend


More recommend