@timmeck/brain-core 2.36.92 → 2.36.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/hypothesis/engine.d.ts +39 -0
- package/dist/hypothesis/engine.js +89 -4
- package/dist/hypothesis/engine.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js.map +1 -1
- package/dist/memory/conversation-memory.d.ts +18 -1
- package/dist/memory/conversation-memory.js +114 -28
- package/dist/memory/conversation-memory.js.map +1 -1
- package/dist/meta-learning/engine.d.ts +68 -0
- package/dist/meta-learning/engine.js +209 -0
- package/dist/meta-learning/engine.js.map +1 -1
- package/dist/synapses/hebbian.d.ts +11 -4
- package/dist/synapses/hebbian.js +17 -5
- package/dist/synapses/hebbian.js.map +1 -1
- package/dist/synapses/synapse-manager.d.ts +2 -2
- package/dist/synapses/synapse-manager.js +2 -2
- package/dist/synapses/synapse-manager.js.map +1 -1
- package/dist/synapses/types.d.ts +10 -0
- package/package.json +1 -1
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import type { NodeRef, SynapseRecord, HebbianConfig, SynapseRepoInterface } from './types.js';
|
|
1
|
+
import type { NodeRef, SynapseRecord, HebbianConfig, SignalScores, SynapseRepoInterface } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Hebbian learning: strengthen a synapse between two nodes.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Uses multiplicative update: w_new = min(1.0, w_old * (1 + effectiveRate))
|
|
5
|
+
* where effectiveRate = learningRate * qualityFactor.
|
|
6
|
+
*
|
|
7
|
+
* Signal quality weighting: when scores are provided, the effective rate is
|
|
8
|
+
* scaled by sqrt(sourceScore * targetScore). Strong co-activations reinforce
|
|
9
|
+
* more than weak ones. Without scores, full learningRate applies.
|
|
10
|
+
*
|
|
11
|
+
* This replaces the old additive formula (w + (1-w) * rate) which converged
|
|
12
|
+
* too fast and saturated synapses to ~1.0 with little differentiation.
|
|
6
13
|
*/
|
|
7
|
-
export declare function strengthen(repo: SynapseRepoInterface, source: NodeRef, target: NodeRef, synapseType: string, config: HebbianConfig, context?: Record<string, unknown
|
|
14
|
+
export declare function strengthen(repo: SynapseRepoInterface, source: NodeRef, target: NodeRef, synapseType: string, config: HebbianConfig, context?: Record<string, unknown>, scores?: SignalScores): SynapseRecord;
|
|
8
15
|
/**
|
|
9
16
|
* Weaken a synapse by a multiplicative factor.
|
|
10
17
|
* Prunes if weight drops below threshold.
|
package/dist/synapses/hebbian.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hebbian learning: strengthen a synapse between two nodes.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Uses multiplicative update: w_new = min(1.0, w_old * (1 + effectiveRate))
|
|
4
|
+
* where effectiveRate = learningRate * qualityFactor.
|
|
5
|
+
*
|
|
6
|
+
* Signal quality weighting: when scores are provided, the effective rate is
|
|
7
|
+
* scaled by sqrt(sourceScore * targetScore). Strong co-activations reinforce
|
|
8
|
+
* more than weak ones. Without scores, full learningRate applies.
|
|
9
|
+
*
|
|
10
|
+
* This replaces the old additive formula (w + (1-w) * rate) which converged
|
|
11
|
+
* too fast and saturated synapses to ~1.0 with little differentiation.
|
|
5
12
|
*/
|
|
6
|
-
export function strengthen(repo, source, target, synapseType, config, context) {
|
|
13
|
+
export function strengthen(repo, source, target, synapseType, config, context, scores) {
|
|
7
14
|
const existing = repo.findBySourceTarget(source.type, source.id, target.type, target.id, synapseType);
|
|
15
|
+
// Quality factor: sqrt(sourceScore * targetScore), defaults to 1.0
|
|
16
|
+
const qualityFactor = scores
|
|
17
|
+
? Math.sqrt(Math.max(0, scores.sourceScore) * Math.max(0, scores.targetScore))
|
|
18
|
+
: 1.0;
|
|
19
|
+
const effectiveRate = config.learningRate * qualityFactor;
|
|
8
20
|
if (existing) {
|
|
9
|
-
// Hebbian:
|
|
10
|
-
const newWeight = Math.min(1.0, existing.weight
|
|
21
|
+
// Multiplicative Hebbian: w *= (1 + effectiveRate), bounded at 1.0
|
|
22
|
+
const newWeight = Math.min(1.0, existing.weight * (1 + effectiveRate));
|
|
11
23
|
repo.update(existing.id, {
|
|
12
24
|
weight: newWeight,
|
|
13
25
|
activation_count: existing.activation_count + 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hebbian.js","sourceRoot":"","sources":["../../src/synapses/hebbian.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"hebbian.js","sourceRoot":"","sources":["../../src/synapses/hebbian.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CACxB,IAA0B,EAC1B,MAAe,EACf,MAAe,EACf,WAAmB,EACnB,MAAqB,EACrB,OAAiC,EACjC,MAAqB;IAErB,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CACtC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,WAAW,CAC5D,CAAC;IAEF,mEAAmE;IACnE,MAAM,aAAa,GAAG,MAAM;QAC1B,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QAC9E,CAAC,CAAC,GAAG,CAAC;IACR,MAAM,aAAa,GAAG,MAAM,CAAC,YAAY,GAAG,aAAa,CAAC;IAE1D,IAAI,QAAQ,EAAE,CAAC;QACb,mEAAmE;QACnE,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;QACvE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE;YACvB,M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 +1,4 @@
|
|
|
1
|
-
import type { NodeRef, SynapseRecord, ActivationResult, SynapsePath, NetworkStats, SynapseRepoInterface } from './types.js';
|
|
1
|
+
import type { NodeRef, SynapseRecord, ActivationResult, SynapsePath, NetworkStats, SynapseRepoInterface, SignalScores } from './types.js';
|
|
2
2
|
export interface SynapseManagerConfig {
|
|
3
3
|
initialWeight: number;
|
|
4
4
|
learningRate: number;
|
|
@@ -18,7 +18,7 @@ export declare class BaseSynapseManager {
|
|
|
18
18
|
protected config: SynapseManagerConfig;
|
|
19
19
|
protected logger: import("winston").Logger;
|
|
20
20
|
constructor(repo: SynapseRepoInterface, config: SynapseManagerConfig);
|
|
21
|
-
strengthen(source: NodeRef, target: NodeRef, synapseType: string, context?: Record<string, unknown
|
|
21
|
+
strengthen(source: NodeRef, target: NodeRef, synapseType: string, context?: Record<string, unknown>, scores?: SignalScores): SynapseRecord;
|
|
22
22
|
weaken(synapseId: number, factor?: number): void;
|
|
23
23
|
find(source: NodeRef, target: NodeRef, synapseType: string): SynapseRecord | undefined;
|
|
24
24
|
activate(startNode: NodeRef, maxDepth?: number, minWeight?: number): ActivationResult[];
|
|
@@ -16,9 +16,9 @@ export class BaseSynapseManager {
|
|
|
16
16
|
this.repo = repo;
|
|
17
17
|
this.config = config;
|
|
18
18
|
}
|
|
19
|
-
strengthen(source, target, synapseType, context) {
|
|
19
|
+
strengthen(source, target, synapseType, context, scores) {
|
|
20
20
|
this.logger.debug(`Strengthening synapse ${source.type}:${source.id} --${synapseType}--> ${target.type}:${target.id}`);
|
|
21
|
-
return strengthen(this.repo, source, target, synapseType, this.hebbianConfig(), context);
|
|
21
|
+
return strengthen(this.repo, source, target, synapseType, this.hebbianConfig(), context, scores);
|
|
22
22
|
}
|
|
23
23
|
weaken(synapseId, factor = 0.5) {
|
|
24
24
|
this.logger.debug(`Weakening synapse ${synapseId} by factor ${factor}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synapse-manager.js","sourceRoot":"","sources":["../../src/synapses/synapse-manager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAY/C;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAIjB;IACA;IAJF,MAAM,GAAG,SAAS,EAAE,CAAC;IAE/B,YACY,IAA0B,EAC1B,MAA4B;QAD5B,SAAI,GAAJ,IAAI,CAAsB;QAC1B,WAAM,GAAN,MAAM,CAAsB;IACrC,CAAC;IAEJ,UAAU,CACR,MAAe,EACf,MAAe,EACf,WAAmB,EACnB,OAAiC;
|
|
1
|
+
{"version":3,"file":"synapse-manager.js","sourceRoot":"","sources":["../../src/synapses/synapse-manager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAY/C;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAIjB;IACA;IAJF,MAAM,GAAG,SAAS,EAAE,CAAC;IAE/B,YACY,IAA0B,EAC1B,MAA4B;QAD5B,SAAI,GAAJ,IAAI,CAAsB;QAC1B,WAAM,GAAN,MAAM,CAAsB;IACrC,CAAC;IAEJ,UAAU,CACR,MAAe,EACf,MAAe,EACf,WAAmB,EACnB,OAAiC,EACjC,MAAqB;QAErB,IAAI,CAAC,MAAM,CAAC,KA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 +50,16 @@ export interface HebbianConfig {
|
|
|
50
50
|
learningRate: number;
|
|
51
51
|
pruneThreshold: number;
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Optional signal quality scores for Hebbian strengthening.
|
|
55
|
+
* When provided, the effective learning rate is scaled by
|
|
56
|
+
* sqrt(sourceScore * targetScore) — strong co-activations
|
|
57
|
+
* reinforce more than weak ones.
|
|
58
|
+
*/
|
|
59
|
+
export interface SignalScores {
|
|
60
|
+
sourceScore: number;
|
|
61
|
+
targetScore: number;
|
|
62
|
+
}
|
|
53
63
|
export interface DecayConfig {
|
|
54
64
|
decayHalfLifeDays: number;
|
|
55
65
|
decayAfterDays: number;
|
package/package.json
CHANGED