Wednesday, 24 August 2016

Maps are better displayed on big (TV) screens

TV sets these days have become more powerful than ever. They are equipped with powerful operating systems like Android and WebOS and their screens seem more magnificent than they could ever be. So why not to use them for map display?
Maps contain information related to spatial data and it is always better to view them with a big clear view of the spatial information they carry. For instance, sometimes it is not so informative to view a generalized weather map in the small screen of a smartphone; a big screen or printing the map in a big paper give you a clear insight of the situation it represents. Also a school could use a set of digital maps for educational purpose rather than using a few printed maps not viewable from distance.
Of course professionals know these things and the use big computer screens for drawing maps but most other people use small screens even at home. Personally, I always thought that TV screens could have much more potentials beyond their traditional use. On this spirit I have released two applications that link viewing my web mapping application WMS Map Viewer On Line to Android TV and Amazon TV. The result is really great try it.

Play Store link

Amazon Appstore link

Saturday, 25 June 2016

Sea Hero Quest

Sea Hero Quest is a mobile game which contributes to research on dementia. It was designed by British game company Glitchers in 2016 in association with Alzheimer's Research UK, University College Londonand the University of East Anglia and with funding from Deutsche Telekom. The idea for the game came from neuroscientist Michael Hornberger of the University of East Anglia who collaborated with Hugo Spiers of University College London and a group of six other neuroscientist.

The way in which players navigate the game will help researchers to understand the mental process of 3D navigation, which is one of the first skills lost in dementia. It is hoped that a large number of people will play the game, thus contributing much more data than could easily be obtained in a laboratory experiment.


Source: wikipedia

Find it in Google Play. There is also a greek version.

Sunday, 5 June 2016

How to describe or represent an infinite object efficiently

There are many cases where you need to represent an infinite mathematical object on a way that you will be able to work on it. In other words, create a representation or a description of an infinite mathematical entity on a way that you can perform computations over it. In these cases just using a variable to denote the entity is not enough. You need a description of its structure and to be able to reproduce any part of the object using this description.
Usually these situations occur in theoretical studies but this does not rule out practical applications. An infinite object can be a number (real, irrational, transcendental etc.) or a sequence like an infinite binary sequence.
It is safe to consider a description that may be inputted in a Turing Machine (TM). It is a general purpose computational model and if you can build a TM that accepts as input your infinite object description then it is an efficient representation of your object, otherwise the description and the object itself are probably uncomputable.
Let’s see a few cases of infinite mathematical objects and how they may be represented in Turing Machines starting from trivial cases and moving on to more difficult ones.

Irrational numbers. Set Q of irrational numbers contains numbers of infinite decimal expansion like the number equal to 3/10. Despite this, it is very easy to describe any irrational number using the definition of infinite numbers. For each irrational number i stands that i = a / b, where a, b are natural numbers. On this way each i is easily described. Using this description we may perform computations between any two irrational numbers.

Algebraic numbers. The set A of algebraic numbers consists of computable numbers so each a of A is Turing computable and has a computable description. Using the definition of algebraic numbers we may construct a description. Each a is the root of some polynomial p so it may have infinite decimal expansion p however is of the form
hn xn+hn-1 xn-1+…+h1 x1+h0 x0
As a is computable p is also be computable, so it is of finite length. In order to represent p in a TM we introduce symbol “|” that substitutes the x^n factor so that p is represented on the tape of a TM as follows
hn | hn-1 | … | h1 | h0
Each p has a bounded number of roots. Let a be the i-th root of p then it may be represented in a TM as
hn | hn-1 | … | h1 | h0^i
by introducing symbol “^” in the alphabet of the TM.

Infinite strings. Each string may be encoded to a binary string so let’s talk about binary strings. Following Computer Science theory, infinite binary strings are either computable or uncomputable. About the uncomputable ones there is not much we can do, it’s clear that you cannot describe something that you can’t compute. The computability of the rest of binary strings implies that for each string s there is algorithm H that produces s. Each character of s may be produced by H so its operation describes it.
Of course H may be simulated in a Universal TM that accepts as input the description of H which is of finite length otherwise it wouldn’t be computable. As a result the description of H stands for a description of s.
Algorithm H is of finite length while s is infinite this directly implies that the structure of s follows some pattern that H iteratively produces while running on TM.

