Technology and Elections: Democracy taken for a ride

We live in a tech savvy world where political polarization is widely done than ever before. Technology which was meant to bring transparency and clarity is used to clog and obscure people of reality.

Elections which are a quintessential part of democracy has been diluted of it’s attempt to create true change and nation building process.

There is a reason to discuss about current trending technologies as the following avenues can create a biased opinion in the minds of voters.

Social Media

  • WhatsApp – Probably one of the most vulnerable platform to spread fake news, easy to opinionate, ability to reach out quickly to masses through groups and the power it gives for sharing content on it’s own platform and posts from other platforms. Political parties have been using this platform excessively to propitiate people by their propaganda.
  • Facebook – Biggest social media platform which literally captures every single action of it’s users on it’s platform. It can influence all it’s members through groups, friend lists, pages, Facebook Ads. Given their ability to target ads to a particular group of people, this platform has the best route to impact people.

Further, the comments on posts and the likes/reactions for a post have multiple fake profiles used by political parties to create a opinion.

  • YouTube – The leading video platform too is not spared from fake news, fake videos in recent years. Simple way of misusing the platform can be through it’s likes and dislikes button, again comments section here too can be misused. Each and every political video has 80 : 1 like, dislike ratio. Edited videos of speeches pose a threat to easier understanding for the people.
  • Twitter – Twitter on the other hand is more for niche users which can be used like a cyber war platform for different political parties. Hashtags, retweets from socially influential people and parody accounts can bemuse people. Also, the follower count of various political leaders is questionable.

The above mentioned points address the user aspects only, if dug deep dark data in back-end higher insights shall be extracted through data dumps and data generated through users. And this data is available with the platform plus the data provider for the user device. If there is a need the government in concerned jurisdiction can also access user data.

IT cell of major political parties today is equivalent to any medium size software consulting firm. It’s almost near to impossible for independent and lesser known political parties to make their presence felt on these above mentioned platforms.

The recent findings of data misuse from Cambridge Analytica from Facebook data is a single case acknowledged properly so far, there are various loopholes on all these platforms which needs to be fixed.

Television

With television channels available on mobile devices the line is thinning between conventional tv’s and internet tv’s. Here consider only conventional tv, there are several channels which operate 24X7 reporting about elections, lobbying for their desired political parties. There is little consensus expressed by these news channels to report unbiased news.

Moreover the surveys and opinion polls conducted by most news channels bring out results in favor of political parties which they approve and validate.

Newspaper / Print Media

Once a heavily dependent mode of news consumption, now reduced in it’s numbers on advent of internet and television. Yet, they are making their presence felt through online news portals these days. All newspapers in circulation today have political affiliation to some or the other political party, this mode is comparatively trustable given there is an organization to look through articles printed on the newspaper.

Unlike the other modes newspapers are on record, from ages.

Thus, with these pointers on current technologies we head towards the Karnataka assembly elections on 12th May 2018. Vote for a candidate without prejudice but with reasoning, if you don’t like any of the candidates, press NOTA.

Exercise your power to vote.

Arrays in JAVA

An array is a collection of variables which are of similar type. Arrays can be accessed with their indexes.

Arrays can be used to store numbers, list of values and other variables.

Consider the following example below :

int[ ] Bitcoin = new int[5];

Here, we are defining an array Bitcoin of integer datatype consisting of 5 Bitcoins.

We can reference each element in the array with an index, say the elements of the array are {5,50,85,22,78}. We can access the 2nd element by using Bitcoin[1]. Note indexing in Java starts at 0.

Let us look into a program to access arrays by referencing:

public class Cryptocurrency {

    public static void main(String[] args) {

        String[ ] Blockchain = { “Amsterdam”, “Berlin”, “Capetown”, “Delhi”};

        System.out.println(Blockchain[2]);

    }

}

Program to calculate length of an array.

public class Coins {

    public static void main(String[] args) {

        int[ ] Bitcoin = new int[5];

        System.out.println(Bitcoin.length);

    }

}

Program to find sum of an array.

public class Coins {

    public static void main(String[] args) {

        int [ ] Bitcoin = {5,50,85,22,78};

        int sum=0;

        for(int k=0; k<Bitcoin.length; k++) {

            sum += Bitcoin[k];

        }

        System.out.println(sum);

    }

}

In this code, the variable sum stores all the variables by adding all the elements of array. Initially the sum is assigned a value of zero. A for loop traverses through the array list because of the expression k<Bitcoin.length, that is the number of elements will be equivalent to a value less than length of the array. Remember, the indexing starts at [0] for arrays.

Printing values of an Array.

public class Coins {

    public static void main(String[] args) {

        int[ ] values = {5,50,85,22,78};

            for (int P: values) {

            System.out.println(P);

        }

    }

}

2D and 3D Arrays

Accessing 2D Array

public class Coins {

    public static void main(String[] args) {

        int[ ][ ] Bitpart = { {77, 55, 34}, {41, 54, 63} };

        int j = Bitpart[1][0];

        System.out.println(j);

    }

}

Accessing 3D Array

public class Coins {

    public static void main(String[] args) {

        int[ ][ ] Bitpart = { {17, 21, 32}, {41,70,44}, {51, 62, 75} };

        Bitpart[0][2] = 32;

        int m = Bitpart[1][0];

        System.out.println(m);

    }

}

Similarly, N dimensional arrays can also be accessed.

Source:1)THE Java™ Programming Language, Fourth Edition

       By Ken Arnold, James Gosling, David Holmes

       2) SoloLearn Online Platform.

Functions and Built-in Functions in Python

Function

A function is the simplest callable object in Python.

NOTE: For Indentation either use TAB space or 4 space characters, never both.

def tax(bill):
“””Adds 25% tax to a restaurant bill.”””
bill *= 1.25
print “With tax: %f” % bill
return bill

def tip(bill):
“””Adds 35% tip to a restaurant bill.”””
bill *= 1.35
print “With tip: %f” % bill
return bill

meal_cost = 100
meal_with_tax = tax(meal_cost)
meal_with_tip = tip(meal_with_tax)

Function Syntax

def spam():                                             /*Header*/
“”” This is spam function”””            /* Comment*/
print “Spaceship!”                            /*body*/

spam()

Call and Response

def square(n):
“””Returns the square of a number.”””
squared = n**2
print “%d squared is %d.” % (n, squared)
return squared

square(5)

Parameters and Arguments

A function can require as many parameters as you’d like, but when called the function, it should generally pass in a matching number of arguments.

def power(base, exponent):  # Add your parameters here!
result = base**exponent
print “%d to the power of %d is %d.” % (base, exponent, result)

power(20, 6)  # Add your arguments here!

Functions Calling Functions

A function can call another function.

def n_plus_one(n):
return n + 1

def couple_add(n):
return n_plus_one(n) + 2

Importing Module

A module is a file that contains definitions, including variables and functions, that we can use once it is imported.

import math
print math.sqrt(25)

math includes a number of useful variables and functions, and sqrt() is one of those functions. In order to access math, all you need is the import keyword. When you simply import a module this way, it’s called a generic import.

It’s possible to import only specific variables or functions from a given module. Pulling in just a single function from a module is called a function import.

# Import *just* the sqrt function from math

from math import sqrt

if we want all the variables and functions in a module but don’t want to have to constantly type math then we can use

# Import *everything* from the math module

from math import *

Built-in Functions

max()

The max() function takes any number of arguments and returns the largest one.

>> maximum = max(10,35,64)
>> print maximum

min()

min() function returns the smallest of a given series of arguments.

>> minimum = (10,35,64)
>> print minimum

abs()

The abs() function returns the absolute value of the number it takes as an argument, it gives the number’s distance from 0 on an imagined number line.
>> absolute = abs(-42)
>> print absolute

type()

The type() function returns the type of the data it receives as an argument.

>> print type(42)
>> print type(4.2)
>> print type(‘spam’)

Now let us see the code which returns biggest, smallest and absolute values.

def biggest_number(*args):
print max(args)
return max(args)

def smallest_number(*args):
print min(args)
return min(args)

def distance_from_zero(arg):
print abs(arg)
return abs(arg)

biggest_number(-105, -53, 51, 100)
smallest_number(-106, -55, 54, 105)
distance_from_zero(-104)

These are some of the functions and built-in functions in python.

Google Analytics for Jan-Feb-March 2018(Q4 )

The statistics for MOHANMA.COM for Jan-Feb-March(starting Jan 26th to 31st March) are as shown above.

There have been a total of 737 sessions with 1673 pageviews.

The Bounce Rate of the website is 66.76%, which is pretty good as lower the bounce rate better the performance of website.

