  Recently the memristive electrical transport properties in NbO$_2$ have
attracted much attention for their promising application to the neuromorphic
computation. At the center of debates is whether the metal-to-insulator
transition (MIT) originates from the structural distortion (Peierls) or the
electron correlation (Mott). With inputs from experiments and first principles
calculations, we develop a thermodynamical model rooted in the scenario of the
MIT driven by a $2^{nd}$ order Peierls instability. We find that the
temperature dependence of the electrical conductivity can be accurately fit by
the band gap varying with temperature due to the gradual weakening of the Nb-Nb
dimers. The resistivity switching can consequently be understood by dimer-free
metallic domains induced by local Joule heating. In solving the heat equation,
we find that the steady state can not be reached if the applied voltage exceeds
a threshold, resulting in the chaotic behavior observed in the high voltage and
current states. With the Ginzburg-Landau theory and the Joule heating equation,
the evolution of the metallic domains under bias voltage can be simulated and
directly verified by experiments.
