(numSamples: number, noise: number)
| 93 | } |
| 94 | |
| 95 | export function regressGaussian(numSamples: number, noise: number): |
| 96 | Example2D[] { |
| 97 | let points: Example2D[] = []; |
| 98 | |
| 99 | let labelScale = d3.scale.linear() |
| 100 | .domain([0, 2]) |
| 101 | .range([1, 0]) |
| 102 | .clamp(true); |
| 103 | |
| 104 | let gaussians = [ |
| 105 | [-4, 2.5, 1], |
| 106 | [0, 2.5, -1], |
| 107 | [4, 2.5, 1], |
| 108 | [-4, -2.5, -1], |
| 109 | [0, -2.5, 1], |
| 110 | [4, -2.5, -1] |
| 111 | ]; |
| 112 | |
| 113 | function getLabel(x, y) { |
| 114 | // Choose the one that is maximum in abs value. |
| 115 | let label = 0; |
| 116 | gaussians.forEach(([cx, cy, sign]) => { |
| 117 | let newLabel = sign * labelScale(dist({x, y}, {x: cx, y: cy})); |
| 118 | if (Math.abs(newLabel) > Math.abs(label)) { |
| 119 | label = newLabel; |
| 120 | } |
| 121 | }); |
| 122 | return label; |
| 123 | } |
| 124 | let radius = 6; |
| 125 | for (let i = 0; i < numSamples; i++) { |
| 126 | let x = randUniform(-radius, radius); |
| 127 | let y = randUniform(-radius, radius); |
| 128 | let noiseX = randUniform(-radius, radius) * noise; |
| 129 | let noiseY = randUniform(-radius, radius) * noise; |
| 130 | let label = getLabel(x + noiseX, y + noiseY); |
| 131 | points.push({x, y, label}); |
| 132 | }; |
| 133 | return points; |
| 134 | } |
| 135 | |
| 136 | export function classifySpiralData(numSamples: number, noise: number): |
| 137 | Example2D[] { |
nothing calls this directly
no test coverage detected
searching dependent graphs…