New visitors account for 76.5% of total visitors and returning visitors account for 23.5%.

India accounts for the highest traffic, with Karnataka being the leading region to in-flowing traffic with 576 sessions so far.

Among devices, mobile phones lead the traffic generated followed by desktop and lastly by tablets.

Apple iphones are the leading mobile phones used to access the website followed by Xiaomi and Motorola phones.

Thanks to everyone who have been visiting the website.

Love,

Mohan M A

Basics of Python – Part 2

Start with Basics of Python – Part 1

Dot Notation

Using dot notation with strings.
Let us consider an example where we convert the string to upper case using dot notation.

>>> mysore = “The city is awesome !”

>>> print len(mysore)
>>> print mysore.upper()

Printing strings

>>> print(“This String”)

Printing Variables

>>> Stone_cold = “Stunner”
>>> print(Stone_cold)

Concatenation

Combining strings together is called concatenation . The + operator combine the strings.

>>> print “Indian “+ “Air ” +”Force ”

The space after the word is to make the string look like sentence.

String Conversion

The str() method converts non-strings into strings.

>>> print “Sourav Ganguly scored “+ str(100) + “on his Test Debut”

String Formatting

The % operator after a string combines a string with variables. The % operator will replace  %s in the string with the string variable.

Example 1:
>>> string_1 = “Sourav”
>>> string_2 = “Dada”

>>> print “Indian captain %s is also called as %s.” % (string_1, string_2)

Example 2:

>>> batsman = raw_input(“Who is the batsman?”)
>>> captain = raw_input(“Who is the captain?”)
>>> series = raw_input(“Which series did he win for India?”)

>>> print “The Indian %s and %s Sourav Ganguly won %s series for India.” % (batsman, captain, series)

Date and Time 

We can import datetime function from datetime module.

>>> from datetime import datetime

Current Date and Time

Here is the code to print current date and time.

>>> from datetime import datetime
>>> now = datetime.now()
>>> print datetime.now()

Control Flow

The ability to choose from different situations based on what’s happening in the program.

>>> x = int(input(“Please enter an integer: “))

Please enter an integer: 35

>>> if x < 0:

…     x = 0

…     print(‘Negative changed to zero’)

… elif x == 0:

…     print(‘Zero’)

… elif x == 1:

…     print(‘Single’)

… else:

…     print(‘More’)

if statements, for statements, range fuction, break and continue, else clause loops, pass statements are few of the control flow statements.

Comparators

Equal to (==)
Not equal to (!=)
Less than (<)
Less than or equal to (<=)
Greater than (>)
Greater than or equal to (>=)

Boolean Operators

AND 

OR 

NOT

Conditional Syntax

The statements used for decision making are called conditional statements.

if condition_1:

statement_block_1

elif condition_2:

statement_block_2

else:

statement_block_3

This post concludes basics of python.

Basics of Python – Part 1

Download the python interpreter from this link . Choose either 3.0 or 2.0 version depending upon your compatibility. In this exercise version 2.0 was used for examples. Based on the current and future trends I would recommend 3.0.

Now let us look into some basic concepts in python programming language.

Variables:

As with most programming languages, assigning a value for a variable is as simple as:
a = 10

Booleans:

The two switch states True or False can be assigned to a variable.
a = True
(or)
a = False

Reassigning variable values:

A variable b = 10 can be given a value as b = 5 in the next line, and the value can be printed using
print b

Indentation:

Indentation is one of the most important aspect of python, either use a Tab space or 4 white spaces but not both. Here’s an example of a simple python function.

def example()
var = 15
return var
print example()

Single-line Comment:

Use # at the beginning of a line to give a single line comment.
# This is a single line comment in python.

Multi-line Comments:

If the comment is more than one line use double inverted comma’s thrice at the start and end of the comment.
“”” This is a multi-line
comment”””

Basic Math Operations:

All basic math operations such as addition(+), subtraction(-), multiplication(*) and division(%) can be performed similar to other programming languages.
>>print 36 + 64
100
>>print 200 – 100
100
>>print 10 * 10
100
>>print 1000 / 10
100

Exponentiation:

In python, the function of exponential can be performed using ** keys.
>> chairs = 10 ** 2
>> print chairs
100

Modulo:

Modulo operation can be performed using %.

Strings:

