@spiky-panda/core 0.1.0

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.
Files changed (130) hide show
  1. package/dist/geometry/geometry.cartesian.d.ts +56 -0
  2. package/dist/geometry/geometry.cartesian.js +229 -0
  3. package/dist/geometry/geometry.cartesian.js.map +1 -0
  4. package/dist/geometry/geometry.interfaces.d.ts +37 -0
  5. package/dist/geometry/geometry.interfaces.js +31 -0
  6. package/dist/geometry/geometry.interfaces.js.map +1 -0
  7. package/dist/geometry/index.d.ts +2 -0
  8. package/dist/geometry/index.js +3 -0
  9. package/dist/geometry/index.js.map +1 -0
  10. package/dist/graph/graph.builder.graph.d.ts +44 -0
  11. package/dist/graph/graph.builder.graph.js +78 -0
  12. package/dist/graph/graph.builder.graph.js.map +1 -0
  13. package/dist/graph/graph.builder.node.d.ts +20 -0
  14. package/dist/graph/graph.builder.node.js +45 -0
  15. package/dist/graph/graph.builder.node.js.map +1 -0
  16. package/dist/graph/graph.builder.olink.d.ts +12 -0
  17. package/dist/graph/graph.builder.olink.js +32 -0
  18. package/dist/graph/graph.builder.olink.js.map +1 -0
  19. package/dist/graph/graph.graph.d.ts +13 -0
  20. package/dist/graph/graph.graph.js +26 -0
  21. package/dist/graph/graph.graph.js.map +1 -0
  22. package/dist/graph/graph.graphItem.d.ts +14 -0
  23. package/dist/graph/graph.graphItem.js +36 -0
  24. package/dist/graph/graph.graphItem.js.map +1 -0
  25. package/dist/graph/graph.interfaces.builder.d.ts +28 -0
  26. package/dist/graph/graph.interfaces.builder.js +2 -0
  27. package/dist/graph/graph.interfaces.builder.js.map +1 -0
  28. package/dist/graph/graph.interfaces.d.ts +59 -0
  29. package/dist/graph/graph.interfaces.js +51 -0
  30. package/dist/graph/graph.interfaces.js.map +1 -0
  31. package/dist/graph/graph.node.d.ts +12 -0
  32. package/dist/graph/graph.node.js +22 -0
  33. package/dist/graph/graph.node.js.map +1 -0
  34. package/dist/graph/graph.olink.d.ts +13 -0
  35. package/dist/graph/graph.olink.js +56 -0
  36. package/dist/graph/graph.olink.js.map +1 -0
  37. package/dist/graph/index.d.ts +9 -0
  38. package/dist/graph/index.js +10 -0
  39. package/dist/graph/index.js.map +1 -0
  40. package/dist/index.d.ts +6 -0
  41. package/dist/index.js +15 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/neuralnetwork/ann/index.d.ts +1 -0
  44. package/dist/neuralnetwork/ann/index.js +2 -0
  45. package/dist/neuralnetwork/ann/index.js.map +1 -0
  46. package/dist/neuralnetwork/ann/mlp/index.d.ts +9 -0
  47. package/dist/neuralnetwork/ann/mlp/index.js +10 -0
  48. package/dist/neuralnetwork/ann/mlp/index.js.map +1 -0
  49. package/dist/neuralnetwork/ann/mlp/mlp.activation.d.ts +22 -0
  50. package/dist/neuralnetwork/ann/mlp/mlp.activation.js +22 -0
  51. package/dist/neuralnetwork/ann/mlp/mlp.activation.js.map +1 -0
  52. package/dist/neuralnetwork/ann/mlp/mlp.builder.d.ts +43 -0
  53. package/dist/neuralnetwork/ann/mlp/mlp.builder.js +168 -0
  54. package/dist/neuralnetwork/ann/mlp/mlp.builder.js.map +1 -0
  55. package/dist/neuralnetwork/ann/mlp/mlp.graph.d.ts +7 -0
  56. package/dist/neuralnetwork/ann/mlp/mlp.graph.js +7 -0
  57. package/dist/neuralnetwork/ann/mlp/mlp.graph.js.map +1 -0
  58. package/dist/neuralnetwork/ann/mlp/mlp.inference.d.ts +13 -0
  59. package/dist/neuralnetwork/ann/mlp/mlp.inference.js +63 -0
  60. package/dist/neuralnetwork/ann/mlp/mlp.inference.js.map +1 -0
  61. package/dist/neuralnetwork/ann/mlp/mlp.interfaces.d.ts +21 -0
  62. package/dist/neuralnetwork/ann/mlp/mlp.interfaces.js +7 -0
  63. package/dist/neuralnetwork/ann/mlp/mlp.interfaces.js.map +1 -0
  64. package/dist/neuralnetwork/ann/mlp/mlp.neuron.d.ts +10 -0
  65. package/dist/neuralnetwork/ann/mlp/mlp.neuron.js +20 -0
  66. package/dist/neuralnetwork/ann/mlp/mlp.neuron.js.map +1 -0
  67. package/dist/neuralnetwork/ann/mlp/mlp.runtime.utils.d.ts +5 -0
  68. package/dist/neuralnetwork/ann/mlp/mlp.runtime.utils.js +48 -0
  69. package/dist/neuralnetwork/ann/mlp/mlp.runtime.utils.js.map +1 -0
  70. package/dist/neuralnetwork/ann/mlp/mlp.synapse.d.ts +6 -0
  71. package/dist/neuralnetwork/ann/mlp/mlp.synapse.js +7 -0
  72. package/dist/neuralnetwork/ann/mlp/mlp.synapse.js.map +1 -0
  73. package/dist/neuralnetwork/ann/mlp/training/index.d.ts +4 -0
  74. package/dist/neuralnetwork/ann/mlp/training/index.js +5 -0
  75. package/dist/neuralnetwork/ann/mlp/training/index.js.map +1 -0
  76. package/dist/neuralnetwork/ann/mlp/training/mlp.loss.d.ts +10 -0
  77. package/dist/neuralnetwork/ann/mlp/training/mlp.loss.js +11 -0
  78. package/dist/neuralnetwork/ann/mlp/training/mlp.loss.js.map +1 -0
  79. package/dist/neuralnetwork/ann/mlp/training/mlp.optimizers.d.ts +7 -0
  80. package/dist/neuralnetwork/ann/mlp/training/mlp.optimizers.js +59 -0
  81. package/dist/neuralnetwork/ann/mlp/training/mlp.optimizers.js.map +1 -0
  82. package/dist/neuralnetwork/ann/mlp/training/mlp.training.d.ts +22 -0
  83. package/dist/neuralnetwork/ann/mlp/training/mlp.training.interfaces.d.ts +27 -0
  84. package/dist/neuralnetwork/ann/mlp/training/mlp.training.interfaces.js +2 -0
  85. package/dist/neuralnetwork/ann/mlp/training/mlp.training.interfaces.js.map +1 -0
  86. package/dist/neuralnetwork/ann/mlp/training/mlp.training.js +107 -0
  87. package/dist/neuralnetwork/ann/mlp/training/mlp.training.js.map +1 -0
  88. package/dist/neuralnetwork/index.d.ts +8 -0
  89. package/dist/neuralnetwork/index.js +9 -0
  90. package/dist/neuralnetwork/index.js.map +1 -0
  91. package/dist/neuralnetwork/nn.builders.d.ts +21 -0
  92. package/dist/neuralnetwork/nn.builders.js +71 -0
  93. package/dist/neuralnetwork/nn.builders.js.map +1 -0
  94. package/dist/neuralnetwork/nn.interfaces.builder.d.ts +16 -0
  95. package/dist/neuralnetwork/nn.interfaces.builder.js +2 -0
  96. package/dist/neuralnetwork/nn.interfaces.builder.js.map +1 -0
  97. package/dist/neuralnetwork/nn.interfaces.d.ts +16 -0
  98. package/dist/neuralnetwork/nn.interfaces.js +18 -0
  99. package/dist/neuralnetwork/nn.interfaces.js.map +1 -0
  100. package/dist/neuralnetwork/nn.neuron.d.ts +8 -0
  101. package/dist/neuralnetwork/nn.neuron.js +10 -0
  102. package/dist/neuralnetwork/nn.neuron.js.map +1 -0
  103. package/dist/neuralnetwork/nn.synapse.d.ts +6 -0
  104. package/dist/neuralnetwork/nn.synapse.js +14 -0
  105. package/dist/neuralnetwork/nn.synapse.js.map +1 -0
  106. package/dist/neuralnetwork/nn.weights.d.ts +42 -0
  107. package/dist/neuralnetwork/nn.weights.js +120 -0
  108. package/dist/neuralnetwork/nn.weights.js.map +1 -0
  109. package/dist/neuralnetwork/snn/index.d.ts +3 -0
  110. package/dist/neuralnetwork/snn/index.js +4 -0
  111. package/dist/neuralnetwork/snn/index.js.map +1 -0
  112. package/dist/neuralnetwork/snn/spike.interfaces.d.ts +50 -0
  113. package/dist/neuralnetwork/snn/spike.interfaces.js +24 -0
  114. package/dist/neuralnetwork/snn/spike.interfaces.js.map +1 -0
  115. package/dist/neuralnetwork/snn/spike.runtime.d.ts +31 -0
  116. package/dist/neuralnetwork/snn/spike.runtime.js +90 -0
  117. package/dist/neuralnetwork/snn/spike.runtime.js.map +1 -0
  118. package/dist/neuralnetwork/snn/spike.stdp.d.ts +11 -0
  119. package/dist/neuralnetwork/snn/spike.stdp.js +33 -0
  120. package/dist/neuralnetwork/snn/spike.stdp.js.map +1 -0
  121. package/dist/types.d.ts +3 -0
  122. package/dist/types.js +2 -0
  123. package/dist/types.js.map +1 -0
  124. package/dist/utils/csv.d.ts +6 -0
  125. package/dist/utils/csv.js +36 -0
  126. package/dist/utils/csv.js.map +1 -0
  127. package/dist/utils/index.d.ts +1 -0
  128. package/dist/utils/index.js +2 -0
  129. package/dist/utils/index.js.map +1 -0
  130. package/package.json +44 -0
