06: I suspect comparing signs is quicker
This commit is contained in:
@ -257,7 +257,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 100,
|
||||
"execution_count": 106,
|
||||
"id": "6e4a6d63",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
@ -281,18 +281,19 @@
|
||||
"def xy_cluster_flip(state,seed,nhat,beta):\n",
|
||||
" '''Perform a cluster move with specified seed and vector nhat on the state at temperature beta.'''\n",
|
||||
" w = len(state)\n",
|
||||
" \n",
|
||||
" # Let's flip along the way, starting with the seed.\n",
|
||||
" state[seed] -= 2*state[seed]@nhat*nhat\n",
|
||||
" cluster_size = 1\n",
|
||||
" # Use a double-ended queue to keep track of what elements to try to expand from.\n",
|
||||
" unvisited = deque([seed])\n",
|
||||
" cluster_size = 1\n",
|
||||
" while unvisited:\n",
|
||||
" site = unvisited.pop()\n",
|
||||
" s_i_n = -state[site]@nhat\n",
|
||||
" for nbr in neighboring_sites(site,w):\n",
|
||||
" s_j_n = state[nbr]@nhat\n",
|
||||
" p_add = 1 - np.exp(-2*beta*s_i_n*s_j_n)\n",
|
||||
" if s_i_n*s_j_n > 0 and rng.uniform() < p_add:\n",
|
||||
" if np.sign(s_i_n) == np.sign(s_j_n) and rng.uniform() < p_add:\n",
|
||||
" state[nbr] -= 2*s_j_n*nhat\n",
|
||||
" unvisited.appendleft(nbr)\n",
|
||||
" cluster_size += 1\n",
|
||||
@ -308,7 +309,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 101,
|
||||
"execution_count": 107,
|
||||
"id": "3f810041",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
@ -339,7 +340,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 102,
|
||||
"execution_count": 108,
|
||||
"id": "bde560e4",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
|
||||
Reference in New Issue
Block a user