Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Scientific Computing with Scala
Scientific Computing with Scala

Scientific Computing with Scala: Learn to solve scientific computing problems using Scala and its numerical computing, data processing, concurrency, and plotting libraries

eBook
$35.98 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Scientific Computing with Scala

Chapter 2. Storing and Retrieving Data

In this chapter, we will discuss data storage and retrieval in Scala. These two things are important to know about, because in most contexts you will need to perform anything that could be considered scientific computing. You will very likely need to read in data in some format and to output the results in some format. For example, a lot of test data for pattern recognition algorithms is stored in CSV format. Another popular way of storing data is in SQL databases. For use in any kind of numerical or symbolic calculations, this data will have to be retrieved. To retrieve it, you must have a way of writing SQL queries to be performed on the said database. Another popular way to store data, especially if the data is large in volume, is HDF5 format files. They are commonly used to store the results of experiments producing large amounts of data that need to be stored in a structured way. Whenever possible, we will try to present the best possible...

Reading and writing CSV files

We will examine reading and writing CSV files here. CSV stands for Comma Separated Values. These files are just records arranged in rows with a row consisting of multiple values separated by commas (and sometimes other separator symbols, such as spaces or tabs). Instead of relying on ready-made libraries to do this, we will write our own small, extensible class for reading and writing data in CSV format.

The reason for this is that the file format is so simple it requires little more effort than reading a text file line by line. Therefore, the resulting code is simple, short, and will save you an extra dependency. Also, there does not seem to be a de facto standard for CSV access in Scala. It will serve us as an introduction to file access in Scala, which may come in handy if you need to read other weird file formats. Here is an example of a CSV file containing a part of the famous IRIS dataset. It is very commonly used to sanity test pattern recognition and...

Reading and writing JSON files

JavaScript Object Notation (JSON) files are a common way of serializing data. It was proposed by Douglas Crockford and is described in the RFC 7159 standard. In particular, they are good at storing complex data structures such as dictionaries. Many languages have strong libraries for JSON support. It is very common to store your program data in JSON files. It is a good format in which to save files and the like. It is also commonly used for storing input data for various simulation programs. It is far more human-readable and -writable than XML and has largely replaced it in some uses. For example, it has largely replaced XML in asynchronous browser/server communication. We will look into several libraries that you can use to access JSON files in Scala.

Here's a small tip for using some third-party libraries. If you download them from GitHub or some other source code repository and the project uses SBT, then the easiest way to use them in your software...

Reading and writing XML files

XML or Extensible Markup Language is a popular markup language. It was designed to be both human- and machine-readable, but with an apparent emphasis on the later. XML is very widely supported and commonly used for file formats of various programs. For example, the popular Open Document Format is XML-based. The popularity of XML is mostly due to its historical use and support. It is often replaced by lighter languages such as JSON because of XML's relative verbosity and complexity. We will assume that the reader has a basic working knowledge of XML. However, to recap the basics, XML consists of tags and text. Tags are the start and end varieties. Start tags look like this: <tag>, while end tags look like this: </tag>. Usually a value in XML is encoded as such: <name>Bob</name>, with a property name as the tag name and its value being the text between the tags. The data between two XML tags can be any valid XML. We will see a more...

Database access using JDBC

In relational databases, data is organized in to tables with multiple columns and rows where each row gets a unique key. Columns usually represent properties while rows represent different objects or data records. Relational databases were proposed by E. F. Codd in the 1970's. They are a popular way of storing all kinds of data. Usually, relation database systems provide fast and convenient access to data using various queries. These queries describe various conditions that have to be satisfied by the data being retrieved. This allows one to select and combine database rows to retrieve information. Virtually all relational database systems use SQL to query and maintain the database. You can use SQL statements to insert data into database, create new tables, drop tables, query data, and perform other tasks. JDBC is Java's standard for connecting to databases and executing SQL statements. One straightforward way of accessing relational databases from Scala...

Database access using Slick

Slick or Scala Language-Integrated Connection Kit (apparently) is a Functional Relational Mapping (FRM) library for Scala that makes it possible to work with relational databases using abstractions natural to the Scala language. The library is developed by Typesafe, which is the company founded by Scala's creator Martin Odersky. Working with the library makes working with databases similar to working with Scala's Collections API. The library can be found at the following website:

http://slick.typesafe.com/

To install the library with sbt, you should add the following to the build.sbt file library dependencies:

