Thursday, April 25, 2013

Pareto frontier graphic via python

Pareto frontiers are not strictly dominated by any others. An element is dominated if there exists an other element in the set of elements having a better score on one criterion and at least the same score on the others. Here a little example Python Pareto frontier code.
import matplotlib.pyplot as plt

def plot_pareto_frontier(Xs, Ys, maxX=True, maxY=True):
    '''Pareto frontier selection process'''
    sorted_list = sorted([[Xs[i], Ys[i]] for i in range(len(Xs))], reverse=maxY)
    pareto_front = [sorted_list[0]]
    for pair in sorted_list[1:]:
        if maxY:
            if pair[1] >= pareto_front[-1][1]:
                pareto_front.append(pair)
        else:
            if pair[1] <= pareto_front[-1][1]:
                pareto_front.append(pair)
    
    '''Plotting process'''
    plt.scatter(Xs,Ys)
    pf_X = [pair[0] for pair in pareto_front]
    pf_Y = [pair[1] for pair in pareto_front]
    plt.plot(pf_X, pf_Y)
    plt.xlabel("Objective 1")
    plt.ylabel("Objective 2")
    plt.show()


An example Pareto frontier graphic is produced by above python function.

Reference 1. http://code.activestate.com/recipes/578230-pareto-front/

Tuesday, March 19, 2013

.htaccess allows a specific IP or username/pass

This example shows that .htaccess file allows a specific IP else username/pass.
Step one: allows specific IP add these lines to .htaccess file

Order Deny,Allow
Deny from all
allow from 123.456.78.90


Step two: create username/password and use them
First of all, you should create username/password file using htpasswd. Type in terminal: "htpasswd -c filename username" press enter and you should input your password (twice). After that you have a .htpasswd file. The file consists of like below line

sirin:$apr1$vp3kZPGK$HdkGNW2KmYO8GJnTe6oRl1

So, you can add these lines to .htaccess file

AuthType Basic
AuthName "Restricted"
AuthUserFile /Users/sirin/foo/bar/.htpasswd
Require valid-user


Step three: combine them
Finally, you combine them below: also adding "satisfy any" selector keyword

AuthType Basic
AuthName "Restricted"
AuthUserFile /Users/sirin/foo/bar/.htpasswd
Require valid-user
Order Deny,Allow
Deny from all
allow from 123.456.78.90
satisfy any