static LC0VerboseMoveStat BuildStatNotExpanded(MCTSNode node, int childIndex) { MCTSNodeStructChild child = node.ChildAtIndexRef(childIndex); LC0VerboseMoveStat stat = new LC0VerboseMoveStat(null, null); stat.MoveString = child.Move.ToString(); stat.MoveCode = child.Move.IndexNeuralNet; stat.P = child.P * 100.0f; stat.U = node.ChildU(childIndex); return(stat); }
static LC0VerboseMoveStat BuildStatExpanded(MCTSNode node, bool isSearchRoot) { LC0VerboseMoveStat stat = new LC0VerboseMoveStat(null, null); float multiplier = isSearchRoot ? 1 : -1; stat.MoveString = isSearchRoot ? "node" : node.Annotation.PriorMoveMG.MoveStr(MGMoveNotationStyle.LC0Coordinate); stat.MoveCode = isSearchRoot ? 20 : node.Parent.ChildAtIndexInfo(node.IndexInParentsChildren).move.IndexNeuralNet; stat.VisitCount = node.N; stat.P = isSearchRoot ? 100 : (node.P * 100.0f); stat.D = node.Ref.DrawP; stat.WL = (node.IsRoot && node.N == 0) ? node.V : (float)node.Q * multiplier; stat.Q = new EncodedEvalLogistic((float)node.Q * multiplier); stat.M = node.MPosition; stat.V = new EncodedEvalLogistic((float)node.V * multiplier); stat.U = isSearchRoot ? 0 : node.Parent.ChildU(node.IndexInParentsChildren); return(stat); }
public static List <LC0VerboseMoveStat> BuildStats(MCTSNode searchRootNode) { List <LC0VerboseMoveStat> stats = new List <LC0VerboseMoveStat>(); BestMoveInfo best = searchRootNode.BestMoveInfo(false); // First process policy moves not yet expanded // starting from last one (lowest probability). for (int i = searchRootNode.NumPolicyMoves - 1; i >= 0; i--) { (MCTSNode node, EncodedMove move, FP16 p)info = searchRootNode.ChildAtIndexInfo(i); if (info.node == null) { LC0VerboseMoveStat stat = BuildStatNotExpanded(searchRootNode, i); stats.Add(stat); } } // Now process moves expanded in order of visit count. MCTSNode[] sortedN = searchRootNode.ChildrenSorted(s => (float)s.N + 0.0001f * s.P); foreach (MCTSNode node in sortedN) { if (!object.ReferenceEquals(node, best.BestMoveNode)) { stats.Add(BuildStatExpanded(node, false)); } } // Save the best move for last. stats.Add(BuildStatExpanded(best.BestMoveNode, false)); // Finally, output the search root node. stats.Add(BuildStatExpanded(searchRootNode, true)); return(stats); }