PDA

View Full Version : Weird Maths / Averages Help



Absol197
2016-10-02, 10:49 AM
Hello all! I have a very odd question, that is also probably somewhat difficult to calculate because of all the different factors that go into it, but I was hoping that at least one of you amazing mathematical types might be able to help me get close to an answer!

Basics of the situation: I have a rather unique population. This population consists of 3,038 beings, and when they die, they reincarnate again. As they reincarnate more and more, they grow more powerful, moving through approximately four levels of power. However, after a certain number of reincarnations, they eventually die permanently, and a new member of the population is created, starting over at the base-line of power.

My goal is to determine, on average, how many members of this population are in each relative level of power, and what the average number of past lives is across the population. I am aware that this will be in constant flux as members are "born," live, die, and new members are occasionally added to replace ones that are lost, but that's why I'm working with averages and probabilities :smalltongue: .

So, numbers! I don't like the new table system on the forums, so I'm going to not be using it, but things aren't too complicated.


Number of Past Lives - Average Power Level - Chance of Reincarnation
0 - 1 - 1
1 - 1 - 1
2 - 2 - 1
3 - 2 - 1
4 - 2 - 1
5 - 3 - 1
6 - 3 - 1
7 - 3 - 1
8 - 3 - 0.9829
9 - 4 - 0.5905
10 - 4 - 0.1770
11 - 4 - 0.0378
12 - 4 - 0.0045
13 - 4 - 0.0001
14 - 5 - 0

Power Level - Average Life Span
1 - 196.13 years
2 - 221.72 years
3 - 274.91 years
4 - 338.26 years
5 - 420.82 years

To simplify, the standard deviation of lifespan is about 5% of the average. Additionally, this is of course assuming that the entire population only dies of old age. While they are much less likely to die of other causes than normal, it is certainly not impossible. Unfortunately, I don't have any idea how to factor early deaths in to the scenario...

So! Ideas on how to go about calculating this? Or is there anyone intrepid enough to calculate it for me (and tell me how you did it)?

Many, many thanks in advance :smallsmile: !

EDIT: Obviously, just looking at things on the surface, the general trend would be for the majority of the population to be of power level 3, with a small number of 1s and 2s for new members rising up the scale, and a small number of 4s at the top who are balancing precariously around their final death. If there is a 5, it is almost certainly the sole 5.

However, I am a very precise person and I want MOAR DETAILS! Unfortunately, my desire for precision outpaces my ability to procure it from numbers :smalltongue: !

jayem
2016-10-02, 01:17 PM
Number of Past Lives - Average Power Level - Chance of Reincarnation
0 - 1 - 1
1 - 1 - 1
2 - 2 - 1
3 - 2 - 1
4 - 2 - 1
5 - 3 - 1
6 - 3 - 1
7 - 3 - 1
8 - 3 - 0.9829
9 - 4 - 0.5905
10 - 4 - 0.1770
11 - 4 - 0.0378
12 - 4 - 0.0045
13 - 4 - 0.0001
14 - 5 - 0

Power Level - Average Life Span
1 - 196.13 years
2 - 221.72 years
3 - 274.91 years
4 - 338.26 years
5 - 420.82 years


Well at equilibrium (if it occurs) the numbers moving into a past life match the numbers moving out. I may have made a stupid error

Indeed I did.
0.0001 is 1/10000 not 1/1000 (changed sig figs)
The aforementioned confusion about generation and years,
When estimating level 4 wizards, the reincarnation rate in the same row is for when they die. I wanted the one above.

So for every Level 14 Dying(restart), there must be a Level 13 Reincarnating.
So a year group of Generation 13 is 0.0001 the size of a year group of generation 14 that is 10000
(and the scaled total number of Generation 13 is 420, the scaled total size of Generation 13 is 3380000, which is less than 1 in actual people, so they only turn up in so many years)
Similarly for Generation 12 is that divided by 0.0045giving 22,222,200

