Discussion
Up to the Bugs Forum
Please feel free to communicate anything you feel could help this project move on. You can receive an email each time a new message is posted by setting up your personal preferences.
EMlearning engine
I am having issues as well. Sadly, it seems that this project is dead.
Powered by Ploneboard
from OpenBayes import learning
from copy import deepcopy
from time import time
import random
from one import *
N = 2000
# sample the network N times
cases = G.Sample(N) # cases = [{'c':0,'s':1,'r':0,'w':1},{...},...]
# delete some observations
for i in range(500):
case = cases[3*i]
rand = random.sample(['c','s','r','w'],1)[0]
case[rand] = '?'
for i in range(50):
case = cases[3*i]
rand = random.sample(['c','s','r','w'],1)[0]
case[rand] = '?'
# copy the BN
G2 = deepcopy(G)
# set all parameters to 1s
G2.InitDistributions()
# Learn the parameters from the set of cases
engine = learning.EMLearningEngine(G2)
# cases = engine.ReadFile('file.xls') #To use the data of file.xls
t = time()
engine.EMLearning(cases, 10)
print 'Learned from %d cases in %1.3f secs' %(N,(time()-t))
# print the learned parameters
for v in G2.all_v:
print v.name, v.distribution.cpt,'\n'
engine.SaveInFile('test.txt',G2,engine.BNet,engine)
###########################################################################
the error is
EM iteration: 1
Traceback (most recent call last):
File "../../tutorial/four.py", line 31, in ?
engine.EMLearning(cases, 10)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/OpenBayes/learning.py", line 58, in EMLearning
while self.hasntConverged(old, new, precision) and iter < max_iter:
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/OpenBayes/learning.py", line 182, in hasntConverged
return not na.alltrue([na.allclose(v.distribution, new.v[v.name].distribution, atol=precision) for v in old.v.values()])
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/numarray/numarraycore.py", line 1518, in allclose
x, y = asarray(array1), asarray(array2)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/numarray/numarraycore.py", line 434, in asarray
return array(seq, type=type, typecode=typecode, copy=0, dtype=dtype)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/numarray/numarraycore.py", line 425, in array
return fromlist(sequence,type,shape)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/numarray/numarraycore.py", line 248, in fromlist
if not len(seq) and type is None:
TypeError: len() of unsized object
i've installed the last version (0.1.0) from here http://svn.berlios.de/wsvn/pybayes/branches/Public/dist/OpenBayes-0.1.0.tar.gz?op=file&rev=143&sc=1
Am i wrong with something?
Francesco