17 Jun 2023
A couple of days ago, I came across a toot from Khalid Abuhakmeh,
showcasing a C# + MVVM implementation of the Game of Life on Avalonia. I
have been experimenting with Avalonia funcUI recently, and thought a conversion
would be both a fun week-end exercise, and an interesting way to take a look at
performance.
Long story short, I took a look at his repository as a starting point, and
proceeded to rewrite it in an Elmish style, shamelessly lifting the core from
his code. The good news is, it did not take a lot of time to get it running,
the less good news is, my version has clear performance issues.
In this post, I will go over how I approached it so far, and where I think
the performance issues might be coming from. In a later post, I’ll try to see
if I can fix these. As the French saying goes, “A chaque jour suffit sa peine”.
You can find the full code here on GitHub
More...
29 May 2023
In the recent weeks, I came across a use case which sounded like a good fit for
a desktop application, which got me curious about the state of affairs for .NET
desktop clients these days. And, as I was looking into this, I quickly came
across Avalonia, and specifically Avalonia.FuncUI. Cross platform
XAML apps, using F# and the Elmish loop? My curiosity was piqued, and I figured
it was worth giving it a try.
In this post, I will go over my first steps trying the library out. My
ambitions are limited: first, how hard is it to get something running? Then,
how hard is it to take an existing Avalonia library (in this case, the
charting library OxyPlot), and bolt it into an Elmish style Avalonia app?
You can find the full code here on GitHub
More...
15 Apr 2023
Some time back, I wrote a small post digging into the
mechanics behind the Nelder Mead solver. As it turns out, I had a use for
it recently, and after copy-pasting my own code a few times, I figured it would
make my life easier to turn that into a NuGet package, Quipu.
So what does it do, and why might you care?
A code example might be the quickest explanation here. Suppose that, for
whatever reason, you were interested in the function f(x) = x ^ 2
, and wanted
to know for what value of x
this function reaches its minimum.
That is easy to solve with the Quipu Nelder-Mead solver:
open Quipu
open Quipu.NelderMead
let f x = x ** 2.0
let solution =
NelderMead.solve
Configuration.defaultValue
(Objective.from f) [ 100.0 ]
printfn $"{solution}"
… which produces the following result:
Optimal (0.0001556843433, [|0.01247735322|])
The function f
reaches a minimum of 0.0001
, for x = 0.0124
.
More...
08 Jan 2023
This post is intended primarily as a note to myself, keeping track as my findings
as I dig into automatic differentiation with DiffSharp. Warning: as a result,
I won’t make a particular effort at pedagogy – hopefully you’ll still find something
of interest in here!
The main question I am interested in here is, how can I use DiffSharp to find the
minimum of a function? I will take a look first at basic gradient descent, to get us
warmed up. In a future installment I plan to explore using the built-in SGD and Adam
optimizers for that same task.
The full code is here on GitHub, available as a .NET interactive notebook.
Test function
The function we will be using in our exploration is the following:
$f(x,y)=0.26 \times (x^2+y^2) - 0.48 \times (x \times y)$
This function, which I lifted this function from this blog post,
translates into this F# code:
let f (x: float, y: float) =
0.26 * (pown x 2 + pown y 2) - 0.48 * x * y
Graphically, this is how the function looks like:
This function has a global minimum for (x = 0.0, y = 0.0)
, and is
unimodal, that is, it has a single peak (or valley in this case). This
makes it a good test candidate for function minimization using gradient
descent.
More...
04 Dec 2022
It is that time of the year again! The holidays are approaching, and the F# Advent
calendar is in full swing. My contribution this year might not be for the broadest
audience, sorry about that :) But if you are into F#, probability theory, and numeric
optimization, this post is for you - hope you enjoy it! And big shout out to
Sergey Tihon for making this happen once again.
You can find the full code for this post here on GitHub.
With the Holidays approaching, Santa Claus, CEO of the Santa Corp, was worried. In preparation
for the season’s spike in activity, Santa had invested in the top-of-the-line gift wrapping
machine for the Elves factory, the Wrapinator 5000. This beast of a machine has two
separate feeders, one delivering Paper, the other Ribbon, allowing the elves to wrap gifts
at a cadence never achieved before.
So why worry? Mister Claus, being no fool, had also invested in monitoring, and the logs for the
Wrapinator 5000 showed quite a few failures. Would the gift wrapping production lines hold up
during the Merry Season?
Mister Claus fiddled anxiously with his luscious beard, alone in his office. And then,
being a Man of Science, he did what any self-respecting CEO would do, and decided it was time
to build a simulation model of his Wrapinator 5000. With a simulation model in hand, he
could analyze his Elves factory, evaluate potential alternative operating policies, and
most importantly, get that peace of mind he so desperately longed for.
More...