11 (48,148,100), 10 (272million), 9 (461million) 8-1 (about 500 million) [these figures are slightly out as I got confused between years and generations, but it's close enough]

However we need to get 5,000,000 level 1 wizards, so need to check that the numbers dying is similar, which I feel ought to be the case regardless of the numbers.
But it might be worth checking, obviously 1 Level 14 dies, 999 Level 13 ...


It would then be worth checking what happens if you shift from that equilibrium, a population of all level 14's will restart, a population of all level 1's will eventually grow to all the other levels. So I think equilibrium will occur (it might be more odd, if the life-expectency was exact).

Also worth checking I haven't done something stupid with the numbers.

[So then obviously you need to scale for generation size, multiply by the year group, and then sum to find the total population that would have a level 14 wizard dying a year (on average). And then divide each generation size by this and times by 3036 to get the actual size.
Which pretty much gives what you expected, almost never a level 15, fairly rarely a level 13ish, having around 600 class 4's, but only 1 of them in their fourth life.

Jasdoif
2016-10-02, 02:48 PM
Well, since you didn't say whether they were all created at the same time or precisely how long they've existed...the only thing there to work with is an individual's incarnations.

So that's what I'm going to work with. On average, the amount of time a single "life" spends at an incarnation is going to be the average lifespan of that number times the chances of getting to that incarnation...which of course the product of all the probabilities of ascending from the prior incarnations. Once I have all those, I can figure out what percentage of the average "life" is spent at that age; and from there I will assume that's representative and multiply it out across the 3,038 beings, to get the most average expectation of the population.


For the last three columns: I'm guessing you'd want something like a snapshot that accounts for all 3,038 individuals, and rounding didn't produce that number exactly; so I used the largest remainder method (https://en.wikipedia.org/wiki/Largest_remainder_method) to get that total: I took the multiplied out expectations rounded down, which added up to 3,030; and then added 1 to the eight figures with the highest remainders.


IncarnationsPower LevelYears HereAscension ChanceChance of Reincarnating This FarEffective YearsAmount of LifetimeBase ExpectationExpected Pop Rounded DownEight Highest RemaindersExpectation
01196.1311196.130.0720554368218.90441704732181219
11196.1311196.130.0720554368218.90441704732181219
22221.7211221.720.0814568472247.46590194132470247
32221.7211221.720.0814568472247.46590194132470247
42221.7211221.720.0814568472247.46590194132470247
53274.9111274.910.1009981142306.83227089423061307
63274.9111274.910.1009981142306.83227089423061307
73274.9111274.910.1009981142306.83227089423061307
83274.910.98291274.910.1009981142306.8322708942306 1307
94338.260.59050.9829332.4757540.1221469723371.0825 0197193710371
104338.260.1770.58040245196.3269327370.07212778722 19.12421741442190219
114338.260.03780.102731233734.74986709440.01276661 8338.784986482338139
124338.260.00450.00388324061.31354497620.000482578 21.466072489112
134338.260.00010.0000174745828438650.00591095240.0 00002171601777698340.0065973262000
145420.8200.00000000174745828438650.00000073536539 52355270.0000000002701630284665690.000000820755280 481436000


It looks like I'd expect, the eight guaranteed incarnations are proportional to the life spans of their corresponding power levels.

219 at Reincarnation 0.
219 at Reincarnation 1.
247 at Reincarnation 2.
247 at Reincarnation 3.
247 at Reincarnation 4.
307 at Reincarnation 5.
307 at Reincarnation 6.
307 at Reincarnation 7.
307 at Reincarnation 8.
371 at Reincarnation 9.
219 at Reincarnation 10.
39 at Reincarnation 11.
2 at Reincarnation 12.
0 at Reincarnation 13.
0 at Reincarnation 14.

Or.

438 at Power Level 1.
741 at Power Level 2.
1228 at Power Level 3.
631 at Power Level 4.
0 at Power Level 5.

Absol197
2016-10-02, 03:15 PM
Most excellent! Thank you, Jasdoif!

Yes, I dowe realize now that I forgot to mention that this population has been cycling for long enough that they've reached, as nearly as possible, their "equilibrium" state.

I did not expect there to be quite that many level 4s! Also, I'm somewhat confused as to why there's such a significant jump at Reincarnation 9 (+64) when the chance of reaching that level has begun to decline. Can you elaborate on what I missed, there?

EDIT: Oh, wait, I think I see it. The population is proportional to the lifespan, and there's a bump at 9. It is decreased by not having a 100% reincarnation chance, but the chance is close enough to 1 that it really doesn't drag the number down as much.

Okay, I got it! Thanks once again for your help!

factotum
2016-10-02, 03:25 PM
Wow. If Jasdoif's numbers are correct, the odds of reaching power level 5 is more than 572 million to one against--with a population of only 3038 that isn't going to come up very often!

Jasdoif
2016-10-02, 03:37 PM
Also, I'm somewhat confused as to why there's such a significant jump at Reincarnation 9 (+64) when the chance of reaching that level has begun to decline. Can you elaborate on what I missed, there?

EDIT: Oh, wait, I think I see it. The population is proportional to the lifespan, and there's a bump at 9. It is decreased by not having a 100% reincarnation chance, but the chance is close enough to 1 that it really doesn't drag the number down as much.Exactly. The chance of reaching Reincarnation 9 is the 98.29% chance of getting there from Reincarnation 8, but since Reincarnation 9 is Power Level 4 the lifespan there is about 23% longer than at Reincarnation 8; which nets out a little under a 21% increase...as does the change between the expected populations at those reincarnations.


Wow. If Jasdoif's numbers are correct, the odds of reaching power level 5 is more than 572 million to one against--with a population of only 3038 that isn't going to come up very often!Yep! Conveniently that part of it is just multiplying all the odds together so it's easy to double-check...and neatly it comes close to 7-in-4-billion. (And consider that it takes 3848.36 years to get that far!)

Douglas
2016-10-02, 03:50 PM
For ease of calculation, let's assume there is no variation around the averages and that the population is in equilibrium. That means the number of people dying each year in any given generation equals the number being born into that generation in that year. I'll also ignore your stated population size for the moment, we can scale for that at the end. For a calculation starting point, I'll say the turnover rate of people with 14 past lives - the power level 5 rarities - is 1. 1 such person dies every year, and another is born to replace him.

With a life span of 420.82 years, that means there are 420.82 of these people at any given time. Let's just ignore that you can't actually have .82 of a person here, we're calculating averages where such fractions can be meaningful.

Now, if 1 new 14-past-lives person is born each year, that means 10,000 13-past-lives people died that year, because that's how many it takes for 1 of them to reincarnate instead of start over. And that means a population of 3,382,600 people with 13 past lives. Filling out the chart:

Number of Past Lives - Turnover Rate - Population
14 - 1 - 420.82
13 - 10,000 - 3,382,600
12 - 2,222,222 - 751,688,889
11 - 58,788,948 - 19,885,949,411
10 - 332,140,947 - 112,349,996,845
9 - 562,474,085 - 190,262,484,072
8 - 572,259,727 - 157,319,921,429
7 - 572,259,727 - 157,319,921,429
6 - 572,259,727 - 157,319,921,429
5 - 572,259,727 - 157,319,921,429
4 - 572,259,727 - 126,881,426,573
3 - 572,259,727 - 126,881,426,573
2 - 572,259,727 - 126,881,426,573
1 - 572,259,727 - 112,237,300,170
0 - 572,259,727 - 112,237,300,170

Ok, we've got a table, but is it correct? There's a consistency number to check - all of the new 0 past lives people have to come from the high generation folks who don't make it to the next past life. Well, it's the number of people dying with 14 past lives, plus the number dying with 13 minus the number reincarnated into 14, plus the number dying with 12 minus the number reincarnated into 13... Let's put that in a formula. Tn is the turnover rate for people with n past lives.

T0 = T14 + (T13 - T14) + (T12 - T13) + (T11 - T12) + (T10 - T11) + (T9 - T10) + (T8 - T9) + (T7 - T8) + (T6 - T7) + (T5 - T6) + (T4 - T5) + (T3 - T4) + (T2 - T3) + (T1 - T2) + (T0 - T1)

Hmm, rearrange the order on that...

T0 = T14 - T14 + T13 - T13 + T12 - T12 + T11 - T11 + T10 - T10 + T9 - T9 + T8 - T8 + T7 - T7 + T6 - T6 + T5 - T5 + T4 - T4 + T3 - T3 + T2 - T2 + T1 - T1 + T0

Well isn't that interesting, almost every added term is immediately cancelled by subtracting the exact same thing. Remove everything that cancels, and you get:
T0 = T0

Trivially true, so this equilibrium works full circle.

Now, to scale for your population size. My population size is 1,557,652,068,013 plus or minus a few for rounding. To get down to your population size, I need to divide by 512,722,866.

Number of Past Lives - Turnover Rate - Population
14 - .00000000195 - .000000821
13 - .0000195 - .0066
12 - .00433 - 1.466
11 - .115 - 38.785
10 - .648 - 219.1
9 - 1.097 - 371.1
8 - 1.116 - 306.8
7 - 1.116 - 306.8
6 - 1.116 - 306.8
5 - 1.116 - 306.8
4 - 1.116 - 247.5
3 - 1.116 - 247.5
2 - 1.116 - 247.5
1 - 1.116 - 218.9
0 - 1.116 - 218.9

Combining the lines that have equal power level, we get:
Power Level - Population
1 - 437.8
2 - 742.5
3 - 1227.2
4 - 630.5
5 - .000000821

A level 5 person will be born approximately once every five hundred million years on average, live for 420 years, and not be matched again for another half billion years.

Absol197
2016-10-02, 04:10 PM
*snip*

Awesome! So we've had two people coming at the question from (what looks like) two slightly different methods and getting the same numbers (within a rounding error). So that confirms that they're accurate, at least! Thanks for your help, Douglas!


Wow. If Jasdoif's numbers are correct, the odds of reaching power level 5 is more than 572 million to one against--with a population of only 3038 that isn't going to come up very often!

For a bit more background, this is not how this population is supposed to work. They are supposed to reincarnate endlessly, arriving at an arbitrarily high maximum power level (shall we call it 30? Let's call it 30; takes about 500-600 lifetimes to get there) eventually and just staying there, only requiring a new individual to start over at 0 if someone chooses not to reincarnate.

However, ~50,000 years ago, something happened and now they're in decline. The % chance of the current highest reincarnation levels is slowly decreasing based on a number of factors:

1) Time. As time passes, the higher levels become harder to reincarnate into;
2) Reincarnations. Every time someone reincarnates, the percentages slip a little;
3) New Souls. Every time someone should reincarnate but doesn't and a new soul has to be created, the percentages slip a lot;
4) Human population. As the population of humans grows, the percentages slip proportionally;
5) Knowledge. As knowledge of the force that caused this decay increases, the percentages slip exponentially.

