neupy icon indicating copy to clipboard operation
neupy copied to clipboard

ART1: calling predict() multiple times does not give same result

Open peterdekker opened this issue 2 years ago • 4 comments

The ART1 documentation says that calling predict/train on the same model multiple times, trains a new model: http://neupy.com/modules/generated/neupy.algorithms.ART1.html Thus I would expect that they give the same result. However, different calls of predict() on the same model give different results. With my data, the result is different for the second run and then stays the same. Code:

from neupy.algorithms import ART1
artnet = ART1(
    step=0.1,
    rho=0.5,
    n_clusters=5,
)
for i in range(10):
    clusters = artnet.predict(data)
    print(clusters)

yields result:

[0. 1. 2. ... 1. 1. 1.]
[0. 1. 1. ... 1. 1. 1.]
[0. 1. 1. ... 1. 1. 1.]
[0. 1. 1. ... 1. 1. 1.]
[0. 1. 1. ... 1. 1. 1.]
[0. 1. 1. ... 1. 1. 1.]
[0. 1. 1. ... 1. 1. 1.]
[0. 1. 1. ... 1. 1. 1.]
[0. 1. 1. ... 1. 1. 1.]
[0. 1. 1. ... 1. 1. 1.]

The data is 2700 data points of about 200 features. If needed I can supply the data.

peterdekker avatar Jan 29 '22 11:01 peterdekker

I may have found the cause. It seems the weight_21 and weight_12 fields of the ART class are re-used across runs, and not reset.

peterdekker avatar Jan 29 '22 13:01 peterdekker

@peterdekker thank you for reporting the problem. I wouldn't necessary say that this is a bug, but rather bad design on my part. It would be reproducible if during each iteration you would initialize a new object

from neupy.algorithms import ART1

for i in range(10):
    artnet = ART1(
        step=0.1,
        rho=0.5,
        n_clusters=5,
    )
    clusters = artnet.predict(data)
    print(clusters)

itdxer avatar Jan 31 '22 15:01 itdxer

Thanks for looking into it! I indeed worked around it by creating a new object. Maybe it would then mainly an issue of describing the predict() method differently in the documentation.

peterdekker avatar Jan 31 '22 15:01 peterdekker

So, given that weights_12 and weights_21 are re-used over invocations of train(), could train() actually be used to train the model incrementally on multiple batches of data? That would actually be useful for me.

peterdekker avatar Jun 24 '22 12:06 peterdekker