libraryDependencies ++= Seq(
  "com.typesafe.slick" %% "slick" % "3.0.3",
  "org.slf4j" % "slf4j-nop" % "1.6.4"
)

Plain SQL

Slick supports Plain SQL queries. This basically means that you can write your queries in straight SQL without having to bother with JDBC access. To use them, you...

Reading and writing CSV files


We will examine reading and writing CSV files here. CSV stands for Comma Separated Values. These files are just records arranged in rows with a row consisting of multiple values separated by commas (and sometimes other separator symbols, such as spaces or tabs). Instead of relying on ready-made libraries to do this, we will write our own small, extensible class for reading and writing data in CSV format.

The reason for this is that the file format is so simple it requires little more effort than reading a text file line by line. Therefore, the resulting code is simple, short, and will save you an extra dependency. Also, there does not seem to be a de facto standard for CSV access in Scala. It will serve us as an introduction to file access in Scala, which may come in handy if you need to read other weird file formats. Here is an example of a CSV file containing a part of the famous IRIS dataset. It is very commonly used to sanity test pattern recognition and...

Reading and writing JSON files


JavaScript Object Notation (JSON) files are a common way of serializing data. It was proposed by Douglas Crockford and is described in the RFC 7159 standard. In particular, they are good at storing complex data structures such as dictionaries. Many languages have strong libraries for JSON support. It is very common to store your program data in JSON files. It is a good format in which to save files and the like. It is also commonly used for storing input data for various simulation programs. It is far more human-readable and -writable than XML and has largely replaced it in some uses. For example, it has largely replaced XML in asynchronous browser/server communication. We will look into several libraries that you can use to access JSON files in Scala.

Here's a small tip for using some third-party libraries. If you download them from GitHub or some other source code repository and the project uses SBT, then the easiest way to use them in your software is to...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Parallelize your numerical computing code using convenient and safe techniques.
  • Accomplish common high-performance, scientific computing goals in Scala.
  • Learn about data visualization and how to create high-quality scientific plots in Scala

Description

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

Who is this book for?

Scientists and engineers who would like to use Scala for their scientific and numerical computing needs. A basic familiarity with undergraduate level mathematics and statistics is expected but not strictly required. A basic knowledge of Scala is required as well as the ability to write simple Scala programs. However, 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.

What you will learn

  • Write and read a variety of popular file formats used to store scientific data
  • Use Breeze for linear algebra, optimization, and digital signal processing
  • Gain insight into Saddle for data analysis
  • Use ScalaLab for interactive computing
  • Quickly and conveniently write safe parallel applications using Scala s parallel collections
  • Implement and deploy concurrent programs using the Akka framework
  • Use the Wisp plotting library to produce scientific plots
  • Visualize multivariate data using various visualization techniques
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 27, 2016
Length: 232 pages
Edition : 1st
Language : English
ISBN-13 : 9781785886942
Category :
Languages :

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : Apr 27, 2016
Length: 232 pages
Edition : 1st
Language : English
ISBN-13 : 9781785886942
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 165.97
Scala for Data Science
$61.99
Scientific Computing with Scala
$48.99
Mastering Scala Machine Learning
$54.99
Total $ 165.97 Stars icon

Table of Contents

10 Chapters
1. Introducing Scientific Computing with Scala Chevron down icon Chevron up icon
2. Storing and Retrieving Data Chevron down icon Chevron up icon
3. Numerical Computing with Breeze Chevron down icon Chevron up icon
4. Using Saddle for Data Analysis Chevron down icon Chevron up icon
5. Interactive Computing with ScalaLab Chevron down icon Chevron up icon
6. Parallel Programming in Scala Chevron down icon Chevron up icon
7. Cluster Computing Using Scala Chevron down icon Chevron up icon
8. Scientific Plotting with Scala Chevron down icon Chevron up icon
9. Visualizing Multi-Dimensional Data in Scala Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(1 Ratings)
5 star 0%
4 star 100%
3 star 0%
2 star 0%
1 star 0%
Stergios Papadimitriou Jun 01, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Scala is a powerful language with a great potential for scientific computing.The book explains well how to exploit better and faster Scala forscientific computing, by describing basic Scala scientific libraries as e.g. Breeze, Saddle etcand the integrated MATLAB like environment that ScalaLab presents.In my opinion, is a useful book, and it worths its price.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela