Skip to content

Instantly share code, notes, and snippets.

@bwasti
Created September 4, 2022 19:35
Show Gist options
  • Save bwasti/9817171e47c75c2d8b484ed69abdae11 to your computer and use it in GitHub Desktop.
Save bwasti/9817171e47c75c2d8b484ed69abdae11 to your computer and use it in GitHub Desktop.
import * as sm from '@shumai/shumai'
class EvalTuner {
constructor() {
this.best_delta = 1
this.best_time = Infinity
this.last_i = 0
}
calculate_better_delta(time_spent) {
}
step(t, i) {
const delta = i - this.last_i
if (delta >= this.best_delta) {
// see how well we did this time
t.eval()
const time_spent = (performance.now() - this.last_time) / delta
console.log("delta", this.best_delta, "took", time_spent, "ms per increment")
this.calculate_better_delta(time_spent)
this.last_i = i
this.last_time = performance.now()
}
}
}
const eval_tuner = new EvalTuner()
const b = sm.randn([1])
let t = sm.randn([1])
for (let i = 0; i < 1000; ++i) {
t = t.add(b)
eval_tuner.step(t, i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment