Monday, September 14, 2015

Bill Gates says software bots will eventually take jobs away in 20 years. What do people think?

Disclaimer: this post is copy-pasted from Quora!



When is the last time you used a travel agent to book a flight?  Bots are already here.

I should also add that my profession is becoming automated. Newspapers like the LA Times are using bots to 'write' stories involving sports results and financial reports. They are virtually indistinguishable from similar reports written by bipeds. Fortunately they haven't invented a Snark Bot or I'd be out of a job.

Any job involving forms processing. As paper shuffling turns into pixel shuffling, there's less and less need for a human to be involved.

What's your credit score? That's determined by an algorithm. Back in the day, a human being had to decide if you were a worthy credit risk.

Life insurance rates? Once upon a time, insurers relied upon actuarial tables built by bipeds. Not anymore.

Also: Planes. Commercial airliners are flown almost entirely by robot, save for take off and landing (and even the latter is mostly automated).

Tl;dr: There are a ton of jobs being performed today by algorithms that used to be done by humans. More are coming. Hope yours isn't one of them.

Ref,
http://www.quora.com/Bill-Gates-says-software-bots-will-eventually-take-jobs-away-in-20-years-What-do-people-think

Friday, September 11, 2015

FUNctional Programming


What is functional programming? What is the difference between this new topic and other programming languages? Why the hell do we need to learn this functional programming? What is this logo talking about?

If this is the first time you hear this concept, you may have the above questions in your mind as I encountered for the first time I heard about "FUNctional Programming" (FP). As a rule of thumb, I don't want to go through the details of FP in this post, but I just want to attract your attention to this new term and answer the aforementioned questions briefly.

Here is the first answer! (without knowing what the question is).

So if you are still with me and would like to learn FP too, first look at the following taxonomy to see the classification of programming languages,

More likely, you never implemented any code in none of these languages, so determination of the type of your favourite programming language is more than welcome in the comments (this is subtle way to know if you read this post, if so you should be able to identify what the type of R is).


This is the first moral lesson we should learn from FP, "war is over", oops, I'm sorry! we have already been overwhelmed in many wars nowadays. Where were we? Aha, I just remember, FP says declaring var is over! But why? Why is it important to have this as the life motto of FP? This is what I will answer later. Let's first answer the vital question, so what on earth is FUNctional Programming? I think, it is better to be patient, if you know what FP is, then please move to the next post and if you have not known it yet, it means either you don't need to know it at all or read the rest of this post!

FP is a list of things you can't do. That's the most simple answer I have for you right now. In fact we can do many things, but we may never think what we can't do, now you can cry. At least this is more convincing for me to know what I can't do rather than knowing what I can. From the information theory point of view, this is more informative with the highest entropy so that facilitates my life. Just a moment, what that weird list could be? There you go,
  • No Assignments (this is different from your homework!).
  • No Varying Your Variables. (Immutable)
  • No While/For Loops.
  • No Control Over Order of Execution. 
  • No Side Effects.
  • No Mutating or changing state.
Characteristic
Imperative approach
Functional approach
Programmer focus
How to perform tasks (algorithms) and how to track changes in state.
What information is desired and what transformations are required.
State changes
Important.
Non-existent.
Order of execution
Important.
Low importance.
Primary flow control
Loops, conditionals, and function (method) calls.
Function calls, including recursion.
Primary manipulation unit
Instances of structures or classes.
Functions as first-class objects and data collections.
Looks cool! Sounds like I don't need to write any code in this fashion! But wait a moment,

Are You FUNing Kidding me? How Can Anyone Program like this ?
Good question! (this phrase reminds me someone)

"Functional Programming is so called because a program consists entirely of functions." 
- John Hughes , Why Functional Programming Matters

What a ridiculous quote! I thought a program consists of coffee :D

Now words of wisdom 
"The Language that does not affect the way you think about programming, is not worth knowing." 
- Alan Perlis

Hmmm, this one makes more sense! At least it saves my time not to learn a languRage (this is not typo! (Can anyone tell me how many exclamation mark did I use so far?!)).

But let's dive into an example,

Imperative

total = 0
i = 0
while i <= 10
  total += i
  i = i + 1
end
total

Functional

 total = (1..10).inject(:+)

I prefer to stop at this point, but I will continue this tutorial based on you feedbacks in comment section (I promise to write the next one with more appropriate syntax and semantic in a classy way), in addition to the answer of question that was raised in this post.

Have a FUNctional programming ;)

Thursday, September 3, 2015

Crawling IMDB Website



Yesterday Farnoush asked me if I teach some web crawling with R in my graduate course.
Well! I thought I must do some web crawling myself first, then teach to the others. To start, you need to know some basic HTML or CSS language. These languages are somehow like Latex. HTML and CSS help to structure of a web page.
First we need some web crawling tools that reads web pages and put them in a proper R class. I suggest installing the rvest R library.
Now lets set our mission: we want to extract the rating of a movie from the IMDB website, for instance. I choose a well-known movie like “sepration” from Asghar Farhadi, an Oscar winning Iranian movie. The family name of the director matches Fanoush’s family name, a nice match, perhaps Farnoush and Asghar are relatives ;).
The IMDB webpage of the movie is here http://www.imdb.com/title/tt1832382/



> library("rvest")
> separation_movie <- html("http://www.imdb.com/title/tt1832382/") ; class(separation_movie)

## [1] "HTMLInternalDocument" "HTMLInternalDocument" "XMLInternalDocument" 
## [4] "XMLAbstractDocument"

Watch carefully! Now the object separation_movie is not only a text file downloaded from the web, it is an HTML object in R. Let’s see how we can find what we need in this HTML object. If you know some basic HTML language, you know that paragraphs are found by <p> and </p> tags. Let’s check the 15th paragraph in the HTML object:

> (separation_movie %>% html_nodes("p"))[15]

## [[1]]
## 
## A married couple are faced with a difficult decision - to improve the life of their child by moving to another country or to stay in Iran and look after a deteriorating parent who has Alzheimer's disease.
## ## attr(,"class") ## [1] "XMLNodeSet"
Wow! the 15th paragraph of IMDB is the story of the movie. Now let’s extract the text from it


> (separation_movie %>% html_nodes("p"))[15]%>%html_text()

## [1] "\nA married couple are faced with a difficult decision - to improve the life of their child by moving to another country or to stay in Iran and look after a deteriorating parent who has Alzheimer's disease.
Well! Now let’s check if we can extract the rating of the movie from the html file. We just need to know how the movie rating is structured inside the html file. If you check the whole HTML object separation_movie you will find that span HTML tag is associated with the rating. Let’s try isolating the span then:
> separation_movie %>% html_nodes("strong span")

## [[1]]
## 8.4 
## 
## attr(,"class")
## [1] "XMLNodeSet"
If you want to extract the rating, just isolate the text inside the HTML tag

separation_movie %>% html_nodes("strong span") %>% html_text() 

## [1] "8.4"
We can easily make a database of IMDB with stories, actors, actor photos, directors, number of ratings, and so on.
We just require to crawl the link to other movies, save their web page addresses and crawl all of our addresses to save the information of the movies.