The numbers I gave you are the best representation I could get of the modern numbers, trying as best as I could to factor in the above. The population is actually 3,039, but the individual that I left out is being purposefully exempted from this decay, at great cost and further expediting the process.

So while power level 5 is very rare now, it used to be super-common before this whole mess started :smallsmile: .

But thank you so much to everyone who did maths for me! <3 <3

~Phee~

Douglas
2016-10-02, 04:49 PM
5) Knowledge. As knowledge of the force that caused this decay increases, the percentages slip exponentially.
Well, that's a serious problem for trying to fix it.


The population is actually 3,039, but the individual that I left out is being purposefully exempted from this decay, at great cost and further expediting the process.
I'm guessing he's well above 5th level and is being held up as their great hope for reversing this mess?

Absol197
2016-10-02, 04:55 PM
Well, that's a serious problem for trying to fix it.

Yeah, pretty much :smalltongue: ! That's what you get when you're messing around with Greater Eldritch AbominationsTM that make Vacuum Metastability Events (https://en.wikipedia.org/wiki/False_vacuum) look like a flintlock pistol! It's made even worse by the fact that if you possess knowledge about this entity, that very knowledge drives you to both to spread it and to kill members of this species, thereby increasing the rate of decay...

As the SCP Foundation would say, highly contagious memetic hazards are a real...witch.


I'm guessing he's well above 5th level and is being held up as their great hope for reversing this mess?

She, and yes, she's still at the full Arbitrarily-High Power Level ("AHPL"). In fact, because of point 5, above, she's the only one who actually knows the truth of the what and why the species is dying off. They know in general terms (they linked their existence to humans, and that turned out to be a bad idea), but they don't know why, or that it's even fixable. And they're all too weak to fix it now, anyway, even if they did know how to do it.

They also don't know she's being purposefully kept at full power at their expense (although, to be fair, neither does she; their "deity," for lack of a better term, is the one doing it, and they don't talk much...or, like, at all). They expect each and every life she lives to be her last, because all the other full-power people died off pretty much right away. Of course, since her lifespans measure centuries like humans measure years, the issue doesn't come up often...

For those interested, the math you so kindly helped me with is being used for an expansion of world-building for this story (http://www.giantitp.com/forums/showthread.php?499854-I-Did-Some-Writing!-It-Has-Dragons!-Wanna-See). WARNING: Moderate-to-poor writing ahead :smalltongue: !

EDIT: Also, side question more in line with this particular slice of the forum's purpose: how frightening is the thought of a Vacuum Metastability Event? No warning, nothing we can do, and physics just reinvents itself in a way that makes it impossible for us to exist. Congrats, thanks for playing, Game Over! :smalleek:

Jeff the Green
2016-10-04, 03:37 AM
I started working on this before Jasdoif and Douglas posted their results and went about it a completely different way. I came up with basically the same numbers, so that's pretty settled.

I'm not so good with math like this, so I wrote a quick simulation using numpy.


# /usr/bin/env python
# -*- coding: utf-8 -*-

import random
import collections
import numpy

LIFESPANS = {1: 196.13,
2: 221.72,
3: 274.91,
4: 338.26,
5: 420.82}

MINIMUM_AGE = 1

POWER = {0: 1,
1: 1,
2: 2,
3: 2,
4: 2,
5: 3,
6: 3,
7: 3,
8: 3,
9: 4,
10: 4,
11: 4,
12: 4,
13: 4,
14: 5}

P_REINCARNATION = {0: 1,
1: 1,
2: 1,
3: 1,
4: 1,
5: 1,
6: 1,
7: 1,
8: 0.9829,
9: 0.5905,
10: 0.1770,
11: 0.0378,
12: 0.0045,
13: 0.0001,
14: 0}

POP_SIZE = 3038

YEARS = 100000

class Population:

def __init__(self, size):
# Individual is a 3-tuple (age, reincarnations, power, death date)
self.year = 0
p = numpy.tile((0,0,1,-1), POP_SIZE).reshape(POP_SIZE, 4)
self.individuals = numpy.where(p < 0,
numpy.random.normal(LIFESPANS[1],
LIFESPANS[1] * 0.5,
p.shape),
p)
self.individuals = self.individuals.astype(int)

def advance(self):
self.year += 1
self.reincarnate()

def reincarnate(self):
# Individuals die if their death date is after the current year
dead = self.individuals[::,3] < self.year
# Create array of probabilites of reincarantion using P_REINCARNATION
# and the number of reincarnations (column 1)
sort_idx = numpy.argsort(list(P_REINCARNATION.keys()))
idx = numpy.searchsorted(list(P_REINCARNATION.keys()),
self.individuals[::,1],
sorter=sort_idx)
p_reincarnation = numpy.asarray(list(P_REINCARNATION.values())
)[sort_idx][idx]
# Determine whether each individual can reincarnate based on
# p_reincarnation
can_reincarnate = numpy.random.rand(POP_SIZE) < p_reincarnation
# Individuals reincarnate if they've died and they can reincarnate
reincarnates = numpy.logical_and(dead, can_reincarnate)
rein_count = self.individuals[::,1]
rein_plusone = rein_count + 1
new_rein_count = numpy.where(dead, numpy.zeros(POP_SIZE), rein_count)
new_rein_count = numpy.where(reincarnates, rein_plusone, new_rein_count)
# Set the new reincarnation count
self.individuals[::,1] = new_rein_count
# get new power levels
sort_idx = numpy.argsort(list(POWER.keys()))
idx = numpy.searchsorted(list(POWER.keys()),
new_rein_count,
sorter=sort_idx)
new_powers = numpy.asarray(list(POWER.values()))[sort_idx][idx]
self.individuals[::,2] = new_powers
sort_idx = numpy.argsort(list(LIFESPANS.keys()))
idx = numpy.searchsorted(list(LIFESPANS.keys()),
new_powers,
sorter=sort_idx)
new_mean_lifespans = numpy.asarray(list(LIFESPANS.values()))[sort_idx][idx]
lifespan_factor = numpy.random.normal(size=POP_SIZE)
new_lifespans = new_mean_lifespans + 0.5 * new_mean_lifespans * lifespan_factor
new_deathdates = new_lifespans + self.year
old_deathdates = self.individuals[::,3]
new_deathdates = numpy.where(dead, new_deathdates, old_deathdates)
self.individuals[::,3] = new_deathdates




def power_count(self):
power_is1 = self.individuals[::,2] == 1
power_is2 = self.individuals[::,2] == 2
power_is3 = self.individuals[::,2] == 3
power_is4 = self.individuals[::,2] == 4
power_is5 = self.individuals[::,2] == 5
powers = numpy.array([numpy.count_nonzero(power_is1),
numpy.count_nonzero(power_is2),
numpy.count_nonzero(power_is3),
numpy.count_nonzero(power_is4),
numpy.count_nonzero(power_is5)])
return powers

def average_reincarnations(self):
re = self.individuals[::,1]
return sum(re) / len(re)

def main():
populations = [Population(POP_SIZE) for i in range(20)]
out = "year,reincarnations,power1,power2,power3,power4,po wer5\n"
for y in range(YEARS):
[pop.advance() for pop in populations]
if y % 100 == 0:

reincarnations = [pop.average_reincarnations()
for pop in populations]
av_rein = sum(reincarnations) / len(reincarnations)
proportions = [pop.power_count() for pop in populations]
proportions = numpy.sum(proportions, axis=0) / len(proportions) / POP_SIZE
print('Year ', y)
print('Average reincarnations: ', av_rein)
print('Percent power-level 1:', proportions[0])
print('Percent power-level 2:', proportions[1])
print('Percent power-level 3:', proportions[2])
print('Percent power-level 4:', proportions[3])
print('Percent power-level 5:', proportions[4])
print('')
out += "{0},{1},{2},{3},{4},{5},{6}\n".format(
y,
av_rein,
proportions[0],
proportions[1],
proportions[2],
proportions[3],
proportions[4]
)
with open('reincarnation_output.csv', 'w+') as file:
file.write(out)

if __name__ == '__main__':
main()


The results are graphed here (https://docs.google.com/spreadsheets/d/1wbbBSxVl-NPcrZOeKRlPtS3JW7zlgKhdEPjX9FlV1z4/pubchart?oid=440813131&format=interactive) and here (https://docs.google.com/spreadsheets/d/1wbbBSxVl-NPcrZOeKRlPtS3JW7zlgKhdEPjX9FlV1z4/pubchart?oid=451925040&format=interactive). There are some disadvantages to this, namely that it's imprecise (I never got an individual with power-level 5, so I can't calculate its frequency), but there's also an advantage: we can see how it gets to equilibrium and how much variation there is year to year. (There's actually considerably more variation than the graphs show since this is the average of 20 populations and that smooths it out.)

Absol197
2016-10-04, 12:34 PM
I started working on this before Jasdoif and Douglas posted their results and went about it a completely different way. I came up with basically the same numbers, so that's pretty settled.

I'm not so good with math like this, so I wrote a quick simulation using numpy.


# /usr/bin/env python
# -*- coding: utf-8 -*-

import random
import collections
import numpy

LIFESPANS = {1: 196.13,
2: 221.72,
3: 274.91,
4: 338.26,
5: 420.82}

MINIMUM_AGE = 1

POWER = {0: 1,
1: 1,
2: 2,
3: 2,
4: 2,
5: 3,
6: 3,
7: 3,
8: 3,
9: 4,
10: 4,
11: 4,
12: 4,
13: 4,
14: 5}

P_REINCARNATION = {0: 1,
1: 1,
2: 1,
3: 1,
4: 1,
5: 1,
6: 1,
7: 1,
8: 0.9829,
9: 0.5905,
10: 0.1770,
11: 0.0378,
12: 0.0045,
13: 0.0001,
14: 0}

POP_SIZE = 3038

YEARS = 100000

class Population:

def __init__(self, size):
# Individual is a 3-tuple (age, reincarnations, power, death date)
self.year = 0
p = numpy.tile((0,0,1,-1), POP_SIZE).reshape(POP_SIZE, 4)
self.individuals = numpy.where(p < 0,
numpy.random.normal(LIFESPANS[1],
LIFESPANS[1] * 0.5,
p.shape),
p)
self.individuals = self.individuals.astype(int)

def advance(self):
self.year += 1
self.reincarnate()

def reincarnate(self):
# Individuals die if their death date is after the current year
dead = self.individuals[::,3] < self.year
# Create array of probabilites of reincarantion using P_REINCARNATION
# and the number of reincarnations (column 1)
sort_idx = numpy.argsort(list(P_REINCARNATION.keys()))
idx = numpy.searchsorted(list(P_REINCARNATION.keys()),
self.individuals[::,1],
sorter=sort_idx)
p_reincarnation = numpy.asarray(list(P_REINCARNATION.values())
)[sort_idx][idx]
# Determine whether each individual can reincarnate based on
# p_reincarnation
can_reincarnate = numpy.random.rand(POP_SIZE) < p_reincarnation
# Individuals reincarnate if they've died and they can reincarnate
reincarnates = numpy.logical_and(dead, can_reincarnate)
rein_count = self.individuals[::,1]
rein_plusone = rein_count + 1
new_rein_count = numpy.where(dead, numpy.zeros(POP_SIZE), rein_count)
new_rein_count = numpy.where(reincarnates, rein_plusone, new_rein_count)
# Set the new reincarnation count
self.individuals[::,1] = new_rein_count
# get new power levels
sort_idx = numpy.argsort(list(POWER.keys()))
idx = numpy.searchsorted(list(POWER.keys()),
new_rein_count,
sorter=sort_idx)
new_powers = numpy.asarray(list(POWER.values()))[sort_idx][idx]
self.individuals[::,2] = new_powers
sort_idx = numpy.argsort(list(LIFESPANS.keys()))
idx = numpy.searchsorted(list(LIFESPANS.keys()),
new_powers,
sorter=sort_idx)
new_mean_lifespans = numpy.asarray(list(LIFESPANS.values()))[sort_idx][idx]
lifespan_factor = numpy.random.normal(size=POP_SIZE)
new_lifespans = new_mean_lifespans + 0.5 * new_mean_lifespans * lifespan_factor
new_deathdates = new_lifespans + self.year
old_deathdates = self.individuals[::,3]
new_deathdates = numpy.where(dead, new_deathdates, old_deathdates)
self.individuals[::,3] = new_deathdates




def power_count(self):
power_is1 = self.individuals[::,2] == 1
power_is2 = self.individuals[::,2] == 2
power_is3 = self.individuals[::,2] == 3
power_is4 = self.individuals[::,2] == 4
power_is5 = self.individuals[::,2] == 5
powers = numpy.array([numpy.count_nonzero(power_is1),
numpy.count_nonzero(power_is2),
numpy.count_nonzero(power_is3),
numpy.count_nonzero(power_is4),
numpy.count_nonzero(power_is5)])
return powers

def average_reincarnations(self):
re = self.individuals[::,1]
return sum(re) / len(re)

def main():
populations = [Population(POP_SIZE) for i in range(20)]
out = "year,reincarnations,power1,power2,power3,power4,po wer5\n"
for y in range(YEARS):
[pop.advance() for pop in populations]
if y % 100 == 0:

reincarnations = [pop.average_reincarnations()
for pop in populations]
av_rein = sum(reincarnations) / len(reincarnations)
proportions = [pop.power_count() for pop in populations]
proportions = numpy.sum(proportions, axis=0) / len(proportions) / POP_SIZE
print('Year ', y)
print('Average reincarnations: ', av_rein)
print('Percent power-level 1:', proportions[0])
print('Percent power-level 2:', proportions[1])
print('Percent power-level 3:', proportions[2])
print('Percent power-level 4:', proportions[3])
print('Percent power-level 5:', proportions[4])
print('')
out += "{0},{1},{2},{3},{4},{5},{6}\n".format(
y,
av_rein,
proportions[0],
proportions[1],
proportions[2],
proportions[3],
proportions[4]
)
with open('reincarnation_output.csv', 'w+') as file:
file.write(out)

if __name__ == '__main__':
main()


The results are graphed here (https://docs.google.com/spreadsheets/d/1wbbBSxVl-NPcrZOeKRlPtS3JW7zlgKhdEPjX9FlV1z4/pubchart?oid=440813131&format=interactive) and here (https://docs.google.com/spreadsheets/d/1wbbBSxVl-NPcrZOeKRlPtS3JW7zlgKhdEPjX9FlV1z4/pubchart?oid=451925040&format=interactive). There are some disadvantages to this, namely that it's imprecise (I never got an individual with power-level 5, so I can't calculate its frequency), but there's also an advantage: we can see how it gets to equilibrium and how much variation there is year to year. (There's actually considerably more variation than the graphs show since this is the average of 20 populations and that smooths it out.)

Interesting! I'm having a bit of trouble reading the results, but doing a timeline analysis like this is helpful, because it isn't just the abstract math but also shows how things progress over time. You said that there's a fair amount of variation yearly? Are you capable of elaborating on that, or is it too difficult to wheedle those figures out of your graphs?

Jasdoif
2016-10-04, 02:02 PM
I started working on this before Jasdoif and Douglas posted their results and went about it a completely different way. I came up with basically the same numbers, so that's pretty settled.

I'm not so good with math like this, so I wrote a quick simulation using numpy.I actually started it as a simulation before I realized that since each "slot" is a chain of reincarnations from the beginning, the probability of hitting a particular reincarnation should be as valid as when exactly a "reset" happens in a complementary sort of way....And when the few minutes of spreadsheeting matched closely to the trillions of years (over one slot) my simulation had ran to that point, I stuck with the former 'cause it was already done :smalltongue:

Jeff the Green
2016-10-04, 03:10 PM
Interesting! I'm having a bit of trouble reading the results

Do you mean that you can't see the graphs or you can't interpret them?

If the former, here's a screenshot:
http://i.imgur.com/FHoHxJx.png
http://i.imgur.com/B08eKse.png


If the latter, the first graph is the breakdown in the percent of the population at each power level. They're stacked on top of each other so it always adds up to 100%. There's a great deal of oscillation right at first, but eventually the randomness of lifespan and chance of reincarnation kicks in and it stabilizes.

The second graph shows the population power levels (not stacked this time) as well as the average number of reincarnations. The number of reincarnations is very different from the percentages, so it's on its own y-axis (the right hand one).


You said that there's a fair amount of variation yearly? Are you capable of elaborating on that, or is it too difficult to wheedle those figures out of your graphs?

Sure. Like I said, the fact that I aggregated 20 simulations obscures just how much variation there is (which is why I ran that many in the first place), so I ran it again with only a single simulation. Graphs are here (https://docs.google.com/spreadsheets/d/1AXBMOiH7RcurQ9bTHMGfv8YxVpsdhNijghPAO2Vylok/pubhtml?gid=466889042&single=true) and here (https://docs.google.com/spreadsheets/d/1AXBMOiH7RcurQ9bTHMGfv8YxVpsdhNijghPAO2Vylok/pubhtml?gid=1796105446&single=true).

As you can see, it's much more "peaky" than the smoothed average of 20 simulations. In fact there are some years when there are more individuals at power-level 4 than at power-level 2.
http://i.imgur.com/iG1P9gA.png
http://i.imgur.com/MR3WN1K.png

Absol197
2016-10-04, 09:35 PM
Great, thanks so much!

Those graphs are neato - it helps me get a firm understanding of the species as they would exist today. Of course, it's almost impossible to factor in premature death, but luckily I don't actually need numbers that accurate :smallsmile: .

Absol197
2016-10-05, 10:16 PM
Ooh, ooh! One more question! Can we determine, on average, how many reincarnations occur in a given year? Or better yet, what an average range is?

This figure is actually important because it just came up. I used ten as a placeholder (average lifespan of 300 years, ~3,000 individuals, divide and conquer!), but an actual figure would be nice.

If it's important, ~12 to 18 months between reincarnations (1 to 1.5 years). Thanks again for all the help!

Douglas
2016-10-05, 10:35 PM
For the average, that's easy - just add up all the turnover rates (except one, because it's the rate of new non-reincarnate births). That gives a total of 10.79 per year.

How far the random variation goes is trickier to calculate.

Absol197
2016-10-06, 10:49 AM
I sorry, I think I may have been unclear - I was wanting to know, generally, how many new members of this population emerge each year, whether through reincarnation or new "birth." They can't tell the difference right away.

And as a corollary question: assuming, like I said, that there is a 1 to 1.5 year gap between death and rebirth for reincarnations, and a 3 to 4 year gap between death and a new soul being "born," (the word they use is "Forged"), and assuming that they aren't discovered until they're between 15 and 25 (bell curve - average 20, standard deviation 2 years), what's a good range for the number of people currently "out of action" at a time?

Once again, assuming my initial question was clear and that ~11 is a good number for the number of new people each year, with an average of 20 years that would mean there are typically around 220 missing at any one time, right? Is there any way to get that a bit more accurate, possibly with a range?

If that number's accurate, then I need to massively re-work something...

Jasdoif
2016-10-06, 01:15 PM
I sorry, I think I may have been unclear - I was wanting to know, generally, how many new members of this population emerge each year, whether through reincarnation or new "birth." They can't tell the difference right away.

And as a corollary question: assuming, like I said, that there is a 1 to 1.5 year gap between death and rebirth for reincarnations, and a 3 to 4 year gap between death and a new soul being "born," (the word they use is "Forged"), and assuming that they aren't discovered until they're between 15 and 25 (bell curve - average 20, standard deviation 2 years), what's a good range for the number of people currently "out of action" at a time?

Once again, assuming my initial question was clear and that ~11 is a good number for the number of new people each year, with an average of 20 years that would mean there are typically around 220 missing at any one time, right? Is there any way to get that a bit more accurate, possibly with a range?Fair warning: I'm lazy.

Since you've gotten three very similar answers on the equilibrium question, I'm simply going to assume that is the equilibrium; that way I can work on the "age" level and not worry about tracking individuals across incarnations (being at equilibrium would largely obviate that). The addition of the delay between incarnations might affect that equilibrium, but see also: lazy.

I'm going to use my results from before, because I can copy/paste the table back into OpenOffice Calc with no fuss I specifically tailored it to have exactly 3,038 individuals.

So for each "age", the average discovered time is going to be the average life span by power level, minus the 20 year average discovery range (I mean, they're still alive before they're discovered, right?). And the average life-and-delay-between-life cycle is going to be the average life span, plus the chance of ascending times the 1.25 average years for reincarnation, plus the chance of not ascending times the 3.5 average years for rebirth.

Divide the discovered time by the cycle time, and you have what percent of time at that "age" is discovered...and from there, what percent of time at that "age" is missing. Divide the one cycle by how long the cycle lasts, and you have how many cycles (ie deaths and the subsequent re-life-ing) happen per year.

Multiply those for each age by the equilibrium number from before, and add up for each age, and we've got the whole population.


IncarnationsPower LevelYears HereAscension ChanceEquilibrium(?)Discovery Time EachDiscoveredLifeTime EachReincarny Time EachRebirth Time EachCycle Time EachDiscoveredLifeTime TotalCycle Time TotalCycles Per Time
01196.13121920176.131.250197.3838572.4743226.221.1 095349073
11196.13121920176.131.250197.3838572.4743226.221.1 095349073
22221.72124720201.721.250222.9749824.8455073.591.1 077723461
32221.72124720201.721.250222.9749824.8455073.591.1 077723461
42221.72124720201.721.250222.9749824.8455073.591.1 077723461
53274.91130720254.911.250276.1678257.3784781.121.1 116743917
63274.91130720254.911.250276.1678257.3784781.121.1 116743917
73274.91130720254.911.250276.1678257.3784781.121.1 116743917
83274.910.982930720254.911.2286250.05985276.198475 78257.3784792.9318251.1115195332
94338.260.590537120318.260.7381251.43325340.431375 118074.46126300.0401251.0897937947
104338.260.17721920318.260.221252.8805341.36175696 98.9474758.223250.6415481524
114338.260.03783920318.260.047253.3677341.67495124 12.1413325.323050.1141435742
124338.260.0045220318.260.0056253.48425341.7498756 36.52683.499750.0058522333
134338.260.0001020318.260.0001253.49965341.7597750 00
145420.820020400.8203.5424.32000


So it's 740,471 average years discovered, and 805,876.588 average years per cycle....That's about 91.88% of their time discovered, so about 8.12% undiscovered...multiply by the 3038 population, that's right about 247 "out of action" at equilibrium.

The total of all the cycles-per-age-times-pop comes to about 11.84, so about 12 re-lifes and deaths per year.


If that number's accurate, then I need to massively re-work something...On this point, and on wanting a range in general, my recommendation: You're writing fiction. The exceptional happens, and the perfectly average is frequently boring. If you want to adjust the averages, that's fine, beware of probabilities and averages killing the story you're trying to tell. If what you (ie your story) need and what the average predicts are wildly divergent, that's fine: Either it's sheer luck, or the involvement some factor that you haven't accounted for or come up with yet. (Off the top of my head...if there's been enough research that the basics of all this could be known in-universe, an organization with sufficient patience could be systematically assassinating individuals centuries apart in hopes of creating a significant dearth in the future to take advantage of...and trying to get so many "undiscovered"s at one time would have the side effect of leaving a lot more of them "discovered" in the times before and after that.)

Absol197
2016-10-06, 01:41 PM
Fair warning: I'm lazy.

Since you've gotten three very similar answers on the equilibrium question, I'm simply going to assume that is the equilibrium; that way I can work on the "age" level and not worry about tracking individuals across incarnations (being at equilibrium would largely obviate that). The addition of the delay between incarnations might affect that equilibrium, but see also: lazy.

That sounds like a reasonable assumption, it's the one I'd use :smalltongue: !


*Snip awesome mathematical coolness*

So it's 740,471 average years discovered, and 805,876.588 average years per cycle....That's about 91.88% of their time discovered, so about 8.12% undiscovered...multiply by the 3038 population, that's right about 247 "out of action" at equilibrium.

The total of all the cycles-per-age-times-pop comes to about 11.84, so about 12 re-lifes and deaths per year.

Great! Very helpful, as always! I thank you :smallsmile: !


On this point, and on wanting a range in general, my recommendation: You're writing fiction. The exceptional happens, and the perfectly average is frequently boring. If you want to adjust the averages, that's fine, beware of probabilities and averages killing the story you're trying to tell. If what you (ie your story) need and what the average predicts are wildly divergent, that's fine: Either it's sheer luck, or the involvement some factor that you haven't accounted for or come up with yet. (Off the top of my head...if there's been enough research that the basics of all this could be known in-universe, an organization with sufficient patience could be systematically assassinating individuals centuries apart in hopes of creating a significant dearth in the future to take advantage of...and trying to get so many "undiscovered"s at one time would have the side effect of leaving a lot more of them "discovered" in the times before and after that.)

Oh, I know quite well that average is boring. I have no intention of sticking with the absolutely average. But it's easier for me to work with the a-typical if I know what the typical actually is :smalltongue: ! A character remarking that an odd dearth of non-recurred individuals is much more convincing when he actually knows (as in, I know) what the normal tends to be.

As for the scene I was reworking, I had ~20 individuals currently unfound when they all gathered for a ceremony. I had intended for that to be approximately average, but what we've found is that is actually very atypical! So now I know that, and can either keep it the same and note that it's unusual (and come up with a suitably sinister reason for it :smallamused: ), or I can adjust the number of attendees to be more in line with what would actually be typical.

So while these figures will likely never come up directly in my work, they are incredibly helpful for allowing me to vary from the norm on purpose instead of on accident! If that makes sense...

EDIT: Plus, one of the characters, the one responsible for teaching new Hatchlings, is also responsible for maintaining their historical records and assisting with identifying the new people they find, and is an all-around smart guy. He would be able to quote these figures on the top of his head :smallbiggrin: .

Lethologica
2016-10-06, 07:17 PM
I feel like we're kinda working backwards. Between the probability distributions and life cycles provided in the OP, and the desired population distribution provided in the OP, which is more important? Because there's a pretty noticeable mismatch between them, and I think it comes from looking at life cycles by reincarnation instead of by soul.

I look at the stages and the population distribution you say you're aiming for, and I basically see 'kid', 'teen', 'adult', 'exceptional elder', and 'unique'. Unique being Vi, presumably (unless it's Brax and Vi's off the charts because of the exemption?). But the number of elders is inflated because the soul mortality rate is 0 all through the first three stages (seven reincarnations). It's like if no one died before the age of 40, but living past 40 was supposed to be exceptional.

The diminishing effect of the sickness can be remodeled to give whatever age-adjusted soul mortality rates you want, though, so it's not like you have to stick with these numbers.

Absol197
2016-10-06, 07:57 PM
I feel like we're kinda working backwards. Between the probability distributions and life cycles provided in the OP, and the desired population distribution provided in the OP, which is more important? Because there's a pretty noticeable mismatch between them, and I think it comes from looking at life cycles by reincarnation instead of by soul.

I look at the stages and the population distribution you say you're aiming for, and I basically see 'kid', 'teen', 'adult', 'exceptional elder', and 'unique'. Unique being Vi, presumably (unless it's Brax and Vi's off the charts because of the exemption?). But the number of elders is inflated because the soul mortality rate is 0 all through the first three stages (seven reincarnations). It's like if no one died before the age of 40, but living past 40 was supposed to be exceptional.

The diminishing effect of the sickness can be remodeled to give whatever age-adjusted soul mortality rates you want, though, so it's not like you have to stick with these numbers.

Hey, it's Leth! Hi, Leth :smallsmile: ! He's the one person who I know has actually read my story here! *waves*

The power levels are not supposed to correspond directly to the Mauna's different social "ranks," as presented. Vi is off the charts (effective power level 30+), Brax is a "level 5," as given here, and the rest are varied.

Random aside, regarding the Mauna's social ranks:
So, the current Mauna divide themselves into seven major levels of social strata:
1. High Nobles (of which there are 7, including Brax, Dallan (replaced by Shuey-Lien after the events of described in "Fallen," as Dallan extinguishes when Vi kills him), Sarin'ii, and three others I haven't explored yet);
2. Nobles (of which there are 28; Shuey-Lien is the highest in this rank, which is why she moves up when a High Noble extinguishes later);
3. ??? (126; Shuey-Lien's advisor is in this rank);
4. ??? (224)
5. ??? (525)
6. ??? (756)
7. ??? (1372)

You'll notice most of the ranks are unnamed - I haven't come up with good titles for them, yet! Also, the numbers aren't fixed - exceptional individuals may move up outside of the normal methods, throwing the numbers off. They are also not based entirely on power level. New Sparks freshly forged because someone extinguished start off in the bottom rank, then move up as things shift. The new Sparks are effectively "learners," while the older Sparks are teachers, and eventually the teachers disappear and the learners become the teacher of the next group! It's a very long, slow cycle.

The "power levels" I enumerate here are just how the metabiology of the Mauna works. The social ranks are just that - social constructs they developed to help organize their society as the Sickness decimated it. The fact that the lowest rank includes people with "power levels" 1 through 3 doesn't matter, because that's not what their ranks measure. The new Sparks may grow in power to match the others relatively quickly, but they still only gain experience one year at a time. If that makes sense :smallsmile: .

Vi is not included in this hierarchy because before, when she was Kyrala, she would show up for one or two days every couple hundred years, get ooh-ed and aah-ed over, give out cryptic advice, and then disappear back to the Watchtower. When Kyrala was around, it was basically, "Do whatever she says." Funnily enough, when they realized who Vi was and realized she would be around for a while, they tried to create a new, temporary rank for her in the hierarchy, called the "Queen." She immediately ix-nayed that :smalltongue: .

This is just how I think. I described the species well before I started writing. I have already altered how they function based on the way my piece(s) developed, and I may do so more now that I've got a better understanding of what the numbers I'd assigned earlier actually result in.

This is pretty much a long-winded way of me saying: I know that the numbers don't need to define my world - I just like it better when I can know what the things I've defined would mean in practice :smallsmile: . I am well aware that I'm free to alter the numbers and situations as best suit my story, and I fully intend to do so :smallsmile: . But thank you for your concern!

EDIT: And yes, looking at the "lifetime" of the soul instead of the individual reincarnation is how the Mauna tend to view it! I'm glad you got that! And if I decide that that number of "4s" is too high (it looks mostly okay to me right now, but I'm going to live with it a while before I make that decision), I will certainly be playing with the recurrence chances for the higher end of the scale to adjust that a bit. Now that a couple of people have helped me with how the math works, I think I can do it myself if I need to...

Knaight
2016-10-10, 06:58 PM
A few approaches have been covered here, but this sort of problem has actually been formalized: take a look at Markov chains (https://en.wikipedia.org/wiki/Markov_chain). I'm not super enthused with the table functionality here, so I'm going to deliberately ignore it to the extent possible. The problem you posed is also involved enough that getting it specifically would involve a fairly large matrix - it's worth you doing for your project, it's not worth me doing for your project. So, lets take a look at a fairly simple example. First, we have a vector that represents the state of the population. It will look something like this:
[# Dead]
[# In Level 1]
[# In Level 2]
[# In Level 3]
.
.
.
[# In Level 15]

These will end up as non-integers, and that's fine. Because the population is at equilibrium we can safely ignore age structure, so that we only need one space on the vector for each level. Then you assemble a 15 by 15 matrix, which represents the chance of getting to any state from any other state in a given time period. The vast majority of these are going to be zeros, but you'll have figures for going to the dead state, figures for staying in a state, and figures for going to the next state. Then you just take your starting vector and multiply it by the matrix until it stabilizes. This would involve programming - MATLAB would probably be the best language for it (specialized in vectors and matrices as it is), but just about anything should be able to do it.

Absol197
2016-10-10, 07:14 PM
I have no knowledge of programming, so while appreciated, unfortunately your method will be of little use to me :smallfrown: .

Sorry. But thank you for the alternative method, anyway! Knowing there is yet another way to do this is helpful, in case I can wrangle one of my friends who CAN program into helping out!

Knaight
2016-10-10, 08:23 PM
I have no knowledge of programming, so while appreciated, unfortunately your method will be of little use to me :smallfrown:

If you can use excel you can brute force it with that. It wouldn't be my preferred method, but it's totally doable.

Absol197
2016-10-10, 08:28 PM
Hmm...I am quite adept at Excel...how would one go about doing so?

Knaight
2016-10-11, 12:26 AM
Hmm...I am quite adept at Excel...how would one go about doing so?

Designate two matrices (one being the 1x15 the other the 15x15), repeatedly multiply them until the first one stabilizes. That's your equilibrium population - I just went to programming because "repeatedly multiply until" is one of those things that tends to mean "stick in a while loop so the computer does the math" for me.