0
$\begingroup$

I have a stream of numbers - efficiency ratio of solar cells - in range 0-100%. The efficiency is defined as (produced/expected)*100.

I'm measuring the ratio every minute, and I'd like to have a "cumulative" ratio that shows the average.

A little problem is at night, when the ratio becomes undefined, since there is no light and no power. I'm setting it to zero at night, and this would be excluded from the computation of average.

Is there some formula how to keep such average, so that it'll show ever-improving average of the efficiency? I want that when the solar cells age, and lose efficiency, that this average would also lower - but when for example snow falls onto the cells, and they don't work properly, it should not ruin the average immediately.

Ideally I'd want to keep just one variable, maybe two. I can no way keep all the past values.

$\endgroup$
4
  • $\begingroup$ I guess that is mostly a question of programming, not of math. Saving that stream of numbers should (at about 0.1kib/data point) only take 50mib per year. Keeping all the past values doesn't really seem like a problem. (And may allow you to do exiting stuff later) Unless you want to display a continuously updating number somewhere in your home, the naive, unoptimized algorithm shouldn't be a problem. (And a decent math library should allow you to average a billion numbers) $\endgroup$ Commented Feb 14, 2015 at 13:45
  • $\begingroup$ That aside, if you really have a constantly updating counter somewhere, comment. Calculating a running average is definitely possible without much computation power. $\endgroup$ Commented Feb 14, 2015 at 13:54
  • $\begingroup$ You're right, I want to display a "real time" value. I hoped there'd be a way to do it without keeping history, but that'll probably indeed be the easiest way. $\endgroup$
    – MightyPork
    Commented Feb 14, 2015 at 14:16
  • $\begingroup$ There is a way (I'll post a solution), but it is susceptible to rounding errors. You can add extra precautions to avoid those though. $\endgroup$ Commented Feb 14, 2015 at 14:18

1 Answer 1

0
$\begingroup$

I'll ignore the night for now. Your programs should be able to sort out all invalid data points and only report the good ones to our function. Let $a_1, ..., a_n$ be the sequence of old data points and $a_{n+1}$ the new one. We use $m_k$ do describe the (arithmetic) mean of the first $k$ values.

$$m_{n+1} = \frac{1}{n+1}\sum_{i=1}^{n+1} a_i = \frac{n}{n+1} \left(\frac{1}{n} \sum_{i=1}^{n} a_i\right) + \frac{a_{n+1}}{n+1} = \frac{n \cdot m_n}{n+1} + \frac{a_{n+1}}{n+1} $$

This formula $m_{n+1} = \frac{n\cdot m_n + a_{n+1}}{n+1}$ is rather easy to implement, but be aware that is is also likely to accumulate errors! The easies way to get around that, is a fresh recalculation of your current $m_{\text{today}}$ once a day at your favorite hour. Make sure to use a well written math library (in your language of choice) to ensure high accuracy & performance.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .