Object-Oriented for the CVM (Continued), and an Oops!
Why Shifting to the Object-Oriented Coding Approach REALLY IS Important:
Well, I hate having to admit it. Mud on my face; all that. But I made a pretty significant Whoops! back this last winter when I posted a “Verification and Validation” document (hah!) to arXiv.
The Sad Story of My Previous Ineptitude
Well, there’s nothing like hearing about someone else’s screw-up in order to make us feel better about our own life, so here goes.
I’d previously used straighforward, structured code to compute the configuration variables for the 2-D CVM.
The problem was, I was carrying over my thinking from the 1-D CVM, and going about things in a simple left-to-right manner.
What I totally missed was that both the z(i) and y(i) configuration variables for the 2-D case need to be computed going two rows up and down from a given node, and not just to the left and right of that node. Essentially, I missed half of each of the z(i) and y(i) variables.
Now, I don’t think that messed up the results too much. I think that the overall gist of what I found will hold true, even when I run what will be new code, on the same problem. (And thank God, that was exploratory work. And I can always post revisions on arXiv. NOW I know why there are so many revisions on some documents.)
The thing is, I didn’t learn about my mistake until I started developing the object-oriented approach. It was a lesson directly from Looking at Friends and Neighbors from a Node’s Point of View (Nodes, Nets, and Grids).
The Old Approach
I’m not going to say that the mistake was totally a function of my using a structured programming method. I’m still all in favor of structure.
The problem was in thinking about the nearest-neighbors and triplets for the configuration variables in a simple left-to-right sense, without looking at the full node topography.
Figure 1 shows my initial visualization looked like, for the 1-D CVM case.
Figure 2 shows how I was looking at the z(i) configuration variables.
This is fine, and it doesn’t need to be changed – for the 1-D case.
The problem was, I was still thinking about the same approach when I started work on the 2-D CVM.
The New Approach – Thinking in Object-Oriented Terms
It wasn’t until I started the object-oriented approach, and ran into snags just thinking of how I would identify all the configuration variables associated with a given node, that I found my error.
More specifically, I was thinking of how to “pad” an area around the 2-D CVM grid.
This is very analogous to how we create a “padded layer” when we work with a convolutional neural network (ConvNet). ConvNets are, of course, ubiquitous in the neural networks / deep learning community, so I’m only citing a single tutorial that shows ConvNet padding; anyone who wants to learn can find a plethora of excellent tutorials. The ConvNet padding allows the full masking filter to be used on edge and corner cells as well as interior ones.
Similarly, we need to create a “padded grid” in working with (an object-oriented form of) CVM. The reason is that when we compute the set of configuration variables for a given node, we need to look at the neighborhood of nodes around that given node. Looking just to the left and the right isn’t enough; we need to look up and down as well.
If I create a padded version of the CVM grid, I can use my old approach of working left-to-right, and top-to-bottom, addressing each node in the original CVM grid in turn. It’s easier if the computations can simply look left and right, and top and bottom, with regard to any particular specific node. Otherwise, for a node on the right edge, the code would have to go find the node on the left side that would be its neighbor, in the sense that we’re creating a CVM grid that is a full envelope; the rows connect with each other at the left-and-right, and top-and-bottom layers.
Now, I’ve been finding it immensely challenging to keep track of what node corresponds with what, in moving from the basic CVM grid to the padded one. However, that’s a subject for a different post.
For the moment, it suffices to illustrate how the z(i) triplet configuration variables really need to be considered, as illustrated in the following Figure 3.
Illustration of the Padded Grid for Object-Oriented CVM Computations
Figure 4 shows what it looks like when we pad around the edges of a 2-D CVM grid. For simplicity, the 2-D CVM grid really is a 1-D; it’s just got two rows. The point is just to show how the padding replicates the values that would be observed from making an “envelope” of the basic grid.
Code Sharing – Yeah, Not Quite Yet
I will share code. Just not yet.
Right now, I’m still figuring out how to cross-reference the padding nodes vs. the originals; I’ve got two notations going on, and all of a sudden, just counting gets difficult.
More than that, I don’t have any real new code to share. The latest bit was a 1-D object-oriented case, it was posted on GitHub, and you’re welcome to it. (See the links below.)
In general, I’m going to wait to share until I’ve gone through not only my own V&V (blooper time!) and also run the code and results and every form of documentation and walkthrough that I can think of by just a few people.
It’s just a way to keep error proliferation down.
Until next week, folks!
Live free or die, my friend –
AJ Maren
Live free or die: Death is not the worst of evils.
Attr. to Gen. John Stark, American Revolutionary War
References & Resources
The Cluster Variation Method – Essential Papers
- Kikuchi, R. (1951). A theory of cooperative phenomena. Phys. Rev. 81, 988-1003, pdf, accessed 2018/09/17.
- Kikuchi, R., & Brush, S.G. (1967), “Improvement of the Cluster‐Variation Method,” J. Chem. Phys. 47, 195; online as: online – for purchase through American Inst. Physics. Costs $30.00 for non-members.
- Maren, A.J. (2016). The Cluster Variation Method: A Primer for Neuroscientists. Brain Sci. 6(4), 44, https://doi.org/10.3390/brainsci6040044; online access, pdf; accessed 2018/09/19.
- Maren, A.J. (June, 2014) The Cluster Variation Method I: 1-D Single Zigzag Chain: Basic Theory, Analytic Solution and Free Energy Variable Distributions at Midpoint (x1 = x2 = 0.5). THM TR2014-002(ajm). DOI: 10.13140/2.1.4415.6485
Previous Related Posts (and One That’s Forward-in-Time)
- Transition to Object-Oriented Python for the Cluster Variation Method
- Looking at Friends and Neighbors from a Node’s Point of View (Nodes, Nets, and Grids) (July 25, 2018)
- The 1-D Cluster Variation Method (CVM) – Simple Application (Nov. 3, 2014)
- Visualizing Configuration Variables with the 1-D Cluster Variation Method (July 9, 2014)
- Analytic Single-Point Solution for Cluster Variation Method Variables (at x1=x2=0.5) (Dec. 8, 2011)
The 1D CVM – Code, Documentation, and V&V Documents (Including Slidedecks)
- GitHub for 1-D Object-Oriented Python Snippets
- Code: 1D-CVM_OO_basic-config-vars_V-and-V_1-1_2018-09-23.py (Python 3.6; self-contained)
- Documentation / V&V: 1D-CVM_Object-oriented-code_V-and-V_2018-10-10-18.pptx
2 thoughts on “Object-Oriented for the CVM (Continued), and an Oops!”