Project Orbiter Galaxy

:lol:

I do have the feeling that he did that on purpose...

Any results of testing the rocky and martian planets already?

I'm not sure if its helpful, but this has some info that seems close to what you are working on?

I have gone through quite some similiar tutorials on the subject, but with my low level of education it would take me several weeks, learning the whole subject from the start, to really comprehend and solve the thing. As it is, my father in law has already come forth with an equation, Now I'm waiting for an answer from him to explain a few details in the notation I don't understand... yeah, it sucks to suck at math. The link you posted is a great read none the less.
 
Last edited:
It seems that using the latest Windows version of Spaceway under Wine that all planets have their textures generated properly.
 
My probability calculations are finally succesfull, thanks to my father in law who worked out the equations for me.

Now I'm running into another problem, which is that these equations calculate with faculties... and faculties can get absolutely freaking huge. Since I have a maximum of 1000 stars per cube, that's a maximum of 1000 checks to do. And the faculty of 1000 is a LOT too large even for a long double to handle. Looks like I'll have to split up the probability calculations into nice little bits. I hope that won't slow the generation down too much...
 
My probability calculations are finally succesfull, thanks to my father in law who worked out the equations for me.

Now I'm running into another problem, which is that these equations calculate with faculties... and faculties can get absolutely freaking huge. Since I have a maximum of 1000 stars per cube, that's a maximum of 1000 checks to do. And the faculty of 1000 is a LOT too large even for a long double to handle. Looks like I'll have to split up the probability calculations into nice little bits. I hope that won't slow the generation down too much...

"Faculty" actually only corresponds to German "Fakultät" in the educational sense (Fachbereich, Lehrkörper). The English word for the mathematical sense of "Fakultät" is "Factorial".

Is there any canceling you can do in the equations? (For example, with 50 ! / 45 !, you only need to calculate 46 * 47 * 48 * 49 * 50, since the 1 * 2 * ... * 45 on either side of the division cancels out).
 
Use AlgLib or CEPHES libraries. They do simplify working out the Gamma function. For large numbers and probabilities edging away from zero and unity the binomial can be approximated by a normal (Gaussian) p.d.f.
 
"Faculty" actually only corresponds to German "Fakultät" in the educational sense (Fachbereich, Lehrkörper). The English word for the mathematical sense of "Fakultät" is "Factorial".

ooops...

Is there any canceling you can do in the equations? (For example, with 50 ! / 45 !, you only need to calculate 46 * 47 * 48 * 49 * 50, since the 1 * 2 * ... * 45 on either side of the division cancels out).

yes, but it's a bit more complicated. That part of the equation looks as follows:
n! / (x! * (n-x)!). x starts as 1 and then grows until the probability gets higher than the random number generated, I don't think it should ever get much higher than 500...

The first Idea I had is that maybe x! * (n-x)! = (x * (n-x))!, but after a test it turns out this is not so. Is there a way to simplify x! * (n-x)! ? If not, I gues I cannot simplify the whole part...

Use AlgLib or CEPHES libraries. They do simplify working out the Gamma function. For large numbers and probabilities edging away from zero and unity the binomial can be approximated by a normal (Gaussian) p.d.f.

your advice is welcome, but as most of the time I don't understand half the words you are using :lol:

I don't even have a high school grade, so be patient.

The trouble here is that some probabilities I'm working with are quite low (well below 1e-5) and will generally be converging towards zero the longer the algorithm runs. Since you said your suggestion's good for probabilities edging away from 1, I take that as a bad sign.
 
Ahh, I'll have a look to see what I can do to help you. Meanwhile, take time to talk to your FiL, as much as you can and as often as possible, not pestering him about probabilities (that's too direct!) but about his branch of mathematics. Poisson approximation (with lambda = number of stars in the sample * probability of single event) is what you're looking for BTW.
 
n! / (x! * (n-x)!). x starts as 1 and then grows until the probability gets higher than the random number generated, I don't think it should ever get much higher than 500...
Well, what are n and x?
Basically, you have:
1*2*3*4*5*...*n
--------------------------------------
1*2*3*4*5*...*x*1*2*3*4*5*...*(n-x)
Should be easily shorten out if the numbers are close.
 
that is pretty clear, the problem is that if n (number of stars) is too high, even a long double is too small to contain the result. The easiest solution will probably be to cut the whole thing into pieces, and instead of n = 1000 the algorithm is run two times with n = 500 instead, or three times with n = 333 if 500! should turn out to be too large too...
 
Hm. Which page of the thread describes what this math is all about?
 
the last one, I think...

Anyways, here's a short summary: I'm rewriting the star generator, because in order to make the pathfinding work I have to have a possibility to quickly check what kind of stars are located in a region without creating the entire region first.

Before, every Star would generate a random number, and then assign a mass to it based on that random number and some probabilities derived from the initial mass function. In other words, I know the probabilities that a star would come out as 90 solar masses, or 60, or whatever, but no way of knowing wheather that region would contain any stars of higher mass ranges without generating the entire region first.

Now I'm switching it around. The generator generates a random number between 0 and 1, and then calculates the probability of at least one star of mass 90 or above occuring in that region. If the random number is lower than that probability, the algorithm goes on and calculates the probability that there be at least two stars above 90 in this region. It goes on as long as the probability is larger than the random number, and quits as soon as the probability falls below. The generator then knows how many stars of 90 or more solar masses it has to generate in this region. Repeat for other mass steps to generate the whole region.

