# Am I worth nothing? Math says YES!

I am a scientist! And as a scientist, I always try to study things, understand them and invent something new, something that changes the world, makes it a bit better or makes something easier. Or maybe just discover some knowledge that leads other researches to invent something useful. We seek to understand the world we live in, and we want to contribute something.

Albert Einstein and friends of the past did tremendously valuable stuff that changed the whole direction of technical evolution in the last decades. And before, there have been other smart guys, inventing something game changing like how to make fire, or that a wheel is turning more easily than a square.

This fact lead me think of what my work is worth for humanity? But then I thought, humanity only exists since a very short time related to the age of the earth? To be more precise, earth exists since about 4.54 Billion (109) years whereas humans exist since roughly only 200.000 years. This picture illustrates the relation a bit more colourful.

It shows the age of our earth in blue and the time portion in which we exist in black. So even if I gonna invent something that is really cool, in the history of earth, it just disappears.

But wait, for how long does our planet exist? And isn’t it just one little tiny planet in the universe? The age of the universe is being estimated by calculating the time elapsed since the big bang, as this is the best we can guess. Which is 13.7 Billion years, nearly 3 times as old as our earth. And the universe has some more planets than the earth. So if I start asking myself what I am worth, I cannot ask what I am worth for the world, I better should ask, what is my value for general existence?

Ok, lets start some calculations. Image I would invent the most brilliant stuff that humans have ever seen, this is just affecting mankind and thus only

of all time since now, which is a dimension of 10-5. This is not too bad, I can still believe, that earth and humans will exists for a few more billion years where they can profit from my discovery. But whatever happens, finally in 7.5 Billion years, sun will absorb earth.

But what happens if earth dies? What is the influence on existence at all. Scary, but the answer is: Absolutely nothing. There are about 1024 planets in the universe, so who cares if one of them dies? You do not want to believe that? On earth, there live about 1016 ants, this is not even one millionth of the estimated number of planets, and do you care when an ant dies?

This reduces my influence dramatically, namely by 1024, together with the time influence, we have an impact in the dimension of 10-29, which is very less:

Just to get a better feeling of this number, if one would print the letter ‘A’ 1029 times next to each other in Times New Roman at font size 12, it would be about 1015 times the way to the sun and back. Light would take about 100,000 years to travel the document of A letters. Assuming further, that it takes one byte to store a character, the text file of As would be so big, that the whole storage available on the world would by far not be able to save this file, there is not even a name for this dimension, it ends with Yottabyte which is 1024.

Well, the result of asking myself what my influence to the overall existence is, is not very motivating, isn’t it? What do you think?

To all you theoretical physicist and computer storage experts out there: Please feel free to correct my numbers and calculations!

Some references:

# How to analyze a Neo4j graph via Blueprints interface using JUNG in Scala

This is a summary of the 3 part blog series I wrote for the www.clueda.com blog in the last month. Please find the original blog posts here:

Graph databases attending more and more interest as they bring significant advantages for specific problems. Mostly, graph databases are used as storage for interactions like one can see for example in social networks. The biggest advantage of graph databases is presumably the easy query for friends and relations between nodes. Here at Clueda, we use graph databases to store our knowledge graph extracted from medical and financial news. Hence, our requirements for graph databases are a bit different, besides using the graph as storage, we also want to run extensive graph analysis algorithms on it in order to get best insights into the data. In this tutorial, we will learn how to apply the Java Universal Network/Graph (JUNG) Framework on an embedded Neo4j database. As we want to keep the database interface flexible, we will use the Blueprints interface to communicate with the graph database. Clueda loves Scala, but the examples showed can easily be transferred to plain Java.

# Preliminaries

This tutorial concentrates on Blueprints, Neo4j and JUNG, especially on how to integrate them. Thus we assume you are familiar with Scala and SBT. If not, there are many good introductions to these topics, for example here:

http://www.scalatutorial.de/

http://www.scala-sbt.org/release/tutorial/Setup.html

In the tutorial, we will use IntelliJ IDEA as IDE on a Ubuntu machine. Please make sure that you have a Java SDK installed, as well as Scala and SBT running on your system.

If you prefer developing with Eclipse, examples should be easy to adopt. You might want to skip the first chapter of this tutorial, which explains how to create a new Scala SBT project in IntelliJ IDEA 13.

