Progess / Project 702

UTCI algorithm

I have been battling with the formula for UTCI. It has such an interesting, regular pattern; I was certain it could be coded into an algorithm more succinctly than coding the full 84-term (1.5 pages worth of page) expression. 22:27, Wednesday August 21st, I have my first (untested) draft of the algorithm:

By working term-by-term through the formula and grouping similar terms, I was able to extract the pattern for the second section (56 terms). This second group can be simplified from 56 terms to 21 terms. Further, the pattern can be expressed in the general form:

\left\{\;\;(depth - n - k + 1)\; Ta^n\; Pa^k \;\;|\;\; \forall{n} \in (0, 1, .. depth), \forall{k} \in (depth - 1, depth - 2, .., 1)\;\;\right\}  \newline  where: \newline  \indent \indent depth = the\; degree\; of\; the\; polynomial \newline  \indent \indent Ta = ambient\; air\; temperature \newline  \indent \indent Pa = vapour\; pressure

An algorithm to generate all 56 terms looks like follows:

int depth = 6;
for (int n = 0; n <= depth; n ++) {
    for (int k = (6 - n); k > 0; k --) {
        yield (depth - n - k + 1) * Ta**n * Pa**k;

In Python, this could be written as a generator expression in a single line:

sum((7 - n - k)*Ta**n*Pa**k for n in range(7) for k in range(6 - n, 0, -1))

I have to say I am pretty happy with this. I still have to test it, make sure it actually works 🙂 But the logic is sound. The other challenge I have, is this algorithm doesn’t allow for the weightings applied to each term in the original formula. I need to figure out how to extract these weightings and apply an aggregate weight to the final sum.


2 thoughts on “UTCI algorithm

  1. Pingback: Run time analysis of UTCI algorithms | :: NickBurns

  2. Note: running time of the python generator expression above was tested, and was slightly slower than defining the generator inside a separate function. At this stage, I imagine this might have something to do with the way Python pre-compiles the code before interpretation, it being slightly more efficient to parse an independent generator block c.f. the inline sum(). There is some anecdotal evidence that loops inside functions perform better than loops in global scope.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s