The document discusses streaming algorithms and techniques for processing data streams. It describes how streaming data arrives rapidly and cannot typically be stored fully. Some key streaming algorithms covered include sampling to create random samples of the data, and counting distinct elements using the Flajolet-Martin algorithm which estimates the number of distinct elements in a stream using multiple hash functions. The document provides examples of problems where streaming algorithms are applicable, such as counting unique words or users from high-volume data streams.
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...Flink Forward
Apache Beam is Flink’s sibling in the Apache family of streaming processing frameworks. The Beam and Flink teams work closely together on advancing what is possible in streaming processing, including Streaming SQL extensions and code interoperability on both platforms.
Beam was originally developed at Google as the amalgamation of its internal batch and streaming frameworks to power the exabyte-scale data processing for Gmail, YouTube and Ads. It now powers a fully-managed, serverless service Google Cloud Dataflow, as well as is available to run in other Public Clouds and on-premises when deployed in portability mode on Apache Flink, Spark, Samza and other runners. Users regularly run distributed data processing jobs on Beam spanning tens of thousands of CPU cores and processing millions of events per second.
In this session, Sergei Sokolenko, Cloud Dataflow product manager, and Reuven Lax, the founding member of the Dataflow and Beam team, will share Google’s learnings from building and operating a global streaming processing infrastructure shared by thousands of customers, including:
safe deployment to dozens of geographic locations,
resource autoscaling to minimize processing costs,
separating compute and state storage for better scaling behavior,
dynamic work rebalancing of work items away from overutilized worker nodes,
offering a throughput-optimized batch processing capability with the same API as streaming,
grouping and joining of 100s of Terabytes in a hybrid in-memory/on-desk file system,
integrating with the Google Cloud security ecosystem, and other lessons.
Customers benefit from these advances through faster execution of jobs, resource savings, and a fully managed data processing environment that runs in the Cloud and removes the need to manage infrastructure.
MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...MongoDB
How do you determine whether your MongoDB Atlas cluster is over provisioned, whether the new feature in your next application release will crush your cluster, or when to increase cluster size based upon planned usage growth? MongoDB Atlas provides over a hundred metrics enabling visibility into the inner workings of MongoDB performance, but how do apply all this information to make capacity planning decisions? This presentation will enable you to effectively analyze your MongoDB performance to optimize your MongoDB Atlas spend and ensure smooth application operation into the future.
Patterns of the Lambda Architecture -- 2015 April - Hadoop Summit, EuropeFlip Kromer
This talk centers on two things: a set of patterns for the architecture of high-scale data systems; and a framework for understanding the tradeoffs we make in designing them.
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...huguk
The task of “data profiling”—assessing the overall content and quality of a data set—is a core aspect of the analytic experience. Traditionally, profiling was a fairly cut-and-dried task: load the raw numbers into a stat package, run some basic descriptive statistics, and report the output in a summary file or perhaps a simple data visualization. However, data volumes can be so large today that traditional tools and methods for computing descriptive statistics become intractable; even with scalable infrastructure like Hadoop, aggressive optimization and statistical approximation techniques must be used. In this talk Sean will cover technical challenges in keeping data profiling agile in the Big Data era. He will discuss both research results and real-world best practices used by analysts in the field, including methods for sampling, summarizing and sketching data, and the pros and cons of using these various approaches.
Sean is Trifacta’s Chief Technical Officer. He completed his Ph.D. at Stanford University, where his research focused on user interfaces for database systems. At Stanford, Sean led development of new tools for data transformation and discovery, such as Data Wrangler. He previously worked as a data analyst at Citadel Investment Group.
Introduction of streaming data, difference between batch processing and stream processing, Research issues in streaming data processing, Performance evaluation metrics , tools for stream processing.
In this Strata 2018 presentation, Ted Malaska and Mark Grover discuss how to make the most of big data at speed.
https://conferences.oreilly.com/strata/strata-ny/public/schedule/detail/72396
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...Flink Forward
Apache Beam is Flink’s sibling in the Apache family of streaming processing frameworks. The Beam and Flink teams work closely together on advancing what is possible in streaming processing, including Streaming SQL extensions and code interoperability on both platforms.
Beam was originally developed at Google as the amalgamation of its internal batch and streaming frameworks to power the exabyte-scale data processing for Gmail, YouTube and Ads. It now powers a fully-managed, serverless service Google Cloud Dataflow, as well as is available to run in other Public Clouds and on-premises when deployed in portability mode on Apache Flink, Spark, Samza and other runners. Users regularly run distributed data processing jobs on Beam spanning tens of thousands of CPU cores and processing millions of events per second.
In this session, Sergei Sokolenko, Cloud Dataflow product manager, and Reuven Lax, the founding member of the Dataflow and Beam team, will share Google’s learnings from building and operating a global streaming processing infrastructure shared by thousands of customers, including:
safe deployment to dozens of geographic locations,
resource autoscaling to minimize processing costs,
separating compute and state storage for better scaling behavior,
dynamic work rebalancing of work items away from overutilized worker nodes,
offering a throughput-optimized batch processing capability with the same API as streaming,
grouping and joining of 100s of Terabytes in a hybrid in-memory/on-desk file system,
integrating with the Google Cloud security ecosystem, and other lessons.
Customers benefit from these advances through faster execution of jobs, resource savings, and a fully managed data processing environment that runs in the Cloud and removes the need to manage infrastructure.
MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...MongoDB
How do you determine whether your MongoDB Atlas cluster is over provisioned, whether the new feature in your next application release will crush your cluster, or when to increase cluster size based upon planned usage growth? MongoDB Atlas provides over a hundred metrics enabling visibility into the inner workings of MongoDB performance, but how do apply all this information to make capacity planning decisions? This presentation will enable you to effectively analyze your MongoDB performance to optimize your MongoDB Atlas spend and ensure smooth application operation into the future.
Patterns of the Lambda Architecture -- 2015 April - Hadoop Summit, EuropeFlip Kromer
This talk centers on two things: a set of patterns for the architecture of high-scale data systems; and a framework for understanding the tradeoffs we make in designing them.
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...huguk
The task of “data profiling”—assessing the overall content and quality of a data set—is a core aspect of the analytic experience. Traditionally, profiling was a fairly cut-and-dried task: load the raw numbers into a stat package, run some basic descriptive statistics, and report the output in a summary file or perhaps a simple data visualization. However, data volumes can be so large today that traditional tools and methods for computing descriptive statistics become intractable; even with scalable infrastructure like Hadoop, aggressive optimization and statistical approximation techniques must be used. In this talk Sean will cover technical challenges in keeping data profiling agile in the Big Data era. He will discuss both research results and real-world best practices used by analysts in the field, including methods for sampling, summarizing and sketching data, and the pros and cons of using these various approaches.
Sean is Trifacta’s Chief Technical Officer. He completed his Ph.D. at Stanford University, where his research focused on user interfaces for database systems. At Stanford, Sean led development of new tools for data transformation and discovery, such as Data Wrangler. He previously worked as a data analyst at Citadel Investment Group.
Introduction of streaming data, difference between batch processing and stream processing, Research issues in streaming data processing, Performance evaluation metrics , tools for stream processing.
In this Strata 2018 presentation, Ted Malaska and Mark Grover discuss how to make the most of big data at speed.
https://conferences.oreilly.com/strata/strata-ny/public/schedule/detail/72396
Automating Speed: A Proven Approach to Preventing Performance Regressions in ...HostedbyConfluent
"Regular performance testing is one of the pillars of Kafka Streams’ reliability and efficiency. Beyond ensuring dependable releases, regular performance testing supports engineers in new feature development with the ability to easily test the performance impact of their features, compare different approaches, etc.
In this session, Alex and John share their experience from developing, using, and maintaining a performance testing framework for Kafka Streams that has prevented multiple performance regressions over the last 5 years. They cover guiding principles and architecture, how to ensure statistical significance and stability of results, and how to automate regression detection for actionable notifications.
This talk sheds light on how Apache Kafka is able to foster a vibrant open-source community while maintaining a high performance bar across many years and releases. It also empowers performance-minded engineers to avoid common pitfalls and bring high-quality performance testing to their own systems."
How EverTrue is building a donor CRM on top of ElasticSearch. We cover some of the issues around scaling ElasticSearch and which aspects of ElasticSearch we are using to deliver value to our customers.
Monitoring Big Data Systems - "The Simple Way"Demi Ben-Ari
Once you start working with distributed Big Data systems, you start discovering a whole bunch of problems you won’t find in monolithic systems.
All of a sudden to monitor all of the components becomes a big data problem itself.
In the talk we’ll mention all of the aspects that you should take in consideration when monitoring a distributed system once you’re using tools like:
Web Services, Apache Spark, Cassandra, MongoDB, Amazon Web Services.
Not only the tools, what should you monitor about the actual data that flows in the system?
And we’ll cover the simplest solution with your day to day open source tools, the surprising thing, that it comes not from an Ops Guy.
Demi Ben-Ari is a Co-Founder and CTO @ Panorays.
Demi has over 9 years of experience in building various systems both from the field of near real time applications and Big Data distributed systems.
Describing himself as a software development groupie, Interested in tackling cutting edge technologies.
Demi is also a co-founder of the “Big Things” Big Data community: http://somebigthings.com/big-things-intro/
Meetup sthlm - introduction to Machine Learning with demo casesZenodia Charpy
Data science and Machine Learning
Machine Learning vs Artificial Intelligence
Machine Learning Algorithms
How to choose ML algorithm mindmap
Supervised Learning generic flow
Unsupervised Learning generic flow
Example cases for supervised and unsupervised learning
Lucas Waye of Tivo talks about how the company uses Presto for SQL analytics. Meetup co-sponsored by Starburst (www.starburstdata.com) and Qubole (www.qubole.com).
5 Practical Steps to a Successful Deep Learning ResearchBrodmann17
Deep Learning has gained a huge popularity over the last several years. Especially due to its magnificent progress in many domains.
Many resources are out there including open source implementations of recent research advancements. This vast availability is somehow misleading because when one actually wants to create a Deep Learning based product, he soon realizes that there is a large gap between these open source implementations and a real production grade Deep Learning product. Closing this gap can take months of work involving large costs, especially on man power and compute power.
Throughout this talk I will talk based on my experience leading the research at Brodmann17 about several aspects we have found to be important for building Deep Learning based computer vision products.
Maximizing Database Tuning in SAP SQL AnywhereSAP Technology
This session illustrates the different tools available in SQL Anywhere to analyze performance issues, as well as describes the most common types of performance problems encountered by database developers and administrators. We also take a look at various tips and techniques that will help boost the performance of your SQL Anywhere database.
Data analysis lecture for IST 400/600 "Science Data Management" at the Syracuse University School of Information Studies. This lecture covers some basic high-level concepts involved in data analysis, with mild emphasis on scientific research contexts.
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...2023240532
Quantitative data Analysis
Overview
Reliability Analysis (Cronbach Alpha)
Common Method Bias (Harman Single Factor Test)
Frequency Analysis (Demographic)
Descriptive Analysis
More Related Content
Similar to CSE545 sp23 (2) Streaming Algorithms 2-4.pdf
Automating Speed: A Proven Approach to Preventing Performance Regressions in ...HostedbyConfluent
"Regular performance testing is one of the pillars of Kafka Streams’ reliability and efficiency. Beyond ensuring dependable releases, regular performance testing supports engineers in new feature development with the ability to easily test the performance impact of their features, compare different approaches, etc.
In this session, Alex and John share their experience from developing, using, and maintaining a performance testing framework for Kafka Streams that has prevented multiple performance regressions over the last 5 years. They cover guiding principles and architecture, how to ensure statistical significance and stability of results, and how to automate regression detection for actionable notifications.
This talk sheds light on how Apache Kafka is able to foster a vibrant open-source community while maintaining a high performance bar across many years and releases. It also empowers performance-minded engineers to avoid common pitfalls and bring high-quality performance testing to their own systems."
How EverTrue is building a donor CRM on top of ElasticSearch. We cover some of the issues around scaling ElasticSearch and which aspects of ElasticSearch we are using to deliver value to our customers.
Monitoring Big Data Systems - "The Simple Way"Demi Ben-Ari
Once you start working with distributed Big Data systems, you start discovering a whole bunch of problems you won’t find in monolithic systems.
All of a sudden to monitor all of the components becomes a big data problem itself.
In the talk we’ll mention all of the aspects that you should take in consideration when monitoring a distributed system once you’re using tools like:
Web Services, Apache Spark, Cassandra, MongoDB, Amazon Web Services.
Not only the tools, what should you monitor about the actual data that flows in the system?
And we’ll cover the simplest solution with your day to day open source tools, the surprising thing, that it comes not from an Ops Guy.
Demi Ben-Ari is a Co-Founder and CTO @ Panorays.
Demi has over 9 years of experience in building various systems both from the field of near real time applications and Big Data distributed systems.
Describing himself as a software development groupie, Interested in tackling cutting edge technologies.
Demi is also a co-founder of the “Big Things” Big Data community: http://somebigthings.com/big-things-intro/
Meetup sthlm - introduction to Machine Learning with demo casesZenodia Charpy
Data science and Machine Learning
Machine Learning vs Artificial Intelligence
Machine Learning Algorithms
How to choose ML algorithm mindmap
Supervised Learning generic flow
Unsupervised Learning generic flow
Example cases for supervised and unsupervised learning
Lucas Waye of Tivo talks about how the company uses Presto for SQL analytics. Meetup co-sponsored by Starburst (www.starburstdata.com) and Qubole (www.qubole.com).
5 Practical Steps to a Successful Deep Learning ResearchBrodmann17
Deep Learning has gained a huge popularity over the last several years. Especially due to its magnificent progress in many domains.
Many resources are out there including open source implementations of recent research advancements. This vast availability is somehow misleading because when one actually wants to create a Deep Learning based product, he soon realizes that there is a large gap between these open source implementations and a real production grade Deep Learning product. Closing this gap can take months of work involving large costs, especially on man power and compute power.
Throughout this talk I will talk based on my experience leading the research at Brodmann17 about several aspects we have found to be important for building Deep Learning based computer vision products.
Maximizing Database Tuning in SAP SQL AnywhereSAP Technology
This session illustrates the different tools available in SQL Anywhere to analyze performance issues, as well as describes the most common types of performance problems encountered by database developers and administrators. We also take a look at various tips and techniques that will help boost the performance of your SQL Anywhere database.
Data analysis lecture for IST 400/600 "Science Data Management" at the Syracuse University School of Information Studies. This lecture covers some basic high-level concepts involved in data analysis, with mild emphasis on scientific research contexts.
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...2023240532
Quantitative data Analysis
Overview
Reliability Analysis (Cronbach Alpha)
Common Method Bias (Harman Single Factor Test)
Frequency Analysis (Demographic)
Descriptive Analysis
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Data and AI
Discussion on Vector Databases, Unstructured Data and AI
https://www.meetup.com/unstructured-data-meetup-new-york/
This meetup is for people working in unstructured data. Speakers will come present about related topics such as vector databases, LLMs, and managing data at scale. The intended audience of this group includes roles like machine learning engineers, data scientists, data engineers, software engineers, and PMs.This meetup was formerly Milvus Meetup, and is sponsored by Zilliz maintainers of Milvus.
Adjusting primitives for graph : SHORT REPORT / NOTESSubhajit Sahu
Graph algorithms, like PageRank Compressed Sparse Row (CSR) is an adjacency-list based graph representation that is
Multiply with different modes (map)
1. Performance of sequential execution based vs OpenMP based vector multiply.
2. Comparing various launch configs for CUDA based vector multiply.
Sum with different storage types (reduce)
1. Performance of vector element sum using float vs bfloat16 as the storage type.
Sum with different modes (reduce)
1. Performance of sequential execution based vs OpenMP based vector element sum.
2. Performance of memcpy vs in-place based CUDA based vector element sum.
3. Comparing various launch configs for CUDA based vector element sum (memcpy).
4. Comparing various launch configs for CUDA based vector element sum (in-place).
Sum with in-place strategies of CUDA mode (reduce)
1. Comparing various launch configs for CUDA based vector element sum (in-place).
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...pchutichetpong
M Capital Group (“MCG”) expects to see demand and the changing evolution of supply, facilitated through institutional investment rotation out of offices and into work from home (“WFH”), while the ever-expanding need for data storage as global internet usage expands, with experts predicting 5.3 billion users by 2023. These market factors will be underpinned by technological changes, such as progressing cloud services and edge sites, allowing the industry to see strong expected annual growth of 13% over the next 4 years.
Whilst competitive headwinds remain, represented through the recent second bankruptcy filing of Sungard, which blames “COVID-19 and other macroeconomic trends including delayed customer spending decisions, insourcing and reductions in IT spending, energy inflation and reduction in demand for certain services”, the industry has seen key adjustments, where MCG believes that engineering cost management and technological innovation will be paramount to success.
MCG reports that the more favorable market conditions expected over the next few years, helped by the winding down of pandemic restrictions and a hybrid working environment will be driving market momentum forward. The continuous injection of capital by alternative investment firms, as well as the growing infrastructural investment from cloud service providers and social media companies, whose revenues are expected to grow over 3.6x larger by value in 2026, will likely help propel center provision and innovation. These factors paint a promising picture for the industry players that offset rising input costs and adapt to new technologies.
According to M Capital Group: “Specifically, the long-term cost-saving opportunities available from the rise of remote managing will likely aid value growth for the industry. Through margin optimization and further availability of capital for reinvestment, strong players will maintain their competitive foothold, while weaker players exit the market to balance supply and demand.”
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Data and AI
Round table discussion of vector databases, unstructured data, ai, big data, real-time, robots and Milvus.
A lively discussion with NJ Gen AI Meetup Lead, Prasad and Procure.FYI's Co-Found
2. Big Data Analytics, The Class
Goal: Generalizations
A model or summarization of the data.
Hadoop File System
MapReduce
Spark
Deep Learning Frameworks
Similarity Search
Recommendation Systems
Link Analysis
Transformers/Self-Supervision
Streaming
Hypothesis Testing
Data Workflow Frameworks Analytics and Algorithms
4. (1) Direct: Often, data …
● … cannot be stored (too big, privacy concerns)
● … are not practical to access repeatedly (reading is too long)
● … are rapidly arriving (need rapidly updated "results")
Why Streaming?
5. (1) Direct: Often, data …
● … cannot be stored (too big, privacy concerns)
● … are not practical to access repeatedly (reading is too long)
● … are rapidly arriving (need rapidly updated "results")
Examples: Google search queries
Satellite imagery data
Text Messages, Status updates
Click Streams
Why Streaming?
6. (1) Direct: Often, data …
● … cannot be stored (too big, privacy concerns)
● … are not practical to access repeatedly (reading is too long)
● … are rapidly arriving (need rapidly updated "results")
(2) Indirect: The constraints for streaming data force one to
solutions that are often efficient even when storing data.
Streaming Approx Random Sample
Distributed IO (MapReduce, Spark)
Why Streaming?
7. (1) Direct: Often, data …
● … cannot be stored (too big, privacy concerns)
● … are not practical to access repeatedly (reading is too long)
● … are rapidly arriving (need rapidly updated "results")
(2) Indirect: The constraints for streaming data force one to
solutions that are often efficient even when storing data.
Streaming Approx Random Sample
Distributed IO (MapReduce, Spark)
Often translates into O(N) or strictly N algorithms.
Process
RECORD GONE
RECORD IN
Why Streaming?
8. ● General Stream Processing Model
● Sampling
● Counting Distinct Elements
● Filtering data according to a criteria
Streaming Topics
9. Standing Queries:
Stored and permanently executing.
Ad-Hoc:
One-time questions
-- must store expected parts /
summaries of streams
Process
for
stream queries
RECORD GONE
RECORD IN
10. Standing Queries:
Stored and permanently executing.
Ad-Hoc:
One-time questions
-- must store expected parts /
summaries of streams
Process
for
stream queries
RECORD GONE
RECORD IN
E.g. How would you handle:
What is the mean of values seen so far?
11. Standing Queries:
Stored and permanently executing.
Ad-Hoc:
One-time questions
-- must store expected parts /
summaries of streams
Process
for
stream queries
RECORD GONE
RECORD IN
E.g. How would you handle:
What is the mean of values seen so far?
Important difference from typical database management:
● Input is not controlled by system staff.
● Input timing/rate is often unknown, controlled by users.
12. Standing Queries:
Stored and permanently executing.
Ad-Hoc:
One-time questions
-- must store expected parts /
summaries of streams
Process
for
stream queries
RECORD GONE
RECORD IN
Important difference from typical database management:
● Input is not controlled by system staff.
● Input timing/rate is often unknown, controlled by users.
Might hold a sliding window of
records instead of single record.
.. , i, h, g, f, e, d, c, b, a
E.g. How would you handle:
What is the mean of values seen so far?
13. Input stream
…, 4, 3, 11, 2, 0, 5, 8, 1, 4
Processor
Output
(Generalization,
Summarization)
A stream of records
(also often referred to as “elements” , “tuples”, "lines", or "rows")
Theoretically, could be anything! search queries, numbers, bits, image files, ...
(Leskovec et al., 2014)
General Stream Processing Model
17. ad-hoc queries
Input stream
…, 4, 3, 11, 2, 0, 5, 8, 1, 4
Processor
Output
(Generalization,
Summarization)
limited
memory archival storage
standing
queries
-- not suitable for
fast queries.
General Stream Processing Model
18. Create a random sample for statistical analysis.
Process RECORD GONE
RECORD IN
Sampling
19. Create a random sample for statistical analysis.
Process RECORD GONE
RECORD IN
Keep?
limited
memory
yes
Sampling
20. Create a random sample for statistical analysis.
Process RECORD GONE
RECORD IN
Keep?
limited
memory
yes
run statistical
analysis
sometime in
future
Sampling
21. Create a random sample for statistical analysis.
1. Simple Sampling: Individual records are what you wish to sample.
Sampling: 2 Versions
22. Create a random sample for statistical analysis.
1. Simple Sampling: Individual records are what you wish to sample.
2. Hierarchical Sampling: Sample an attribute of a record.
(e.g. records are tweets, but with to sample users)
Sampling: 2 Versions
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
tweet!
24. Create a random sample for statistical analysis.
1. Simple Sampling: Individual records are what you wish to sample.
Sampling
25. Create a random sample for statistical analysis.
1. Simple Sampling: Individual records are what you wish to sample.
record = stream.next()
if ?: #keep: e.g., true 5% of the time
memory.write(record)
yes
limited
memory
Sampling
RECORD GONE
RECORD IN
26. Create a random sample for statistical analysis.
1. Simple Sampling: Individual records are what you wish to sample.
record = stream.next()
if random() <= .05: #keep: true 5% of the time
memory.write(record)
random() < .05?
yes
limited
memory
Sampling
RECORD GONE
RECORD IN
27. Create a random sample for statistical analysis.
1. Simple Sampling: Individual records are what you wish to sample.
record = stream.next()
if random() <= .05: #keep: true 5% of the time
memory.write(record)
Problem: records/rows often are not units-of-analysis for statistical analyses
E.g. user_ids for searches, tweets; location_ids for satellite images
limited
memory
run statistical
analysis
sometime in
future
Sampling
28. 2. Hierarchical Sampling: Sample an attribute of a record.
(e.g. records are tweets, but with to sample users)
record = stream.next()
if random() <= .05: #keep: true 5% of the time
memory.write(record)
Solution: ?
Sampling
30. 2. Hierarchical Sampling: Sample an attribute of a record.
(e.g. records are tweets, but with to sample users)
record = stream.next()
if ??: #keep:
memory.write(record)
Solution: instead of checking random digit; hash the attribute being sampled.
– streaming: only need to store hash functions; may be part of standing query
Sampling
31. 2. Hierarchical Sampling: Sample an attribute of a record.
(e.g. records are tweets, but with to sample users)
record = stream.next()
if hash(record[‘user_id’]) == 1: #keep
memory.write(record)
Solution: instead of checking random digit; hash the attribute being sampled.
– streaming: only need to store hash functions; may be part of standing query
How many buckets to hash into?
Sampling
32. ● General Stream Processing Model
● Sampling
● Counting Distinct Elements
● Filtering data according to a criteria
Streaming Topics
33. Moments:
● Suppose mi
is the count of distinct element i in the data
● The kth moment of the stream is
Counting Moments
34. Moments:
● Suppose mi
is the count of distinct element i in the data
● The kth moment of the stream is
● 0th moment: count of distinct elements
● 1st moment: length of stream
● 2nd moment: sum of squares
(measures uneveness; related to variance)
Counting Moments
35. Moments:
● Suppose mi
is the count of distinct element i in the data
● The kth moment of the stream is
● 0th moment: count of distinct elements
● 1st moment: length of stream
● 2nd moment: sum of squares
(measures uneveness; related to variance)
Trivial: just increment
a counter
Counting Moments
36. Counting Moments
Moments:
● Suppose mi
is the count of distinct element i in the data
● The kth moment of the stream is
● 0th moment: count of distinct elements
● 1st moment: length of stream
● 2nd moment: sum of squares
(measures uneveness; related to variance)
0th moment
Applications
Counting…
distinct words in large document.
distinct websites (URLs).
users that visit a site without storing.
unique queries to Alexa.
37. Counting Moments
Moments:
● Suppose mi
is the count of distinct element i in the data
● The kth moment of the stream is
● 0th moment: count of distinct elements
● 1st moment: length of stream
● 2nd moment: sum of squares
(measures uneveness; related to variance)
0th moment
One Solution: Just keep a set (hashmap, dictionary, heap)
Problem: Can’t maintain that many in memory; disk storage is too slow
Applications
Counting…
distinct words in large document.
distinct websites (URLs).
users that visit a site without storing.
unique queries to Alexa.
38. Moments:
● Suppose mi
is the count of distinct element i in the data
● The kth moment of the stream is
● 0th moment: count of distinct elements
● 1st moment: length of stream
● 2nd moment: sum of squares
(measures uneveness; related to variance)
0th moment
Streaming Solution: Flajolet-Martin Algorithm
General idea:
n -- suspected total number of elements observed
pick a hash, h, to map each element to log2
n bits (buckets)
Counting Moments
39. Moments:
● Suppose mi
is the count of distinct element i in the data
● The kth moment of the stream is
● 0th moment: count of distinct elements
● 1st moment: length of stream
● 2nd moment: sum of squares
(measures uneveness; related to variance)
0th moment
Streaming Solution: Flajolet-Martin Algorithm
General idea:
n -- suspected overestimate of total number of elements observed
pick a hash, h, to map each element to log2
n bits (buckets)
--------------------------------
R = 0 #current max number of zeros at tail
for each stream element, e:
r(e) = trailZeros(h(e)) #num of trailing 0s from h(e)
R = r(e) if r[e] > R
estimated_distinct_elements = 2R
Counting Moments
40. Counting Moments
Moments:
● Suppose mi
is the count of distinct element i in the data
● The kth moment of the stream is
● 0th moment: count of distinct elements
● 1st moment: length of stream
● 2nd moment: sum of squares
(measures uneveness; related to variance)
0th moment
Streaming Solution: Flajolet-Martin Algorithm
General idea:
n -- suspected total number of elements observed
pick a hash, h, to map each element to log2
n bits (buckets)
--------------------------------
R = 0 #current max number of zeros at tail
for each stream element, e:
r(e) = trailZeros(h(e)) #num of trailing 0s from h(e)
R = r(e) if r[e] > R
estimated_distinct_elements = 2R
# m
Mathematical Intuition
P( trailZeros(h(e)) >= i ) = 2-i
# P(h(e) == __0) = .5; P(h(e) == __00) = .25; …
P( trailZeros(h(e)) < i ) = 1 - 2-i
for m elements: = (1 - 2-i
)m
P( one e has trailZeros > i) = 1 - (1 - 2-i
)m
≈ 1 - e-m2^-i
If 2R
>> m, then 1 - (1 - 2-i
)m
≈ 0
If 2R
<< m, then 1 - (1 - 2-i
)m
≈ 1
41. Counting Moments
Moments:
● Suppose mi
is the count of distinct element i in the data
● The kth moment of the stream is
● 0th moment: count of distinct elements
● 1st moment: length of stream
● 2nd moment: sum of squares
(measures uneveness; related to variance)
0th moment
Streaming Solution: Flajolet-Martin Algorithm
General idea:
n -- suspected total number of elements observed
pick a hash, h, to map each element to log2
n bits (buckets)
--------------------------------
R = 0 #current max number of zeros at tail
for each stream element, e:
r(e) = trailZeros(h(e)) #num of trailing 0s from h(e)
R = r(e) if r[e] > R
estimated_distinct_elements = 2R
# m
Mathematical Intuition
P( trailZeros(h(e)) >= i ) = 2-i
# P(h(e) == __0) = .5; P(h(e) == __00) = .25; …
P( trailZeros(h(e)) < i ) = 1 - 2-i
for m elements: = (1 - 2-i
)m
P( one e has trailZeros > i) = 1 - (1 - 2-i
)m
≈ 1 - e-m2^-i
If 2R
>> m, then 1 - (1 - 2-i
)m
≈ 0
If 2R
<< m, then 1 - (1 - 2-i
)m
≈ 1
Problem:
Unstable in practice.
Solution:
Multiple hash functions
but how to combine?
42. Moments:
● Suppose mi
is the count of distinct element i in the data
● The kth moment of the stream is
● 0th moment: count of distinct elements
● 1st moment: length of stream
● 2nd moment: sum of squares
(measures uneveness; related to variance)
Counting Moments
0th moment
Streaming Solution: Flajolet-Martin Algorithm
General idea:
n -- suspected total number of elements observed
pick a hash, h, to map each element to log2
n bits (buckets)
--------------------------------
Rs = list()
for h in hashes:
R = 0 #potential max number of zeros at tail
for each stream element, e:
r(e) = trailZeros(h(e)) #num of trailing 0s from h(e)
R = r(e) if r[e] > R
Rs.append(2R
)
groupRs = [Rs[i:i+log n] for i in range(0, len(Rs), log n)]
estimated_distinct_elements = median(map(mean, groupRs))
Problem:
Unstable in practice.
Solution: Multiple hash functions
1. Partition into groups of size log n
2. Take mean in groups
3. Take median of group means
43. Moments:
● Suppose mi
is the count of distinct element i in the data
● The kth moment of the stream is
● 0th moment: count of distinct elements
● 1st moment: length of stream
● 2nd moment: sum of squares
(measures uneveness; related to variance)
Counting Moments
0th moment
Streaming Solution: Flajolet-Martin Algorithm
General idea:
n -- suspected total number of elements observed
pick a hash, h, to map each element to log2
n bits (buckets)
--------------------------------
Rs = list()
for h in hashes:
R = 0 #potential max number of zeros at tail
for each stream element, e:
r(e) = trailZeros(h(e) #num of trailing 0s from h(e)
R = r(e) if r[e] > R
Rs.append(2R
)
groupRs = [Rs[i:i+log n] for i in range(0, len(Rs), log n)]
estimated_distinct_elements = median(map(mean, groupRs))
Problem:
Unstable in practice.
Solution: Multiple hash functions
1. Partition into groups of size log n
2. Take mean in groups
3. Take median of group means
A good approach anytime one
has many “low resolution”
estimates of a true value.
44. Moments:
● Suppose mi
is the count of distinct element i in the data
● The kth moment of the stream is
Examples
● 0th moment: count of distinct elements
● 1st moment: length of stream
● 2nd moment: sum of squares (measures uneveness related to variance)
2nd moment
Streaming Solution: Alon-Matias-Szegedy Algorithm
(Exercise; Out of Scope; see in MMDS)
Counting Moments
47. Counting Moments
For streaming, just need to store
(1) number of elements, (2) sum of
elements, and (3) sum of squares.
standard deviation
(square-root of variance for numeric data)
48. Counting Moments
For streaming, just need to store
(1) number of elements, (2) sum of
elements, and (3) sum of squares.
However, challenge:
Sum of squares can blow up!
standard deviation
(square-root of variance for numeric data)
49. Filtering: Select elements with property x
Example: 40B safe email addresses for spam detector
Filtering Data
50. Filtering: Select elements with property x
Example: 40B safe email addresses for spam filter
The Bloom Filter (approximates; allows false positives but not false negatives)
Given:
|S| keys to filter; will be mapped to |B| bits
hashes = h1,
h2
, …, hk
independent hash functions
Filtering Data
51. Filtering: Select elements with property x
Example: 40B safe email addresses for spam filter
The Bloom Filter (approximates; allows false positives but not false negatives)
Given:
|S| keys to filter; will be mapped to |B| bits
hashes = h1,
h2
, …, hk
independent hash functions
Algorithm:
set all B to 0 #B is a bit vector
for each i in hashes, for each s in S:
set B[hi
(s)] = 1 #all bits resulting from
Filtering Data
52. Filtering: Select elements with property x
Example: 40B safe email addresses for spam detector
The Bloom Filter (approximates; allows false positives but not false negatives)
Given:
|S| keys to filter; will be mapped to |B| bits
hashes = h1,
h2
, …, hk
independent hash functions
Algorithm:
set all B to 0 #B is a bit vector
for each i in hashes, for each s in S:
set B[hi
(s)] = 1 #all bits resulting from
… #usually embedded in other code
while key x arrives next in stream #filter:
if B[hi
(x)] == 1 for all i in hashes:
#do as if x is in S
else: #do as if x not in S
Filtering Data
53. Filtering: Select elements with property x
Example: 40B safe email addresses for spam filter
The Bloom Filter (approximates; allows false positives but not false negatives)
Given:
|S| keys to filter; will be mapped to |B| bits
hashes = h1,
h2
, …, hk
independent hash functions
Algorithm:
set all B to 0 #B is a bit vector
for each i in hashes, for each s in S:
set B[hi
(s)] = 1 #all bits resulting from
… #usually embedded in other code
while key x arrives next in stream #filter:
if B[hi
(x)] == 1 for all i in hashes:
#do as if x is in S
else: #do as if x not in S
Filtering Data
Setup filter
Apply Filter
54. Filtering Data
Filtering: Select elements with property x
Example: 40B safe email addresses for spam filter
The Bloom Filter (approximates; allows FPs)
Given:
|S| keys to filter; will be mapped to |B| bits
hashes = h1,
h2
, …, hk
independent hash functions
Algorithm:
set all B to 0
for each i in hashes, for each s in S:
set B[hi
(s)] = 1
… #usually embedded in other code
while key x arrives next in stream #filter:
if B[hi
(x)] == 1 for all i in hashes:
#do as if x is in S
else: #do as if x not in S
What is the probability of a false
positive (FP)?
Q: What fraction of |B| are 1s?
(Leskovec et al., 2014)
55. Filtering Data
Filtering: Select elements with property x
Example: 40B safe email addresses for spam filter
The Bloom Filter (approximates; allows FPs)
Given:
|S| keys to filter; will be mapped to |B| bits
hashes = h1,
h2
, …, hk
independent hash functions
Algorithm:
set all B to 0
for each i in hashes, for each s in S:
set B[hi
(s)] = 1
… #usually embedded in other code
while key x arrives next in stream #filter:
if B[hi
(x)] == 1 for all i in hashes:
#do as if x is in S
else: #do as if x not in S
What is the probability of a false
positive?
Q: What fraction of |B| are 1s?
A: Analogy:
Throw |S| * k darts at n targets.
1 dart: 1/n
d darts: (1 - 1/n)d
= prob of 0
= e-d/n
are 0s
(Leskovec et al., 2014)
56. Filtering Data
Filtering: Select elements with property x
Example: 40B safe email addresses for spam filter
The Bloom Filter (approximates; allows FPs)
Given:
|S| keys to filter; will be mapped to |B| bits
hashes = h1,
h2
, …, hk
independent hash functions
Algorithm:
set all B to 0
for each i in hashes, for each s in S:
set B[hi
(s)] = 1
… #usually embedded in other code
while key x arrives next in stream #filter:
if B[hi
(x)] == 1 for all i in hashes:
#do as if x is in S
else: #do as if x not in S
What is the probability of a false
positive?
Q: What fraction of |B| are 1s?
A: Analogy:
Throw |S| * k darts at n targets.
1 dart: 1/n
d darts: (1 - 1/n)d
= prob of 0
= e-d/n
are 0s
(Leskovec et al., 2014)
= e-1
for large n
57. Filtering Data
Filtering: Select elements with property x
Example: 40B safe email addresses for spam filter
The Bloom Filter (approximates; allows FPs)
Given:
|S| keys to filter; will be mapped to |B| bits
hashes = h1,
h2
, …, hk
independent hash functions
Algorithm:
set all B to 0
for each i in hashes, for each s in S:
set B[hi
(s)] = 1
… #usually embedded in other code
while key x arrives next in stream #filter:
if B[hi
(x)] == 1 for all i in hashes:
#do as if x is in S
else: #do as if x not in S
What is the probability of a false
positive?
Q: What fraction of |B| are 1s?
A: Analogy:
Throw |S| * k darts at n targets.
1 dart: 1/n
d darts: (1 - 1/n)d
= prob of 0
= e-d/n
are 0s
thus, (1 - e-d/n
) are 1s
probability all k being 1?
(Leskovec et al., 2014)
58. Filtering Data
Filtering: Select elements with property x
Example: 40B safe email addresses for spam filter
The Bloom Filter (approximates; allows FPs)
Given:
|S| keys to filter; will be mapped to |B| bits
hashes = h1,
h2
, …, hk
independent hash functions
Algorithm:
set all B to 0
for each i in hashes, for each s in S:
set B[hi
(s)] = 1
… #usually embedded in other code
while key x arrives next in stream #filter:
if B[hi
(x)] == 1 for all i in hashes:
#do as if x is in S
else: #do as if x not in S
What is the probability of a false
positive?
Q: What fraction of |B| are 1s?
A: Analogy:
Throw |S| * k darts at n targets.
1 dart: 1/n
d darts: (1 - 1/n)d
= prob of 0
= e-d/n
are 0s
thus, (1 - e-d/n
) are 1s
probability all k being 1?
(1 - e-(|S|*k)/n
)k
|S| size of set
k: number of hash functions
n: number of buckets
Note: Can expand S as stream
continues as long as |B| has room
(e.g. adding verified email addresses)
(Leskovec et al., 2014)
59. Side Note on Generating Hash Functions:
What hash functions to use?
Start with 2 decent hash functions
e.g. ha
(x) = ascii(string) % large_prime_number
hb
(x) = (3*ascii(string) + 16) % large_prime_number
Add together multiplying the second times i:
hi
(x) = ha
(x) + i*hb
(x) % |BUCKETS|
e.g. h5
(x) = ha
(x) + 5*hb
(x) % 100
https://www.eecs.harvard.edu/~michaelm/postscripts/rsa2008.pdf
Popular choices: md5 (fast, predistable); mmh3 (easy to seed; fast)
60. ● General Stream Processing Model
● Sampling
○ approx. random
○ hierarchical approx. random
● Counting Elements
○ distinct elements
○ mean, standard deviation
● Filtering data according to a criteria
○ bloom filter setup + application
○ calculating false positives
Streaming Topics