Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Bayesian network: Please am currently doing a project on bayesian networks in java and am stuck on how to calculate p(a|b) because from a questionnaire, i only have the values of p(a), p(b). Please anyone with experience in this field can help me out. websites that i checked required that i have the value of p(anb). How do i calculate p(anb) in this case since the probabilities if a, b were calculated from a questionnaire Please anybody help me out and i have to calculate this p(a|b) for several variables. I would really appreciate if anyone helps me out. Thanks
Bayes' theorem states that the probability of A given B, P(A|B), is equal to the probability of both A and B occurring, P(A∩B), divided by the probability that B occurs, P(B).
That is,
p(A|B) = P(A∩B) / P(B)
Now, P(A∩B) is equal to the probability of B given A, P(B|A), times the probability of A, P(A).
That is,
P(A∩B) = P(B|A) x P(A)
In your experiments, P(B|A) should already be known from your sample. That is, of the total population of A, how many samples correspond to B.
This would give the final formula,
p(A|B) = [P(B|A) x P(A)] / P(B)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
To help Beta Rabbit crack the lock, write a function answer(n) which returns the smallest positive integer base b, at least 2, in which the integer n is a palindrome. The input n will satisfy "0 <= n <= 1000."
Test cases
Inputs:
(int) n = 0
Output:
(int) 2
Inputs:
(int) n = 42
Output:
(int) 4
it is not the problem I need help with as there are similar ones on this site. It is the actual question. this input n they talk about, what the hell does it stand for? It can't be the base as b represents the base. It is not the positive integer they want for output because it is independent of that number and in the test cases it doesn't seem to have any correlation with it. Does it just want me to find the smallest palindrome of any base that's less than 1000 in decimal? Thanks to anyone that takes the time to help me figure this out , it's part of Google's foobar questions. I don't mind doing the work to solve the flecking thing as long as I can understand what the thing is asking.
What is Google Foobar?
I may not give you a full answer, but think about it this way. The number n, convert it to the output base... see if it's a palindrome
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How to round up a decimal number to a whole number?
So for example when it is 1.25 rounds to 1 or -3.25 rounds to -3 etc
if you want decimal part do this .
double value = 1.25;
int i = (int)value;
if you want to round value , do this
Math.round(value);
Use Math.round(float number) method http://docs.oracle.com/javase/6/docs/api/java/lang/Math.html#round(float) if you want to round it. If you want to cut decimal part just cast it to int.
A small trick I've learned during the years is just adding the value 0.5 to the value you want to round. After you did that, you can round it to an integer.
It's a generic workaround, which will work with alot of programming languages.
I dont know much about Java, but I think you will find a round-Method in the API. The package should be Math.
Edit:\
To round UP you could just add 1 instead of the value 0.5.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
How many digits System.nanoTime() produce. Whether these digits are fixed or can vary in count?
Thanks
System.nanotime returns a high-resolution clock value from your system. It does not have any kind of defined interpretation other than that if you take the difference between the return value from two separate calls to System.nanotime, you will get an approximate number of nanoseconds that elapsed between those calls.
So the number of digits is not fixed, because there is no specific format for System.nanotime's value, and there is no meaningful way to interpret it. Only use the difference between two calls to System.nanotime.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am having trouble generating this code which I'm sure I'm just in a coder's block or something because it seems as though it should be easy but can't get it for the life of me.
I have a program which needs random numbers generated within a certain range which is to represent money. The stipulation is that the money need be in between 2 and 200 and represent only even dollars only so $2, $4, $6...so on. I have done extensive searching online which yield a bounty of code to represent random numbers in a range in java but not the part about being only even.
Any ideas?
If you wanted to be clever, you could make sure the least significant bit of the number is not set:
int num = (new Random().nextInt(199) & ~1) + 2;
This will ensure that the number is always even.
Thanks Eyal Shneider and Omaha
Marcelo's comment from the OP is the correct answer, though.
Get a number between 1-100, and multiple by 2:
int num = (new Random().nextInt(100) + 1) * 2;
int rand = new Random.nextInt(200);
int result = 2;
while(result < rand) {
result += 2;
}
return result;
(I'd make it recursive but I've got to go meet my wife for dinner.)
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Sorry if that title confused you its kinda hard for me to ask this without explaining it.
I am writing a (fairly) simple program to find the roots of a quartic (biquadratic) function.
My main question (I should know this >.>) is how do i get x in the quartic function (ax^4 * bx^3 * cx^2 * dx * e = 0) to stay as x and not be given a value. just sorta a place holder. this is part of it: ( b1 * x * c1 / 2 ); so i dont want x to be replaced. i just want it to stay as x and everything else around it multiply as you normaly would when solving the problem by hand.
My second question is from this site:
http://easycalculation.com/algebra/learn-quartic-equation.php
We haven't covered Quartics in school yet but We have covered cubics and quadratics so I know enough that i can follow a long for the most part except for right after it talks about the discriminant.
y2=(- term1 + r13*cos(q3+(2∏)/3) )
y3=(- term1 + r13*cos(q3+(4∏)/3) )
i dont get the parts with 2∏ and 4∏. If you know a simple way to explain it, please do :D if not i can always look it up and try to figure it out from there.
And my last question. I know how with the discriminant of quadratics depending on what it is depends on one root, no roots, or two roots. How does that apply with quartics and what should i do to check for that in my code (if you think i cant figure it out lol).
ummm i believe thats it. i can add info if needed. I dont think my code would be needed but i would prefer not to post it either way.
Thanks for the help.
-Ryan
The approach cited relies on a trigonometric identity described here used to solve cubic equations. The symbol ∏ is a capital π, or Math.PI in Java.
See also this example that uses org.jscience.mathematics.function.Polynomial and references a convenient root-finding algorithm.
The approach that you are looking for is called Symbolic Programming.
I do not, however, know of any stable Java libraries which allow for such programming.