@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 @@
1
+ {"version":3,"file":"nn.weights.js","sourceRoot":"","sources":["../../src/neuralnetwork/nn.weights.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,2FAA2F;AAC3F,4GAA4G;AAC5G,gFAAgF;AAChF,cAAc;AACd,MAAM,OAAO,UAAU;IACnB,aAAa;IACb,iCAAiC;IACjC,oDAAoD;IACpD,gEAAgE;IAChE,cAAc;IACd,MAAM,CAAC,MAAM,CAAC,KAAa,EAAE,MAAc;QACvC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC;QAC9C,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;IAC3C,CAAC;IAED,aAAa;IACb,sBAAsB;IACtB,8CAA8C;IAC9C,uDAAuD;IACvD,cAAc;IACd,MAAM,CAAC,EAAE,CAAC,KAAa;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QACnC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;IAC3C,CAAC;IAED,aAAa;IACb,2DAA2D;IAC3D,iDAAiD;IACjD,cAAc;IACd,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC;QAC9B,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC1B,OAAO,IAAI,GAAG,MAAM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G,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC;IAC5D,CAAC;CACJ","sourcesContent":["/// <summary>\r\n/// WeightInit provides commonly used weight initialization strategies for neural networks.\r\n/// These initializers are not specific to MLPs and are widely used in various types of neural architectures\r\n/// including CNNs, RNNs, Transformers, and others, especially in deep learning.\r\n/// </summary>\r\nexport class WeightInit {\r\n /// <summary>\r\n /// Glorot/Xavier initialization.\r\n /// Typically used with tanh or sigmoid activations.\r\n /// Scales weights to keep variance roughly equal across layers.\r\n /// </summary>\r\n static Glorot(fanIn: number, fanOut: number): number {\r\n const limit = Math.sqrt(6 / (fanIn + fanOut));\r\n return (Math.random() * 2 - 1) * limit;\r\n }\r\n\r\n /// <summary>\r\n /// He initialization.\r\n /// Typically used with ReLU and its variants.\r\n /// Helps prevent vanishing gradients in deep networks.\r\n /// </summary>\r\n static He(fanIn: number): number {\r\n const limit = Math.sqrt(6 / fanIn);\r\n return (Math.random() * 2 - 1) * limit;\r\n }\r\n\r\n /// <summary>\r\n /// Gaussian initialization using the Box-Muller transform.\r\n /// Can be used as a general-purpose initializer.\r\n /// </summary>\r\n static Normal(mean = 0, stdDev = 1): number {\r\n let u = 1 - Math.random();\r\n let v = 1 - Math.random();\r\n return mean + stdDev * Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);\r\n }\r\n\r\n /// <summary>\r\n /// Uniform initialization between min and max values.\r\n /// </summary>\r\n static Uniform(min = -1, max = 1): number {\r\n return Math.random() * (max - min) + min;\r\n }\r\n}\r\n\r\nexport enum WeightInitializerType {\r\n /// <summary>\r\n /// Glorot/Xavier initializer, typically used with tanh or sigmoid activations.\r\n /// </summary>\r\n Glorot = \"glorot\",\r\n\r\n /// <summary>\r\n /// He initializer, typically used with ReLU-like activations.\r\n /// </summary>\r\n He = \"he\",\r\n\r\n /// <summary>\r\n /// Normal (Gaussian) initializer using the Box-Muller transform.\r\n /// </summary>\r\n Normal = \"normal\",\r\n\r\n /// <summary>\r\n /// Uniform initializer between min and max values.\r\n /// </summary>\r\n Uniform = \"uniform\",\r\n}\r\n\r\n/// <summary>\r\n/// Interface for weight initialization strategies.\r\n/// </summary>\r\nexport interface IWeightInitializer {\r\n type: WeightInitializerType;\r\n next(): number;\r\n}\r\n\r\n/// <summary>\r\n/// Glorot/Xavier initializer class for use in builder chains.\r\n/// </summary>\r\nexport class Glorot implements IWeightInitializer {\r\n private limit: number;\r\n\r\n public constructor(fanIn: number, fanOut: number) {\r\n this.limit = Math.sqrt(6 / (fanIn + fanOut));\r\n }\r\n\r\n public get type(): WeightInitializerType {\r\n return WeightInitializerType.Glorot;\r\n }\r\n\r\n public next(): number {\r\n return (Math.random() * 2 - 1) * this.limit;\r\n }\r\n}\r\n\r\n/// <summary>\r\n/// He initializer class, typically used with ReLU-like activations.\r\n/// </summary>\r\nexport class He implements IWeightInitializer {\r\n private limit: number;\r\n\r\n public constructor(fanIn: number) {\r\n this.limit = Math.sqrt(6 / fanIn);\r\n }\r\n public get type(): WeightInitializerType {\r\n return WeightInitializerType.He;\r\n }\r\n\r\n public next(): number {\r\n return (Math.random() * 2 - 1) * this.limit;\r\n }\r\n}\r\n\r\n/// <summary>\r\n/// Normal (Gaussian) initializer using the Box-Muller transform.\r\n/// </summary>\r\nexport class Normal implements IWeightInitializer {\r\n public constructor(private mean = 0, private stdDev = 1) {}\r\n\r\n public get type(): WeightInitializerType {\r\n return WeightInitializerType.Normal;\r\n }\r\n\r\n public next(): number {\r\n let u = 1 - Math.random();\r\n let v = 1 - Math.random();\r\n return this.mean + this.stdDev * Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);\r\n }\r\n}\r\n\r\n/// <summary>\r\n/// Uniform initializer between min and max.\r\n/// </summary>\r\nexport class Uniform implements IWeightInitializer {\r\n public constructor(private min = -1, private max = 1) {}\r\n\r\n public get type(): WeightInitializerType {\r\n return WeightInitializerType.Uniform;\r\n }\r\n\r\n public next(): number {\r\n return Math.random() * (this.max - this.min) + this.min;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,3 @@
1
+ export * from "./spike.interfaces";
2
+ export * from "./spike.runtime";
3
+ export * from "./spike.stdp";
@@ -0,0 +1,4 @@
1
+ export * from "./spike.interfaces";
2
+ export * from "./spike.runtime";
3
+ export * from "./spike.stdp";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/neuralnetwork/snn/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./spike.interfaces\";\r\nexport * from \"./spike.runtime\";\r\nexport * from \"./spike.stdp\";\r\n"]}
@@ -0,0 +1,50 @@
1
+ import { Nullable } from "../../types";
2
+ import { IGraph, INode } from "../../graph";
3
+ import { INeuron, ISynapse } from "../nn.interfaces";
4
+ /**
5
+ * Represents a discrete spike event traveling through the network
6
+ */
7
+ export interface ISpike {
8
+ timestamp: number;
9
+ amplitude: number;
10
+ source: INode;
11
+ }
12
+ /**
13
+ * Represents the internal state of a spiking neuron
14
+ */
15
+ export interface ISpikeNeuronState {
16
+ membranePotential: number;
17
+ lastSpikeTime: Nullable<number>;
18
+ spikes: Array<ISpike>;
19
+ }
20
+ /**
21
+ * Represents a neuron in the Spiking Neural Network
22
+ */
23
+ export interface ISpikeNeuron extends INeuron, ISpikeNeuronState {
24
+ threshold: number;
25
+ state: this;
26
+ }
27
+ /**
28
+ * Represents a synapse (connection between two neurons)
29
+ */
30
+ export interface ISpikeSynapse extends ISynapse {
31
+ delay: number;
32
+ plasticity?: Nullable<boolean>;
33
+ }
34
+ /**
35
+ * Represents the entire Spiking Neural Network as a directed graph
36
+ */
37
+ export interface ISnnGraph extends IGraph<ISpikeNeuron, ISpikeSynapse> {
38
+ }
39
+ /**
40
+ * Type guard for INeuron
41
+ */
42
+ export declare function isNeuron(obj: unknown): obj is ISpikeNeuron;
43
+ /**
44
+ * Type guard for ISynapse
45
+ */
46
+ export declare function isSynapse(obj: unknown): obj is ISpikeSynapse;
47
+ /**
48
+ * Type guard for ISnnGraph
49
+ */
50
+ export declare function isSnnGraph(obj: unknown): obj is ISnnGraph;
@@ -0,0 +1,24 @@
1
+ import { isGraph, isNode, isOlink } from "../../graph";
2
+ /**
3
+ * Type guard for INeuron
4
+ */
5
+ export function isNeuron(obj) {
6
+ return isNode(obj) && "membranePotential" in obj && "threshold" in obj && "lastSpikeTime" in obj && "spikes" in obj && Array.isArray(obj.spikes);
7
+ }
8
+ /**
9
+ * Type guard for ISynapse
10
+ */
11
+ export function isSynapse(obj) {
12
+ return isOlink(obj) && "weight" in obj && "delay" in obj && obj.weight !== undefined && obj.delay !== undefined;
13
+ }
14
+ /**
15
+ * Type guard for ISnnGraph
16
+ */
17
+ export function isSnnGraph(obj) {
18
+ return (isGraph(obj) &&
19
+ Array.isArray(obj.nodes) &&
20
+ Array.isArray(obj.links) &&
21
+ obj.nodes.every(isNeuron) &&
22
+ obj.links.every(isSynapse));
23
+ }
24
+ //# sourceMappingURL=spike.interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spike.interfaces.js","sourceRoot":"","sources":["../../../src/neuralnetwork/snn/spike.interfaces.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AA0CtE;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAY;IACjC,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,mBAAmB,IAAI,GAAG,IAAI,WAAW,IAAI,GAAG,IAAI,eAAe,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,KAAK,CAAC,OAAO,CAAE,GAAoB,CAAC,MAAM,CAAC,CAAC;AACvK,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,GAAY;IAClC,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,QAAQ,IAAI,GAAG,IAAI,OAAO,IAAI,GAAG,IAAK,GAAqB,CAAC,MAAM,KAAK,SAAS,IAAK,GAAqB,CAAC,KAAK,KAAK,SAAS,CAAC;AAC1J,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAAY;IACnC,OAAO,CACH,OAAO,CAAC,GAAG,CAAC;QACZ,KAAK,CAAC,OAAO,CAAE,GAA2C,CAAC,KAAK,CAAC;QACjE,KAAK,CAAC,OAAO,CAAE,GAA2C,CAAC,KAAK,CAAC;QAChE,GAA2C,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC;QACjE,GAA2C,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CACtE,CAAC;AACN,CAAC","sourcesContent":["import { Nullable } from \"../../types\";\r\nimport { IGraph, INode, isGraph, isNode, isOlink } from \"../../graph\";\r\nimport { INeuron, ISynapse } from \"../nn.interfaces\";\r\n\r\n/**\r\n * Represents a discrete spike event traveling through the network\r\n */\r\nexport interface ISpike {\r\n timestamp: number; // Time of the spike\r\n amplitude: number; // Strength of the spike\r\n source: INode; // Neuron that emitted the spike\r\n}\r\n\r\n/**\r\n * Represents the internal state of a spiking neuron\r\n */\r\nexport interface ISpikeNeuronState {\r\n membranePotential: number; // Current charge of the neuron\r\n lastSpikeTime: Nullable<number>; // Last time the neuron spiked\r\n spikes: Array<ISpike>; // Spikes emitted by the neuron\r\n}\r\n\r\n/**\r\n * Represents a neuron in the Spiking Neural Network\r\n */\r\nexport interface ISpikeNeuron extends INeuron, ISpikeNeuronState {\r\n threshold: number; // Activation threshold\r\n state: this;\r\n}\r\n\r\n/**\r\n * Represents a synapse (connection between two neurons)\r\n */\r\nexport interface ISpikeSynapse extends ISynapse {\r\n delay: number; // Time delay for spike transmission\r\n plasticity?: Nullable<boolean>; // Whether STDP is applied\r\n}\r\n\r\n/**\r\n * Represents the entire Spiking Neural Network as a directed graph\r\n */\r\nexport interface ISnnGraph extends IGraph<ISpikeNeuron, ISpikeSynapse> {}\r\n\r\n/**\r\n * Type guard for INeuron\r\n */\r\nexport function isNeuron(obj: unknown): obj is ISpikeNeuron {\r\n return isNode(obj) && \"membranePotential\" in obj && \"threshold\" in obj && \"lastSpikeTime\" in obj && \"spikes\" in obj && Array.isArray((obj as ISpikeNeuron).spikes);\r\n}\r\n\r\n/**\r\n * Type guard for ISynapse\r\n */\r\nexport function isSynapse(obj: unknown): obj is ISpikeSynapse {\r\n return isOlink(obj) && \"weight\" in obj && \"delay\" in obj && (obj as ISpikeSynapse).weight !== undefined && (obj as ISpikeSynapse).delay !== undefined;\r\n}\r\n\r\n/**\r\n * Type guard for ISnnGraph\r\n */\r\nexport function isSnnGraph(obj: unknown): obj is ISnnGraph {\r\n return (\r\n isGraph(obj) &&\r\n Array.isArray((obj as IGraph<ISpikeNeuron, ISpikeSynapse>).nodes) &&\r\n Array.isArray((obj as IGraph<ISpikeNeuron, ISpikeSynapse>).links) &&\r\n (obj as IGraph<ISpikeNeuron, ISpikeSynapse>).nodes.every(isNeuron) &&\r\n (obj as IGraph<ISpikeNeuron, ISpikeSynapse>).links.every(isSynapse)\r\n );\r\n}\r\n"]}
@@ -0,0 +1,31 @@
1
+ import { ISpikeNeuron, ISnnGraph } from "./spike.interfaces";
2
+ import { STDPFunction, ISTDPConfig } from "./spike.stdp";
3
+ export declare class SNNRuntime {
4
+ /**
5
+ * Prepares input spikes from an ISnnGraph by binding input data to the graph's input nodes.
6
+ */
7
+ static prepareInputs(graph: ISnnGraph, inputData: number[]): Array<{
8
+ neuron: ISpikeNeuron;
9
+ amplitude: number;
10
+ }>;
11
+ private _stdpRule;
12
+ private _stdpConfig;
13
+ private _tick;
14
+ constructor(stdpRule?: STDPFunction, stdpConfig?: ISTDPConfig);
15
+ get tick(): number;
16
+ /**
17
+ * Injects spikes into the input neurons and propagates them through the network until no more spikes occur.
18
+ */
19
+ pulse(inputSpikes: Array<{
20
+ neuron: ISpikeNeuron;
21
+ amplitude: number;
22
+ }>): void;
23
+ /**
24
+ * Fires a neuron and resets its membrane potential.
25
+ */
26
+ private _fireNeuron;
27
+ /**
28
+ * Applies STDP learning to the active synapse using the configured rule and weight bounds.
29
+ */
30
+ private _applySTDP;
31
+ }
@@ -0,0 +1,90 @@
1
+ import { STDP, DEFAULT_STDP_CONFIG } from "./spike.stdp";
2
+ export class SNNRuntime {
3
+ /**
4
+ * Prepares input spikes from an ISnnGraph by binding input data to the graph's input nodes.
5
+ */
6
+ static prepareInputs(graph, inputData) {
7
+ if (graph.inputs.length !== inputData.length) {
8
+ throw new Error(`Input data size (${inputData.length}) does not match the number of graph inputs (${graph.inputs.length})`);
9
+ }
10
+ return graph.inputs.map((neuron, index) => ({
11
+ neuron,
12
+ amplitude: inputData[index],
13
+ }));
14
+ }
15
+ constructor(stdpRule, stdpConfig) {
16
+ this._tick = 0;
17
+ this._stdpRule = stdpRule ?? STDP.exponential();
18
+ this._stdpConfig = stdpConfig ?? DEFAULT_STDP_CONFIG;
19
+ }
20
+ get tick() {
21
+ return this._tick;
22
+ }
23
+ /**
24
+ * Injects spikes into the input neurons and propagates them through the network until no more spikes occur.
25
+ */
26
+ pulse(inputSpikes) {
27
+ let activeSpikes = [];
28
+ // Step 1: Inject initial spikes
29
+ for (const { neuron, amplitude } of inputSpikes) {
30
+ neuron.membranePotential += amplitude;
31
+ if (neuron.membranePotential >= neuron.threshold) {
32
+ activeSpikes.push(this._fireNeuron(neuron));
33
+ }
34
+ }
35
+ // Step 2: Process spikes continuously until no more spikes are generated
36
+ while (activeSpikes.length > 0) {
37
+ const nextSpikes = [];
38
+ this._tick++;
39
+ for (const spike of activeSpikes) {
40
+ const neuron = spike.source;
41
+ // Step 3: Propagate to connected neurons via 'onsc' links
42
+ const synapses = neuron.onsc();
43
+ if (synapses) {
44
+ for (const synapse of synapses) {
45
+ const postNeuron = synapse.ofin;
46
+ // Apply synaptic weight
47
+ postNeuron.membranePotential += spike.amplitude * synapse.weight;
48
+ // If neuron reaches threshold, it fires
49
+ if (postNeuron.membranePotential >= postNeuron.threshold) {
50
+ const newSpike = this._fireNeuron(postNeuron);
51
+ nextSpikes.push(newSpike);
52
+ // Apply STDP only to the active synapse
53
+ this._applySTDP(synapse);
54
+ }
55
+ }
56
+ }
57
+ }
58
+ // Continue propagation if new spikes were created
59
+ activeSpikes = nextSpikes;
60
+ }
61
+ }
62
+ /**
63
+ * Fires a neuron and resets its membrane potential.
64
+ */
65
+ _fireNeuron(neuron) {
66
+ this._tick++;
67
+ const spike = {
68
+ timestamp: this._tick,
69
+ amplitude: neuron.membranePotential,
70
+ source: neuron,
71
+ };
72
+ neuron.spikes.push(spike);
73
+ neuron.membranePotential = 0;
74
+ neuron.lastSpikeTime = spike.timestamp;
75
+ return spike;
76
+ }
77
+ /**
78
+ * Applies STDP learning to the active synapse using the configured rule and weight bounds.
79
+ */
80
+ _applySTDP(synapse) {
81
+ const preNeuron = synapse.oini;
82
+ const postNeuron = synapse.ofin;
83
+ if (preNeuron.lastSpikeTime !== null && postNeuron.lastSpikeTime !== null) {
84
+ const deltaT = postNeuron.lastSpikeTime - preNeuron.lastSpikeTime;
85
+ synapse.weight = this._stdpRule(deltaT, synapse.weight);
86
+ synapse.weight = Math.max(this._stdpConfig.minWeight, Math.min(this._stdpConfig.maxWeight, synapse.weight));
87
+ }
88
+ }
89
+ }
90
+ //# sourceMappingURL=spike.runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spike.runtime.js","sourceRoot":"","sources":["../../../src/neuralnetwork/snn/spike.runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAA6B,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEpF,MAAM,OAAO,UAAU;IACnB;;OAEG;IACI,MAAM,CAAC,aAAa,CAAC,KAAgB,EAAE,SAAmB;QAC7D,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE,CAAC;YAC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Aa,KAAK,IAAI,IAAI,UAAU,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;YACxE,MAAM,MAAM,GAAG,UAAU,CAAC,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC;YAClE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YACxD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAChH,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { ISpikeNeuron, ISnnGraph, ISpike, ISpikeSynapse } from \"./spike.interfaces\";\r\nimport { STDP, STDPFunction, ISTDPConfig, DEFAULT_STDP_CONFIG } from \"./spike.stdp\";\r\n\r\nexport class SNNRuntime {\r\n /**\r\n * Prepares input spikes from an ISnnGraph by binding input data to the graph's input nodes.\r\n */\r\n public static prepareInputs(graph: ISnnGraph, inputData: number[]): Array<{ neuron: ISpikeNeuron; amplitude: number }> {\r\n if (graph.inputs.length !== inputData.length) {\r\n throw new Error(`Input data size (${inputData.length}) does not match the number of graph inputs (${graph.inputs.length})`);\r\n }\r\n\r\n return graph.inputs.map((neuron, index) => ({\r\n neuron,\r\n amplitude: inputData[index],\r\n }));\r\n }\r\n\r\n private _stdpRule: STDPFunction;\r\n private _stdpConfig: ISTDPConfig;\r\n private _tick: number = 0;\r\n\r\n public constructor(stdpRule?: STDPFunction, stdpConfig?: ISTDPConfig) {\r\n this._stdpRule = stdpRule ?? STDP.exponential();\r\n this._stdpConfig = stdpConfig ?? DEFAULT_STDP_CONFIG;\r\n }\r\n\r\n public get tick(): number {\r\n return this._tick;\r\n }\r\n\r\n /**\r\n * Injects spikes into the input neurons and propagates them through the network until no more spikes occur.\r\n */\r\n public pulse(inputSpikes: Array<{ neuron: ISpikeNeuron; amplitude: number }>) {\r\n let activeSpikes: ISpike[] = [];\r\n\r\n // Step 1: Inject initial spikes\r\n for (const { neuron, amplitude } of inputSpikes) {\r\n neuron.membranePotential += amplitude;\r\n\r\n if (neuron.membranePotential >= neuron.threshold) {\r\n activeSpikes.push(this._fireNeuron(neuron));\r\n }\r\n }\r\n\r\n // Step 2: Process spikes continuously until no more spikes are generated\r\n while (activeSpikes.length > 0) {\r\n const nextSpikes: ISpike[] = [];\r\n this._tick++;\r\n\r\n for (const spike of activeSpikes) {\r\n const neuron = spike.source;\r\n\r\n // Step 3: Propagate to connected neurons via 'onsc' links\r\n const synapses = neuron.onsc<ISpikeSynapse>();\r\n if (synapses) {\r\n for (const synapse of synapses) {\r\n const postNeuron = synapse.ofin as ISpikeNeuron;\r\n\r\n // Apply synaptic weight\r\n postNeuron.membranePotential += spike.amplitude * synapse.weight;\r\n\r\n // If neuron reaches threshold, it fires\r\n if (postNeuron.membranePotential >= postNeuron.threshold) {\r\n const newSpike = this._fireNeuron(postNeuron);\r\n nextSpikes.push(newSpike);\r\n\r\n // Apply STDP only to the active synapse\r\n this._applySTDP(synapse);\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Continue propagation if new spikes were created\r\n activeSpikes = nextSpikes;\r\n }\r\n }\r\n\r\n /**\r\n * Fires a neuron and resets its membrane potential.\r\n */\r\n private _fireNeuron(neuron: ISpikeNeuron): ISpike {\r\n this._tick++;\r\n const spike: ISpike = {\r\n timestamp: this._tick,\r\n amplitude: neuron.membranePotential,\r\n source: neuron,\r\n };\r\n\r\n neuron.spikes.push(spike);\r\n neuron.membranePotential = 0;\r\n neuron.lastSpikeTime = spike.timestamp;\r\n\r\n return spike;\r\n }\r\n\r\n /**\r\n * Applies STDP learning to the active synapse using the configured rule and weight bounds.\r\n */\r\n private _applySTDP(synapse: ISpikeSynapse) {\r\n const preNeuron = synapse.oini as ISpikeNeuron;\r\n const postNeuron = synapse.ofin as ISpikeNeuron;\r\n\r\n if (preNeuron.lastSpikeTime !== null && postNeuron.lastSpikeTime !== null) {\r\n const deltaT = postNeuron.lastSpikeTime - preNeuron.lastSpikeTime;\r\n synapse.weight = this._stdpRule(deltaT, synapse.weight);\r\n synapse.weight = Math.max(this._stdpConfig.minWeight, Math.min(this._stdpConfig.maxWeight, synapse.weight));\r\n }\r\n }\r\n}\r\n"]}
@@ -0,0 +1,11 @@
1
+ export type STDPFunction = (deltaT: number, weight: number) => number;
2
+ export interface ISTDPConfig {
3
+ minWeight: number;
4
+ maxWeight: number;
5
+ }
6
+ export declare const DEFAULT_STDP_CONFIG: ISTDPConfig;
7
+ export declare class STDP {
8
+ static exponential(learningRate?: number, tau?: number): STDPFunction;
9
+ static hebbian(learningRate?: number): STDPFunction;
10
+ static threshold(window?: number, potentiation?: number, depression?: number): STDPFunction;
11
+ }
@@ -0,0 +1,33 @@
1
+ export const DEFAULT_STDP_CONFIG = {
2
+ minWeight: 0.01,
3
+ maxWeight: 1.0,
4
+ };
5
+ export class STDP {
6
+ static exponential(learningRate = 0.01, tau = 20) {
7
+ return (deltaT, weight) => {
8
+ if (deltaT > 0) {
9
+ return weight + learningRate * Math.exp(-deltaT / tau); // LTP
10
+ }
11
+ else if (deltaT < 0) {
12
+ return weight - learningRate * Math.exp(deltaT / tau); // LTD
13
+ }
14
+ return weight;
15
+ };
16
+ }
17
+ static hebbian(learningRate = 0.005) {
18
+ return (deltaT, weight) => {
19
+ return weight + learningRate * deltaT;
20
+ };
21
+ }
22
+ static threshold(window = 10, potentiation = 0.02, depression = 0.01) {
23
+ return (deltaT, weight) => {
24
+ if (Math.abs(deltaT) < window) {
25
+ return weight + potentiation;
26
+ }
27
+ else {
28
+ return weight - depression;
29
+ }
30
+ };
31
+ }
32
+ }
33
+ //# sourceMappingURL=spike.stdp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spike.stdp.js","sourceRoot":"","sources":["../../../src/neuralnetwork/snn/spike.stdp.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,mBAAmB,GAAgB;IAC5C,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,GAAG;CACjB,CAAC;AAEF,MAAM,OAAO,IAAI;IACN,MAAM,CAAC,WAAW,CAAC,eAAuB,IAAI,EAAE,MAAc,EAAE;QACnE,OAAO,CAAC,MAAc,EAAE,MAAc,EAAU,EAAE;YAC9C,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;gBACb,OAAO,MAAM,GAAG,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM;YAClE,CAAC;iBAAM,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;gBACpB,OAAO,MAAM,GAAG,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM;YACjE,CAAC;YACD,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC;IACN,CAAC;IAEM,MAAM,CAAC,OAAO,CAAC,eAAuB,KAAK;QAC9C,OAAO,CAAC,MAAc,EAAE,MAAc,EAAU,EAAE;YAC9C,OAAO,MAAM,GAAG,YAAY,GAAG,MAAM,CAAC;QAC1C,CAAC,CAAC;IACN,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,SAAiB,EAAE,EAAE,eAAuB,IAAI,EAAE,aAAqB,IAAI;QAC/F,OAAO,CAAC,MAAc,EAAE,MAAc,EAAU,EAAE;YAC9C,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAAC;gBAC5B,OAAO,MAAM,GAAG,YAAY,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACJ,OAAO,MAAM,GAAG,UAAU,CAAC;YAC/B,CAAC;QACL,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["export type STDPFunction = (deltaT: number, weight: number) => number;\r\n\r\nexport interface ISTDPConfig {\r\n minWeight: number;\r\n maxWeight: number;\r\n}\r\n\r\nexport const DEFAULT_STDP_CONFIG: ISTDPConfig = {\r\n minWeight: 0.01,\r\n maxWeight: 1.0,\r\n};\r\n\r\nexport class STDP {\r\n public static exponential(learningRate: number = 0.01, tau: number = 20): STDPFunction {\r\n return (deltaT: number, weight: number): number => {\r\n if (deltaT > 0) {\r\n return weight + learningRate * Math.exp(-deltaT / tau); // LTP\r\n } else if (deltaT < 0) {\r\n return weight - learningRate * Math.exp(deltaT / tau); // LTD\r\n }\r\n return weight;\r\n };\r\n }\r\n\r\n public static hebbian(learningRate: number = 0.005): STDPFunction {\r\n return (deltaT: number, weight: number): number => {\r\n return weight + learningRate * deltaT;\r\n };\r\n }\r\n\r\n public static threshold(window: number = 10, potentiation: number = 0.02, depression: number = 0.01): STDPFunction {\r\n return (deltaT: number, weight: number): number => {\r\n if (Math.abs(deltaT) < window) {\r\n return weight + potentiation;\r\n } else {\r\n return weight - depression;\r\n }\r\n };\r\n }\r\n}\r\n"]}
@@ -0,0 +1,3 @@
1
+ /** Alias type for value that can be null */
2
+ export type Nullable<T> = T | null;
3
+ export type SingleOrArray<T> = T | Array<T>;
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/** Alias type for value that can be null */\r\nexport type Nullable<T> = T | null;\r\n\r\nexport type SingleOrArray<T> = T | Array<T>;\r\n"]}
@@ -0,0 +1,6 @@
1
+ export declare class CSVParser {
2
+ private delimiter;
3
+ constructor(delimiter?: string);
4
+ parse(csv: string): string[][];
5
+ private parseLine;
6
+ }
@@ -0,0 +1,36 @@
1
+ export class CSVParser {
2
+ constructor(delimiter = ",") {
3
+ this.delimiter = delimiter;
4
+ }
5
+ parse(csv) {
6
+ const lines = csv.trim().split(/\r?\n/);
7
+ return lines.map((line) => this.parseLine(line));
8
+ }
9
+ parseLine(line) {
10
+ const cells = [];
11
+ let cell = "";
12
+ let inQuotes = false;
13
+ for (let i = 0; i < line.length; i++) {
14
+ const char = line[i];
15
+ if (char === '"') {
16
+ if (inQuotes && line[i + 1] === '"') {
17
+ cell += '"';
18
+ i++; // skip next quote
19
+ }
20
+ else {
21
+ inQuotes = !inQuotes;
22
+ }
23
+ }
24
+ else if (char === this.delimiter && !inQuotes) {
25
+ cells.push(cell);
26
+ cell = "";
27
+ }
28
+ else {
29
+ cell += char;
30
+ }
31
+ }
32
+ cells.push(cell);
33
+ return cells;
34
+ }
35
+ }
36
+ //# sourceMappingURL=csv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv.js","sourceRoot":"","sources":["../../src/utils/csv.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAS;IAGlB,YAAmB,SAAS,GAAG,GAAG;QAC9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IAEM,KAAK,CAAC,GAAW;QACpB,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACrD,CAAC;IAEO,SAAS,CAAC,IAAY;QAC1B,MAAM,KAAK,GAAG,EAAE,CAAC;QACjB,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,IAAI,QAAQ,GAAG,KAAK,CAAC;QAErB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAErB,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;gBACf,IAAI,QAAQ,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;oBAClC,IAAI,IAAI,GAAG,CAAC;oBACZ,CAAC,EAAE,CAAC,CAAC,kBAAkB;gBAC3B,CAAC;qBAAM,CAAC;oBACJ,QAAQ,GAAG,CAAC,QAAQ,CAAC;gBACzB,CAAC;YACL,CAAC;iBAAM,IAAI,IAAI,KAAK,IAAI,CAAC,SAAS,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAC9C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACjB,IAAI,GAAG,EAAE,CAAC;YACd,CAAC;iBAAM,CAAC;gBACJ,IAAI,IAAI,IAAI,CAAC;YACjB,CAAC;QACL,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["export class CSVParser {\r\n private delimiter: string;\r\n\r\n public constructor(delimiter = \",\") {\r\n this.delimiter = delimiter;\r\n }\r\n\r\n public parse(csv: string): string[][] {\r\n const lines = csv.trim().split(/\\r?\\n/);\r\n return lines.map((line) => this.parseLine(line));\r\n }\r\n\r\n private parseLine(line: string): string[] {\r\n const cells = [];\r\n let cell = \"\";\r\n let inQuotes = false;\r\n\r\n for (let i = 0; i < line.length; i++) {\r\n const char = line[i];\r\n\r\n if (char === '\"') {\r\n if (inQuotes && line[i + 1] === '\"') {\r\n cell += '\"';\r\n i++; // skip next quote\r\n } else {\r\n inQuotes = !inQuotes;\r\n }\r\n } else if (char === this.delimiter && !inQuotes) {\r\n cells.push(cell);\r\n cell = \"\";\r\n } else {\r\n cell += char;\r\n }\r\n }\r\n\r\n cells.push(cell);\r\n return cells;\r\n }\r\n}\r\n"]}
@@ -0,0 +1 @@
1
+ export * from "./csv";
@@ -0,0 +1,2 @@
1
+ export * from "./csv";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC","sourcesContent":["export * from \"./csv\";\r\n"]}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@spiky-panda/core",
3
+ "version": "0.1.0",
4
+ "description": "Core library for Spikypanda - geometry, graph, and neural network primitives",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": ["dist"],
17
+ "sideEffects": false,
18
+ "scripts": {
19
+ "build": "npm run clean && npm run compile",
20
+ "clean": "rimraf dist bundle && rimraf tsconfig.build.tsbuildinfo",
21
+ "compile": "npm run compile:source",
22
+ "compile:source": "tsc -b tsconfig.build.json",
23
+ "watch:source": "tsc -b tsconfig.build.json -w",
24
+ "bundle": "webpack --mode production",
25
+ "bundle:dev": "webpack --mode development",
26
+ "bundle:watch": "webpack --mode development --watch",
27
+ "prepublishOnly": "npm run build"
28
+ },
29
+ "keywords": ["spikypanda", "geometry", "graph", "neural-network", "spiking-neural-network"],
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/GuillaumePelletier/spikypanda.git",
34
+ "directory": "packages/dev/core"
35
+ },
36
+ "peerDependencies": {
37
+ "reflect-metadata": "^0.2.2",
38
+ "tslib": "^2.8.1"
39
+ },
40
+ "devDependencies": {
41
+ "rimraf": "~6.0.1",
42
+ "ts-loader": "^9.5.0"
43
+ }
44
+ }