Assigning strings values and printing them.
python = “Hello world!”
print(“python”)

Escaping characters:

In python both single quotes and double quotes can be used for commenting. When using single quote, the interpreter doesn’t understands the code. In such cases we can use escape characters such as backslash(\).
‘Isn\’t it the python?’

Accessing by Index:

We can access any character of a string by indexing. Indexing starts from 0.
>>sixth_letter = “python”[5]
>>print sixth_letter
n

String methods:

We can calculate length of the string using len()
>>python = “Indian”
>>len(python)
>>print len(python)
6

We can convert lower case string to upper case string
>>python = “indian”
>>”indian”.upper()
>>print python.upper()
INDIAN

We can convert upper case string to lower case string
>>python = “INDIAN”
>>”INDIAN”.lower()
>>print python.lower()
indian

We can convert a variable to a string
>>pi = 3.14
>>print str(pi)
3.14

So, this concludes basics of python part-1.

Understanding Apache Spark

In my last blog post I had discussed about data, now let us understand a modern tool to process huge datasets(BigData) so as to extract insights from data.

Apache Spark – A fast and general engine for large-scale data processing. Spark is a more sophisticated version of data processing engine compared to engines using MapReduce model.

One of the key feature with Apache Spark is Resilient distributed datasets(RDD’s). These are data structures available in Spark.

Spark can run on Hadoop YARN cluster. The biggest advantage to keep large datasets in memory adds to the capability of Spark over MapReduce.

Applications types that find Spark’s processing model helpful are:

  1. Iterative algorithms
  2. Interactive analysis

Other areas which make Spark more adoptable are:

Spark DAG(Directed Acyclic Graph) – This component of the engine helps to convert variable number of operations into a single job.

User Experience – Spark makes user experience smooth by having a plethora of API’s to perform data processing tasks.

Spark has API’s in these languages: Scala, Java, Python and R.

Spark programming comprising of the Spark shell(also known as Spark CLI or Spark REPL) makes it simple to work on datasets. REPL stands for read-eval-print loop.

Spark on the other hand provides modules for:

  1. Machine learning(MLib) – Provides a framework for distributed machine learning.
  2. Graph processing(Graphx) – Provides a framework for distributed graph processing.
  3. Stream processing(Spark Streaming) – Helpful for streaming(real-time) analytics. Data ingestion takes place in mini-batches and RDD transformations are performed upon these mini-batches.
  4. SQL(Spark SQL) – Provides data abstraction known as SchemaRDD which supports structured and semi-structured data.

These components operate on Spark core. Spark core provides platform for in memory computing and referencing datasets in external storage systems.

Companies that are using Apache Spark – Google, Facebook, Twitter, Amazon, Oracle, et al.

Spark services are provided on notable cloud platforms such as Google Cloud Platform(GCP), Amazon Web Services(AWS) and Microsoft Azure.

Source: Apache Spark

 

Data: The new “OIL” of Information Era

Dataoil

Anything and everything that can be produced, which we can quantify is referred as data. In simple words granular information is data. Automobiles and machinery have been running on oil extracted from earth. In the Internet age devices, machines and all mundane activities shall be driven by data.

All data that exists can be classified into three forms:

  1. Structured Data
  2. Semi-structured Data
  3. Unstructured Data

Structured Data – Structured data is a standardized format for providing information. Examples: Sensor data, machine generated data, etc.

Semi-structured Data – Semi structured Data does not exist in standard form but can be used to derive structured form with little effort. Examples: JSON, XML, etc.

Unstructured Data – Unstructured Data is any data that is not organized but may contain data which can be extracted. Examples: Social media data, Human languages, etc.

Most global tech giants operate from data generated by their users. Google, Amazon, Facebook, Uber, et al. come under the same umbrella. The insights derived from structured and semi structured data can help us in decision making. The magnitude and scale at which these companies generate data is astounding.

Databases play a very important role in storing data. But traditional databases are no longer a choice to store data in today’s fast moving world. New age file systems and infrastructure have started operating to cater the demands of ever expanding Internet space.

In the human world, the voice, speech, text, walking speed, everything can be classified as unstructured data, since we can derive a lot of insights from them. A mobile device per individual is pretty much sufficient to analyse the behavior of a sizable population in a region.

Data collected from a population for a relatively considerable time can be used to derive patterns about the population. Hence, data is the driving force which will fuel innovation and economy from here.