The tutorial is split into 3 parts:

Part 1: Create a Scala SBT project
Part 2: Install Neo4j
Part 3: Install Blueprints Neo4j and use JUNG

# 1. Create a Scala SBT project

To get started, we first create a new Scala SBT project in IntelliJ IDEA. On the welcome screen, select “Create New Project

Select project type “Scala” on the left side and “SBT” on the right side to create a project backed by SBT:

Give the project a meaningful name, I will call it Neo4JBlueprintJung and select the Java Project SDK that is installed on your machine.
Create the project by clicking the “Finish” button:

IntelliJ IDEA will open a new project for you. It can take a few seconds until the project is initialized completely and the “src” folder shows up. Right click on the “src/main/scala” folder and select “New” -> “Package” to create a new package:

I am calling my package com.clueda”. Next, lets create a new Scala file and simply name it “Main”:

Please note to choose kind  to be “Object” in order to get an executable Scala object:

Time to execute our class for the first time in order to see that everything works as expected. Before we can run the class, we need to update it like this:

object Main extends App{
println("Hello Clueda!")
}


Right click somewhere at the file and choose “Run Main”

The run dialog pops up at the bottom of IntelliJ IDEA and should print “Hello Clueda!

## Next

In the next part of this tutorial, we will install and configure Neo4j, before we set up the Blueprints interface and analyze the graph in Part 3.

# 2. Install Neo4j

In order to install Neo4j, we first need to download it from the Neo4j website:

Neo4j comes in a free community edition as well as a paid enterprise edition. For this tutorial, we will go with the free edition.

At this point, we need to pay attention! As we want the Neo4j database be used from Scala via the Blueprints interface, we cannot just install the latest version. We need to check which is the latest version supported by the Neo4j Blueprints implementation. To do so, we check the maven repository for the latest release:

http://search.maven.org/#artifactdetails|com.tinkerpop.Blueprints|Blueprints-neo4j2-graph|2.5.0|jar

Please note that the correct repository for Neo4j versions higher than 2 is called neo4j2 instead of neo4j!

From the maven dependencies we see that the latest version supported for Neo4j is 2.0.1

Neo4j comes in a compressed archive. For installation, all you need to do is extracting the archive. As we will use Neo4j embedded in the Scala project, I will extract the files inside the project structure of our Neo4jBlueprintJung project.

Since IntelliJ IDEA 13, there is an integrated Terminal which can be very useful. You will find it at the bottom left of the window. Of course, all the following can also be done from the system terminal directly.

We first gonna test if neo4j works properly by starting the database for the first time.

Inside the neo4j-community-2.0.4 folder, run this command from the terminal:

./bin/neo4j start


The console will print some logging and once its finished it will present you with the REST starting point at http://localhost:7474. If you open that address in a browser, you will see the Neo4j web interface, which is pretty handy for executing commands and visualizing nodes and relations of the database.  Please see the neo4j documentation for more information:

The database created is actually stored in a directory that can be configured inside the /conf/neo4j-server.properties file.

From here we see, the database is stored in the neo4j-community-2.0.4 folder under directory root in file graph.db. We could easily change the directory here by replacing the path here.

You can stop the database by calling:

./bin/neo4j stop


Attention! Please make sure that the neo4j database server is NOT running when using it embedded from the Scala project! The server is locking the .db folder which leads to a connection problem when starting it from via Blueprints. If you want to use both in parallel, you need to run the server and connect to it using Rexter instead of embedding it!

OK great, Neo4j is installed and running! Next we need to integrate it into our Scala project.

## Next

As we fulfilled all prerequisites and set up everything we need, its time to see the real magic, how we can use Neo4j via Blueprints and run graph analytics on it in the last Part 3.

# 3. Install Blueprints Neo4j

In order to connect to Neo4j via Blueprints, we first need to add the following dependency to our projects build.SBT file (this is copied from the maven repository as seen above):

libraryDependencies += "com.tinkerpop.blueprints" % "blueprints-neo4j2-graph" % "2.5.0"


After editing the build SBT file, IntelliJ IDEA will ask you to re-import the project. Press “Refresh”

On refreshing, IntelliJ IDEA is updating and downloading SBT dependencies, which may take some minutes. You can see the status in the status bar at the bottom of IntelliJ IDEA.

## Connect to Graph Database

