random unit vector in multi-dimensional space

后端 未结 5 1944
栀梦
栀梦 2020-12-05 10:42

I\'m working on a data mining algorithm where i want to pick a random direction from a particular point in the feature space.

If I pick a random number for each of

5条回答
  •  情深已故
    2020-12-05 11:09

    #define SCL1 (M_SQRT2/2)
    #define SCL2 (M_SQRT2*2)
    
    // unitrand in [-1,1].
    double u = SCL1 * unitrand();
    double v = SCL1 * unitrand();
    double w = SCL2 * sqrt(1.0 - u*u - v*v);
    
    double x = w * u;
    double y = w * v;
    double z = 1.0 - 2.0 * (u*u + v*v);
    

提交回复
热议问题