-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.ts
More file actions
23 lines (22 loc) · 1.12 KB
/
mod.ts
File metadata and controls
23 lines (22 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { PCA } from "https://raw.githubusercontent.com/gnlow/deno-pca/master/mod.ts"
import { NumericalTuple, tuple } from "https://raw.githubusercontent.com/randkid/Randkid/master/mod.ts"
import birthdate from "https://raw.githubusercontent.com/randkid/birthdate/master/mod.ts"
import gender from "https://raw.githubusercontent.com/randkid/gender/master/mod.ts"
import { gaussian } from "https://deno.land/x/gaussian/mod.ts"
import { hash } from "https://raw.githubusercontent.com/gnlow/planter/master/mod.ts"
import f from "./src/f_model.js"
import m from "./src/m_model.js"
export default new NumericalTuple({
inputMaterials: tuple([birthdate, gender]),
ranges: [],
rand(seed, birthDateVal, genderVal) {
const date = new Date(birthDateVal)
const models = genderVal == "f" ? f : m
const pca = PCA.load(models[2013 - date.getFullYear()].model)
const randomized = pca.getStandardDeviations().splice(0, 5)
.map((σ: number, i: number) =>
gaussian(0, σ**2).ppf(hash(seed, i))
)
return Array.from(pca.invert([randomized]).data[0]) as number[]
}
})