raputil.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:onsager_deep_learning 作者: mborgerding 项目源码 文件源码
def hexagonal_uniform(N,as_complex=False):
    'returns uniformly distributed points of shape=(2,N) within a hexagon whose minimum radius is 1.0'
    phi = 2*pi/6 *.5
    S = np.array( [[1,1],np.tan([phi,-phi])] ) # vectors to vertices of next hexagon ( centered at (2,0) )a
    # uniformly sample the parallelogram defined by the columns of S
    v = np.matmul(S,np.random.uniform(0,1,(2,N)))
    v[0] = 1 - abs(v[0]-1) # fold back to make a triangle
    c = (v[0] + 1j*v[1]) * np.exp( 2j*pi/6*np.floor( np.random.uniform(0,6,N) ) ) # rotate to a random sextant
    if as_complex:
        return c
    else:
        return np.array( (c.real,c.imag) )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号