Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 114 115 [116] 117 118 ... 173

Author Topic: Mathematics Help Thread  (Read 228538 times)

ZetaX

  • Bay Watcher
    • View Profile
Re: Mathematics Help Thread
« Reply #1725 on: February 06, 2015, 08:17:52 pm »

Having an explicit inversion is an important goal for the thing I'm working on, which is a number generation scheme

Considering that exp, ln, arctan and such are also only computed numerically, why is not using Newton's method or some Taylor series also a legitimate way of inverting it¿ Sure, it won't be a function you can put in your average calculator, but that's really the only difference.

In other words: there is nothing special about exp or ln, they are not that more easy to compute than many other functions. They just happen to have names (for good but different reasons) and the others don't.
Logged

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: Mathematics Help Thread
« Reply #1726 on: February 06, 2015, 09:24:33 pm »

Well, what I'm trying to make is a probability distribution function that I can manipulate in particular ways. Specifically, it's got to have 3 peaks, whose magnitude I can scale arbitrarily, exactly one of those peaks (the central one) needs to be skewed to an arbitrary degree, and because I actually want to use this as a number generator, I need to be able to perform those manipulations not by manipulating the PDF itself, but by manipulating the inverse of its integral, and I need that to be both relatively quick to compute on the fly and comprehensible enough that I can debug the fucker when I inevitably fuck up the formatting.

Arctan happens to be the CDF of a valid PDF and have a fairly trivial inversion, so it seemed like a good choice, and I've already got the peak scaling part worked out, so it's just been a matter of getting the skew thing to work. MagmaMcFry's suggestion seems to have worked, although the derivative I wind up with (that is, the PDF) is nightmarish in form - which is fine, because I'll never actually need to do any calculations with it after I get it tweaked.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: Mathematics Help Thread
« Reply #1727 on: February 07, 2015, 06:47:52 am »

Well, what I'm trying to make is a probability distribution function that I can manipulate in particular ways. Specifically, it's got to have 3 peaks, whose magnitude I can scale arbitrarily, exactly one of those peaks (the central one) needs to be skewed to an arbitrary degree, and because I actually want to use this as a number generator, I need to be able to perform those manipulations not by manipulating the PDF itself, but by manipulating the inverse of its integral, and I need that to be both relatively quick to compute on the fly and comprehensible enough that I can debug the fucker when I inevitably fuck up the formatting.

Well why didn't you just say that in the first place? You can just take the weighted average of three bell curves, and you don't actually need the resulting ICDF:
Code: [Select]
float getPDFFromWeightedAverageOfDistributions(weight1,  distribution1, weight2, distribution2, weight3, distribution3, x) {
  return (weight1*distribution1.pdf(x) + weight2*distribution2.pdf(x)+weight3*distribution3.pdf(x)/(weight1+weight2+weight3);
}

float getCDFFromWeightedAverageOfDistributions(weight1,  distribution1, weight2, distribution2, weight3, distribution3, x) {
  return (weight1*distribution1.cdf(x) + weight2*distribution2.cdf(x)+weight3*distribution3.cdf(x)/(weight1+weight2+weight3);
}

//You don't actually need the inverse CDF of the weighted average if you generate random numbers like this
float getRandomNumberFromWeightedAverageOfDistributions(weight1,  distribution1, weight2, distribution2, weight3, distribution3) {
  float selector = randFloat(weight1 + weight2 + weight3);
  if (selector < weight1) return distribution1.getRandomNumber();
  if (selector < weight1 + weight2) return distribution2.getRandomNumber();
  return distribution3.getRandomNumber();
}
Logged

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: Mathematics Help Thread
« Reply #1728 on: February 07, 2015, 10:45:01 am »

Yeah, that handles the scaling bits but I'm not sure it helps with the skew very much, although I suppose it would make it a fair bit more readable one way or the other. Also means I've got better odds of finding a function in an existing library that does what I want, since I don't need to worry about the peaks. Will look into that later today. Thanks!
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

Graknorke

  • Bay Watcher
  • A bomb's a bad choice for close-range combat.
    • View Profile
Re: Mathematics Help Thread
« Reply #1729 on: February 12, 2015, 02:33:35 pm »

So I have a set of numbers, and I need to know the relationship between them but have no idea how I would even begin to work that out. I am reasonably certain they're trending towards a something but don't know how to pin down the exact relationship from term to term.

Looking at it it would appear to be some kind of y=1/x relationship but beyond that I can't make out much.
Logged
Cultural status:
Depleted          ☐
Enriched          ☑

frostshotgg

  • Bay Watcher
  • It was a ruse
    • View Profile
Re: Mathematics Help Thread
« Reply #1730 on: February 12, 2015, 03:19:28 pm »

Graphing it on excel, it appears to be a transformation of y=1/x, translated up a certain value and such.
Logged

Graknorke

  • Bay Watcher
  • A bomb's a bad choice for close-range combat.
    • View Profile
Re: Mathematics Help Thread
« Reply #1731 on: February 12, 2015, 03:51:14 pm »

Well I could guess that bit. I was kind of looking for anyone who knows a general method to work out what that function is. It's pretty clearly a rectangular hyperbola(and yes y does trend to infinity as x trends to 0), but I don't really know how to figure out the exact equation for it.

EDIT: Though then again x is actually discrete so maybe I should try finding an equation for a general term either? Actually that would probably fit my problem better, even if it gives the same answer for the limit to infinity.
« Last Edit: February 12, 2015, 04:12:50 pm by Graknorke »
Logged
Cultural status:
Depleted          ☐
Enriched          ☑

Graknorke

  • Bay Watcher
  • A bomb's a bad choice for close-range combat.
    • View Profile
Re: Mathematics Help Thread
« Reply #1732 on: February 12, 2015, 04:30:39 pm »

Well, do you just have the five points, or do you have more than that? If you just have the 5 points then that could be one of many, many functions.
Well those five are the ones I could get right now that my calculator would still display as fractions. I could go on for a while but I can tell you from the context that the progression converges on somewhere around 273.2
Logged
Cultural status:
Depleted          ☐
Enriched          ☑

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: Mathematics Help Thread
« Reply #1733 on: February 12, 2015, 04:33:48 pm »

Well, do you just have the five points, or do you have more than that? If you just have the 5 points then that could be one of many, many functions.
Well those five are the ones I could get right now that my calculator would still display as fractions. I could go on for a while but I can tell you from the context that the progression converges on somewhere around 273.2
Do you have any restrictions on what the relation should look like? Because if not, you could just take any old relation and add those five points.
Logged

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: Mathematics Help Thread
« Reply #1734 on: February 12, 2015, 04:40:04 pm »

Make a scatter plot and then just run it through your regression of choice. Calculators usually have at least a few simpler ones, and there are tons of different ones you can find online.
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

Graknorke

  • Bay Watcher
  • A bomb's a bad choice for close-range combat.
    • View Profile
Re: Mathematics Help Thread
« Reply #1735 on: February 12, 2015, 04:42:27 pm »

Well, do you just have the five points, or do you have more than that? If you just have the 5 points then that could be one of many, many functions.
Well those five are the ones I could get right now that my calculator would still display as fractions. I could go on for a while but I can tell you from the context that the progression converges on somewhere around 273.2
Do you have any restrictions on what the relation should look like? Because if not, you could just take any old relation and add those five points.

It relates directly to a physical system (electronic circuits to be specific, adding resistors in parallel), so it has to make sense, and the only thing that would make sense in the context would be a rectangular hyperbola.

Make a scatter plot and then just run it through your regression of choice. Calculators usually have at least a few simpler ones, and there are tons of different ones you can find online.
It's not linear though :/
Logged
Cultural status:
Depleted          ☐
Enriched          ☑

Leafsnail

  • Bay Watcher
  • A single snail can make a world go extinct.
    • View Profile
Re: Mathematics Help Thread
« Reply #1736 on: February 12, 2015, 04:54:03 pm »

It sounds like it would be easier to address the physics than to try and guess with maths.  What do your two variables actually represent?  I take it you already know the formula for adding resistors in parallel (1/Rt = 1/R1 + 1/R2)?
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: Mathematics Help Thread
« Reply #1737 on: February 12, 2015, 04:54:32 pm »

So x would be the number of resistors at a certain point and y would be the total resistance or something? Maybe you could give the exact problem so we can help you better?
Logged

Graknorke

  • Bay Watcher
  • A bomb's a bad choice for close-range combat.
    • View Profile
Re: Mathematics Help Thread
« Reply #1738 on: February 12, 2015, 05:11:33 pm »

I kind of didn't want to be having the question solved for me but fine.

The premise is that there is a repeating pattern of 3 100ohm resistors, each set of 3 connected parallel to the middle resistor of the previous 3.
I was indeed using x as the number of times this pattern repeats and y as the total resistance.

EDIT: Well I pretty much got a solution to my problem, works by assuming that in an infinite set of rungs you will have the same resistance across the middle rung no matter how far along you are, it being infinite and all. I should probably have thought of that sooner.
« Last Edit: February 12, 2015, 05:46:03 pm by Graknorke »
Logged
Cultural status:
Depleted          ☐
Enriched          ☑

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: Mathematics Help Thread
« Reply #1739 on: February 12, 2015, 06:36:50 pm »

Make a scatter plot and then just run it through your regression of choice. Calculators usually have at least a few simpler ones, and there are tons of different ones you can find online.
It's not linear though :/
I know you solved your problem but I figured I'd post this anyways. For a hyperbolic system you can always transform it over to be a linear system, run a regression on it to solve for the constants, and then transform back with the now known constants.
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.
Pages: 1 ... 114 115 [116] 117 118 ... 173