473,387 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

instantiate new objects

Hello @ all,

i'm a newbie in python and have written a module for computations in a
bayesian network.

The module can be found at:
http://www.informatik.uni-freiburg.d...ffenh/bayes.py

In this module i define four classes.
- cdp (conditional probability [distribution]) consisting of cdp_entry
objects
- graph ( a graph class )
- bayesNet ( the bayesian network, a subclass of graph )
My problem is the following:
I have a global method test() in the module, where i want to test my
implementation of the em-learning algorithm, for learning parameters in
a bayesian network.
When I import this module in the python environment and then run the
test method, everything seems to be ok, and the calculations that are
hardcoded in this method seems to be correct.
In the test method i instantiate a bayesNet object for the further
calculations.
The results that are computed and printed are probability distributions
in the bayesian network, but this is not important for the problem.
The problem comes when i want to run the test method again for a second
time. What happens is that the "same" expressions/computations listed
in the test method leads to another results, even if the commands are
the same.
I can only imagine that this comes out of some objects that are not
destroyed and influence the new bayesNet object that is created there.

If there is a problem with the instantiations, it is in the test method
which is at the end of the file bayes.py (see above)
Does someone see the problem there???

If you need some more information about what happens in the module
please write me a mail, but i hope the comments are enough to understand
the problem.

If you think this is too much off-topic we can discuss the problem out
of the newsgroup.

thanks in advance,
Felix Steffenhagen
Jul 18 '05 #1
2 2198
Felix Steffenhagen wrote:
[snip]
In: http://www.informatik.uni-freiburg.d...ffenh/bayes.py [bayes.test gives different results each time it is called]


Without looking in the slightest at what you are implementing or how, this
implies that state is maintained between calls to test

The question is where/how is the state maintained?

1) global module variables? - you don't have any
2) attributes of global objects?

I used:
def attrs(obj): ... return dict((name,getattr(obj,name)) for name in dir(obj) if not
callable(getattr(obj, name)) and name not in ("__doc__","__module__"))

to verify that the classes are not gaining (non-callable) attributes

3) as mutable default parameters?

See:
line 135: def __init__(self,V,E,p=[]):
line 150: def generate_cpd(self,node, rest, values={}):
line 360: def computeJPD(self, rest, values={}):

I guess one (or more) of these is the culprit

Before running:

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information. bayesNet.generate_cpd.func_defaults ({},) bayesNet.__init__.func_defaults ([],) bayesNet.computeJPD.func_defaults ({},) test() V = {'a': [0, 1], 'b': [0, 1]}
[snip results]

After test:
bayesNet.generate_cpd.func_defaults ({'a': 1, 'b': 1},) bayesNet.__init__.func_defaults ([],) bayesNet.computeJPD.func_defaults ({'a': 1, 'b': 1},)


HTH

Michael
Jul 18 '05 #2
The default mutual parameters in the method bayes.generate_cpd(...)
was the problem, thanks alot for the hint and for this code snippet
to find such problems :-).

Greetings,
Felix

Michael Spencer wrote:
Without looking in the slightest at what you are implementing or how,
this implies that state is maintained between calls to test

The question is where/how is the state maintained?
.
.
.
3) as mutable default parameters?

See:
line 135: def __init__(self,V,E,p=[]):
line 150: def generate_cpd(self,node, rest, values={}):
line 360: def computeJPD(self, rest, values={}):

I guess one (or more) of these is the culprit

Before running:

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> bayesNet.generate_cpd.func_defaults ({},) >>> bayesNet.__init__.func_defaults ([],) >>> bayesNet.computeJPD.func_defaults ({},) >>> test() V = {'a': [0, 1], 'b': [0, 1]}
[snip results]

After test:
>>> bayesNet.generate_cpd.func_defaults ({'a': 1, 'b': 1},) >>> bayesNet.__init__.func_defaults ([],) >>> bayesNet.computeJPD.func_defaults ({'a': 1, 'b': 1},) >>>


HTH

Michael

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Glenn Serpas | last post by:
I have Class A and Class B .. Class B has a private member that is a pointer to a Class A object. private: B *mypointer ; I instantiate the A object A* myobject new = A();
16
by: gabon | last post by:
Due a big project I would like to create different javascript classes and assign them to divs. But how? :) I know the usage of prototype but given that this could be possible: function...
9
by: the_grove_man | last post by:
I guess my question can go in two directions. I create applications that run multiple queries against a database. Generally speaking in the past I have used a Data Control (calling it dat1)...
0
by: jason | last post by:
i have classic ASP code that is calling a C# class library, which is wrapped for COM interop, and registered in the COM+ MMC. i have written 3 objects for the class library so far, and all three...
14
by: Ray5531 | last post by:
I have a console application in my local computer which I like to use remoting in it,to instanciate an object (MyClass.dll) in a web application(its bin folder) in a completely seperated box(in the...
7
by: J-T | last post by:
I can instantiate my object in my *ASP.NET* application in two ways: A) public sealed class RSSingleton { private static ReportingServiceProxy m_RsProxy=null; static RSSingleton() {...
6
by: Chris Kennedy | last post by:
I have a dataset, datatable and data row which I have declared public in my class. I instantiate them in one sub routine and go to use them again and I get an 'Cannot find table 0' wrror Public...
1
by: Donald Westfield | last post by:
I have my own module, called mystuff.py, which is to be imported for an app. The number of classes in the module will vary, so I need a subroutine that will instantiate all of them as objects,...
4
by: Tomas | last post by:
A newbie question: How can I instantiate objects dynamically in VB.NET. E.g. I have the object 'Player' and I would like to instantiate it with the several instances (James, Gunner, etc.), without...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.