So if the pathfinding is checking a region for a star of a certain mass (because jump distances are depending on mass), it can easily check wheather there are stars in the mass region it is looking for (if it finds one it still has to walk it through the evolution cycle to see if it is still that mass at the time, but that doesn't take too long if it has only to be done with a few stars).

The problem was to find an equation that allows me to calculate the probability that at least x stars are formed in a region containing n stars. As I said, the probability p that a star turns out a certain mass I already had.

That equation was provided by my father in law, and looks as follows:

pE = n! / (x! * (n - x)!) * q^(n-x) * p^x;
pT = Sum[pE(n,1)...pE(n,x)];

pE is the probability that exactly x out of n stars will be in that mass range.
pT is the probability that AT LEAST x out of n stars will be in that mass range, so the result I need in the end.

p is the probability of getting a star in that mass range with n = 1, q is 1 - p.

The whole thing is working very decently, up to the point where n! is too big for any data type to handle. As I said, the most simple solution seems to be to cut n into smaller pieces and run the algorithm multiple times. A bit of performance loss, but a sure-fire way.
However, If there is a way to simplify n! / (x! * (n-x)! so n! doesn't have to be calculated in the first place, that would solve the problem more efficiently.

n has a maximum value of 1000, by the way.

---------- Post added at 05:50 PM ---------- Previous post was at 05:33 PM ----------

I just ran the checks, it turns out that the maximum value for n is only 170. n! is then 7.2574156153079940e+306. At n = 171, even a long double returns #INF. That would mean cutting the process up into quite small pieces, so that the algorithm has to run 6 times when n = 1000. That'd be a bit more of a performance drop than I expected, but still doable, since I can run them parallel (i.e. I don't have to calculate all the probabilities 6 times, I only have to generate six random numbers. It's a bit of a bummer none the less, so if there's any way to circumvent calculating n!, it would be a much better solution...)
 
Last edited:
I asked my Dad, and he thought that the results can probably be taken from Pascal's triangle, which, looking things up on Wikipedia, seems to be true. http://en.wikipedia.org/wiki/Pascal's_triangle

I did take a course in Discrete Mathematics last year, but it was all in German and I think I got rid of my notes. This all did seem vaguely familiar though...
 
Indeed, my father in law mentioned Pascals triangle in his explanation of the equation, but I didn't pay it much heed...

n! / (x! * (n - x)!) is in fact the binomial coefficient (whatever that exactly means, but that's not too important, all I need is an alternate way to calculate it). So, what I have to do is... errr... somehow create Pascals triangle and skip down along it until I find the right place...? Should be doable, but won't come easy to a n00b like me. Let's see if I can get it to work...
 
Repeat: you don't need to calculate binomial coefficients. If the probability is low, you can approximate the binomial probability distribution by Poisson:

The Poisson distribution is used to model the number of events occurring within a given time interval.

p(x, lambda) = exp(-lambda)*pow(lambda, x)/factorial(x)

lambda in your case is equal to the number of stars in the sample times the probability of a single star having a given property.

EDIT: x will be usually small, so it won't be subject to overflow in the factorial.
 
Thanks, I had a look at the Poisson equation. Problem is, I don't know how suitable it is, because I don't ONLY have low probabilities. I'll have very low probabilities for higher masses, while below 2 solar masses the probability will start at allmost 1...
 
Indeed, my father in law mentioned Pascals triangle in his explanation of the equation, but I didn't pay it much heed...

n! / (x! * (n - x)!) is in fact the binomial coefficient (whatever that exactly means, but that's not too important, all I need is an alternate way to calculate it). So, what I have to do is... errr... somehow create Pascals triangle and skip down along it until I find the right place...? Should be doable, but won't come easy to a n00b like me. Let's see if I can get it to work...

It's simple addition: Each cell C(n, x) in Pascal's triangle can be calculated with C(n, x) = C(n-1, x-1) + C(n-1, x) For every n and x that is greater than 0, and

C(n, 0) = 1 for all n
C(0, x) = 0 for all k > 0


So, Java-ish pseudocode:

Code:
public int getPascalCell(int n, int x)
{
      if (n > 0 && x > 0)
           return (getPascalCell(n-1, x-1) + getPascalCell(n-1, x));
      else if (n == 0)
           return 1;
      else
           return 0;
}
 
I think I found a pretty decent numerical solution:

http://bytes.com/topic/c/answers/740805-binomial-coefficients

---------- Post added at 04:47 PM ---------- Previous post was at 08:28 AM ----------

YES! it works! and as a perk, that solution even requires significantly less cycles than calculating all the factorials!

And I'm finally free to go on! :tiphat:
 
Hmmm, the new generation method has some not entirely unexpected sideffects of which I have been lucky enough to find an example.

It can happen that a certain mass class gets an incredibly low roll (it's chance, after all), which means that, no matter how unprobable it is it can happen that a whole cube is populated by the same type of stars. Or at least, initially the same. I happend over a cube with nothing but white dwarfs and one lonely B-star. It wasn't hard to guess what the remnants where before they got their aging....

I'll have to find some sensible saveguards for this kind of stuff. A first sensible saveguard would undoubtedly be to exclude the number 0 from the roll, but I'm not sure if that'll be enough.
 
Back
Top