Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Lesson 05 Analyzing Structures
1. Analyzing Structures CS 5010 Program Design Paradigms “Bootcamp” Week 03, Lesson 3 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA 1
2. Template for recursive/mixed data ;; A Foo is one of ;; -- (make-foo1 Number FooFoo) ;; -- (make-foo2 Foo Boolean) ;; -- (make-foo3 Number Boolean) (define-struct foo1 (field1 field2 field3)) (define-struct foo2 (field1 field2)) (define-struct foo3 (field1 field2)) (define (foo-fn f) (cond [(foo1? f) (... (foo1-field1 f) (foo-fn (foo1-field2 f)) (foo-fn (foo1-field3 f)))] [(foo2? f) (... (foo-fn (foo2-field1 f)) (foo2-field2 f))] [else (... (foo3-field1 f) (foo3-field2 f))]))
3. Which variant do we have? In this case, it's easy– we have predicates Sometimes not so easy for SoS, we had to distinguish between strings and non-strings. Before, we had adam? and eve? Today's topic: How to design predicates
4. An Example Problem We are given a list of bird observations. Each observation consists of 3 parts: beak, wings, belly We have a table for converting an observation to a species:
8. A cleverer approach: a decision tree beak Yellow Black wings Blue Red Yellow-Bellied belly Plain Star Plain-Bellied Star-Bellied
9. Code using Decision Tree ;; observation2species : Observation -> Species ;; strategy: decision tree (define (observation2species obs) (if (yellow? (observation-beak obs)) (if (black? (observation-wings obs)) "Yellow-Bellied Blackbird" (not-ybb-to-species obs)) (not-ybb-to-species obs))) ;; not-ybb-to-species : Observation -> Species ;; Given an observation THAT IS KNOWN NOT TO BE A YBB ;; determine which species of sneetch it is. (define (not-ybb-to-species obs) (if (plain? (observation-belly obs)) "Plain-Bellied-Sneetch" "Star-Bellied-Sneetch")) A side-condition like this is called an INVARIANT
10. Decision Trees vs. Truth Tables Truth table code is boring, but reliable Decision Tree: may take effort to get right! Testing is vital! Decision Tree: shorter Have to figure out order of tests Decision Tree: sometimes necessary what if you couldn't see the blackbird's belly? this happens often in practice.
11. Summary Use wishlist functions to discriminate between cases. Use truth tables or decision trees to figure out what's what. Test, test, test!
Editor's Notes
Welcome to Week 3, Lesson 2: Recursive Data Definitions EverywhereIn this lesson, we will see some of the many ways in which recursive data definitions can arise.