Book Image

Clojure Data Analysis Cookbook

By : Eric Rochester
Book Image

Clojure Data Analysis Cookbook

By: Eric Rochester

Overview of this book

<p>Data is everywhere and it's increasingly important to be able to gain insights that we can act on. Using Clojure for data analysis and collection, this book will show you how to gain fresh insights and perspectives from your data with an essential collection of practical, structured recipes.<br /><br />"The Clojure Data Analysis Cookbook" presents recipes for every stage of the data analysis process. Whether scraping data off a web page, performing data mining, or creating graphs for the web, this book has something for the task at hand.<br /><br />You'll learn how to acquire data, clean it up, and transform it into useful graphs which can then be analyzed and published to the Internet. Coverage includes advanced topics like processing data concurrently, applying powerful statistical techniques like Bayesian modelling, and even data mining algorithms such as K-means clustering, neural networks, and association rules.</p>
Table of Contents (18 chapters)
Clojure Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Managing program complexity with agents


Agents build on the STM, and each agent acts a lot like a reference. You use agents by sending the agent messages—functions that manipulate the agent's state—and those are run in the thread pool.

We create agents with the agent function, and we send messages to them with send and send-off. Whatever the function returns is the agent's new state value.

For this recipe, we'll again solve the same problem we did in the last recipe, Managing program complexity with STM.

Getting ready

We will include the same references in the project.clj file and the same requirements in the REPL as we did in the Managing program complexity with STM recipe. We will also use the same input file, bound to the name data-file again.

And we'll also use several utility functions from the last recipe: lazy-read-csv, with-header, ->int, sum-item, and sum-items.

How to do it…

To use agents, we just need to add a few functions to the ones from the last recipe.

  1. The first one is called...