## Plotting functions with LaTeX & Tikz

I’ve been working on some notes for my students on Neural Networks. I am using Pandoc to write the text, and convert it back to LaTeX for PDF generation, and to HTML, for making the documents available online. In a future post I might talk about Pandoc, but for now, I want to share something I found on TeX Stack Exchange to plot functions. To make it clear how to use, I am presenting four simple examples: four common activation functions used in Neural Networks.

To start with, the well known sigmoid function: $a = \frac{1}{1+e^{-z}}$:

This can be achieved with the following tikzpicture environment:

\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xmax=10,
xmin=-10,
ymin=-0.05,
ymax=1.05,
xlabel={$x$},
ylabel={$y$}
]
thick, blue] {1/(1+exp(-x)};
\end{axis}
\end{tikzpicture}

Now, for the tanh, defined as $a=\frac{e^z – e^{-z}}{e^z + e^{-z}}$, you get:

With the following code:

\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xmax=10,
xmin=-10,
ymin=-1.05,
ymax=1.05,
xlabel={$x$},
ylabel={$y$}]
thick, blue] {(exp(x) - exp(-x))/(exp(x) + exp(-x))};
\end{axis}
\end{tikzpicture}

I was already loving it, but it was awesome when I tested the ReLU math, and it worked as expected: $a=\max(0, z)$

This one can be obtained using the simple…

\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xmax=6,
xmin=-6,
ymin=-0.05,
ymax=5.05,
xlabel={$x$},
ylabel={$y$}]
\addplot [domain=-5.5:5.5, samples=100, thick, blue] {max(0, x)};
\end{axis}
\end{tikzpicture}


And now, although not being extremely interesting, the Leaky ReLU (well, not implemented exactly as the definition, just to get it a little more easy to read): $a=max(0.001 \times z, z)$

With the cheating…

\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xmax=6,
xmin=-6,
ymin=-1.05,
ymax=5.05,
xlabel={$x$},
ylabel={$y$}]
thick, blue] {max(0.1 * x, x)};
\end{axis}
\end{tikzpicture}


And to conclude, and just for reference, do not forget to load the required packages:

\usepackage{tikz}
\usepackage{pgfplots}

## Arango::Tango Perl 5 Module

(cross posted from blogs.perl.org)

I am planning on a new project, and a friend suggested me to look to Arango, as an alternative do Mongo, specially because it includes a graphs query language integrated. As I am not really used to Mongo at all, decided to give it a try.

Unfortunately I did not find a proper module to use Arango from Perl. Therefore I decided to start one from scratch. Probably not a great idea as my free time is likely non-existent. But nevertheless, I did it. Arango::DB was born!

I am trying to abstract major entities (database, collection, document, cursor) in order to use them directly as proper objects in Perl, and at the same time, try to keep a low code profile, delegating most options directly to Arango REST interface. In order not to be too relaxed, I am using JSON::Schema::Fit to validate the parameters sent to Arango API.

The main problem is that there are too many options and endpoints to use, and too few time to do it. Anyway, there is a working version, that already allows the storage of documents, and querying them using AQL. Unfortunately all the user-related functionalities are not yet implemented.

While I would love to keep maintaining and defining the direction of the module, I am very grateful to any patches, bug fixes of added functionalities, keeping the same simple approach in mind.

Regarding using a module for objects, I might decide to use Moo, but for now, I am still happy using Perl blessed hashes directly.

Hope to post more news very soon.

GIT repository: https://gitlab.com/ambs/perl5-arango-tango/
Latest release: https://metacpan.org/pod/Arango::Tango

## Mobile Phones for Elder People

I am not sure about other countries, but in Portugal there are some mobile phones (usually not smartphones) which are catalogued as for elder people. As you can see above, they have big buttons, with large numbers. But things stop there. If you try to use any of them, you will notice that the text shown in the screen is quite small (not talking about the current time, as shown in the images). For example, it is quite hard for someone with impaired vision to read a message. One can argue that elder people will not use SMS. But if that is the understanding of the phone makers, just remove that functionality from the phone. In the other hand, if you think elder people will read and/or send messages, then, allow him to configure the font size.

