Esempio n. 1
0
def bishleshan(category,topic):
	unigrams = nepunigrams()
	countername = defaultdict(int)
	print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"+topic.upper()+"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
	for name,engnames in category.items():
		bigramslist = []
		bigrmsent = []
		for word,count in unigrams:
			if name in word:
				countername[engnames] += count
		nepalibigrm = nepbigrams(name,sentlist)
		for bigrams,count in nepalibigrm[:4]:
			bigramslist.append(bigrams)
			for sentence in sentlist:
				if bigrams in sentence:
					bigrmsent.append(sentence.strip())
		sentsscore = analyzescore(bigramslist,bigrmsent)
		print "\n++++++++++++++++++++++++++++++++++++++++++++++++SENTIMENT ANALYSIS OF WORD :"+name+"++++++++++++++++++++++++++++++++++++++++++++\n"
		print "In references to :",nepalibigrm[0][0]," OR ",nepalibigrm[1][0]
		print "==========================================================>>>>>>POSITIVE SENTENCES<<<<<<==========================================================\n"
		print "==========================================================>>>>>>>>>>>>>>><<<<<<<<<<<<<<<==========================================================\n"
		for line,score in sentsscore[:4]:
			print line,score,'\n'
		print "==========================================================>>>>>>NEGATIVE SENTENCES<<<<<<=========================================================\n"
		print "==========================================================>>>>>>>>>>>>>>><<<<<<<<<<<<<<<=========================================================\n"
		for line,score in sentsscore[-4:]:
			print line,score,'\n'
	topword = sorted(countername.items(),key=lambda x : x[1],reverse=True)[0][0]
	topname = category.keys()[category.values().index(topword)]
	namepie = piedata(topname)
	pieplot(namepie,"MONTHLY HITS ON WORD : "+category[topname])
	plotdata(countername,"TOP NAMES TOPICS")
	return 0
Esempio n. 2
0
def main(argv):
    argid = {'func':['-id'], 'files':['simdata/svcsimn_d4a1_4.json'], '-m':['plus'], '-yl':['In-degree'], '-axisfsize':['large'], '-j':[1]}
    argavgid = {'func':['-ad'], 'files':['simdata/svcsimn_d4a1_4.json'], '-m':['plus'], '-xl':['Timestep'], '-yl':['Average in-degree'], '-axisfsize':['large'], '-j':[150]}

    #ax = p.plt.axes([0.13, 0.15, 0.6, 0.75])
    p.plt.subplot(211)

    p.plotdata(pl.loadarg([argid])
        , xylabels={'x': pl.getargval(argid, '-xl', [''])[0], 'y': pl.getargval(argid, '-yl', [''])[0]}
        , markset=pl.getargval(argid, '-m', ['var'])[0]
        , isbase=False
        , xlim=pl.getargval(argid, '-xlim')
        , ylim=pl.getargval(argid, '-ylim')
        , legloc=int(pl.getargval(argid, '-loc', ['1'])[0])
        , ncol=int(pl.getargval(argid, '-ncol', ['1'])[0])
        , numpoints=int(pl.getargval(argid, '-numpoints', ['1'])[0])
        , axisfsize=pl.getaxisfsize(argid))

    p.plt.subplot(212)

    p.plotdata(pl.loadarg([argavgid])
        , xylabels={'x': pl.getargval(argavgid, '-xl', [''])[0], 'y': pl.getargval(argavgid, '-yl', [''])[0]}
        , markset=pl.getargval(argavgid, '-m', ['var'])[0]
        , isbase=False
        , xlim=pl.getargval(argavgid, '-xlim')
        , ylim=pl.getargval(argavgid, '-ylim')
        , legloc=int(pl.getargval(argavgid, '-loc', ['1'])[0])
        , ncol=int(pl.getargval(argavgid, '-ncol', ['1'])[0])
        , numpoints=int(pl.getargval(argavgid, '-numpoints', ['1'])[0])
        , axisfsize=pl.getaxisfsize(argavgid))

    p.plt.gcf().suptitle('In-degree of each random failed service (top) and the average in-degree\n of the available services (bottom) during cascading failure simulation', fontsize=14)
    p.processplot(p.plt)
Esempio n. 3
0
theta = np.zeros([2,1])
iterations = 1500
alpha = 0.01
ones = np.ones((m,1))
X = np.hstack((ones, X)) # adding the intercept term


