bowen-xu / PyNARS

MIT License
26 stars 8 forks source link

[Bug] Add OpenNARS-style Distributor in Bag #83

Closed maxeeem closed 7 months ago

maxeeem commented 8 months ago

Describe the bug

Higher priority items in Bag should have higher frequency of being picked with lower priority items still having a chance at being selected but much lower than high priority items. This is related to attention and resource allocation.

To Reproduce

Behavior in OpenNARS seems different and closer to what I expected. On 10 takes, I consistently get 6/4 instead of 0/10 or 1/9 in PyNARS. On 100 it's about 50/50.

// b = new Bag(100, 1000, nar.narParameters)
public void testBagPriority(final Bag<NullItem,CharSequence> b) {

    final NullItem na = new NullItem(0.9f);
    final NullItem nb = new NullItem(0.8f);

    b.putIn(na);
    b.putIn(nb);
    b.putIn(new NullItem(0.21f));
    b.putIn(new NullItem(0.24f));
    b.putIn(new NullItem(0.25f));
    b.putIn(new NullItem(0.26f));
    b.putIn(new NullItem(0.27f));
    b.putIn(new NullItem(0.28f));
    b.putIn(new NullItem(0.23f));
    b.putIn(new NullItem(0.22f));

    int hi = 0;
    int lo = 0;
    for (int i = 0; i < 10; i++) {
        final NullItem item = b.takeOut();
        if (item == na || item == nb) {
            hi += 1;
        } else {
            lo += 1;
        }
        b.putIn(item);
    }
    System.out.println(hi + "\t" + lo);

Additional context

Add any other context about the problem here.

ccrock4t commented 8 months ago

Hi Maxim, can you clarify the numbers about the current behavior vs. expected behavior in each system?

maxeeem commented 8 months ago

Hi Maxim, can you clarify the numbers about the current behavior vs. expected behavior in each system?

Yeah, so this is following our discussion over email earlier. Basically, if we have a bag with 10 items, 2 high priority and 8 low priority, and then we perform take 10 times, currently in PyNARS the high priority items will get picked less than 10% of the time. In OpenNARS the two high priority items get picked consistently about 60% of the time which is what we want.

Also, see my comment on the PR for some neat graphs :)