3

I’m trying to write a function that grows somewhat logarithmically from an initial value to a final value. I know only roughly what the initial and final values should be and how I want the function’s shape of the graph to look, but everything I’ve tried either grows too fast or continues growing well after my final values.

It’s been several years since I’ve done anything beyond basic algebra, derivatives and matrix operations, but (with the help of Google), I remember the basic function transformations ($af(x - h) + v$). However, these do not seem to help much, as I’m still having trouble coming up with a formula such that the output scales appropriately. All of my attempts involved starting with a “basic” function which has a similar shape to what I’d like ($\ln(x)$, $\sqrt x$, $1/x$, etc.), then applying transforms in an attempt to make it play nice. When that didn’t work, I tried using an exponential to get a function that grows up to (roughly) my maximum ($\max \times (1 - e^{-x})$). Like the first attempts, this still ended up growing too quickly.

So, I’m at a loss. I don’t remember the process I should be using to get the function I’m looking for and it feels like I’m just trying stuff randomly at this point. How do I go about building this thing?

Also, I apologize for being vague with my information. I’d like to provide more details, but there simply aren’t any. This is for a game I’m attempting to develop, so the values aren’t set in stone, nor is the shape I’ve suggested. I’ll probably end up repeating this process as I find myself needing different values and growth, hence my focus on the process rather than a concrete solution.

Edit: A simple example that might help express my intent: The function in question is to be used for a bonus reward to be given to a player as they build a chain of “kills” or victories. I expect players to easily build chains around 1-10 without much effort, so I want there to be some noticeable growth to show the player that longer chains $=$ higher reward. At chains of around 60-80 is where I’d like to see the reward maximize. The problem (and why I’ve not stated these values up to now) is that certain victories aren’t worth as much as others, to prevent players from beating on weaker players for easy rewards. So their chain is expressed with a point system: That 1-10 chain will be somewhere around 80-120 points, and the 60-80 chains will be around 550-750. In terms of the function/graph, the input/$x$ is the player’s current chain in points and the output/$y$ is the reward.

Side note: I’m not even remotely sure I’m asking the question properly, nor do I know what tags should be added. If someone knows something that would better summarize what I’m asking, please feel free to correct the title and tags. :(

Rócherz
  • 3,976
Ceiu
  • 33
  • "or continues growing well after my final values". What do you want the function to do after your desired final value? –  Feb 15 '14 at 19:22
  • Ideally, I'd prefer that once my y value hits the desired final value, it doesn't grow or grows so slowly that it doesn't matter. Not sure if it will help, but this is to be used for a bonus reward type thing. After the reward gets so high, I'd prefer it didn't grow much afterward. I /could/ just dump it into a min() function in code, but that feels like a lazy/poor solution to something that could probably be better expressed in the formula itself. – Ceiu Feb 15 '14 at 19:24
  • How about something with a horizontal asymptote then? You could make the desired final value be the asymptote, or a little bit less if it's important that that value be actually reached. –  Feb 15 '14 at 19:28
  • Oh, I see you already mentioned $1-e^{-x}$. –  Feb 15 '14 at 19:29
  • I've tried a bunch of things (arctan was one), but without any systematic process, I wasn't able to get it to work -- It always hit my max almost immediately or grew too much beyond my desired x values.

    On a more personal note, I feel my problems here are that I: (a) don't remember/know the graphs of enough of these functions to make a proper decision on which to use as a basis. (b) don't know if I'm going about this the proper way.

    As I stated above, I feel I'm just doing things randomly and hoping for something that works "good enough."

    – Ceiu Feb 15 '14 at 19:31
  • I don't think there can be a systematic process when there's no precise goal. For example, if you had a function which was flat up to some initial value, then rose linearly to a final value, and then was flat after that, would this be satisfactory? Why or why not? –  Feb 15 '14 at 19:36
  • That's unfortunate, though understandable (re: no process). As far as the shape of what you suggested, it could work, though not as well as I'd like in-game. I'm hoping to have the reward grow noticeably as the player builds a streak of "kills," but not so quickly that there's no growth for 90% of the streak. I guess I'd like to see it start to trail off around 60-70% through my x values (which, I'm estimating around 580-720 in steps of 10 or 15). – Ceiu Feb 15 '14 at 19:37
  • Can you provide some sample value pairs that you want the function to hit or get close to? – oks Feb 15 '14 at 19:40
  • Would a logistic function work for you? – tabstop Feb 15 '14 at 19:42
  • Quite possibly. I've added the part of the game I'm working on into the question. I was hoping to avoid it, since I was hoping to get more help on the process, as I'll need to do this for a few other areas of the game as well. :( – Ceiu Feb 15 '14 at 19:49

1 Answers1

1

Not really an answer, but probably too long for a comment:

So I was working off of http://en.wikipedia.org/wiki/Generalized_logistic_curve, and fitting parameters based on your desires; I set $A=80$ as the lower bound, and $K=750$ as the upper bound. I cheated a bit, and set 60 as where the fastest growth should be and 80 as where we should be at basically the peak. (I suspect you want that first number a little lower.) I therefore set $\nu=60/80=0.75$ and $M=60$. I decided that when $x=60$ you wanted $550$ points, so I solved for the value of $Q$ that makes that happen ($0.304616$ if my calculator skills are correct). (Again that might not actually match what you want.) The value of $B$ determines how spread out the increasing-ness is; when $B=1$ it goes almost straight up, while when $B=0.1$ it looks like this: logistic growth

If that "shape" looks right, you can probably tweak the parameters to be more like what you want.

tabstop
  • 1,598
  • Wow, that's perfect. So, from the comments and your process, is it safe to conclude that I was going about it correctly, but using the wrong "base" functions? – Ceiu Feb 16 '14 at 06:57