in reply to Re: A data selection problem(in3D).
in thread A data selection problem(in3D).

Having found the Logistic function; played with the parameters and understood their effects, I went to apply it to my problem and realised that I had reached the wrong conclusion about how I needed to curve my way through the dataset.

In a nutshell, rather than this parameterised curve, in need this one (produced by rotating the first left 90° and then flipping the image vertically.)

I've proved (to myself) that I have no intuition for what maths is likely to produce such results; if you have any clues to this new requirement I'd be a great help?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^2: A data selection problem(in3D).(Dammit! New requirement.)

Replies are listed 'Best First'.
Re^3: A data selection problem(in3D).(Dammit! New requirement.)
by pryrt (Abbot) on Apr 08, 2017 at 00:01 UTC

    Suggestion 1: given a parameter p that goes from -1 to 1, non-inclusive, you could do f(p) = tan(p*pi/2), but that doesn't give much control of the slopes. Given the logistic(p,L,K) = L / (1 + exp(-k*p)), you could do something like f(p) = tan( (2*logistic(p,L,K)-1)*pi/2 ), which allows some tuning... but I'm still not sure it's really tunable enough

    Even before this additional wrinkle, I was cogitating that maybe going the route of a Bezier curve would be the right way to go: given a set of k coordinates P_i for i=(0..k-1), where each coordinate is in n-dimensional space, you could use a (k-1)th-order Bezier to "get near" each of those k points (exactly hitting the two endpoints). For example, if your k=5 coordinates were the (H,S,V) for white, yellow, bright gold, dark gold, black -- then you could do a quartic Bezier (the wp article goes to cubic, but quartic would just be f(t) = (1-t)**4 * P0 + 4*(1-t)**3 * t * P1 + 6*(1-t)**2 * t**2 * P2 + 4*(1-t) * t**3 * P3 + 1*t**4 * P4. Or it might be easier to do a piecewise quadratic or cubic Bezier. The benefits of various Bezier is you can plop those points anywhere (you can make a circle out of four piecewise Beziers) to make highly arbitrary points... and you can tune them to get wonderfully sharp slopes.

      Suggestion 1: given a parameter p that goes from -1 to 1, non-inclusive, you could do f(p) = tan(p*pi/2), but that doesn't give much control of the slopes. Given the logistic(p,L,K) = L / (1 + exp(-k*p)), you could do something like f(p) = tan( (2*logistic(p,L,K)-1)*pi/2 ), which allows some tuning... but I'm still not sure it's really tunable enough

      Thanks. I'll take a look at that.

      I'm currently playing with tanh(), which produces a knee that bends in the right direction; and the slope can be tuned by simple scaling, but...as it contains a division, 1.0 has to be special cased to avoid divide by zero; and as it is basically log, you have to remove then put back the negative to produce the 'other half' of the curve.

      The latter is simple if a little messy; the former is a right royal pain the arse.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice.

      After going round and around trying to get tan()/tanh() to do what I wanted, I ended up with using (relatively) simple exponentiation:

      sub myCurve { my( $x, $p ) = ( @_, 5 ); my $sgn = $x <=> 0; $sgn * abs( $x )**$p; }

      The jiggery pokery with the sign is so that I can supply input in the range -1 .. 1 and get the rotational symmetry I wanted.

      Its effect is demonstrated in this image. You'll probably need to zoom in to read the text and see the effect clearly.

      The top 10 pixel band, labelled "X->Y", is a simple linear path through the relevant hsv space; and the second band ("X**1") is identical but with the coordinates passed through my mapping algorithm with the exponent set to 1 to check it follows the same path.

      The third band "x**2" is the input coordinates passed through the mapping with the exponent set to 2. This shows the effect I was after, that of reducing the near black and near white ~3rds at either end and stretching the middle 3rd to fill the space.

      The other bands are higher exponents showing that the effect is configurable to a high degree. It looses some of the black and white at either end due to truncation to integer pixels which I can probably live with, or I could just replace the highest and lowest values in the gradient with black and white.

      This is only curving the gradient in 2D at the moment; I've still to get the mapping right for the third dimension (hsv-V), but I'll get there.

      Thanks for your input.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice.