Custom error function

Hi Community,

I was wondering how to implement --i.e. in swarming-- the Mahalanobis Distance, defined as:

image
In the wiki there are not many info about custom error function and after reading the wiki.metrics I still don’t feel any clever.

I am really looking forward for some good hint.
Thank you!

I’m sorry. This is where the dragons are in nupic.

Trying to train the dragon, this is my best shot:

#initialize?
if tools.getData('first') is None:
  tools.storeData('first', 0)
if tools.getData('invCov') is None:
  tools.storeData('invCov', 0)
if tools.getData('trans') is None:
  tools.storeData('trans', 0)

#sum over i
tools.storeData('first', tools.getData('first') + (prediction - groundTruth))
tools.storeData('invCov', **???** ) #how calculate inv.Covariance Matrix?? 
tools.storeData('trans', tools.getData('trans') + transpose(prediction - groundTruth))  
#how calculate transpose?

#wrap up
tools.storeData('result', (tools.getData('first')*tools.getData('invCov')*(tools.getData('trans')**1/2)
tools.getData('result')

Still how to calculate the inverse Cov matrix and to transpose are open enigmas.
@rhyolight what’s the name of this programming language?

It’s python, but there is some strange configuration majic happening down there. I have honestly shied away from the swarming codebase ever since discovering it.