@@ -0,0 +1,32 @@
1
+ import { GraphOLink } from "./graph.olink";
2
+ export class LinkBuilder {
3
+ constructor() {
4
+ this._ctor = GraphOLink; // Default constructor
5
+ }
6
+ withType(c) {
7
+ this._ctor = c;
8
+ return this;
9
+ }
10
+ withFrom(node) {
11
+ this._from = node;
12
+ return this;
13
+ }
14
+ withTo(node) {
15
+ this._to = node;
16
+ return this;
17
+ }
18
+ build(...args) {
19
+ if (!this._from || !this._to) {
20
+ throw new Error("From and To MUST be defined before building a link.");
21
+ }
22
+ const ctr = this._ctor ?? GraphOLink;
23
+ return new ctr(this._from, this._to, ...args);
24
+ }
25
+ reset() {
26
+ this._ctor = GraphOLink; // Reset to default constructor
27
+ this._from = undefined;
28
+ this._to = undefined;
29
+ return this;
30
+ }
31
+ }
32
+ //# sourceMappingURL=graph.builder.olink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.builder.olink.js","sourceRoot":"","sources":["../../src/graph/graph.builder.olink.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,OAAO,WAAW;IAAxB;QACY,UAAK,GAA4B,UAAU,CAAC,CAAC,sBAAsB;IA8B/E,CAAC;IA1BU,QAAQ,CAAmB,CAAqB;QACnD,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,OAAO,IAAI,CAAC;IAChB,CAAC;IACM,QAAQ,CAAC,IAAW;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,OAAO,IAAI,CAAC;IAChB,CAAC;IACM,MAAM,CAAC,IAAW;QACrB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;QAChB,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,GAAG,IAAW;QACvB,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QAC3E,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,IAAI,UAAU,CAAC;QACrC,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAClD,CAAC;IACM,KAAK;QACR,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC,+BAA+B;QACxD,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC;QACrB,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import { IOlink, INode } from \"./graph.interfaces\";\r\nimport { ILinkBuilder, LinkConstructor } from \"./graph.interfaces.builder\";\r\nimport { GraphOLink } from \"./graph.olink\";\r\n\r\nexport class LinkBuilder implements ILinkBuilder {\r\n private _ctor: LinkConstructor<IOlink> = GraphOLink; // Default constructor\r\n private _from?: INode;\r\n private _to?: INode;\r\n\r\n public withType<T extends IOlink>(c: LinkConstructor<T>): ILinkBuilder {\r\n this._ctor = c;\r\n return this;\r\n }\r\n public withFrom(node: INode): ILinkBuilder {\r\n this._from = node;\r\n return this;\r\n }\r\n public withTo(node: INode): ILinkBuilder {\r\n this._to = node;\r\n return this;\r\n }\r\n\r\n public build(...args: any[]): IOlink {\r\n if (!this._from || !this._to) {\r\n throw new Error(\"From and To MUST be defined before building a link.\");\r\n }\r\n const ctr = this._ctor ?? GraphOLink;\r\n return new ctr(this._from, this._to, ...args);\r\n }\r\n public reset(): ILinkBuilder {\r\n this._ctor = GraphOLink; // Reset to default constructor\r\n this._from = undefined;\r\n this._to = undefined;\r\n return this;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,13 @@
1
+ import { ICartesian } from "../geometry";
2
+ import { Nullable } from "../types";
3
+ import { IGraph, INode, IOlink } from "./graph.interfaces";
4
+ import { GraphNode } from "./graph.node";
5
+ export declare class Graph<N extends INode, L extends IOlink> extends GraphNode implements IGraph<N, L> {
6
+ nodes: N[];
7
+ links: L[];
8
+ inputs: N[];
9
+ outputs: N[];
10
+ hiddens: N[];
11
+ constructor(nodes?: N[], links?: L[], inputs?: Nullable<N[]>, outputs?: Nullable<N[]>, hiddens?: Nullable<N[]>, onsc?: Nullable<L[]>, opsc?: Nullable<L[]>, position?: ICartesian);
12
+ clone(): any;
13
+ }
@@ -0,0 +1,26 @@
1
+ import { GraphNode } from "./graph.node";
2
+ export class Graph extends GraphNode {
3
+ constructor(nodes = [], links = [], inputs = null, outputs = null, hiddens = null, onsc = null, opsc = null, position) {
4
+ super(onsc, opsc, position); // Pass `position` to `GraphNode`
5
+ this.nodes = nodes;
6
+ this.links = links;
7
+ this.inputs = inputs ?? this.nodes.filter((n) => n.opsc().length === 0);
8
+ this.outputs = outputs ?? this.nodes.filter((n) => n.onsc().length === 0);
9
+ this.hiddens = hiddens ?? this.nodes.filter((n) => !this.inputs.includes(n) && !this.outputs.includes(n));
10
+ }
11
+ clone() {
12
+ var copy = super.clone();
13
+ copy.nodes = this.nodes.map((n) => n.clone());
14
+ copy.links = this.links.map((l) => {
15
+ const cloned = l.clone();
16
+ cloned.oini = copy.nodes[this.nodes.indexOf(l.oini)]; // the underlying setter is taking care of unbind/bind the link from/to node
17
+ cloned.ofin = copy.nodes[this.nodes.indexOf(l.ofin)]; // ...
18
+ return cloned;
19
+ });
20
+ copy.inputs = copy.nodes.filter((n) => n.opsc().length === 0);
21
+ copy.outputs = copy.nodes.filter((n) => n.onsc().length === 0);
22
+ copy.hiddens = copy.nodes.filter((n) => !copy.inputs.includes(n) && !copy.outputs.includes(n));
23
+ return copy;
24
+ }
25
+ }
26
+ //# sourceMappingURL=graph.graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.graph.js","sourceRoot":"","sources":["../../src/graph/graph.graph.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,OAAO,KAAyC,SAAQ,SAAS;IAOnE,YACI,QAAa,EAAE,EACf,QAAa,EAAE,EACf,SAAwB,IAAI,EAC5B,UAAyB,IAAI,EAC7B,UAAyB,IAAI,EAC7B,OAAsB,IAAI,EAC1B,OAAsB,IAAI,EAC1B,QAAqB;QAErB,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,iCAAiC;QAC9D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;QACxE,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;QAC1E,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9G,CAAC;IAEM,KAAK;QACR,IAAI,IAAI,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC9B,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;YACzB,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,4EAA4E;YACrI,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM;YAC/D,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;QAC9D,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;QAC/D,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/F,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import { ICartesian } from \"../geometry\";\r\nimport { Nullable } from \"../types\";\r\nimport { IGraph, INode, IOlink } from \"./graph.interfaces\";\r\nimport { GraphNode } from \"./graph.node\";\r\n\r\nexport class Graph<N extends INode, L extends IOlink> extends GraphNode implements IGraph<N, L> {\r\n public nodes: N[];\r\n public links: L[];\r\n public inputs: N[];\r\n public outputs: N[];\r\n public hiddens: N[];\r\n\r\n public constructor(\r\n nodes: N[] = [],\r\n links: L[] = [],\r\n inputs: Nullable<N[]> = null,\r\n outputs: Nullable<N[]> = null,\r\n hiddens: Nullable<N[]> = null,\r\n onsc: Nullable<L[]> = null,\r\n opsc: Nullable<L[]> = null,\r\n position?: ICartesian\r\n ) {\r\n super(onsc, opsc, position); // Pass `position` to `GraphNode`\r\n this.nodes = nodes;\r\n this.links = links;\r\n this.inputs = inputs ?? this.nodes.filter((n) => n.opsc().length === 0);\r\n this.outputs = outputs ?? this.nodes.filter((n) => n.onsc().length === 0);\r\n this.hiddens = hiddens ?? this.nodes.filter((n) => !this.inputs.includes(n) && !this.outputs.includes(n));\r\n }\r\n\r\n public clone(): any {\r\n var copy = super.clone();\r\n copy.nodes = this.nodes.map((n) => n.clone());\r\n copy.links = this.links.map((l) => {\r\n const cloned = l.clone();\r\n cloned.oini = copy.nodes[this.nodes.indexOf(<N>l.oini)]; // the underlying setter is taking care of unbind/bind the link from/to node\r\n cloned.ofin = copy.nodes[this.nodes.indexOf(<N>l.ofin)]; // ...\r\n return cloned;\r\n });\r\n\r\n copy.inputs = copy.nodes.filter((n) => n.opsc().length === 0);\r\n copy.outputs = copy.nodes.filter((n) => n.onsc().length === 0);\r\n copy.hiddens = copy.nodes.filter((n) => !copy.inputs.includes(n) && !copy.outputs.includes(n));\r\n return copy;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,14 @@
1
+ import { IGraphItem, ITaggable } from "./graph.interfaces";
2
+ export declare class GraphItem implements IGraphItem {
3
+ private _id?;
4
+ private _tag?;
5
+ private _bag?;
6
+ get tag(): string | undefined;
7
+ get id(): any | undefined;
8
+ set id(v: any);
9
+ get bag(): unknown | undefined;
10
+ set bag(v: unknown);
11
+ withTag(tag: string): ITaggable;
12
+ dispose(): void;
13
+ clone(): this;
14
+ }
@@ -0,0 +1,36 @@
1
+ import { CloneMetadataKey, IsCloneable } from "./graph.interfaces";
2
+ export class GraphItem {
3
+ get tag() {
4
+ return this._tag;
5
+ }
6
+ get id() {
7
+ return this._id;
8
+ }
9
+ set id(v) {
10
+ this._id = v;
11
+ }
12
+ get bag() {
13
+ return this._bag;
14
+ }
15
+ set bag(v) {
16
+ this._bag = v;
17
+ }
18
+ withTag(tag) {
19
+ this._tag = tag;
20
+ return this;
21
+ }
22
+ dispose() {
23
+ // Dispose logic if needed
24
+ }
25
+ clone() {
26
+ const ctor = this.constructor;
27
+ const clone = new ctor();
28
+ const props = Reflect.getMetadata(CloneMetadataKey, this) || [];
29
+ for (const key of props) {
30
+ const value = this[key];
31
+ clone[key] = IsCloneable(value) ? value.clone() : structuredClone(value);
32
+ }
33
+ return clone;
34
+ }
35
+ }
36
+ //# sourceMappingURL=graph.graphItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.graphItem.js","sourceRoot":"","sources":["../../src/graph/graph.graphItem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAc,WAAW,EAAa,MAAM,oBAAoB,CAAC;AAE1F,MAAM,OAAO,SAAS;IAKlB,IAAW,GAAG;QACV,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,IAAW,EAAE;QACT,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IAED,IAAW,EAAE,CAAC,CAAK;QACf,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;IACjB,CAAC;IAED,IAAW,GAAG;QACV,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,IAAW,GAAG,CAAC,CAAS;QACpB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IAClB,CAAC;IAEM,OAAO,CAAC,GAAW;QACtB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,OAAO;QACV,0BAA0B;IAC9B,CAAC;IAEM,KAAK;QACR,MAAM,IAAI,GAAG,IAAI,CAAC,WAA6B,CAAC;QAChD,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC,gBAAgB,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;QAEhE,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACtB,MAAM,KAAK,GAAI,IAAY,CAAC,GAAG,CAAC,CAAC;YAChC,KAAa,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACtF,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["import { CloneMetadataKey, IGraphItem, IsCloneable, ITaggable } from \"./graph.interfaces\";\r\n\r\nexport class GraphItem implements IGraphItem {\r\n private _id?:any;\r\n private _tag?: string;\r\n private _bag?: unknown;\r\n\r\n public get tag(): string | undefined {\r\n return this._tag;\r\n }\r\n\r\n public get id() : any | undefined{\r\n return this._id;\r\n }\r\n\r\n public set id(v:any) {\r\n this._id = v;\r\n }\r\n\r\n public get bag() : unknown | undefined{\r\n return this._bag;\r\n }\r\n\r\n public set bag(v:unknown) {\r\n this._bag = v;\r\n }\r\n\r\n public withTag(tag: string): ITaggable {\r\n this._tag = tag;\r\n return this;\r\n }\r\n\r\n public dispose(): void {\r\n // Dispose logic if needed\r\n }\r\n\r\n public clone(): this {\r\n const ctor = this.constructor as new () => this;\r\n const clone = new ctor();\r\n const props = Reflect.getMetadata(CloneMetadataKey, this) || [];\r\n\r\n for (const key of props) {\r\n const value = (this as any)[key];\r\n (clone as any)[key] = IsCloneable(value) ? value.clone() : structuredClone(value);\r\n }\r\n\r\n return clone;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,28 @@
1
+ import { ICartesian } from "../geometry/geometry.interfaces";
2
+ import { Nullable, SingleOrArray } from "../types";
3
+ import { IGraph, INode, IOlink } from "./graph.interfaces";
4
+ export type LinkConstructor<T extends IOlink> = new (from: INode, to: INode, ...args: any[]) => T;
5
+ export interface ILinkBuilder {
6
+ withType<T extends IOlink>(c: LinkConstructor<T>): ILinkBuilder;
7
+ withFrom(node: INode): ILinkBuilder;
8
+ withTo(node: INode): ILinkBuilder;
9
+ build(...args: any[]): IOlink;
10
+ }
11
+ export type NodeConstructor<T extends INode> = new (onsc: Nullable<IOlink[]>, opsc: Nullable<IOlink[]>, position?: ICartesian, ...args: any[]) => T;
12
+ export interface INodeBuilder {
13
+ withType<T extends INode>(c: NodeConstructor<T>): INodeBuilder;
14
+ withPosition(p: ICartesian): INodeBuilder;
15
+ withInputs(link: SingleOrArray<IOlink> | SingleOrArray<ILinkBuilder>): INodeBuilder;
16
+ withOutputs(link: SingleOrArray<IOlink> | SingleOrArray<ILinkBuilder>): INodeBuilder;
17
+ build(...args: any[]): INode;
18
+ }
19
+ export type GraphConstructor<N extends INode, L extends IOlink, T extends IGraph<N, L>> = new (nodes: N[], links: L[], inputs: Nullable<N[]>, outputs: Nullable<N[]>, hiddens: Nullable<N[]>, onsc: Nullable<L[]>, opsc: Nullable<L[]>, position?: ICartesian, ...args: any[]) => T;
20
+ export interface IGraphBuilder<N extends INode, L extends IOlink> {
21
+ withNodePosition(p: ICartesian): IGraphBuilder<N, L>;
22
+ withNodeInputs(link: SingleOrArray<IOlink> | SingleOrArray<ILinkBuilder>): IGraphBuilder<N, L>;
23
+ withNodeOutputs(link: SingleOrArray<IOlink> | SingleOrArray<ILinkBuilder>): IGraphBuilder<N, L>;
24
+ withType<T extends IGraph<N, L>>(c: GraphConstructor<N, L, T>): IGraphBuilder<N, L>;
25
+ withNodes(node: SingleOrArray<N> | SingleOrArray<INodeBuilder>): IGraphBuilder<N, L>;
26
+ withLinks(link: SingleOrArray<L> | SingleOrArray<ILinkBuilder>): IGraphBuilder<N, L>;
27
+ build<T extends IGraph<N, L>>(...args: any[]): Nullable<T>;
28
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=graph.interfaces.builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.interfaces.builder.js","sourceRoot":"","sources":["../../src/graph/graph.interfaces.builder.ts"],"names":[],"mappings":"","sourcesContent":["import { ICartesian } from \"../geometry/geometry.interfaces\";\r\nimport { Nullable, SingleOrArray } from \"../types\";\r\nimport { IGraph, INode, IOlink } from \"./graph.interfaces\";\r\n\r\nexport type LinkConstructor<T extends IOlink> = new (from: INode, to: INode, ...args: any[]) => T;\r\n\r\nexport interface ILinkBuilder {\r\n withType<T extends IOlink>(c: LinkConstructor<T>): ILinkBuilder;\r\n withFrom(node: INode): ILinkBuilder;\r\n withTo(node: INode): ILinkBuilder;\r\n build(...args: any[]): IOlink;\r\n}\r\n\r\nexport type NodeConstructor<T extends INode> = new (onsc: Nullable<IOlink[]>, opsc: Nullable<IOlink[]>, position?: ICartesian, ...args: any[]) => T;\r\n\r\nexport interface INodeBuilder {\r\n withType<T extends INode>(c: NodeConstructor<T>): INodeBuilder;\r\n withPosition(p: ICartesian): INodeBuilder;\r\n withInputs(link: SingleOrArray<IOlink> | SingleOrArray<ILinkBuilder>): INodeBuilder;\r\n withOutputs(link: SingleOrArray<IOlink> | SingleOrArray<ILinkBuilder>): INodeBuilder;\r\n build(...args: any[]): INode;\r\n}\r\n\r\nexport type GraphConstructor<N extends INode, L extends IOlink, T extends IGraph<N, L>> = new (\r\n nodes: N[],\r\n links: L[],\r\n inputs: Nullable<N[]>,\r\n outputs: Nullable<N[]>,\r\n hiddens: Nullable<N[]>,\r\n onsc: Nullable<L[]>,\r\n opsc: Nullable<L[]>,\r\n position?: ICartesian,\r\n ...args: any[]\r\n) => T;\r\n\r\nexport interface IGraphBuilder<N extends INode, L extends IOlink> {\r\n // the Node part of the graph\r\n withNodePosition(p: ICartesian): IGraphBuilder<N, L>;\r\n withNodeInputs(link: SingleOrArray<IOlink> | SingleOrArray<ILinkBuilder>): IGraphBuilder<N, L>;\r\n withNodeOutputs(link: SingleOrArray<IOlink> | SingleOrArray<ILinkBuilder>): IGraphBuilder<N, L>;\r\n\r\n // the graph part of the graph\r\n withType<T extends IGraph<N, L>>(c: GraphConstructor<N, L, T>): IGraphBuilder<N, L>;\r\n withNodes(node: SingleOrArray<N> | SingleOrArray<INodeBuilder>): IGraphBuilder<N, L>;\r\n withLinks(link: SingleOrArray<L> | SingleOrArray<ILinkBuilder>): IGraphBuilder<N, L>;\r\n build<T extends IGraph<N, L>>(...args: any[]): Nullable<T>;\r\n}\r\n"]}
@@ -0,0 +1,59 @@
1
+ import { ICartesian } from "../geometry/geometry.interfaces";
2
+ import { Nullable } from "../types";
3
+ export declare const CloneMetadataKey: unique symbol;
4
+ export declare function cloneable(target: Object, propertyKey: string | symbol): void;
5
+ export interface ICloneable<T = any> {
6
+ clone(): T;
7
+ }
8
+ export declare function IsCloneable<T = any>(obj: unknown): obj is ICloneable<T>;
9
+ export interface IDisposable {
10
+ dispose(): void;
11
+ }
12
+ export interface ITaggable {
13
+ withTag(tag: string): ITaggable;
14
+ tag?: string;
15
+ }
16
+ export interface IIDentifiable {
17
+ id?: any;
18
+ }
19
+ export interface IHasBag {
20
+ /**
21
+ * Runtime-only container for execution context.
22
+ * Can be safely overwritten between runs.
23
+ */
24
+ bag?: unknown;
25
+ }
26
+ export interface IGraphItem extends IDisposable, ICloneable, ITaggable, IIDentifiable, IHasBag {
27
+ }
28
+ export interface INode extends IGraphItem {
29
+ position?: ICartesian;
30
+ onsc<L extends IOlink>(): Array<L>;
31
+ opsc<L extends IOlink>(): Array<L>;
32
+ }
33
+ export interface INodeSet<N extends INode> extends Array<N> {
34
+ }
35
+ export interface IOlink extends IGraphItem {
36
+ oini: Nullable<INode>;
37
+ ofin: Nullable<INode>;
38
+ }
39
+ export interface ILinkSet<L extends IOlink> extends Array<L> {
40
+ }
41
+ export interface IGraph<N extends INode, L extends IOlink> extends INode {
42
+ nodes: INodeSet<N>;
43
+ links: ILinkSet<L>;
44
+ inputs: INodeSet<N>;
45
+ outputs: INodeSet<N>;
46
+ hiddens: INodeSet<N>;
47
+ }
48
+ /**
49
+ * Type guard for INode
50
+ */
51
+ export declare function isNode<N extends INode>(obj: unknown): obj is N;
52
+ /**
53
+ * Type guard for IOlink
54
+ */
55
+ export declare function isOlink<L extends IOlink>(obj: unknown): obj is L;
56
+ /**
57
+ * Type guard for IGraph
58
+ */
59
+ export declare function isGraph<N extends INode, L extends IOlink>(obj: unknown): obj is IGraph<N, L>;
@@ -0,0 +1,51 @@
1
+ import { isCartesian } from "../geometry/geometry.interfaces";
2
+ export const CloneMetadataKey = Symbol("cloneable");
3
+ /// <summary>
4
+ /// Marks a property as cloneable for automatic deep copying
5
+ /// </summary>
6
+ export function cloneable(target, propertyKey) {
7
+ const proto = target.constructor.prototype;
8
+ const existingProps = Reflect.getMetadata(CloneMetadataKey, proto) || [];
9
+ Reflect.defineMetadata(CloneMetadataKey, [...existingProps, propertyKey], proto);
10
+ }
11
+ /// <summary>
12
+ /// Type guard to check if an object implements ICloneable
13
+ /// </summary>
14
+ export function IsCloneable(obj) {
15
+ return typeof obj === "object" && obj !== null && typeof obj.clone === "function";
16
+ }
17
+ /**
18
+ * Type guard for INode
19
+ */
20
+ export function isNode(obj) {
21
+ return (typeof obj === "object" &&
22
+ obj !== null &&
23
+ ("position" in obj ? obj.position === undefined || isCartesian(obj.position) : true) && // Ensure position is undefined or ICartesian3
24
+ "onsc" in obj &&
25
+ "opsc" in obj);
26
+ }
27
+ /**
28
+ * Type guard for IOlink
29
+ */
30
+ export function isOlink(obj) {
31
+ return typeof obj === "object" && obj !== null && "oini" in obj && "ofin" in obj && isNode(obj.oini) && isNode(obj.ofin);
32
+ }
33
+ /**
34
+ * Type guard for IGraph
35
+ */
36
+ export function isGraph(obj) {
37
+ return (isNode(obj) &&
38
+ "nodes" in obj &&
39
+ "links" in obj &&
40
+ "inputs" in obj &&
41
+ "outputs" in obj &&
42
+ Array.isArray(obj.nodes) &&
43
+ Array.isArray(obj.links) &&
44
+ Array.isArray(obj.inputs) &&
45
+ Array.isArray(obj.outputs) &&
46
+ obj.nodes.every(isNode) &&
47
+ obj.links.every(isOlink) &&
48
+ obj.inputs.every(isNode) &&
49
+ obj.outputs.every(isNode));
50
+ }
51
+ //# sourceMappingURL=graph.interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.interfaces.js","sourceRoot":"","sources":["../../src/graph/graph.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAG1E,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAEpD,aAAa;AACb,4DAA4D;AAC5D,cAAc;AACd,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,WAA4B;IAClE,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC;IAC3C,MAAM,aAAa,GAAa,OAAO,CAAC,WAAW,CAAC,gBAAgB,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;IACnF,OAAO,CAAC,cAAc,CAAC,gBAAgB,EAAE,CAAC,GAAG,aAAa,EAAE,WAAW,CAAC,EAAE,KAAK,CAAC,CAAC;AACrF,CAAC;AASD,aAAa;AACb,0DAA0D;AAC1D,cAAc;AACd,MAAM,UAAU,WAAW,CAAU,GAAY;IAC7C,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,OAAQ,GAAW,CAAC,KAAK,KAAK,UAAU,CAAC;AAC/F,CAAC;AAmDD;;GAEG;AACH,MAAM,UAAU,MAAM,CAAkB,GAAY;IAChD,OAAO,CACH,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,8CAA8C;QACtI,MAAM,IAAI,GAAG;QACb,MAAM,IAAI,GAAG,CAChB,CAAC;AACN,CAAC;AACD;;GAEG;AACH,MAAM,UAAU,OAAO,CAAmB,GAAY;IAClD,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,CAAE,GAAc,CAAC,IAAI,CAAC,IAAI,MAAM,CAAE,GAAc,CAAC,IAAI,CAAC,CAAC;AACrJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAAoC,GAAY;IACnE,OAAO,CACH,MAAM,CAAC,GAAG,CAAC;QACX,OAAO,IAAI,GAAG;QACd,OAAO,IAAI,GAAG;QACd,QAAQ,IAAI,GAAG;QACf,SAAS,IAAI,GAAG;QAChB,KAAK,CAAC,OAAO,CAAE,GAAoB,CAAC,KAAK,CAAC;QAC1C,KAAK,CAAC,OAAO,CAAE,GAAoB,CAAC,KAAK,CAAC;QAC1C,KAAK,CAAC,OAAO,CAAE,GAAoB,CAAC,MAAM,CAAC;QAC3C,KAAK,CAAC,OAAO,CAAE,GAAoB,CAAC,OAAO,CAAC;QAC3C,GAAoB,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;QACxC,GAAoB,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;QACzC,GAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;QACzC,GAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAC9C,CAAC;AACN,CAAC","sourcesContent":["import { ICartesian, isCartesian } from \"../geometry/geometry.interfaces\";\r\nimport { Nullable } from \"../types\";\r\n\r\nexport const CloneMetadataKey = Symbol(\"cloneable\");\r\n\r\n/// <summary>\r\n/// Marks a property as cloneable for automatic deep copying\r\n/// </summary>\r\nexport function cloneable(target: Object, propertyKey: string | symbol): void {\r\n const proto = target.constructor.prototype;\r\n const existingProps: string[] = Reflect.getMetadata(CloneMetadataKey, proto) || [];\r\n Reflect.defineMetadata(CloneMetadataKey, [...existingProps, propertyKey], proto);\r\n}\r\n\r\n/// <summary>\r\n/// Interface for cloneable objects\r\n/// </summary>\r\nexport interface ICloneable<T = any> {\r\n clone(): T;\r\n}\r\n\r\n/// <summary>\r\n/// Type guard to check if an object implements ICloneable\r\n/// </summary>\r\nexport function IsCloneable<T = any>(obj: unknown): obj is ICloneable<T> {\r\n return typeof obj === \"object\" && obj !== null && typeof (obj as any).clone === \"function\";\r\n}\r\n\r\nexport interface IDisposable {\r\n dispose(): void;\r\n}\r\n\r\nexport interface ITaggable {\r\n withTag(tag: string): ITaggable;\r\n tag?: string;\r\n}\r\n\r\nexport interface IIDentifiable{\r\n id?:any;\r\n}\r\n\r\nexport interface IHasBag {\r\n /**\r\n * Runtime-only container for execution context.\r\n * Can be safely overwritten between runs.\r\n */\r\n bag?: unknown;\r\n}\r\n\r\nexport interface IGraphItem extends IDisposable, ICloneable, ITaggable, IIDentifiable, IHasBag {}\r\n\r\nexport interface INode extends IGraphItem {\r\n position?: ICartesian;\r\n onsc<L extends IOlink>(): Array<L>;\r\n opsc<L extends IOlink>(): Array<L>;\r\n}\r\n\r\n// we define the INodeSet and ILinkSet interfaces to be able to use them to group nodes and links\r\n// this is particularly useful when we want to perform operations on a group such Layers in Neural Networks\r\n// or attach specific properties to a group of nodes or links.\r\nexport interface INodeSet<N extends INode> extends Array<N> {}\r\n\r\nexport interface IOlink extends IGraphItem {\r\n oini: Nullable<INode>;\r\n ofin: Nullable<INode>;\r\n}\r\n\r\nexport interface ILinkSet<L extends IOlink> extends Array<L> {}\r\n\r\nexport interface IGraph<N extends INode, L extends IOlink> extends INode {\r\n nodes: INodeSet<N>;\r\n links: ILinkSet<L>;\r\n inputs: INodeSet<N>;\r\n outputs: INodeSet<N>;\r\n hiddens: INodeSet<N>;\r\n}\r\n\r\n/**\r\n * Type guard for INode\r\n */\r\nexport function isNode<N extends INode>(obj: unknown): obj is N {\r\n return (\r\n typeof obj === \"object\" &&\r\n obj !== null &&\r\n (\"position\" in obj ? obj.position === undefined || isCartesian(obj.position) : true) && // Ensure position is undefined or ICartesian3\r\n \"onsc\" in obj &&\r\n \"opsc\" in obj\r\n );\r\n}\r\n/**\r\n * Type guard for IOlink\r\n */\r\nexport function isOlink<L extends IOlink>(obj: unknown): obj is L {\r\n return typeof obj === \"object\" && obj !== null && \"oini\" in obj && \"ofin\" in obj && isNode((obj as IOlink).oini) && isNode((obj as IOlink).ofin);\r\n}\r\n\r\n/**\r\n * Type guard for IGraph\r\n */\r\nexport function isGraph<N extends INode, L extends IOlink>(obj: unknown): obj is IGraph<N, L> {\r\n return (\r\n isNode(obj) &&\r\n \"nodes\" in obj &&\r\n \"links\" in obj &&\r\n \"inputs\" in obj &&\r\n \"outputs\" in obj &&\r\n Array.isArray((obj as IGraph<N, L>).nodes) &&\r\n Array.isArray((obj as IGraph<N, L>).links) &&\r\n Array.isArray((obj as IGraph<N, L>).inputs) &&\r\n Array.isArray((obj as IGraph<N, L>).outputs) &&\r\n (obj as IGraph<N, L>).nodes.every(isNode) &&\r\n (obj as IGraph<N, L>).links.every(isOlink) &&\r\n (obj as IGraph<N, L>).inputs.every(isNode) &&\r\n (obj as IGraph<N, L>).outputs.every(isNode)\r\n );\r\n}\r\n"]}
@@ -0,0 +1,12 @@
1
+ import { ICartesian } from "../geometry";
2
+ import { Nullable } from "../types";
3
+ import { GraphItem } from "./graph.graphItem";
4
+ import { INode, IOlink } from "./graph.interfaces";
5
+ export declare class GraphNode extends GraphItem implements INode {
6
+ protected _onsc: IOlink[];
7
+ protected _opsc: IOlink[];
8
+ position?: ICartesian;
9
+ constructor(onsc?: Nullable<IOlink[]>, opsc?: Nullable<IOlink[]>, position?: ICartesian);
10
+ onsc<L extends IOlink>(): Array<L>;
11
+ opsc<L extends IOlink>(): Array<L>;
12
+ }
@@ -0,0 +1,22 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { GraphItem } from "./graph.graphItem";
3
+ import { cloneable } from "./graph.interfaces";
4
+ export class GraphNode extends GraphItem {
5
+ constructor(onsc = null, opsc = null, position) {
6
+ super();
7
+ this._onsc = onsc ?? [];
8
+ this._opsc = opsc ?? [];
9
+ this.position = position;
10
+ }
11
+ onsc() {
12
+ return this._onsc;
13
+ }
14
+ opsc() {
15
+ return this._opsc;
16
+ }
17
+ }
18
+ __decorate([
19
+ cloneable,
20
+ __metadata("design:type", Object)
21
+ ], GraphNode.prototype, "position", void 0);
22
+ //# sourceMappingURL=graph.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.node.js","sourceRoot":"","sources":["../../src/graph/graph.node.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAiB,MAAM,oBAAoB,CAAC;AAE9D,MAAM,OAAO,SAAU,SAAQ,SAAS;IAMpC,YAAmB,OAA2B,IAAI,EAAE,OAA2B,IAAI,EAAE,QAAqB;QACtG,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAEM,IAAI;QACP,OAAO,IAAI,CAAC,KAAiB,CAAC;IAClC,CAAC;IAEM,IAAI;QACP,OAAO,IAAI,CAAC,KAAiB,CAAC;IAClC,CAAC;CACJ;AAhBqB;IAAjB,SAAS;;2CAA8B","sourcesContent":["import { ICartesian } from \"../geometry\";\r\nimport { Nullable } from \"../types\";\r\nimport { GraphItem } from \"./graph.graphItem\";\r\nimport { cloneable, INode, IOlink } from \"./graph.interfaces\";\r\n\r\nexport class GraphNode extends GraphItem implements INode {\r\n protected _onsc: IOlink[];\r\n protected _opsc: IOlink[];\r\n\r\n @cloneable public position?: ICartesian; \r\n\r\n public constructor(onsc: Nullable<IOlink[]> = null, opsc: Nullable<IOlink[]> = null, position?: ICartesian) {\r\n super();\r\n this._onsc = onsc ?? [];\r\n this._opsc = opsc ?? [];\r\n this.position = position;\r\n }\r\n\r\n public onsc<L extends IOlink>(): Array<L> {\r\n return this._onsc as Array<L>;\r\n }\r\n\r\n public opsc<L extends IOlink>(): Array<L> {\r\n return this._opsc as Array<L>;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,13 @@
1
+ import { Nullable } from "../types";
2
+ import { GraphItem } from "./graph.graphItem";
3
+ import { INode, IOlink } from "./graph.interfaces";
4
+ export declare class GraphOLink extends GraphItem implements IOlink {
5
+ private _oini;
6
+ _ofin: Nullable<INode>;
7
+ constructor(oini?: INode, ofin?: INode);
8
+ get oini(): Nullable<INode>;
9
+ set oini(n: Nullable<INode>);
10
+ get ofin(): Nullable<INode>;
11
+ set ofin(n: Nullable<INode>);
12
+ dispose(): void;
13
+ }
@@ -0,0 +1,56 @@
1
+ import { GraphItem } from "./graph.graphItem";
2
+ export class GraphOLink extends GraphItem {
3
+ constructor(oini, ofin) {
4
+ super();
5
+ this._oini = oini ?? null;
6
+ if (this._oini) {
7
+ this._oini.onsc().push(this);
8
+ }
9
+ this._ofin = ofin ?? null;
10
+ if (this._ofin) {
11
+ this._ofin.opsc().push(this);
12
+ }
13
+ }
14
+ get oini() {
15
+ return this._oini;
16
+ }
17
+ set oini(n) {
18
+ if (this._oini !== n) {
19
+ if (this._oini) {
20
+ const a = this._oini.onsc();
21
+ a.splice(a.indexOf(this));
22
+ }
23
+ this._oini = n;
24
+ if (this._oini) {
25
+ this._oini.onsc().push(this);
26
+ }
27
+ }
28
+ }
29
+ get ofin() {
30
+ return this._ofin;
31
+ }
32
+ set ofin(n) {
33
+ if (this._ofin !== n) {
34
+ if (this._ofin) {
35
+ const a = this._ofin.opsc();
36
+ a.splice(a.indexOf(this));
37
+ }
38
+ this._ofin = n;
39
+ if (this._ofin) {
40
+ this._ofin.opsc().push(this);
41
+ }
42
+ }
43
+ }
44
+ dispose() {
45
+ if (this._oini) {
46
+ const tmp = this._oini.onsc();
47
+ tmp.splice(tmp.indexOf(this));
48
+ }
49
+ if (this._ofin) {
50
+ const tmp = this._ofin.opsc();
51
+ tmp.splice(tmp.indexOf(this));
52
+ }
53
+ super.dispose();
54
+ }
55
+ }
56
+ //# sourceMappingURL=graph.olink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.olink.js","sourceRoot":"","sources":["../../src/graph/graph.olink.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,MAAM,OAAO,UAAW,SAAQ,SAAS;IAIrC,YAAmB,IAAY,EAAE,IAAY;QACzC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,IAAI,IAAI,IAAI,CAAC;QAC1B,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,IAAI,IAAI,CAAC;QAC1B,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;IACL,CAAC;IAED,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,IAAW,IAAI,CAAC,CAAkB;QAC9B,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC;YACnB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;gBAC5B,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAC9B,CAAC;YACD,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;YACf,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjC,CAAC;QACL,CAAC;IACL,CAAC;IAED,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,IAAW,IAAI,CAAC,CAAkB;QAC9B,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC;YACnB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;gBAC5B,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAC9B,CAAC;YACD,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;YACf,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjC,CAAC;QACL,CAAC;IACL,CAAC;IAEM,OAAO;QACV,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAC9B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAClC,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAC9B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAClC,CAAC;QACD,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;CACJ","sourcesContent":["import { Nullable } from \"../types\";\r\nimport { GraphItem } from \"./graph.graphItem\";\r\nimport { INode, IOlink } from \"./graph.interfaces\";\r\n\r\nexport class GraphOLink extends GraphItem implements IOlink {\r\n private _oini: Nullable<INode>;\r\n public _ofin: Nullable<INode>;\r\n\r\n public constructor(oini?: INode, ofin?: INode) {\r\n super();\r\n this._oini = oini ?? null;\r\n if (this._oini) {\r\n this._oini.onsc().push(this);\r\n }\r\n this._ofin = ofin ?? null;\r\n if (this._ofin) {\r\n this._ofin.opsc().push(this);\r\n }\r\n }\r\n\r\n public get oini(): Nullable<INode> {\r\n return this._oini;\r\n }\r\n\r\n public set oini(n: Nullable<INode>) {\r\n if (this._oini !== n) {\r\n if (this._oini) {\r\n const a = this._oini.onsc();\r\n a.splice(a.indexOf(this));\r\n }\r\n this._oini = n;\r\n if (this._oini) {\r\n this._oini.onsc().push(this);\r\n }\r\n }\r\n }\r\n\r\n public get ofin(): Nullable<INode> {\r\n return this._ofin;\r\n }\r\n\r\n public set ofin(n: Nullable<INode>) {\r\n if (this._ofin !== n) {\r\n if (this._ofin) {\r\n const a = this._ofin.opsc();\r\n a.splice(a.indexOf(this));\r\n }\r\n this._ofin = n;\r\n if (this._ofin) {\r\n this._ofin.opsc().push(this);\r\n }\r\n }\r\n }\r\n\r\n public dispose(): void {\r\n if (this._oini) {\r\n const tmp = this._oini.onsc();\r\n tmp.splice(tmp.indexOf(this));\r\n }\r\n if (this._ofin) {\r\n const tmp = this._ofin.opsc();\r\n tmp.splice(tmp.indexOf(this));\r\n }\r\n super.dispose();\r\n }\r\n}\r\n"]}
@@ -0,0 +1,9 @@
1
+ export * from "./graph.interfaces";
2
+ export * from "./graph.interfaces.builder";
3
+ export * from "./graph.graphItem";
4
+ export * from "./graph.node";
5
+ export * from "./graph.olink";
6
+ export * from "./graph.graph";
7
+ export * from "./graph.builder.node";
8
+ export * from "./graph.builder.olink";
9
+ export * from "./graph.builder.graph";
@@ -0,0 +1,10 @@
1
+ export * from "./graph.interfaces";
2
+ export * from "./graph.interfaces.builder";
3
+ export * from "./graph.graphItem";
4
+ export * from "./graph.node";
5
+ export * from "./graph.olink";
6
+ export * from "./graph.graph";
7
+ export * from "./graph.builder.node";
8
+ export * from "./graph.builder.olink";
9
+ export * from "./graph.builder.graph";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/graph/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC","sourcesContent":["export * from \"./graph.interfaces\";\r\nexport * from \"./graph.interfaces.builder\";\r\nexport * from \"./graph.graphItem\";\r\nexport * from \"./graph.node\";\r\nexport * from \"./graph.olink\";\r\nexport * from \"./graph.graph\";\r\nexport * from \"./graph.builder.node\";\r\nexport * from \"./graph.builder.olink\";\r\nexport * from \"./graph.builder.graph\";\r\n"]}
@@ -0,0 +1,6 @@
1
+ import "reflect-metadata";
2
+ export * from "./types";
3
+ export * from "./geometry";
4
+ export * from "./graph";
5
+ export * from "./neuralnetwork";
6
+ export * from "./utils";
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import "reflect-metadata";
2
+ export * from "./types";
3
+ export * from "./geometry";
4
+ export * from "./graph";
5
+ export * from "./neuralnetwork";
6
+ export * from "./utils";
7
+ // ensure that the global namespace is defined
8
+ if (typeof window !== "undefined") {
9
+ window.SPIKYPANDA = window.SPIKYPANDA || {};
10
+ // Assign S only if it is not already defined
11
+ if (!window.S) {
12
+ window.S = window.SPIKYPANDA;
13
+ }
14
+ }
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AAExB,8CAA8C;AAC9C,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAC1B,MAAO,CAAC,UAAU,GAAS,MAAO,CAAC,UAAU,IAAI,EAAE,CAAC;IAE1D,6CAA6C;IAC7C,IAAI,CAAO,MAAO,CAAC,CAAC,EAAE,CAAC;QACb,MAAO,CAAC,CAAC,GAAS,MAAO,CAAC,UAAU,CAAC;IAC/C,CAAC;AACL,CAAC","sourcesContent":["import \"reflect-metadata\";\r\n\r\nexport * from \"./types\";\r\nexport * from \"./geometry\";\r\nexport * from \"./graph\";\r\nexport * from \"./neuralnetwork\";\r\nexport * from \"./utils\";\r\n\r\n// ensure that the global namespace is defined\r\nif (typeof window !== \"undefined\") {\r\n (<any>window).SPIKYPANDA = (<any>window).SPIKYPANDA || {};\r\n\r\n // Assign S only if it is not already defined\r\n if (!(<any>window).S) {\r\n (<any>window).S = (<any>window).SPIKYPANDA;\r\n }\r\n}\r\n"]}
@@ -0,0 +1 @@
1
+ export * from "./mlp";
@@ -0,0 +1,2 @@
1
+ export * from "./mlp";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/neuralnetwork/ann/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC","sourcesContent":["export * from \"./mlp\";\r\n"]}
@@ -0,0 +1,9 @@
1
+ export * from "./mlp.activation";
2
+ export * from "./mlp.interfaces";
3
+ export * from "./mlp.inference";
4
+ export * from "./mlp.runtime.utils";
5
+ export * from "./mlp.builder";
6
+ export * from "./training";
7
+ export * from "./mlp.synapse";
8
+ export * from "./mlp.neuron";
9
+ export * from "./mlp.graph";
@@ -0,0 +1,10 @@
1
+ export * from "./mlp.activation";
2
+ export * from "./mlp.interfaces";
3
+ export * from "./mlp.inference";
4
+ export * from "./mlp.runtime.utils";
5
+ export * from "./mlp.builder";
6
+ export * from "./training";
7
+ export * from "./mlp.synapse";
8
+ export * from "./mlp.neuron";
9
+ export * from "./mlp.graph";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/neuralnetwork/ann/mlp/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC","sourcesContent":["export * from \"./mlp.activation\";\r\nexport * from \"./mlp.interfaces\";\r\nexport * from \"./mlp.inference\";\r\nexport * from \"./mlp.runtime.utils\";\r\nexport * from \"./mlp.builder\";\r\nexport * from \"./training\";\r\nexport * from \"./mlp.synapse\";\r\nexport * from \"./mlp.neuron\";\r\nexport * from \"./mlp.graph\";\r\n"]}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Common activation functions
3
+ */
4
+ export declare const ActivationFunctions: {
5
+ relu: {
6
+ fn: (x: number) => number;
7
+ derivative: (y: number) => 0 | 1;
8
+ };
9
+ sigmoid: {
10
+ fn: (x: number) => number;
11
+ derivative: (y: number) => number;
12
+ };
13
+ tanh: {
14
+ fn: (x: number) => number;
15
+ derivative: (y: number) => number;
16
+ };
17
+ linear: {
18
+ fn: (x: number) => number;
19
+ derivative: (_y: number) => number;
20
+ };
21
+ };
22
+ export type ActivationFunctionName = keyof typeof ActivationFunctions;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Common activation functions
3
+ */
4
+ export const ActivationFunctions = {
5
+ relu: {
6
+ fn: (x) => Math.max(0, x),
7
+ derivative: (y) => (y > 0 ? 1 : 0),
8
+ },
9
+ sigmoid: {
10
+ fn: (x) => 1 / (1 + Math.exp(-x)),
11
+ derivative: (y) => y * (1 - y), // y = sigmoid(x)
12
+ },
13
+ tanh: {
14
+ fn: (x) => Math.tanh(x),
15
+ derivative: (y) => 1 - y * y, // y = tanh(x)
16
+ },
17
+ linear: {
18
+ fn: (x) => x,
19
+ derivative: (_y) => 1,
20
+ },
21
+ };
22
+ //# sourceMappingURL=mlp.activation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mlp.activation.js","sourceRoot":"","sources":["../../../../src/neuralnetwork/ann/mlp/mlp.activation.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAC/B,IAAI,EAAE;QACF,EAAE,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;QACjC,UAAU,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7C;IAED,OAAO,EAAE;QACL,EAAE,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,UAAU,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,iBAAiB;KAC5D;IAED,IAAI,EAAE;QACF,EAAE,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/B,UAAU,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,cAAc;KACvD;IAED,MAAM,EAAE;QACJ,EAAE,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC;QACpB,UAAU,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,CAAC;KAChC;CAC0C,CAAC","sourcesContent":["import { IActivationFunction } from \"./mlp.interfaces\";\r\n\r\n/**\r\n * Common activation functions\r\n */\r\nexport const ActivationFunctions = {\r\n relu: {\r\n fn: (x: number) => Math.max(0, x),\r\n derivative: (y: number) => (y > 0 ? 1 : 0),\r\n },\r\n\r\n sigmoid: {\r\n fn: (x: number) => 1 / (1 + Math.exp(-x)),\r\n derivative: (y: number) => y * (1 - y), // y = sigmoid(x)\r\n },\r\n\r\n tanh: {\r\n fn: (x: number) => Math.tanh(x),\r\n derivative: (y: number) => 1 - y * y, // y = tanh(x)\r\n },\r\n\r\n linear: {\r\n fn: (x: number) => x,\r\n derivative: (_y: number) => 1,\r\n },\r\n} satisfies Record<string, IActivationFunction>;\r\n\r\nexport type ActivationFunctionName = keyof typeof ActivationFunctions;\r\n"]}