Once refreshing is finished, we can create a new Blueprints neo4jGraph by calling:

// get embedded blueprint neo4j graph
val graph:Neo4j2Graph = new Neo4j2Graph("neo4j-community-2.0.4/data/graph.db");

// close connection to graph, important!
graph.shutdown();


Note that the constructor takes a string of the path to the database file that should be used for the embedded version of the Neo4j database.
It is very important to shutdown the graph at the end of the program in order to release the lock on the graph.db file!

Further, we need to add the following import

import com.tinkerpop.Blueprints.impls.neo4j2.Neo4j2Graph


Run the project to see that everything works fine. It should compile and run without any errors.
If you get an error like this:

Exception in thread “main” java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, /home/torsten/IdeaProjects/Neo4JBlueprintJung/neo4j-community-2.0.4/data/graph.db
at com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph.<init>(Neo4j2Graph.java:163)
at com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph.<init>(Neo4j2Graph.java:135)
at com.clueda.Main$delayedInit$body.apply(Main.scala:17)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40) at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) at scala.App$$anonfunmain1.apply(App.scala:71) at scala.App$$anonfun$main$1.apply(App.scala:71) at scala.collection.immutable.List.foreach(List.scala:318) at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
at scala.App$class.main(App.scala:71) at com.clueda.Main$.main(Main.scala:13)
at com.clueda.Main.main(Main.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, /home/torsten/IdeaProjects/Neo4JBlueprintJung/neo4j-community-2.0.4/data/graph.db
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:330)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:63)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:92) at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:198) at com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph.<init>(Neo4j2Graph.java:153) … 16 more Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component ‘org.neo4j.kernel.StoreLockerLifecycleAdapter@30a6aae0’ was successfully initialized, but failed to start. Please see attached cause exception. at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:509)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115)
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:307)
… 20 more
Caused by: org.neo4j.kernel.StoreLockException: Unable to obtain lock on store lock file: neo4j-community-2.0.4/data/graph.db/store_lock. Please ensure no other process is using this database, and that the directory is writable (required even for read-only access)
at org.neo4j.kernel.StoreLocker.checkLock(StoreLocker.java:82)
\end{algorithmic}
\end{algorithm}

Algorithms can be referenced like an image, by calling:

??

If you like to include a list of algorithms at the end of your thesis, simply write

\listofalgorithms

at the position you want the list to appear.

# Howto Write a Thesis using LaTeX: Export Scalable Graphs from Excel to Inkscape

The trick with creating nice looking and scalable graphs is the same as discussed in Howto Write a Thesis using LaTeX: Generate Resolution Independent Figures Using Inkscape. Instead of saving the graph as ‘common’ image, meaning as bitmap, jpeg or png, graphs should also be generated as vector graphics.

Unfortunately, Excel does not provide an obvious way to export graphs as vector graphics (at least, I do not know any). But, fortunately, there is a little workaround which I will describe in this little tutorial.

First, assume we have some data present in an Excel sheet and generated any plot from the data. In the example below, I put in some data from the top of my head (without any scientific verification!) on how probable it is to went totally crazy, formatting your hard drive, destroy all your lab equipment and move to any abbey in Tibet for the rest of your live dependent on the amount of time you spend already to prepare your thesis.

To export this nice and somehow scary graph from Excel and to import it in our LaTeX document, we first need to select the graph by clicking on it, you should see a border around the figure. Note that it is important to select the figure only as we just want to export the graph and not the whole document!

Next, we select File->Save As … from the context menu and save it as PDF! See the screenshot below (Sorry, my installation of Excel is German)

That’s all that needs to be done in Excel. Actually, we would be easily able to import the PDF just generated into our LaTeX document, but there is some beautification needed which is best to be done with Inkscape.

To do so, we first open Inkscape and select File->Open (do NOT use Import!) from the context menu. Browse to the recently generated PDF file and press the Open button.

It might take a few seconds until the next dialogue should pop up. Do not touch any configuration at the import dialogue, simply press OK. The graph may be placed like that:

Note that the imported graph behaves like it would have been created with Inkscape meaning that you can easily click elements, remove or edit them. I personally do not like the grey border around the graph, so I remove it by clicking the border and removing it. You might want to change the colour, axis titles, font size or whatever…

