-
Notifications
You must be signed in to change notification settings - Fork 30
Gibbs sampling #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Gibbs sampling #305
Changes from all commits
aad5c7b
4558c26
d4f1d5e
087cf73
f43e507
b709417
8e1ebba
7797293
dcec610
ff71de7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,27 +37,76 @@ | |
|
||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.LinkedList; | ||
import java.util.Map; | ||
|
||
import blog.common.DefaultDGraph; | ||
import blog.common.DefaultDGraph.NodeInfo; | ||
import blog.common.Util; | ||
import blog.sample.TraceParentRecEvalContext; | ||
import blog.world.PartialWorld; | ||
|
||
/** | ||
* This class provides a default implementation of CBNs. Over the next few weeks, | ||
* all inference algorithms will be modified to use CBNs. | ||
* This class provides a default implementation of CBNs. | ||
* Uses a DefaultCBN rather than a DefaultDGraph, so as to avoid | ||
* ClassCastExceptions. | ||
* | ||
* @author Da Tang | ||
* @since Sep 7, 2014 | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. author? |
||
|
||
public class DefaultCBN extends DefaultDGraph implements CBN { | ||
/** | ||
* Uses a DefaultCBN rather than a DefaultDGraph, so as to avoid ClassCastExceptions | ||
*/ | ||
public Object clone() { | ||
DefaultCBN clone = new DefaultCBN(); | ||
clone.nodeInfo = (Map) ((HashMap) nodeInfo).clone(); | ||
for (Iterator iter = clone.nodeInfo.entrySet().iterator(); iter.hasNext();) { | ||
Map.Entry entry = (Map.Entry) iter.next(); | ||
entry.setValue(((NodeInfo) entry.getValue()).clone()); | ||
} | ||
return clone; | ||
} | ||
/** | ||
* clone method for the class Default CBN. | ||
*/ | ||
public Object clone() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment??? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the purpose of clone??? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the comment seems strange There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not written by me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry. but please fix. |
||
DefaultCBN clone = new DefaultCBN(); | ||
clone.nodeInfo = (Map) ((HashMap) nodeInfo).clone(); | ||
for (Iterator iter = clone.nodeInfo.entrySet().iterator(); iter.hasNext();) { | ||
Map.Entry entry = (Map.Entry) iter.next(); | ||
entry.setValue(((NodeInfo) entry.getValue()).clone()); | ||
} | ||
return clone; | ||
} | ||
|
||
@Override | ||
public boolean isContingentOn(PartialWorld world, BayesNetVar X, | ||
BayesNetVar Y, BayesNetVar Z) { | ||
TraceParentRecEvalContext context = new TraceParentRecEvalContext(world); | ||
if (Z instanceof VarWithDistrib) { | ||
((VarWithDistrib) Z).getDistrib(context); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no use? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will be used sometimes. |
||
} else if (Z instanceof DerivedVar) { | ||
((DerivedVar) Z).getValue(context); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no use? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used. |
||
} else { | ||
return true; | ||
} | ||
|
||
LinkedList<BayesNetVar> parentTrace = new LinkedList<BayesNetVar>(); | ||
parentTrace.addAll(context.getParentTrace()); | ||
|
||
int x = parentTrace.indexOf(X), y = parentTrace.indexOf(Y); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to put in two lines There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean two empty lines? |
||
if (x < 0 || y < 0) { | ||
return false; | ||
} | ||
if (X instanceof NumberVar) { | ||
if (x < y && world.getCBN().getAncestors(Y).contains(X)) { | ||
if (Util.verbose()) { | ||
System.out.println("\t Contingent relations type 1: " + X.toString() | ||
+ " " + Y.toString() + " " + Z.toString()); | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
if (x < y) { | ||
if (Util.verbose()) { | ||
System.out.println("\t Contingent relations type 2: " + X.toString() | ||
+ " " + Y.toString() + " " + Z.toString()); | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment?