04-04-2018 07:59 AM
I'm using the Mean PtByPt.vi in the NI_PtbyPt.lvlib to calculate a running average over time. My sample length is unknown, so the sample size is set to 0. I also use the initialize input to reset the running average calculation at various times as needed. I'm not getting the expected results.
When I set Initialize to True, I'm expecting the running average to reset to 0, and it doesn't. After looking at the block diagram (which frankly I can't believe this is allowed to ship with LabVIEW) I see that shift register is reset if an array of values is used, but not if the "Infinite horizon" approach (the one I'm using) is used.
Am I missing something?
04-04-2018 08:28 AM
When initialize is true, the "Init" case is executed instead of the "Infinite horizon". The input x is taken as the first data, hence the output mean equals x.
04-04-2018 08:39 AM
I get that's what it's doing. My expectation was that the init state was more of a reset. I've created my own version with that approach, but I wanted to see if I was on island or not with my expectation of how the VI should operate.
04-04-2018 08:58 AM
@B.Settles wrote:
I get that's what it's doing. My expectation was that the init state was more of a reset. I've created my own version with that approach, but I wanted to see if I was on island or not with my expectation of how the VI should operate.
Guess the init is not a reset, and that's the bottom line.
I agree, the VI won't win any beauty contests, but I've seen worse (also from NI).
My biggest objections against the hole idea of PtByPt is that it doesn't scale up. So if I use a PtByPt VI in a class method, it works on an object. Then I scale up and use the method on an array of objects, and the PtByPt method won't work properly, since the same instance is invoked on all class objects...
I find I have to rewrite each PtByPt VI I need to a class with an init and an execute. Sometimes that's easy, sometimes hard. But usually the code gets better.
04-04-2018 09:10 AM
@B.Settles wrote:
When I set Initialize to True, I'm expecting the running average to reset to 0, and it doesn't.
So you expect the value you are passing into the VI to be completely ignored when you reset it? It is a reset. It is clearing out all of the previous data and performing a new mean starting with your current data point. The average of X is X. So it makes complete sense to me. I would not expect a 0 output on a reset.
04-04-2018 09:23 AM
@crossrulz wrote:
@B.Settles wrote:
When I set Initialize to True, I'm expecting the running average to reset to 0, and it doesn't.
So you expect the value you are passing into the VI to be completely ignored when you reset it? It is a reset. It is clearing out all of the previous data and performing a new mean starting with your current data point. The average of X is X. So it makes complete sense to me. I would not expect a 0 output on a reset.
Agreed. The only ambiguity is that "init" does not automatically imply the current iteration counts. It does for all PtByPt VI's AFAIK. And since it does, while init is true, PtByPt Mean should return the current input value. It is usually convenient that it works that way, and the other way around would almost always be inconvenient.
04-04-2018 09:29 AM
This one of the few times I've found the LabVIEW help to be less than helpful. All it says for initialize is: "initialize, when TRUE, initializes the internal state of the VI." It should probably be more specific in what initializes.
04-04-2018 09:52 AM
BTW 0 would never be expected (by me). If init=true means the current cycle is not included as a valid cycle, I'd expect NaN as a result, not zero.
04-04-2018 12:43 PM
In making my own version, I did find another "error" in that the size needed to be reset to 0 also, which would give the NaN.
So my desire was to use the Init as a reset and ignore whatever the input value was (if I'm resetting, the value is invalid/garbage in my use case and there could be multiple resets in a row). Seeing as I'm on an island on this one, I'll move on with my own version.
04-04-2018 12:54 PM
If I were writing my own API for a functional global, maybe I would break up the two operations into "Clear" (where no value is input) and "Add Point" to make it more clear what is going on. For a palette VI though, this behavior has never messed me up. At some point you will need to add your first point, this just forces you to make that coincide with your reset logic.