Contributive Sensitive Maps

  • 5 Replies
  • 2255 Views
*

Zero

  • Eve
  • ***********
  • 1287
Contributive Sensitive Maps
« on: April 04, 2022, 04:31:19 pm »
The evolution of the SMaps presented in the Postcard NoSQL thread is CSMaps.
SMap was about "sensing" when you set values. CSMap is the other way around: it adds an "acting when you get" values.
The idea is to "pull" computation: if you're getting values, it means you're curious about them, which means that work should be made around these values to enhance them, complete them, ...etc. It's exactly like focusing on something: when you direct your attention on something, you drive your "computations" on it.

The code is still super-small scale:

Code

// Contributive Sensitive Maps

class CSMap extends Map {

    sensors = {};
    contributors = {};

    constructor(content) {
        super();
        if (content)
            for (let [k, v] of content) this.set(k, v);
    }

    sense(id) {
        return this.sensors[id].solution;
    }

    removeContributor(id) {
        delete this.contributors[id];
    }

    contributor(id, parameters, mapper) {
        this.contributors[id] = { parameters, mapper };
    }

    removeSensor(id) {
        delete this.sensors[id];
    }

    sensor(id, initial, reducer) {
        this.sensors[id] = { reducer, solution: initial };
        this.forEach((value, key) => {
            this.sensors[id].solution =
                this.sensors[id].reducer(
                    this.sensors[id].solution,
                    key,
                    value
                )
        });
    }

    touch(key, previous) {
        for (let s in this.sensors)
            this.sensors[s].solution =
                this.sensors[s].reducer(
                    this.sensors[s].solution,
                    key,
                    super.get(key),
                    previous
                );
    }

    get(...args) {
        let result = super.get(...args);
        for (let c in this.contributors)
            this.contributors[c].mapper.call(
                this,
                args[0],
                result,
                this.contributors[c].parameters
            );
        return result;
    }

    set(...args) {
        let previous = super.get(args[0]);
        let result = super.set(...args);
        this.touch(args[0], previous);
        return result;
    }

    delete(...args) {
        let previous = super.get(args[0]);
        let result = super.delete(...args);
        this.touch(args[0], previous);
        return result;
    }
}


Example usage:

Code: text

let csmap = new CSMap();

csmap.set('i1', "foo");

csmap.set('i2', "bar");

csmap.sensor("string counter", 0, function (solution, key, newValue, oldValue) {

    if (typeof oldValue != "string" && typeof newValue == "string") ++solution;
    if (typeof oldValue == "string" && typeof newValue != "string") --solution;

    return solution;
})

csmap.sensor("string selector", new Set(), function (solution, key, newValue, oldValue) {

    if (typeof newValue == "string") solution.add(key);
    else solution.delete(key);

    return solution;
});

csmap.contributor("curious about numbers", { stuff: 55 }, function (key, value, parameters) {

    if (typeof value == "number")
        csmap.set("curious about", { what: key, myStuff: parameters.stuff });
});

csmap.set('i3', "baz");

console.log("counter:", csmap.sense("string counter"));

csmap.set('i3', 4);

console.log("counter:", csmap.sense("string counter"));
console.log("selector:", csmap.sense("string selector"));

console.log("getting i3:", csmap.get('i3'));

console.log("csmap:", csmap);

/* CONSOLE >>

    counter: 3
    counter: 2
    selector: Set(2) { 'i1', 'i2' }
    getting i3: 4
    csmap: CSMap(4) [Map] {
        'i1' => 'foo',
        'i2' => 'bar',
        'i3' => 4,
        'curious about' => { what: 'i3', myStuff: 55 },
        sensors: {
            'string counter': { reducer: [Function (anonymous)], solution: 2 },
            'string selector': { reducer: [Function (anonymous)], solution: [Set] }
        },
        contributors: {
            'curious about numbers': { parameters: [Object], mapper: [Function (anonymous)] }       
        }
    }
*/

*

MagnusWootton

  • Replicant
  • ********
  • 634
Re: Contributive Sensitive Maps
« Reply #1 on: April 04, 2022, 09:36:34 pm »
so are you "detecting" what the semantic of the variable is coming into the system via context?
Otherwise you couldn't "concentrate" the program on it... or am I way off the mark...

*

Zero

  • Eve
  • ***********
  • 1287
Re: Contributive Sensitive Maps
« Reply #2 on: April 05, 2022, 08:55:31 am »
In this scheme, "contributors" are meant to be minimal hooks executed on each read access. Variables are supposed to carry their own semantics (see Wild ontology). These hooks have parameters that can be modified at runtime.

The idea is to generate activity where values are interesting, that is, where you "get" values.

*

MagnusWootton

  • Replicant
  • ********
  • 634
Re: Contributive Sensitive Maps
« Reply #3 on: April 05, 2022, 09:08:04 am »
If you want to supply a variable which has a definite semantic,  it needs to what row its going into the database,   usually that's impossible for a computer to do by itself.     As far as I know you have to pre-know what it is,  you cant work it out afterwards.

*

Zero

  • Eve
  • ***********
  • 1287
Re: Contributive Sensitive Maps
« Reply #4 on: April 05, 2022, 09:29:16 am »
There's no row / no column, it's a NoSQL-style document store. Sorry I don't understand your reply.

*

Zero

  • Eve
  • ***********
  • 1287
Re: Contributive Sensitive Maps
« Reply #5 on: April 05, 2022, 11:39:24 am »
I think I'll build something along the lines of PLEXIL now, inside of CSMap, and through the IntentManager.

But first, I need linked data.
« Last Edit: April 05, 2022, 01:58:53 pm by Zero »

 


OpenAI Speech-to-Speech Reasoning Demo
by MikeB (AI News )
March 31, 2024, 01:00:53 pm
Say good-bye to GPUs...
by MikeB (AI News )
March 23, 2024, 09:23:52 am
Google Bard report
by ivan.moony (AI News )
February 14, 2024, 04:42:23 pm
Elon Musk's xAI Grok Chatbot
by MikeB (AI News )
December 11, 2023, 06:26:33 am
Nvidia Hype
by 8pla.net (AI News )
December 06, 2023, 10:04:52 pm
How will the OpenAI CEO being Fired affect ChatGPT?
by 8pla.net (AI News )
December 06, 2023, 09:54:25 pm
Independent AI sovereignties
by WriterOfMinds (AI News )
November 08, 2023, 04:51:21 am
LLaMA2 Meta's chatbot released
by 8pla.net (AI News )
October 18, 2023, 11:41:21 pm

Users Online

306 Guests, 0 Users

Most Online Today: 313. Most Online Ever: 2369 (November 21, 2020, 04:08:13 pm)

Articles