Please, the first that does that, send me a message and I will buy one for my mother.

## Linux, 2017!

First of all, please do not read this post as a complain. Just as an analysis. I am a Linux user for decades. I remember using Linux in my first year of University, somewhere about 1996. I never stopped using Linux, in the server, but during some years, somewhere between 2002 and 2017 I was a Mac user for the desktop (one PPC Mac Book, two Intel Mac Book Pro). Back to the beginning of 2017 I needed an update, and decided to go back to Linux. Mostly because of the price of a decent Mac Book Pro when compared with a generic laptop. I decided on a Dell, and without a lot of thinking, decided on a Dell with a 4K display. Well, I had a hard time trying to install a distribution. Tried Mint, Debian and Ubuntu. Curiously, all gave trouble with UEFI boot, but the one that ended up installing a working Linux was Mint Given it is Debian based, I can keep up with the Debian updates, and install most packages available only for Ubuntu.

While I see some applications getting better, from 2002 to 2017, it seems Linux community continues rewriting the wheel. I can’t see any big difference from what I am experiencing today in the desktop with what I was experiencing earlier with Gnome 1. Yes, the code was changed. It might be more stable, faster, support a couple of new things. But it seems we continue rewriting and rewriting the same old applications.

Then there is the issue with a 4K display. Even if GTK3 has support for High DPI screens, a lot of  applications are not written for this toolkit. And I am not sure, at all, that this is something that need to be managed by the graphical toolkit. I still think it is a Xorg issue, where we should be able to define DPIs for each screen, and have the basic low-level tools scale everything. As this is how I see things, I decided today to look to the blog of Xorg. And it doesn’t have news since 2013. As I could read, now most work is done as independent libraries. Nevertheless, it is strange no changes were needed to be done in 4 years.

Also curious that a bunch of applications using node.js are being working great. Examples are GitKraken, Code, Atom, Franz… and even Sublime is working great on 4K (even if it has some other issues). Unfortunately Unity3d is not working properly in 4K, but that looks more like an issue with their own GUI system, than anything else (but then, if Xorg took care of things, maybe it would work great, just like it works acceptably under Windows). But other things, like old Gtk, Xlib, QT or even Java applications still look like needing a microscope to be read.

So, here I am, with a shiny new laptop, deciding to keep Linux, or getting back to.. huh.. windows! Yeah, I do dual boot, but I like Linux for most things. But some aren’t possible As a teacher, I know I will have problems when trying to use a beamer. When connecting an external display, everything will look monstrous. Or I can change the resolution on the built-in screen, go searching the HiDPI switch, turn it of, restart the session for it to be correctly applied, and then use the laptop. Shame.

And yes, I know a lot of this is my fault. If I did not change to Mac, and if like me other hundred of developers didn’t do the same, probably we would have a lot more Linux users, writing and patching these applications. Or we would just end up with a lot of more distributions, a lot more window manager, but with the same main issues.

At last, but not less important, I would like to thank you to everyone that is still working on Linux making it better. I know this is not a paid job. I know you (and I) do what we want, and what makes us happy. That is why this is not a complain text. Just looking to what I see, without pointing any fingers.

## MonoGame: From Windows to Linux

The traditional way to have a C# MonoGame Project compile both under Linux and Windows is to use a tool named Protobuild. With the last version (3.6), the MonoGame OpenGL template for a cross platform game includes references to the libraries in the three main formats: DLL for windows, DyLib for mac, and so for Linux. This seemed like a good chance for making things work.

And it mostly did. Change to the path where the .csproj file resides, and run xbuild. The bin folder should be created, and inside there, a path accordingly with your project configuration. For example, bin/DesktopGL/AnyCPU/Debug. Then, go there, and just run your game with
mono Project.exe.

(future work: check how to make things work outside the output dir)

## Euclidea – Geometric Construction Game

Euclidea is a very interesting game. Something new, a different game, educational, fun, difficult, challenging. A great game. If you like geometry, if you loved how to build geometric constructions on paper, but always made them blur, you will love this game.

