diff --git a/src/teaching/cse-662/2019fa/index.md b/src/teaching/cse-662/2019fa/index.md index 8bbdafb9..00d9e075 100644 --- a/src/teaching/cse-662/2019fa/index.md +++ b/src/teaching/cse-662/2019fa/index.md @@ -78,8 +78,8 @@ After the taking the course, students should be able to: ## Lecture Notes * **Aug 27** - Intro and Seeds ([slides](slide/2019-08-27-Introduction.html)) - - +* **Sep 3** - Functional Data Structures ([slides](slide/2019-09-03-FunctionalDS.html)) +* **Sep 5** - Lazy Transactions ([reading](https://dl-acm-org.gate.lib.buffalo.edu/citation.cfm?id=2610529)) --- diff --git a/src/teaching/cse-662/2019fa/slide/2019-08-29-Seeds.erb b/src/teaching/cse-662/2019fa/slide/2019-08-29-Seeds.erb deleted file mode 100644 index d8dd5edb..00000000 --- a/src/teaching/cse-662/2019fa/slide/2019-08-29-Seeds.erb +++ /dev/null @@ -1,465 +0,0 @@ - - - -
- - -Learned Index Structures due Weds (1 week)
-Lots of devices with...
Not all data sources are created equal.
-Even within one data set, some data may be more trustworthy than others.
-How do you train a classifier/neural net/markov model/etc... on mixed-quality data?
-Problem: Usually easier to "fix" than to label missing data.
-But what if the data is already labeled!
-Ideally the model is interpretable as well.
-Have a question?
- -Most people will give you a bad answer.
- -A few will give you a bad answer.
- -The average of a bunch of bad answers and a few good answers is a good answer?
-Problem: Often there is a very large number of possible worlds.
- -Solution: Break down possible worlds by choices.
- -Question: Which choices have the biggest impact on a query result?
-Sensitivity analysis and explanations for robust query evaluation in probabilistic databases.
- Kanagal, Li, Deshpande (SIGMOD 2011)
Tracing data errors with view-conditioned causality
- Meliou, Gatterbauer, Nath, Suciu (SIGMOD 2011)
Unit of Choice: Is a tuple (fact) in the source data or not?
-Let queries call a nondeterministic "choice" function that decides which "world" to visit.
- -
- SELECT CASE VGTerm("A", ROWID) WHEN 1 THEN "FOO"
- ELSE "BAR"
- END AS A, Input.*
- FROM Input;
-
-
- VGTerm("A", ROWID) generates a separate value for each row.
-Learned Index Structures due Weds (in class)
-One person from each group should email me...
Mutable vs Immutable Data
-
- X = [ "Alice", "Bob", "Carol", "Dave" ]
-
-
- X : | -Alice | -Bob | -Carol | -Dave | -
- print(X[2]) // -> "Carol"
-
-
-
- X[2] = "Eve"
-
-
- X : | -Alice | -Bob | -Eve | -Dave | -
- print(X[2]) // -> "Eve"
-
-
-
- X = [ Alice, Bob, Carol, Dave ]
-
-
- X : | -Alice | -Bob | -Carol | -Dave | -
Thread 1 | -Thread 2 | - -
---|---|
|
-
|
-
🤔 |
Can these problems be avoided?
-Mutable vs Immutable Data
-
- X = [ "Alice", "Bob", "Carol", "Dave" ]
-
-
- X : | -Alice | -Bob | -Carol | -Dave | -
- print(X[2]) // -> "Carol"
-
-
-
- X[2] = "Eve"
-
-
- Don't allow writes!
- -But what if we need to update the structure?
- -X : | -Alice | -Bob | -Carol | -Dave | -
X' : | -Alice | -Bob | -Eve | -Dave | -
Slooooooooooooooooooooooow!
-Data is always added, not replaced!
-How would you implement:
-
- list update(list, index, new_value)
-
- Implement a set with:
-
- set init()
- boolean is_member(set, elem)
- set insert(set, elem)
-
- Can we do better?
-x = "expensive()" |
- Fast (Just saving a 'todo') |
-
print(x) |
- Slow (Performing the 'todo') |
-
print(x) |
- Fast ('todo' already done) |
-
Make it better!
-
- concatenate(a, b) {
- a', front = pop(a)
- if a' is empty {
- return (front, b)
- } else {
- return (front, "concatenate(a', b)")
- }
- }
-
-
- What is the time complexity of this concatenate?
-What happens to reads?
-Save work for later... -
Allow operation A to 'pay it forward' for another operation B that hasn't happened yet.
- -... or allow an operation B to 'borrow' from another operation A that hasn't happened yet.
- -
- queue enqueue(queue, item) {
- return {
- current : queue.current,
- todo : push(queue.todo, item)
- )
- }
-
- What is the cost?
-
- queue dequeue(queue) {
- if(queue.current != NULL){
-
- return { current: pop(queue.current), todo: queue.todo }
-
- } else if(queue.todo != NULL) {
-
- return { current: reverse(queue.todo), todo: NULL }
-
- } else {
- return { current: NULL, todo: NULL }
+---
+template: templates/cse662_2019_slides.erb
+title: Functional Data Structures
+date: Sept. 3
+---
+
+
+
+ Mutable vs Immutable Data
+
+
+
+
+ X = [ "Alice", "Bob", "Carol", "Dave" ]
+
+
+
+
+ X :
+ Alice
+ Bob
+ Carol
+ Dave
+
+
+
+
+ print(X[2]) // -> "Carol"
+
+
+
+ X[2] = "Eve"
+
+
+
+
+ X :
+ Alice
+ Bob
+ Eve
+ Dave
+
+
+
+
+ print(X[2]) // -> "Eve"
+
+
+
+
+
+
+ X = [ Alice, Bob, Carol, Dave ]
+
+
+
+
+ X :
+ Alice
+ Bob
+ Carol
+ Dave
+
+
+
+
+
+ Thread 1
+ Thread 2
+
+
+
+ X[2] = "Eve"
+
+
+ print(X[2])
+
+
+ 🤔
+
+
+
+
+ Mutable Data Structures
+
+ - The programmer's intended ordering is unclear.
+ - Atomicity/Correctness requires locking.
+ - Versioning requires copying the data structure.
+ - Cache coherency is expensive.
+
+ Can these problems be avoided?
+
+
+
+
+
+ Mutable vs Immutable Data
+
+
+
+
+ X = [ "Alice", "Bob", "Carol", "Dave" ]
+
+
+
+
+ X :
+ Alice
+ Bob
+ Carol
+ Dave
+
+
+
+
+ print(X[2]) // -> "Carol"
+
+
+
+ X[2] = "Eve"
+
+
+ Don't allow writes!
+
+ But what if we need to update the structure?
+
+
+
+
+ Idea 1: Copy
+
+
+
+ X :
+ Alice
+ Bob
+ Carol
+ Dave
+
+
+
+
+
+ X' :
+ Alice
+ Bob
+ Eve
+ Dave
+
+
+
+ Slooooooooooooooooooooooow!
+
+
+
+ Idea 2: Break it Down
+
+ Data is always added, not replaced!
+
+
+
+ Immutable Data Structures
+ (aka 'Functional' or 'Persistent' Data Structures)
+
+ - Once an object is created it never changes.
+ - The object persists until all pointers to it go away, at which point it is garbage collected.
+ - Only the "root" pointer is ever allowed to change, to point to a new version.
+
+
+
+
+
+
+
+
+ Linked List Stacks
+
+
+
+
+
+
+
+
+
+ Class Exercise 1
+
+ How would you implement:
+
+ list update(list, index, new_value)
+
+
+
+
+ Class Exercise 2
+
+ Implement a set with:
+
+ set init()
+ boolean is_member(set, elem)
+ set insert(set, elem)
+
+
+
+
+
+
+ Lazy Evaluation
+
+
+ Can we do better?
+
+
+
+ Putting off Work
+
+
+
+ x = "expensive()"
+ Fast
(Just saving a 'todo')
+
+
+ print(x)
+ Slow
(Performing the 'todo')
+
+
+ print(x)
+ Fast
('todo' already done)
+
+
+
+
+
+ Class Exercise 3
+
+
+ Make it better!
+
+
+
+ Putting off Work
+
+ concatenate(a, b) {
+ a', front = pop(a)
+ if a' is empty {
+ return (front, b)
+ } else {
+ return (front, "concatenate(a', b)")
+ }
+ }
+
+
+ What is the time complexity of this concatenate?
+ What happens to reads?
+
+
+
+ Lazy Evaluation
+ Save work for later...
+
+ - ... and avoid work that is never requred.
+ - ... to spread out work over multiple calls.
+ - ... for better "amortized" costs.
+
+
+
+
+
+
+
+ Amortized Analysis
+ Allow operation A to 'pay it forward' for another operation B that hasn't happened yet.
+
+ ... or allow an operation B to 'borrow' from another operation A that hasn't happened yet.
+
+
+ - A's time complexity goes up by X.
+ - B's time complexity goes down by X.
+
+
+
+
+ Example: Amortized Queues
+
+
+
+
+
+ Example: Amortized Queues
+
+
+ queue enqueue(queue, item) {
+ return {
+ current : queue.current,
+ todo : push(queue.todo, item)
+ )
+ }
+
+ What is the cost?
+
+
+
+ Example: Amortized Queues
+
+
+ queue dequeue(queue) {
+ if(queue.current != NULL){
+
+ return { current: pop(queue.current), todo: queue.todo }
+
+ } else if(queue.todo != NULL) {
+
+ return { current: reverse(queue.todo), todo: NULL }
+
+ } else {
+
+ return { current: NULL, todo: NULL }
+
+ }
}
- }
-
- What is the cost?
-
+
+ What is the cost?
+Critical requirement of amortized analysis: Must ensure that every credit consumed is created.
-Critical requirement of amortized analysis: Must ensure that every credit consumed was once created.
+ + diff --git a/src/teaching/cse-662/2019fa/slide/graphics/2018-08-31-AmortizedQueue.svg b/src/teaching/cse-662/2019fa/slide/graphics/2018-08-31-AmortizedQueue.svg new file mode 100644 index 00000000..f6b14dc2 --- /dev/null +++ b/src/teaching/cse-662/2019fa/slide/graphics/2018-08-31-AmortizedQueue.svg @@ -0,0 +1,529 @@ + + + + diff --git a/src/teaching/cse-662/2019fa/slide/graphics/2018-08-31-FunctionalStack.svg b/src/teaching/cse-662/2019fa/slide/graphics/2018-08-31-FunctionalStack.svg new file mode 100644 index 00000000..9ffe0265 --- /dev/null +++ b/src/teaching/cse-662/2019fa/slide/graphics/2018-08-31-FunctionalStack.svg @@ -0,0 +1,1028 @@ + + + + diff --git a/src/teaching/cse-662/2019fa/slide/graphics/2018-08-31-FunctionalStackMerge.svg b/src/teaching/cse-662/2019fa/slide/graphics/2018-08-31-FunctionalStackMerge.svg new file mode 100644 index 00000000..f5fea9a6 --- /dev/null +++ b/src/teaching/cse-662/2019fa/slide/graphics/2018-08-31-FunctionalStackMerge.svg @@ -0,0 +1,650 @@ + + + + diff --git a/src/teaching/cse-662/2019fa/slide/graphics/2018-08-31-FunctionalTreeInsertion.svg b/src/teaching/cse-662/2019fa/slide/graphics/2018-08-31-FunctionalTreeInsertion.svg new file mode 100644 index 00000000..364f8d11 --- /dev/null +++ b/src/teaching/cse-662/2019fa/slide/graphics/2018-08-31-FunctionalTreeInsertion.svg @@ -0,0 +1,362 @@ + + + +