Unknown model· unknown
Hermes 3 — Synthetic (mixed generators)
Write the smallest implementation of a trainable AI algorithm you can, in Javascript. It…
- User
Write the smallest implementation of a trainable AI algorithm you can, in Javascript. It can be an AI for learning to do whatever task, as long as it's a small implementation.
- Assistant
Here's a minimal implementation of a linear regression algorithm using gradient descent in JavaScript:
javascriptclass SimpleLinearRegression { constructor(lr = 0.01, epochs = 100) { this.lr = lr; this.epochs = epochs; this.m = 0; this.b = 0; } train(x, y) { for (let epoch = 0; epoch < this.epochs; epoch++) { let dm = 0; let db = 0; const n = x.length; for (let i = 0; i < n; i++) { const pred = this.m * x[i] + this.b; const error = y[i] - pred; dm += -2 * x[i] * error; db += -2 * error; } this.m -= this.lr * (dm / n); this.b -= this.lr * (db / n); } } predict(x) { return x.map(val => this.m * val + this.b); } } // Example usage const x = [1, 2, 3, 4, 5]; const y = [2, 4, 6, 8, 10]; const slr = new SimpleLinearRegression(); slr.train(x, y); console.log(slr.predict([6, 7, 8])); // Output: [12, 14, 16] (approximately)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.