Next, we go to File->Document Properties… to set the page size to fit the graph with some spacing of 10px.

Last, we save the plot as PDF file by selecting File->Save as from the context menu.
Remind that you need to select PDF as file type. That’s it, we just created a resolution independent scalable graph with Excel and Inkscape. Of course, this PDF can be included in our LaTeX document in the same way as any other image, namely by writing:

A scary and maybe exaggerated Graph is shown in Figure ??.
\begin{figure}[ht]
\centering
\includegraphics[width=0.5\textwidth]{fig/FreakingOut.pdf}
\caption[Short caption]{Detailed caption}
\label{fig:imageGraph}
\end{figure}

Also, the graphicx package should be added to the preamble of the Thesis.tex file:

\usepackage{graphicx}

# Howto Write a Thesis using LaTeX: Excel to LaTeX Table

Generating nice tables in plain LaTeX can be really annoying as it is very hard to get an overview of columns and rows for raw text. One possibility would be to use a WYSIWYG editor that comes with many development environments.

You can find a nice tool for generating tables in TexMaker by selecting Quick Tabular from the Wizard menu item.

But, in most cases, we do not want to insert tables manually. Instead, most of the data already exists in any other program and we would like to generate a table from our existing data. Also, there are much more specialised application for editing and generating tables, one and probably the most common one is Microsoft Excel.

Fortunately, there is a great tool that let’s you export your existing Excel table to LaTeX code, called  Excel2LaTeX!

# 1. Install Software

Go to http://www.ctan.org/tex-archive/support/excel2latex/ and download the latest Excel2LaTeX.xla file. Next, open the file with Excel.
You might get asked if you want to activate Makros and this is a potential security issue. As we know what we are about to do, we accept Makros. And that’s it, the add on is already installed!

Note that the Add-Ins tab needs to be activated for some Excel versions separately!

Now comes the easy part, select the area of your table you want to export to LaTeX and click the Convert table to LaTeX button. The following dialog pops up:

Click either the Copy to Clipboard button to copy the LaTeX text or save it to a file by choosing Save to File:.
For some reason, copying the text snippet did not work for me on Windows 8, so I had to copy it manually!

Next, as we have the table as LaTeX code in our Clipboard, we only need to paste it to our LaTeX file. Navigate to the position where you want to insert the table in your TexMaker file and paste the content. Note that you might need to load the following packages in the preamble depending on how fancy your table is styled:

\usepackage{booktabs}
\usepackage{color}

The generated code for the example table looks like:

% Table generated by Excel2LaTeX from sheet 'Tabelle1'
\begin{table}[htbp]
\centering
\begin{tabular}{rrr}
\toprule
\multicolumn{1}{c}{\textbf{Name}} & \multicolumn{1}{c}{\textbf{Age}} & \multicolumn{1}{c}{\textbf{Score}} \\
\midrule
Maria & 23    & 1 \\
Thomas & 21    & 0.78 \\
\textit{Alicia} & 19    & 0.27 \\
Mark  & 31    & 0.45 \\
&       &  \\
\bottomrule
\end{tabular}%
\end{table}%

Note that you also might want to update the table caption:

Cool, we just inserted a table from Excel to our LaTeX document! Wasn’t that much easier than typing it yourself?

Please also note, that the newly inserted table is automatically listed in the list of tables we inserted at the end of the document.

# Howto write a thesis using LaTeX, Part 3: Tips and Tricks

We’ve already seen in part 1 and part 2 of this tutorial, how to install and set up software components and howto organize folders and files. Also, we have created a basic structure of our thesis. In this final part 3, I will give you some tips and tricks that made my live easier while creating my PhD thesis.

To be easier found by search engines, I’m gonna create a separate post for each single tip, trick or hack, whatever name you prefer. But, in order to preserve the scope of this tutorial, we will see how to include the generated stuff into our test thesis.

So, here you go, a list of tips, tricks and hacks helping you with your thesis:

Assume you have generated an image like described in the link above, you can use the following code to include it to your thesis:

An example figure is shown in Figure ??.
\begin{figure}[ht]
\centering
\includegraphics[width=0.5\textwidth]{fig/image.pdf}
\caption[Short caption]{Detailed caption}
\label{fig:image}
\end{figure}

And of course, we need to import the graphicx package in the preamble of the Thesis.tex file:

\usepackage{graphicx}