[pymvpa] Custom distance metrics for SOM
Sheen, David A.
dsheen at nist.gov
Mon Nov 30 15:41:39 UTC 2015
Hi,
I'm trying to use a custom distance metric for the self-organizing map
in PyMVPA, and I'm having some difficulty. The documentation says that I
can define the SOM as follows:
som = SimpleSOMMapper(size, niter,
learning_rate=something,distance_metric=d)
where d is a function such that distance_between_x_and_y = d(x,y), and
presumably x and y are vectors and d returns a scalar.
However, the SOM package appears to pass a matrix to distance_metric,
and it's unclear what the expected inputs and outputs from
distance_metric are supposed to be in this case.
For instance the following code:
def jeffries(x,y):
entropy_xy = sp.stats.entropy(x,y)
entropy_yx = sp.stats.entropy(y,x)
jeffries_entropy = (entropy_xy+entropy_yx)/2.0
return jeffries_entropy
som = SimpleSOMMapper(size, niter,
learning_rate=something,distance_metric=jeffries)
produces this error:
PyMVPA/mvpa2/mappers/som.pyc in _train(self, samples)
159 np.hstack((
160 # upper left
--> 161 k[self._dqdshape[0]:0:-1,
self._dqdshape[1]:0:-1],
162 # upper right
163 k[self._dqdshape[0]:0:-1,
:self._dqdshape[3]])),
IndexError: too many indices for array
Does anyone have any experience with this issue?
Dave
More information about the Pkg-ExpPsy-PyMVPA
mailing list