mini-jstorch 1.0.0 → 1.0.2

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 ADDED
@@ -0,0 +1,24 @@
1
+ # mini-jstorch
2
+ *NOTICE!*:
3
+ This versions is still on a **BETA** Versions of **mini-jstorch**!
4
+ So maybe the features is not many and completely *SO* BE PATIENCE!!
5
+
6
+ ---
7
+
8
+ **Version: 1.0.2**
9
+ A lightweight and browser-compatible deep learning framework inspired by **PyTorch** — written in pure JavaScript.
10
+ Perfect for CodePen, web demos, and fast prototyping.
11
+
12
+ ---
13
+
14
+ ## Features
15
+
16
+ - # `Sequential` model API
17
+ - # Fully modular layers (e.g., `Dense`)
18
+ - # Activation functions: `ReLU`, `Sigmoid`
19
+ - # Model serialization (`saveModel`, `loadModel`)
20
+ - # Works on both **Node.js** and **browser**
21
+ - # No native bindings, 100% JavaScript
22
+ - # Inspired by PyTorch, but mini-sized
23
+
24
+ ---
@@ -0,0 +1,7 @@
1
+ export function relu(x) {
2
+ return x.map(v => Math.max(0, v));
3
+ }
4
+
5
+ export function sigmoid(x) {
6
+ return x.map(v => 1 / (1 + Math.exp(-v)));
7
+ }
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // index.js
2
+ export { Sequential } from './models/Sequential.js';
3
+ export { Dense } from './layers/Dense.js';
4
+ export * as activations from './activations/relu.js';
5
+ export * as io from './utils/io.js';
@@ -0,0 +1,17 @@
1
+ import { dot, add } from '../utils/math.js';
2
+
3
+ export class Dense {
4
+ constructor(inputSize, outputSize, activation = x => x) {
5
+ this.weights = Array.from({ length: outputSize }, () =>
6
+ Array.from({ length: inputSize }, () => Math.random() * 0.1)
7
+ );
8
+ this.bias = Array(outputSize).fill(0);
9
+ this.activation = activation;
10
+ this.name = "Dense";
11
+ }
12
+
13
+ forward(input) {
14
+ const z = add(dot(this.weights, input), this.bias);
15
+ return z.map(this.activation);
16
+ }
17
+ }
@@ -0,0 +1,20 @@
1
+ export class Sequential {
2
+ constructor() {
3
+ this.layers = [];
4
+ }
5
+
6
+ add(layer) {
7
+ this.layers.push(layer);
8
+ }
9
+
10
+ predict(input) {
11
+ return this.layers.reduce((out, layer) => layer.forward(out), input);
12
+ }
13
+
14
+ summary() {
15
+ console.log("Sequential model:");
16
+ this.layers.forEach((layer, i) => {
17
+ console.log(` Layer ${i + 1}: ${layer.name || "unnamed"}`);
18
+ });
19
+ }
20
+ }
package/package.json CHANGED
@@ -1,12 +1,21 @@
1
1
  {
2
2
  "name": "mini-jstorch",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
+ "description": "A lightweight JavaScript neural network framework for browser & Node.js, inspired by PyTorch.",
4
5
  "main": "index.js",
5
- "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1"
7
- },
8
- "keywords": [],
9
- "author": "",
10
- "license": "ISC",
11
- "description": ""
6
+ "keywords": [
7
+ "neural-network",
8
+ "javascript",
9
+ "lightweight",
10
+ "ai",
11
+ "machine-learning",
12
+ "browser",
13
+ "mini"
14
+ ],
15
+ "author": "Rizal",
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/rizal-editors/mini-jstorch.git"
20
+ }
12
21
  }
package/utils/io.js ADDED
@@ -0,0 +1,25 @@
1
+ export function saveModel(model) {
2
+ const modelData = {
3
+ layers: model.layers.map(layer => ({
4
+ name: layer.name,
5
+ weights: layer.weights,
6
+ bias: layer.bias
7
+ }))
8
+ };
9
+ return JSON.stringify(modelData);
10
+ }
11
+
12
+ export function loadModel(json, ModelClass, LayerClass) {
13
+ const data = typeof json === 'string' ? JSON.parse(json) : json;
14
+ const model = new ModelClass();
15
+
16
+ data.layers.forEach(layer => {
17
+ const dense = new LayerClass(0, 0); // dummy init
18
+ dense.weights = layer.weights;
19
+ dense.bias = layer.bias;
20
+ dense.name = layer.name;
21
+ model.add(dense);
22
+ });
23
+
24
+ return model;
25
+ }
package/utils/math.js ADDED
@@ -0,0 +1,9 @@
1
+ export function dot(weights, input) {
2
+ return weights.map(row =>
3
+ row.reduce((sum, val, i) => sum + val * input[i], 0)
4
+ );
5
+ }
6
+
7
+ export function add(a, b) {
8
+ return a.map((val, i) => val + b[i]);
9
+ }