Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 103 104 [105] 106 107 ... 173

Author Topic: Mathematics Help Thread  (Read 228637 times)

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: Mathematics Help Thread
« Reply #1560 on: May 08, 2014, 02:34:10 am »

(exp(i*360°/n)-1) != 0
For n > 1.

[/nitpicking] :D
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

frostshotgg

  • Bay Watcher
  • It was a ruse
    • View Profile
Re: Mathematics Help Thread
« Reply #1561 on: May 08, 2014, 08:33:59 am »

Thanks for the explanations guys, it actually makes a lot of sense.
Logged

ZetaX

  • Bay Watcher
    • View Profile
Re: Mathematics Help Thread
« Reply #1562 on: May 09, 2014, 12:21:10 pm »

If f(x)=x^n+a_1·x^{n-1}+...+a_n is any monic polynomial, then -a_1 is the sum of its roots and (-1)^n a_n is their product by Vieta (who gives you several more fomrulas for the other coefficients). Use that on f(x) = x^n - a to see that the n-th roots of a sum to zero unless n=1.
Logged

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: Mathematics Help Thread
« Reply #1563 on: June 03, 2014, 05:27:06 am »

First off, I'm not sure whether to post this here or in the coding thread.

Anyways, onto my little complex problem.

The statement is simple, but execution is far from it AFAIK.
Basically, I want to generate a probability mass function. The probability concerns the following:

Say you have n∈ℕ\{0} events and you want to know what the probability of x events occurring is where 0 <= x <= n. Each event is a binary choice of true and false. The kicker? The probability of it being true follows an arbitrary probability sequence pk where 1 <= k <= n is the occurrence index. In other words, if we call each event Uk∈{0,1} then P(Uk = 1) = pk.

So, if X = U1 + U2 + ... + Un, then the probability mass function is f(x) = P(X = x).

Easy to state on paper, but generating the values of f(x) is a pain. Now, if pk = p where p is a constant probability, then this is a plain old binomial distribution. However,  since it's not constant, then it becomes a lot more complicated.


There are two algorithms I have that work. The first one:
  • Generate all unique permutations of x 1s and n-x 0s.
  • For each permutation i, generate a value mi = mi,n:
    • Base case: mi,0 = 1
    • Recursive case: mi,j = pj*mi,j-1 , when the jth symbol is a 1
      mi,j = (1-pj)*mi,j-1 , when the jth symbol is a 0
  • f(x) is thus the sum of all mi.

The second one:
  • Base cases:
    • mn,x,1 = pn
    • mn,x,0 = 1-pn
    • mn,v,0 = mn,w,1=  0 where {v,w} != {x,x}
    • mz,v,0mz,w,1 = 0 where v > x, w > x, and z < n
  • Recursive case:
    • mi,j,0 = (1-pi)(mi+1,j,0 + mi+1,j+1,1)
    • mi,j,1 = pi(mi+1,j,0 + mi+1,j+1,1)
  • f(x) = m1,0,0 + m1,1,1

Technically, step 1.4. isn't necessary but it's there to prevent unnecessary backtracking.

In any case, both of these have horrible computational complexities. Just for the first one, the number of permutations is n!/(x!(n-x)!) and each of them needs to be parsed so the minimum complexity is n*n!/(x!(n-x)!) which I believe is O(n*n!). Sure, easy when n is small, but I'm interested when n is around 10-100. For n = 30 I couldn't be arsed to wait any longer. 20 is the maximum I've been willing to wait.

Then to spin it around even further, say I kept x fixed but varied n? What would the probability mass function g(n) be? Is it as simple as generating all the values with f(x) where n is varied and then dividing all values with the total sum?

Is there a way to make this faster? Knowing the structures of the probability mass functions would be nice but I don't necessarily care what the functions f(x) and g(n) look like as long as I can generate the values in a reasonable amount of time.

EDIT:

Alright, I might have a solution using probability generating functions. I'm a bit unfamiliar with this field so if anyone would be willing to chip in, be my guest.

Let Uk be an indicator variable for the kth event such that Uk∈{0,1} and P(Uk = 1) = pk .
The PGF of Uk is GUk(z) = 1 - pk + pk z .

Now, let Xn = U1 + U2 + U3 + ... + Un . Since Uk are independent from each other, GXn(z) = GU1(z)GU2(z)GU3(z)...GUn(z).

And boy do the tests show rapid speed increase!

From there, P(Xn = x) = (dx/dzx)GXn(z)/x!
which should be easier to manage and give a representation of the probability mass function.
« Last Edit: June 03, 2014, 09:14:15 am by da_nang »
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: Mathematics Help Thread
« Reply #1564 on: June 03, 2014, 01:18:51 pm »

