How to apply this linear transformation $(x:=2x+1)$ on R-sequence result to generate points in range $[-1,1]$?

35 Views Asked by At

I want to used R-sequence proposed by Martin Roberts to generate points in range [-1,1]. In this post, Martin Roberts mentioned that:

... to convert to a range of [-1,1], simply apply the linear transformation x:=2x+1. The result is

(-0.361655, -0.657913, -0.900599)

(-0.72331, 0.684174, 0.198802)

(0.915035, 0.0262616, -0.701797)

(0.55338, -0.631651, 0.397604)

(0.191725, 0.710436, -0.502995),...

I am not specialist in math, I just want to know how to apply this transformation to generate points in range [-1,1]? and in which part of the provided code?

This code generates points in range [0,1]

# Use Newton-Rhapson-Method
def gamma(d):
    x=1.0000
    for i in range(20):
        x = x-(pow(x,d+1)-x-1)/((d+1)*pow(x,d)-1)
    return x

d=3
n=5

g = gamma(d)
alpha = np.zeros(d)                 
for j in range(d):
    alpha[j] = pow(1/g,j+1) %1
z = np.zeros((n, d))    
for i in range(n):
    z = (0.5 + alpha*(i+1)) %1

print(z)

The result is:

(0.319173, 0.171044, 0.0497005)
(0.138345, 0.842087, 0.599401)
(0.957518, 0.513131, 0.149101)
(0.77669, 0.184174, 0.698802)
(0.595863, 0.855218, 0.248502) ...

How to apply this linear transformation x:=2x+1 to get this result:

(-0.361655, -0.657913, -0.900599)
(-0.72331, 0.684174, 0.198802)
(0.915035, 0.0262616, -0.701797)
(0.55338, -0.631651, 0.397604)
(0.191725, 0.710436, -0.502995),...
1

There are 1 best solutions below

1
On BEST ANSWER

The linear transformation seems to be false. You need

$f: \begin{cases} [0, 1] &\to [-1, 1] \\ x &\mapsto 2x \mathop{\mathbf{-}} 1 \end{cases}$

Simply apply the linear transformation (a function!) to every element in the vector. Since I have no python installed, the following source code to do this is not tested:

# ...
for i in range(n):
    for j in range(d):
        z[i][j] = 2 * z[i][j] - 1
print(z)

EDIT: Another method would use list comprehension, something like [[2 * z[i][j] - 1 for j in range(d)] for i in range(n)] (again untested). But Python does not operate on matrices implicitly like Mathematica and Octave do.