scala

Linear Regression with Adam Optimizer

Alexey Novakov published on

6 min, 1077 words

Adam is one more optimization algorithm used in neural networks. It is based on adaptive estimates of lower-order moments. It has more hyper-parameters than classic Gradient Descent to tune externally

Good default settings for the tested machine learning problems are:

  • α = 0.001, // learning rate. We have already seen this one in classic Gradient Descent.
  • β1 = 0.9,
  • β2 = 0.999
  • eps = 10−8.
Read More

Linear Regression with Gradient Descent

Alexey Novakov published on

5 min, 914 words

In this article we are going to use Scala mini-library for Deep Learning that we developed earlier in order to study basic linear regression task. We will learn model weights using perceptron model, which will be our single unit network layer that emits target value. This model will predict a target value yHat based on two trained parameters: weight and bias. Both are scalar numbers. Weights optimization is going to be based on implemented Gradient descent algorithm:

Model equation:

y = bias + weight * x
Read More

Algorithms: Largest Sum Contiguous Subarray

Alexey Novakov published on

2 min, 297 words

Most of the algorithmic tasks are related to iterating over arrays of data. They often can be expressed as a function which takes some input and returns some single value or an array of values. For instance:

def maxSum(a: Array[Int]): Array[Int] = ???
Read More

Categories: scala

SBT Plugins

Alexey Novakov published on

8 min, 1554 words

SBT is a Scala Build Tool. It is written in Scala and can compile, build artefacts for Scala and Java projects. SBT is also the first build tool in the Scala eco-system and the most used one among Scala developers. I am using SBT already for many years and found the following useful plugins which I use in most of my projects:

Read More

Categories: scala

Monads in Scala

Alexey Novakov published on

9 min, 1784 words

Once you start dig deeper into Scala and its suitability for functional programming, you meet Monads. In this blog post, we will explore Monads in Scala: their usage and usefulness.



Read More

Categories: scala

Tags: fp

Cats-Effect: Cancel Scala Process on Timeout

Alexey Novakov published on

3 min, 540 words



Sometimes Scala developer needs to call external program, which is running outside of the JVM. In this case, we use scala.sys.process package. Process package has bunch of functions to spin up new processes, consume their outputs and errors. Also, spawned process can be stopped. Usually, we run external programs for a short period of time to make some side-effect. Then, we analyse its exit code to apply some error handling logic in our main Scala program. It worth to say that process API is blocking execution thread, when we are waiting for its completion. To summarise, Scala developer wants to do the following:

Read More

Categories: scala

Scala FS2 - handle broken CSV lines

Alexey Novakov published on

4 min, 682 words

Recently, I ran into a familiar situation by doing data processing, where I needed to deal with a fragmented data stream. Having fragments, I had to detect manually where exactly new line/message starts and where current line/message ends in the stream. As turned out, one can aggregate intermediate state of the fragmented stream using scan function.

Let us dig down into how scan function is working.



Read More

Categories: scala