# difference and smooth in the matsumsig model

This time a couple of operators in the MatSumSig model.

Difference:
```f[k] => - f[k-1]/2 + f[k] - f[k+1]/2

[ f0  ]       [  1 -1  0  0  0  0  0  0  0  0  0 ] [ f0  ]
[ f1  ]       [ -1  2 -1  0  0  0  0  0  0  0  0 ] [ f1  ]
[ f2  ]       [  0 -1  2 -1  0  0  0  0  0  0  0 ] [ f2  ]
[ f3  ]       [  0  0 -1  2 -1  0  0  0  0  0  0 ] [ f3  ]
[ f4  ]       [  0  0  0 -1  2 -1  0  0  0  0  0 ] [ f4  ]
[ f5  ] = 1/2 [  0  0  0  0 -1  2 -1  0  0  0  0 ] [ f5  ]
[ f6  ]       [  0  0  0  0  0 -1  2 -1  0  0  0 ] [ f6  ]
[ f7  ]       [  0  0  0  0  0  0 -1  2 -1  0  0 ] [ f7  ]
[ f8  ]       [  0  0  0  0  0  0  0 -1  2 -1  0 ] [ f8  ]
[ f9  ]       [  0  0  0  0  0  0  0  0 -1  2 -1 ] [ f9  ]
[ f10 ]       [  0  0  0  0  0  0  0  0  0 -1  1 ] [ f10 ]
```
And note that we don't have currency conservation, since the sum of columns = 0, instead of 1. Originally I thought this thing would be useful (eg, for edge detection in images), but so far, not particularly.

Next is smooth, and this one is clearly useful.
Smooth:
```f[k] => f[k-1]/4 + f[k]/2 + f[k+1]/4

[ f0  ]       [ 3 1 0 0 0 0 0 0 0 0 0 ] [ f0  ]
[ f1  ]       [ 1 2 1 0 0 0 0 0 0 0 0 ] [ f1  ]
[ f2  ]       [ 0 1 2 1 0 0 0 0 0 0 0 ] [ f2  ]
[ f3  ]       [ 0 0 1 2 1 0 0 0 0 0 0 ] [ f3  ]
[ f4  ]       [ 0 0 0 1 2 1 0 0 0 0 0 ] [ f4  ]
[ f5  ] = 1/4 [ 0 0 0 0 1 2 1 0 0 0 0 ] [ f5  ]
[ f6  ]       [ 0 0 0 0 0 1 2 1 0 0 0 ] [ f6  ]
[ f7  ]       [ 0 0 0 0 0 0 1 2 1 0 0 ] [ f7  ]
[ f8  ]       [ 0 0 0 0 0 0 0 1 2 1 0 ] [ f8  ]
[ f9  ]       [ 0 0 0 0 0 0 0 0 1 2 1 ] [ f9  ]
[ f10 ]       [ 0 0 0 0 0 0 0 0 0 1 3 ] [ f10 ]
```
Now an example representation in BKO:
```smooth |f0> => 0.75|f0> + 0.25|f1>
smooth |f1> => 0.25|f0> + 0.5|f1> + 0.25|f2>
smooth |f2> => 0.25|f1> + 0.5|f2> + 0.25|f3>
smooth |f3> => 0.25|f2> + 0.5|f3> + 0.25|f4>
smooth |f4> => 0.25|f3> + 0.5|f4> + 0.25|f5>
smooth |f5> => 0.25|f4> + 0.5|f5> + 0.25|f6>
smooth |f6> => 0.25|f5> + 0.5|f6> + 0.25|f7>
smooth |f7> => 0.25|f6> + 0.5|f7> + 0.25|f8>
smooth |f8> => 0.25|f7> + 0.5|f8> + 0.25|f9>
smooth |f9> => 0.25|f8> + 0.5|f9> + 0.25|f10>
smooth |f10> => 0.25|f9> + 0.75|f10>

sa: matrix[smooth]
[ f0  ] = [  0.75  0.25  0     0     0     0     0     0     0     0     0     ] [ f0  ]
[ f1  ]   [  0.25  0.5   0.25  0     0     0     0     0     0     0     0     ] [ f1  ]
[ f2  ]   [  0     0.25  0.5   0.25  0     0     0     0     0     0     0     ] [ f2  ]
[ f3  ]   [  0     0     0.25  0.5   0.25  0     0     0     0     0     0     ] [ f3  ]
[ f4  ]   [  0     0     0     0.25  0.5   0.25  0     0     0     0     0     ] [ f4  ]
[ f5  ]   [  0     0     0     0     0.25  0.5   0.25  0     0     0     0     ] [ f5  ]
[ f6  ]   [  0     0     0     0     0     0.25  0.5   0.25  0     0     0     ] [ f6  ]
[ f7  ]   [  0     0     0     0     0     0     0.25  0.5   0.25  0     0     ] [ f7  ]
[ f8  ]   [  0     0     0     0     0     0     0     0.25  0.5   0.25  0     ] [ f8  ]
[ f9  ]   [  0     0     0     0     0     0     0     0     0.25  0.5   0.25  ] [ f9  ]
[ f10 ]   [  0     0     0     0     0     0     0     0     0     0.25  0.75  ] [ f10 ]
```
Some notes:
1) this clearly has currency conservation, since all columns sum to 1.
2) this thing rapidly approaches a Gaussian smooth, if you iterate it a few times. eg, in image edge enhancement, smooth^20 gave good results. See here. In the case of mapping posting times to 1440 buckets in a day, 300 to 500 smooths gave the best results.

Home
previous: simm in the matsumsig model
next: simple prolog vs bko example

updated: 19/12/2016
by Garry Morrison
email: garry -at- semantic-db.org