Transcendental numbers. These numbers have infinite decimal or binary expansions but for each one there are algorithms that may produce any part of its expansion. Following the same reasoning as with infinite strings, the description of any algorithm that generates the sequence of digits of the decimal or binary expansion of a transcendental number may stand for its description.




Thursday, 28 January 2016

Geometry and randomness reduction

Think of a 2-dimensional space, say a piece of paper. Let’s call it d. Each point p in d is random on the sense that on there is nothing special about p in comparison with any other point in d.
Now let us define arbitrarily in d a coordinate system and place in some point that we also choose arbitrarily coordinates (0, 0). Based on our coordinate system and its metrics the points in d now have coordinates and they are not so random anymore. The interesting thing is that some points in d are still more random than others, before explaining this let's talk very very briefly about randomness.
The sense of randomness on modern science is studied in many fields and has to do with probabilities, complexity and our descriptive ability and there are many different ways to define it. I think the easiest way to discuss it is through examples. Let a and b be two strings
a) 100000000
b) 197599249
String a is less random than b for a number of reasons. At first if we use a random number generator (or simply throw some dices) it is really difficult to generate string a with number 0 to appear 9 times consecutively, a string with structure similar to b is more possible to come up.
Then string a is more special while b is more common. You can characterize a as special as it has lower information entropy and lower Kolmogorov complexity (or else algorithmic complexity). This kind of complexity is related to the best means we may use to describe this string. Given a computational machine T the algorithmic complexity of a string s is equal to the smaller algorithm that we may develop in T so that T will produce s. Algorithmic complexity is uncomputable so we may not get an absolute number as a measure of complexity for s. Nevertheless it has an interesting property based on the invariance theorem which allows us to compare the complexities among different strings. No matter what computational model we choose the difference in algorithmic complexity between two given strings will still hold. This means that we may use just one computational machine T in order to examine the randomness of a and b. Let us describe abstractly two programs that produce these strings.
a) printf(10^9)
b) printf(14057^2)
These are probably the shortest descriptions of the strings. String a has sorter description so it is less complex and more special than b.
Now let's go back to our 2D plane d in which we have defined a coordinate system. Some points on d are less random than others on the sense that we may form more special descriptions on them and some points are more special as they have more special properties than others. The point in (2, 2) is less random than the point in (1.9876, 3.4567).
Moreover if we define a straight line between point p1 and p2 there are along the line some points that are more special than the rest. The midpoint of the line and the points that split the line in segments l1 and l2 for which stands that l1/ l2 = n, where n is some integer, they have this special property that makes them more special and less random than the rest of the points on the line. Also all the points on the line are described by the equation of the line y = mx + c which makes them more special than the points in the rest of d.
As mentioned earlier the coordinate system is arbitrary places in d, yet this does not affect generality. No matter where we place point (0, 0) there will still be special points as described so far. The existence of less random points in d given any coordinate system is a property of d and an effect of defining geometrical structures in space.
If in d we draw regular shapes then the points on their periphery will have even more special description and properties. Their positions may be described using the equation of each shape. Also the space enclosed in a regular shape is described by its equations and is affected by its properties.
The same reasoning stands for classical geometry as well. Without using coordinate systems but instead using rulers and compasses we may describe special properties in any space and in geometrical shapes in it.
Geometry is one of the ways that humans have invented in order to describe the world around them and it has an important utility, it makes space less random by providing methods on describing special properties of it.


Sunday, 15 November 2015

Change layout dynamically in Android applications. A case study.

