示例#1
0
文件: regml.py 项目: ssyoon/semnet
sys.path.append('./rw')
import rw
import numpy as np
import random
import math
import sys

numnodes=15
numlinks=4
probRewire=.3
numx=3
graph_seed=1
x_seed=graph_seed
randomseed=1

g,a=rw.genG(numnodes,numlinks,probRewire,seed=graph_seed)
Xs=[rw.genX(g, seed=x_seed+i) for i in range(numx)]

def PfromB(b):
    P=np.empty([numnodes,numnodes],dtype=float)  # set P from b (transition matix P[to,from])
    for colnum, col in enumerate(b.T):
        for rownum, row in enumerate(col):
            P[rownum,colnum]=math.exp(row)/sum([math.exp(i) for i in col])
    return P

def regml():
    
    #random.seed(randomseed)     # only for replicability
    #np.random.seed(randomseed)

    # free parameters
示例#2
0
})

toygraph = rw.Toygraphs({
    'graphtype': "steyvers",
    'numnodes': 50,
    'numlinks': 6
})

fh = open('priming_test.csv', 'w')

seed = 15

for td in toydata:
    print "numx: ", td.numx
    # generate data with priming and fit best graph
    g, a = rw.genG(toygraph, seed=seed)
    [Xs, irts, alter_graph] = rw.genX(g, td, seed=seed)
    bestgraph_priming, ll = rw.uinvite(Xs,
                                       td,
                                       toygraph.numnodes,
                                       fitinfo=fitinfo,
                                       seed=seed,
                                       debug=True)
    priming_cost = rw.cost(bestgraph_priming, a)
    print priming_cost

    td.priming = 0.0
    # fit best graph assuming no priming
    bestgraph_nopriming, ll = rw.uinvite(Xs,
                                         td,
                                         toygraph.numnodes,
示例#3
0
import rw
import numpy as np

steps=[]
ehs=[]
meaneh=[]
meanstep=[]

fh1 = open('ehmean.csv','w')
fh2 = open('eh.csv','w')

for i in range(10000):
    print i
    g,a=rw.genG(20,4,.3)
    X,step=rw.genX(g,use_irts=1)
    eh=rw.expectedHidden([X],a,len(a))[0]
    steps.append(step)
    ehs.append(eh)
    meaneh.append(np.mean(eh))
    meanstep.append(np.mean(step))

for num, i in enumerate(meaneh):
    fh1.write(str(i) + "," + str(meanstep[num-1]) + "\n")

ehs=rw.flatten_list(ehs)
steps=rw.flatten_list(steps)

for num, i in enumerate(ehs):
    fh2.write(str(i) + "," + str(steps[num-1]) + "\n")

fh1.close()
示例#4
0
文件: search.py 项目: ssyoon/semnet
irts = rw.Irts({
    'data': [],
    'irttype': "gamma",
    'beta': (1 / 1.1),
    'irt_weight': 0.9,
    'rcutoff': 20
})

fitinfo = rw.Fitinfo({
    'tolerance': 1500,
    'startGraph': "naiverw",
    'prob_multi': 1.0,
    'prob_overlap': 0.5
})

x_seed = 1
graph_seed = 1
td = toydata[0]

g, a = rw.genG(toygraphs, seed=graph_seed)

[Xs,
 irts.data] = zip(*[rw.genX(g, td, seed=x_seed + i) for i in range(td.numx)])
Xs = list(Xs)
irts.data = list(irts.data)
[Xs, irts.data, alter_graph] = rw.trimX(td.trim, Xs,
                                        irts.data)  # trim data when necessary

rw.drawMat(a, cmap=plt.cm.BuGn)
newmat = rw.drawMatChange(Xs, a, td, (0, 1), keep=0)  # e.g.