J = costfunction.cost(X, y, theta)
print(J)

theta, J_history = gradientdes.gradientDescent(X, y, theta, alpha, iterations)
print(theta)

J = costfunction.cost(X, y, theta)
print(J)

plot.plotdata(X,y,theta)

predict1 = np.dot([1, 3.5], theta)
print('For population = 35,000, we predict a profit of')
print(predict1*10000)

predict2 = np.dot([1, 7], theta)
print('For population = 70,000, we predict a profit of')
print(predict2*10000)


j_plot.j_plot(X, y, theta)


Esempio n. 4
0
def main(argv):
    lsarg = []

    lsarg.append({'func':['-pl'], 'files':['simdata/plotfunceff_tri-sf_d2_d8.json'], '-m':['reddia-'], '-l':['scale-free']})
    lsarg.append({'func':['-pl'], 'files':['simdata/plotfunceff_tri-exp_d2_d8.json'], '-m':['bluepenta-'], '-l':['exponential']})
    lsarg.append({'func':['-pl'], 'files':['simdata/plotfunceff_tri-rand_d2_d8.json'], '-m':['trihexaorg-'], '-l':['random'], '-t':['The effect of $\langle dep \\rangle$ on cascading failure in service networks'], '-xl':['Degree of dependency $\langle dep \\rangle$'], '-yl':['Cascade failed services $n_c$ (in fraction)'], '-axisfsize':['large'], '-ncol':[3], '-loc':[2]})

    for i in range(len(lsarg)):
        ds = []
        func = lsarg[i]['func'][0]

        step = p.STEP
        argstep = getargval(lsarg[i], '-j')
        if argstep:
            step = int(argstep[0])

        with open(lsarg[i]['files'][0]) as f:
            ds = json.load(f)

        logx = False
        arglogx = getargval(lsarg[i], '-logx')
        if arglogx:
            logx = int(arglogx[0]) > 0

        logy = False
        arglogy = getargval(lsarg[i], '-logy')
        if arglogy:
            logy = int(arglogy[0]) > 0

        lb = p.LOGBINBASE
        arglb = getargval(lsarg[i], '-lb')
        if arglb:
            lb = float(arglb[0])

        xlim = getargval(lsarg[i], '-xlim')
        ylim = getargval(lsarg[i], '-ylim')

        plotfile = getargval(lsarg[i], '-v', [None])[0]

        axisfsize = getargval(lsarg[i], '-axisfsize', ['medium'])[0]
        try:
            axisfsize = int(axisfsize)
        except:
            pass

        ncol = int(getargval(lsarg[i], '-ncol', [1])[0])
        numpoints = int(getargval(lsarg[i], '-numpoints', [1])[0])

        p.plotdata(ds
            , getargval(lsarg[i], '-l')
            , getargval(lsarg[i], '-t', [''])[0]
            , {'x': getargval(lsarg[i], '-xl', [''])[0], 'y': getargval(lsarg[i], '-yl', [''])[0]}
            , getargval(lsarg[i], '-m', ['var'])[0]
            , isbase=False
            , logx=logx
            , logy=logy
            , xlim=xlim
            , ylim=ylim
            , legloc=int(getargval(lsarg[i], '-loc', ['1'])[0])
            , ncol=ncol
            , numpoints=numpoints
            , axisfsize=axisfsize
            , ax=p.plt.gca())

    p.processplot(p.plt, getargval(lsarg[i], '-s', [None])[0])
Esempio n. 5
0
import pandas as pd
import scipy.optimize as op
import matplotlib.pyplot as plt
import plot
import costfunction
import gradient
import accuracy

data = pd.read_csv('Data/ex2data1.txt', header=None)
X = data.iloc[:, [0, 1]]
y = data.iloc[:, 2]
m = len(y)

print(data.head())

plot.plotdata(X, y)

(m, n) = X.shape
y = y[:, np.newaxis]
ones = np.ones((m, 1))
X = np.hstack((ones, X))
#theta = np.zeros((X.shape[1],1))

#c = costfunction.cost(X, y, theta)
#print(c)

#test_theta = [[-24], [0.2], [0.2]]
#print(np.shape(test_theta))
#print(gradient.grad(X, y, test_theta))

#X = np.array([[1,2,3], [1,3,4]])