25 Replies Latest reply on Dec 7, 2017 4:57 PM by skwan

    Linear Regression in AF

    troycarrick

      Looking for a means to determine the rate of change for a value over time. Was looking at performing a linear regression for a set time period and comparing that with the slope for the time period directly before and after it.

       

       

       

      Any ability to use an Analysis template to perform the simple linear regression calculation?

       

       

       

       

        • Re: Linear Regression in AF
          skwan

          There is not a built in function for linear regression.  However, functions are available for you to apply numerical methods to calculate it.

            • Re: Linear Regression in AF
              Roger Palmen

              As far as i understand linear regressions, you must consider all values over time. Within AF, you can't really pull all values over a given time period into a formula and do some calculations over that.

               

              Best option i can think of is a custom DataReference.

                • Re: Linear Regression in AF
                  John Messinger

                  I had to calculate linear regression in the project I am currently working on, and also found that it wasn't easily done in the AF analytics. I ended up calculating it in some custom AF-SDK code in PI-ACE using the MathNet.Numerics library (numerics.mathdotnet.com). Doesn't immediately address the issue of templating this, but longer term this is something I would like to do too. A custom calculation Data Reference is one option as Roger suggested, but won't suit my particular project requirement.

                    • Re: Linear Regression in AF

                      John: Can you expand on the business use case? What kind of data is it? And, what do you do after the linear fit?  Is the time-range for the data, say last 24 hours etc.?

                        • Re: Linear Regression in AF
                          John Messinger

                          Gopal,

                           

                          The use case is to calculate the rate of gas leakage from SF6 insulated circuit breakers and transformers. We're running a linear regression on the previous 12 months of gas density readings to determine the leakage rate using the slope, and using the y-intercept to then predict the date at which the gas density will reach a pre-defined critical level. There is added complexity in the fact that I am required to apply a number of rules to filter the input data prior to running the regression calculation. The 'daily' readings we use are actually an average of the values between 10pm and 4am each day for the 12 month calculation period.

                           

                          Unfortunately there is nothing simple about this particular calculation requirement  

                            • Re: Linear Regression in AF
                              Roger Palmen

                              What do you do with the predicted date? This might be just a report, e.g. through PI DataLink, Excel services etcetera that delivers the information when needed. So i thing the optimal solution in your case will be mainly dependant on the business process it is used in.

                               

                              There is litlle that can beat the flexibility and ease of use of PI DataLink and Excel. So if that is applicable in your case, that would be my recommendation.

                                • Re: Linear Regression in AF
                                  John Messinger

                                  The predicted date is used by the business to determine and plan maintenance on the equipment, specifically topping up the insulating gas. The results are reported based on these dates, with the soonest date predictions at the top. There are other drivers as well, such as OH&S for staff entering the substations  and potential reporting to environmental regulatory agencies.

                                   

                                  Excel and DataLink aren't really options here, as we are performing these calculations on a monthly scheduled basis for some 4000+ elements in the asset hierarchy. Automating the calculations in a server based environment one of the business requirements - they are actually wanting to move away from an existing Excel based system.

                                   

                                  Using PI-ACE with the AFSDK seems to be a good option for us in this instance, as it gives us the ability to collect and filter the input values according to the business rules as well as perform the actual calculations. It also is dynamic enough to automatically handle changes in the asset hierarchy as equipment is commissioned or decommissioned.

                                   

                                  The key point of this was that it isn't that straight forward to calculate linear regressions using the built in AF functionality, either through the DR's that come out of the box, or with Asset based Analytics. While it would ultimately be desirable to be able to do this through templating and avoid writing custom code, at the moment it doesn't seem possible as you said yourself in response to the original post.

                                    • Re: Linear Regression in AF
                                      Roger Palmen

                                      Thanks for explaining the circumstances. Clarifies a lot on the requirements that drive the solution in a certain direction.

                                       

                                      I'd personally still go for a custom DR, as the effort required for building an ACE module will be similar as for a custom DR. And the DR will be much more future proof. If you start on ACE now, you will likely need a strategic solution for the long term anyway.

                                       

                                      And AF is very fast. I used to do online cost caclulations with a daily granulatity over one year for a few hundred assets. That query took just 20 seconds on OLEDB Enterprise, providing a full report on all assets. So using a well-built DR, online calculations might be suffucient, but be very, VERY careful in the access paths to highly aggregated online calculated values as this can explode quickly if you're not careful.

                                       

                                      PS: I'll put a linear regression DR on my list of DR's i'd like to have...

                                       

                                      PPS: Integration with R might be a nice one. See this post: vcampus.osisoft.com/.../predictive-analytics-using-pi-and-r.aspx

                                      1 of 1 people found this helpful
                                        • Re: Linear Regression in AF
                                          Asle Frantzen

                                          I have written a custom DR for calculating slopes of regression lines (with user-configurable duration), to determine slow leaks in SF6 switching gear. Works like a charm!

                                           

                                          I've also written - and made public here on vCampus through my blog - a RegressionLine add-in for ProcessBook. This one includes the y-intercept as far as I can remember.

                                           

                                          The code is similar, and although I don't currently output the y-intercept in my custom DR it shouldn't be much work to make it do that as well. We don't currently market this as a product, but if you are interested we can probably work something out (either ready-to-use dll, or complete code). If you are interested contact Amitec through our website www.amitec.no

                                          1 of 1 people found this helpful