## Getting back to Linux: Part #1

After the last Apple keynote, the news on Mac Book Pro, and the exorbitant price, I took part of this Sunday to look back to Linux as a Desktop. Although I work usually on a 2011 Mac, that runs perfectly (just some bumps), I have a Lenovo laptop. So, I decided to install the Linux distribution I have been using lately for my servers: debian.

First I downloaded the netinstall image. It complained of missing drivers for wi-fi and ethernet. Then, I downloaded the non-free netinstall image. Same behavior.

Well, decided to keep it, and use a USB stick to install the missing packages. After going from/to my mac to download missing packages and dependencies, I got something. The card is detected, the correct (at least it seems) module is loaded, ifconfig shows the device, but ifup fails to bring it up.

After googling and fighting with wpa (first I was thinking this was the problem), I found out that Linux was just deciding that it couldn’t load the interface, and mentioned something about rfkill, that I am not sure what it is.

Googled a little more and found articles saying that my Lenovo has some other wireless card than the one listed by lspci. Strange.

In any case, the day is almost over, and I need to get back to my job. My conclusion so far is a quote from an old teacher, now a friend: Linux is still a Cowboys operating system.

Not sure about all Linux distributions, but debian for sure.

Usually I do not play much on my Android phone. But when waiting for someone or something, to have a good puzzle is worth it.

Slitherlink, as you can look up in the Internet, is not an idea of this app author. It is a known puzzle, and if you look up in Google Play, you will notice a few implementations.

I can’t say that this one is the best, as I did not test any other. But it installed correctly, runs smoothly, and seems to have some good diversity of modes and difficulty levels. Therefore, I am quite happy with it, happy enough to consider buying the ad-free version, with extra levels. Truth be said, the free version includes a good mount of levels, and ads are not intrusive. So, kudos for that.

About the game, it is up to you to read about it and test it. It can be seen as some sort of minesweeper, with some reasoning mechanisms also used in sudoku.

## eXist-db: Installing XQuery functx module

Using the blog as a notepad, I will start posting here some notes on things I discover and are not very clear in the documentation (or I just did not find it at first).

In the last times I have been hacking in eXist-db, and writing XQuery. I noticed a website with a lot of interesting functions with the functx prefix. The eXist-db website help reference returns hits for this module. But it is not installed by default (or at least, it can happen on not being installed by default).

To install it, just run this XQuery command:

repo:install-and-deploy("http://www.functx.com", "1.0", "http://exist-db.org/exist/apps/public-repo/public/functx-1.0.xar")

After installation the functx module can be loaded with
import module namespace functx = "http://www.functx.com" at "/db/system/repo/functx-1.0/functx/functx.xql";

Also, for reference, I found the list of eXist packages here.

## IGI Global: the clown of scientific publishing?

I am not sure how I agreed to write a chapter for a book to be published in IGI Global. Probably, being edited by a friend that invited me personally to send a proposal made the difference.

I have my contribution ready, but starting to think on just forgetting it. Why? Because IGI Global is, surely, kidding with me. They have a set of rules for their contributions, and somewhere in the middle, they say, and I quote:

LaTex. LaTex files are NOT accepted because they are not compatible with IGI Global’s typesetting program. As an alternative, we require that you use MathType (see “Equations” below).

First, dear IGI, when not possible to use the fancy form of LaTeX, the latest X should be in uppercase. Second, if hey are not compatible with your typesetting program, that is probably because you are using the wrong typesetting program. And, no, LaTeX is not useful only for math. Please learn what LaTeX is, try to use it, then evaluate how it can be useful or not for your editorial requirements.

Third (or fourth, I think I will stop counting), look to other publishing houses. Who are your adversaries? Springer, probably. Do you know they use LaTeX? Yeah, they do! And they create good quality document. Of course they do, they use LaTeX. And no, I have an IGI book, and no, your books does not have typesetting quality. I am sorry.

Finally, because I have some hours to lose formatting the chapter, if you want us to use Microsoft Word, please create a template in Word. Do you know what that is? You know how it can be useful? Do you? I am sure you don’t.