anchor.diff:          fun({AllDegree, InDegree}) ->
               {AllDegree + NodeDegree, InDegree + CommWeight}
           end, {NodeDegree, CommWeight}, Weights#louvain_weights.weights)}.
  +
  +compare_weights(WA, WB) ->
  +    ?ASSERTEQUAL(WA#louvain_weights.m, WB#louvain_weights.m),
  +    WeightsDA = lists:sort(lists:filter(fun({_,{0.0,0.0}}) -> false; (_) -> true end, dict:to_list(WA#louvain_weights.weights))),
  +    WeightsDB = lists:sort(lists:filter(fun({_,{0.0,0.0}}) -> false; (_) -> true end, dict:to_list(WB#louvain_weights.weights))),
  +    ?ASSERTEQUAL(WeightsDA, WeightsDB).
   
   % weight of all edges to neighbors, and weights to neighboring communities.
   % weights to neighboring communities exclude Node
  
positive.code: %% Python implementation - https://bitbucket.org/taynaud/python-louvain
  %% @end
  
  -define(ASSERTEQUAL(A,B), begin case A == B of true -> ok; false -> error({A, not_equal, B}) end end).
  
  -module(part_louvain).
  
  
negative.code:                 end, {NodeComm, 0.0}, NeighborCommWeightsD),
  %           file:write(FD, io_lib:format("add node comm: ~p degree ~p comm weight ~p~n", [BestComm, NodeDegree, LookupCommWeight(BestComm)])),
              Weights2 = add_node(BestComm, NodeDegree, LookupCommWeight(BestComm), Weights1),
              % XXX
  %           file:write(FD, io_lib:format("weights after add: ~p~n", [dict:to_list(Weights2#louvain_weights.weights)])),
  %           file:write(FD, io_lib:format("node: ~p comm: ~p -> ~p~n", [Node, NodeComm, BestComm])),
              {(BestComm /= NodeComm) or Mods, Weights2, GD#louvain_graphd{communitiesd = dict:store(Node, BestComm, CommunitiesD)}}
          end, {false, Weights0, GD0}, GD0#louvain_graphd.neighborsd),
      % XXX recompute weights and see if they match the new weights
      compare_weights(NewWeights, weights(NewGD)),
      NewModularity = modularity(NewWeights),
      ?DEBUG("OneLevel Modularity: ~p -> ~p", [Modularity, NewModularity]),
  %   file:write(FD, io_lib:format("m: ~g, weights: ~p~n", [NewWeights#louvain_weights.m, dict:to_list(NewWeights#louvain_weights.weights)])),
  