Search code examples
samplinglogarithm

Logarithmic sampling


I am working with values between [minValue,maxValue] and I want to create a vector of values in between this range. But I want more values near to the minValue.

Example:

min = 1 max = 100

vector = [1,1.1,1.5,2,3,5,10,15,30,50,100];

Something like that.

The goal is to be more accurate around the minimum.

Is that possible to implement that?


Solution

  • You can start with by generating numbers from 0 to 1 with constant step (for example 0.1). Then power them with some exponent - the bigger exponent, the sharper curve. Then shift and multiply to get into your desired min-max range.

    Pseudocode:

    min = 1.0
    max = 100.0
    exponent = 2.0 // Sharpness
    result = []
    
    for(i = 0.0; i <= 1.0; i += 0.1) {
        result.push(pow(i, exponent) * (max - min) + min)
    }