As I understand it, your problem is as follows: Given n biased coins, each of which has its own probability pi to land on heads, what is the probability of landing exactly k heads if you throw all of them once? Math says the following: Let p(n,k) be the probability of throwing k heads with the first n coins. Then p(n,k)=pn*p(n-1,k-1)+(1-pn)*p(n-1,k). With a direct recursion, you'll get O(2^n) recursive calls, which you don't want. But if you use memoized recursion, you'll only get O(k(n-k)) calls, which is obviously much better.
The probability mass function approach is actually isomorphic to the memoized recursion, except it can have a little unnecessary overhead (it's O(n^2)) when your k is much smaller or only a little smaller than your n. If k << n, you can throw away all monomials of degree > k when calculating GXn. If n-k << n, you can transform the problem by replacing all pi by 1-pi and then calculating p(n,n-k) instead of p(n,k), basically you count tails instead of heads.
Logged

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: Mathematics Help Thread
« Reply #1565 on: June 03, 2014, 04:31:10 pm »

I'll have to program that into Matlab tomorrow, then! :D

Looking closer into the problem, it seems a Poisson Binomial distribution is at work here as the PGFs are identical. Now if only it had a neat closed-form PMF...
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: Mathematics Help Thread
« Reply #1566 on: June 07, 2014, 10:27:22 am »

Quick question:

If one shone a flashlight at flat wall at an angle such that an ellipse formed with semimajor and semiminor axes a and b respectively, would the light intensity follow a bivariate normal distribution centered at the center of the ellipse with standard deviations a and b in the x and y directions respectively and truncated to within the elliptical area?
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: Mathematics Help Thread
« Reply #1567 on: June 07, 2014, 10:41:21 am »

Nope. First of all, you're talking about irradiance, not intensity. Second, the closer half of the ellipse would get more light than the further half. Third, flashlights usually have a really weird light distribution (if you shine it directly at a wall, you get rings of brighter and less bright areas).

Here's a formula to help you calculate the irradiance from a point light source onto a specific point on a wall: Ee = Iecos(α)/r2, where Ee is the irradiance, Ie is the radiant intensity (the "brightness" of the torch in that direction), r is the distance, and α is the angle of incidence onto the wall.

Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Mathematics Help Thread
« Reply #1568 on: June 10, 2014, 12:57:04 am »

Is finding f(t) from this equation:

f'(t) = F/m0 * 1/sqrt (1-(f(t))2/c2)

possible? O_o
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

frostshotgg

  • Bay Watcher
  • It was a ruse
    • View Profile
Re: Mathematics Help Thread
« Reply #1569 on: June 10, 2014, 01:30:43 am »

If I understand the way that's written correctly, flip everything over, divide by m0/F, then clean up a bit from there. I think your final answer will come out as +- f(t) because of square roots, but other than that it'll work. That looks vaguely like a physics equation, so you can just apply logic to determine the sign.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Mathematics Help Thread
« Reply #1570 on: June 10, 2014, 01:44:33 am »

But isn't it a differential equation? Don't you need to integrate somewhere?
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

frostshotgg

  • Bay Watcher
  • It was a ruse
    • View Profile
Re: Mathematics Help Thread
« Reply #1571 on: June 10, 2014, 02:05:43 am »

If you just want to solve for f(t), I don't think so. You'd have to integrate somewhere if the equation had d(whatever) somewhere in it. It's hard to tell in just a single line of text the way things are laid out.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Mathematics Help Thread
« Reply #1572 on: June 10, 2014, 02:26:48 am »



Is that better? :D Here, F, m0, and c are all constants. The right side is the derivative of f(t), and the left side has f(t).
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

frostshotgg

  • Bay Watcher
  • It was a ruse
    • View Profile
Re: Mathematics Help Thread
« Reply #1573 on: June 10, 2014, 02:49:15 am »

Ah. That's much clearer. Yeah, I'm gonna let someone else explain it. If you just want the answer I can give it to you, but I suspect you want a thorough explanation and I'm terrible at explaining that particular part of calculus.
Logged

crazysheep

  • Bay Watcher
  • [PREFSTRING:fluffy wool]
    • View Profile
Re: Mathematics Help Thread
« Reply #1574 on: June 10, 2014, 03:09:40 am »

That looks like you need to solve a nonlinear differential equation..
Logged
"Don't be in such a hurry to grow up, for there's nothing a kid can't do."
Pages: 1 ... 103 104 [105] 106 107 ... 173