Android applications are usually built to function in a variety of devices that have different screen dimensions and also they must be functional in any orientation of the screen and in any change of the orientation. Moreover the efficient use of space especially in devices with small screens is very important and gives great value to the application, so the GUI of an activity must be designed with special care to screen sizes and orientation changes.
The indicative way to design the GUI of an activity is to prepare a layout file for it. This is a more straight forward procedure than defining the graphical elements of your app programmatically and is easier to handle and test. All the default layout files are stored in /res/layout directory of the projects file structure. In case you want to prepare a layout file for an activity with landscape orientation, you have to create directory /res/layout-land and you place the layout file in there. When the size of the screen matters and you want different UI for different screen sizes then you must create a layout for each case. For instance, a layout designed for screens with smaller size larger than 600 dp must be placed in a directory named layout-sw600dp and if you want to combine screen sizes and orientation you must place the appropriate layout file in the directory named layout-600dp-land.
All the layouts that refer to the same activity must have the same name regardless of the directory they are stored. When an app is executed, Android will search for the most appropriate layout considering the screen size and orientation. In case there is not a special layout defined, Android will use the layout stored in the default directory.
Problems start when some of the elements of the screen change dynamically while the app is running and a layout has already been loaded. In most cases the change in the orientation of the screen causes troubles in the dynamically changed elements. When orientation changes, Android usually reloads the activity losing all the changes the user has caused. In order to avoid that you must edit the manifest file and in the activities that are declare some how like this

        <activity
            android:name=".app.MyActivity"
            android:label="@string/title_activity_myactivity" >
        </activity>


add one line of code changing them like this

        <activity
            android:name=".app.MyActivity"
            android:configChanges="keyboardHidden|screenSize|orientation"
            android:label="@string/title_activity_myactivity" >
        </activity>


This tells Android that you know what to do with your activity so it shouldn’t change anything on its own. Let’s see now what you should do when it is you that you want to cause layout changes when orientation changes. In order to present this more efficiently I will use the example of my app called Map This Way.
In an activity of this app called activity_line the user may record the GPS tracks along a route. In the layout there is some text that is updated with the current GPS coordinates and a map view that shows user’s current location. In big screens when the screen is in landscape orientation the map is better to be on the right of the screen and the text on the left and when the screen orientation is vertical the map view is better displayed under the text. In small screens the map view should always be under the text. In order to do this I prepared layout files for all cases. Then I had to arrange how the app will behave in screen orientation changes.


Orientation changes are detected and manipulated by the onConfigurationChanged method which must be overridden.

@Override
public void onConfigurationChanged(Configuration newConfig){
     super.onConfigurationChanged(newConfig);
     setContentView(R.layout.activity_line);
}


The above code reloads the UI of the activity using the most appropriate layout file for the new orientation of the screen. The advantage of using this technique instead of letting Android do the changes is that in this method you may add code to define how the activity elements will be displayed in the new screen. The disadvantage is that the elements are initialized and reloaded so you will have to add code so as to initialize them properly and update the values of the layout elements with the changes that have occurred so far. Also you have to restart procedures that may have stopped after orientation changed like advertisement display etc.
In the case of my app the map view has to be updated so the users will see their current location and if the mapping procedure has started the colors and functionality of layout elements has to be adjusted accordingly.
In general, a good way to deal with such situations is to initialize the layout elements in the onConfigurationChanged method as you did in the onCreate method. So for update of the map view of my app I use the method showmap(x, y) which updates the location of the map and it is executed in both methods.
Another problem occurs when you have to pass some value from a variable that affects layout elements to the newly initialized elements after orientation changes. For this, the use of some global variable is very helpful. In my app when the mapping procedure has started, a red button appears which may be pressed by the user and cause the stopping of the mapping procedure. The way I worked around this issue is the declaration of a global boolean variable called mapping which takes the value true when mapping has started and false otherwise also the declaration of a global Button instance. Then I used both in onConfigurationChanged method.
All the above were formed as follows.

@Override
public void onConfigurationChanged(Configuration newConfig){
    super.onConfigurationChanged(newConfig);
    setContentView(R.layout.activity_line);
   showmap(x, y);
   if (mapping){
        button1=(Button) findViewById(R.id.button1);
        button1.setBackgroundColor(0xffff0000);
   }
}

Then activity_line is functional and ready to use.