-
Notifications
You must be signed in to change notification settings - Fork 154
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
Questions about explicit sampling #726
Comments
Hi,
First, that warning has been changed in more recent versions of Figaro, and it’s much more informative now ☺
Second, the function you mention below shouldn’t be triggering that warning. That warning comes when you try to use a factored algorithm on a model with continuous elements, in which case the continuous ones are sampled.
The function you have below seems to be fine. Drawing the samples one at a time or all at once shouldn’t matter as long as the mean/std stay the same (FYI, the parameter to the Normal in Figaro is variance, not standard deviation).
+ + + + + + + + + + + + + +
Brian Ruttenberg, PhD
Senior Scientist
Decision Management Systems Division
Government Services
Charles River Analytics Inc.
617.491.3474 x730
www.cra.com<http://www.cra.com/>
From: toncho11 [mailto:[email protected]]
Sent: Friday, October 27, 2017 10:36 AM
To: p2t2/figaro <[email protected]>
Cc: Subscribed <[email protected]>
Subject: [p2t2/figaro] Questions about explicit sampling (#726)
Hi,
Two questions:
1. I get this warning: Warning: Sampling element Normal(200.0, 50.0) even though no sampler defined for this universe.
Is this a problem?
2. I use this function:
def GetSampleFromNormal(mean : Int, std : Int): Long =
{
val sample = Normal(mean,std);
Forward(sample);
println("system: wait time ms: " + sample.value.toLong.toInt);
return sample.value.toLong;
}
but I wonder does it make a difference if I
* I call the function GetSampleFromNormal from time to time
* I draw the samples just one time without leaving the function GetSampleFromNormal
In the second case I am sure I will get a Normal distribution with parameters specified, but when calling the function GetSampleFromNormal the way it is coded now I am not sure.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<#726>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AFJOJanLfD5YkuzT7dOgMq8g1aI4nLhCks5swepGgaJpZM4QJJxJ>.
|
Hi, Thanks for your quick reply. Sure it is the variance. Yes, I am using a factored algorithm in this universe to calculate the probabilities of a Bayes Net. All my variables are of type Flip in my model. I am using: VariableElimination.probability(e.probVariable, true) for each variable in my Bayes net. Is there a more optimized way to calculate the probabilities of several variables all-together? And I am also drawing samples from a Normal distribution. |
Yes, you can say:
Val alg = VariableElimination(target1, target2, etc)
Alg.start()
Alg.probability(target1, true)
Not clear to me what the normal is doing, but if you’re using a factored algorithm that’s where the warning is coming from.
+ + + + + + + + + + + + + +
Brian Ruttenberg, PhD
Senior Scientist
Decision Management Systems Division
Government Services
Charles River Analytics Inc.
617.491.3474 x730
www.cra.com<http://www.cra.com/>
From: toncho11 [mailto:[email protected]]
Sent: Friday, October 27, 2017 3:30 PM
To: p2t2/figaro <[email protected]>
Cc: Brian Ruttenberg <[email protected]>; Comment <[email protected]>
Subject: Re: [p2t2/figaro] Questions about explicit sampling (#726)
Hi,
Thanks for your quick reply. Sure it is the variance.
Yes, I am using a factored algorithm in this universe to calculate the probabilities of a Bayes Net. All my variables are of type Flip in my model. I am using:
VariableElimination.probability(e.probVariable, true)
for each variable in my Bayes net. Is there a more optimized way to calculate the probabilities of several variables all-together? And I am also drawing samples from a Normal distribution.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#726 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AFJOJWlUzFYEQA-lukOvmiYErXQkiy1Dks5swi8ogaJpZM4QJJxJ>.
|
I still do not understand if the warning is important. It seems like it is not possible instead of: target1, target2, to give a: val list = scala.List[com.cra.figaro.language.Element[_]] ? |
Generally, you shouldn't use If you want to round the value of a Normal to an integer, as you do in your For example, you could do: def makeRoundedNormal(mean: Int, variance: Int) : Element[Int] = {
val n = Normal(mean, variance)
def round(d: Double) = d.toInt
val nRounded= Apply(n,round)
nRounded
}
|
Also - You can convert a collection to a variable length list of arguments. So you could do something like: val targets = List(target1,target2,target2)
val algorithm = VariableElimination(targets:_*)
...
targets.map{ t => algorithm,probability(t,true) } |
Thanks! It helps! For the Normal dist sampling: if I use the expected value ... I still get a double value that I need to round ... so it is better to use the MPV. I consider the Most Probable Value = Most Likely Value. So this is the final version with MPV (Most Probable Value)
Is it OK? It feels a bit heavy all this. Actually there is a slight difference between expected value and most likely value. And for the Flip:
Should it be improved in a similar way as for the normal? I think it is correct (see above) because the output of Flip is discrete already (true or false). |
Hi,
Two questions:
I get this warning: Warning: Sampling element Normal(200.0, 50.0) even though no sampler defined for this universe.
Is this a problem?
I use this function:
def GetSampleFromNormal(mean : Int, std : Int): Long =
{
val sample = Normal(mean,std);
}
but I wonder does it make a difference if I
In the second case I am sure I will get a Normal distribution with parameters specified, but when calling the function GetSampleFromNormal from time to time the way it is coded now I am not sure.
The text was updated successfully, but these errors were encountered: