Book Image

Scientific Computing with Scala

By : Vytautas Jancauskas
Book Image

Scientific Computing with Scala

By: Vytautas Jancauskas

Overview of this book

Scala is a statically typed, Java Virtual Machine (JVM)-based language with strong support for functional programming. There exist libraries for Scala that cover a range of common scientific computing tasks – from linear algebra and numerical algorithms to convenient and safe parallelization to powerful plotting facilities. Learning to use these to perform common scientific tasks will allow you to write programs that are both fast and easy to write and maintain. We will start by discussing the advantages of using Scala over other scientific computing platforms. You will discover Scala packages that provide the functionality you have come to expect when writing scientific software. We will explore using Scala's Breeze library for linear algebra, optimization, and signal processing. We will then proceed to the Saddle library for data analysis. If you have experience in R or with Python's popular pandas library you will learn how to translate those skills to Saddle. If you are new to data analysis, you will learn basic concepts of Saddle as well. Well will explore the numerical computing environment called ScalaLab. It comes bundled with a lot of scientific software readily available. We will use it for interactive computing, data analysis, and visualization. In the following chapters, we will explore using Scala's powerful parallel collections for safe and convenient parallel programming. Topics such as the Akka concurrency framework will be covered. Finally, you will learn about multivariate data visualization and how to produce professional-looking plots in Scala easily. After reading the book, you should have more than enough information on how to start using Scala as your scientific computing platform
Table of Contents (16 chapters)
Scientific Computing with Scala
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

In this book, we will look into using Scala as a scientific computing platform. It is intended for people who already have experience with scientific computing and Scala. We will see how to do things that are possible in other numerical/scientific computing platforms in Scala. We will cover numerical computation, data storage and retrieval, structured data analysis, interactive computing, visualization, and other important topics.

What this book covers

Chapter 1, Introducing Scientific Computing with Scala, looks into the feasibility of using Scala for scientific computing. An overview of the state-of-the-art libraries and tools in Scala scientific computing is given here.

Chapter 2, Storing and Retrieving Data, provides various options for storing and retrieving data in Scala. Popular data storage and retrieval formats that you may encounter in scientific computing are explored.

Chapter 3, Numerical Computing with Breeze, is about using the Breeze library for numerical computing.

Chapter 4, Using Saddle for Data Analysis, explores the functionality of the Saddle library for structured data analysis and manipulation.

Chapter 5, Interactive Computing with ScalaLab, explores the possibilities offered by the ScalaLab environment for interactive computing.

Chapter 6, Parallel Programming in Scala, is about parallel programming in Scala. Various techniques, including JVM threads, parallel collections, and actor-based concurrency with Akka, are covered.

Chapter 7, Cluster Computing Using Scala, teaches how to use Scala programs in distributed computing environments and shows how to use MPI from Scala, and more.

Chapter 8, Scientific Plotting with Scala, gives various options for carrying out plots in Scala.

Chapter 9, Visualizing Multi-Dimensional Data in Scala, elaborates on advanced plotting and visualization.

What you need for this book

You will need Scala and SBT installed on your system. Technically, you only need SBT, since SBT will install the required version of Scala for you. You can get Scala and SBT from the following websites:

It is advisable that you use a UNIX-like operating system for this book. However, this is not strictly necessary for most chapters. You will also need a Scala IDE or a text editor. Setting up Emacs to work with Scala and SBT is covered in the book. Alternatively, you can use any editor you are comfortable with.

Who this book is for

This book is for scientists and engineers who would like to use Scala for their scientific and numerical computing needs. Basic familiarity with undergraduate-level mathematics and statistics is expected but not strictly required. Basic knowledge of Scala is required as well as the ability to write simple Scala programs. Complicated programming concepts are not used in the book. Anyone who wants to explore using Scala for writing scientific or engineering software will benefit from the book.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "For now, simply create a new folder called csvreader and a file in it called CSVReader.scala."

A block of code is set as follows:

object CSVReader {
    def main(args: Array[String]) {
        for (line <- Source.fromFile("iris.csv").getLines()) {
            println(line)
        }
    }
}

Any command-line input or output is written as follows:

scala> xs dot ws
res2: Double = 27.5

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "You can access it via the Plot menu option."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/ScientificComputingwithScala_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.