Spaces:
Running
Running
abril4416 commited on
Commit ·
055a863
1
Parent(s): c04888d
Rename logistic cost labels to cost function wording
Browse files
logistic-regression/cost-visualization.html
CHANGED
|
@@ -73,10 +73,10 @@
|
|
| 73 |
<div id="modelDefinition" class="model-definition"></div>
|
| 74 |
|
| 75 |
<p class="hint">
|
| 76 |
-
The height represents
|
| 77 |
</p>
|
| 78 |
<p class="hint">
|
| 79 |
-
Each trajectory point is one gradient-descent update: horizontal movement = parameter changes, vertical movement =
|
| 80 |
</p>
|
| 81 |
|
| 82 |
<div id="landscapeSummary" class="landscape-summary"></div>
|
|
@@ -130,6 +130,6 @@
|
|
| 130 |
</main>
|
| 131 |
|
| 132 |
<script src="https://cdn.plot.ly/plotly-2.35.2.min.js"></script>
|
| 133 |
-
<script src="cost.js?v=
|
| 134 |
</body>
|
| 135 |
</html>
|
|
|
|
| 73 |
<div id="modelDefinition" class="model-definition"></div>
|
| 74 |
|
| 75 |
<p class="hint">
|
| 76 |
+
The height represents the cost function J(theta). Lower points correspond to parameter values that better fit class labels.
|
| 77 |
</p>
|
| 78 |
<p class="hint">
|
| 79 |
+
Each trajectory point is one gradient-descent update: horizontal movement = parameter changes, vertical movement = cost-function change.
|
| 80 |
</p>
|
| 81 |
|
| 82 |
<div id="landscapeSummary" class="landscape-summary"></div>
|
|
|
|
| 130 |
</main>
|
| 131 |
|
| 132 |
<script src="https://cdn.plot.ly/plotly-2.35.2.min.js"></script>
|
| 133 |
+
<script src="cost.js?v=20260816a"></script>
|
| 134 |
</body>
|
| 135 |
</html>
|
logistic-regression/cost.js
CHANGED
|
@@ -494,7 +494,7 @@ function buildHover(meta, point) {
|
|
| 494 |
`Iteration: ${point.step}`,
|
| 495 |
`${meta.p1Name}: ${point.p1.toFixed(4)}`,
|
| 496 |
`${meta.p2Name}: ${point.p2.toFixed(4)}`,
|
| 497 |
-
`
|
| 498 |
].join("<br>");
|
| 499 |
}
|
| 500 |
|
|
@@ -597,9 +597,9 @@ function updateSummary(caseKey) {
|
|
| 597 |
|
| 598 |
if (state.trajectory.length === 0) {
|
| 599 |
landscapeSummary.innerHTML = `
|
| 600 |
-
<span class="landscape-pill">Start
|
| 601 |
-
<span class="landscape-pill">Current
|
| 602 |
-
<span class="landscape-pill">Final
|
| 603 |
<span class="landscape-pill">Reduction: --</span>
|
| 604 |
<span class="landscape-pill">Iterations: 0 / 0</span>
|
| 605 |
`;
|
|
@@ -613,9 +613,9 @@ function updateSummary(caseKey) {
|
|
| 613 |
const reduction = ((start.cost - final.cost) / Math.max(1e-9, start.cost)) * 100;
|
| 614 |
|
| 615 |
landscapeSummary.innerHTML = `
|
| 616 |
-
<span class="landscape-pill">Start
|
| 617 |
-
<span class="landscape-pill">Current
|
| 618 |
-
<span class="landscape-pill">Final
|
| 619 |
<span class="landscape-pill">Reduction: ${reduction.toFixed(1)}%</span>
|
| 620 |
<span class="landscape-pill">Iterations: ${idx} / ${state.trajectory.length - 1}</span>
|
| 621 |
<span class="landscape-pill">${meta.p1Name}: ${current.p1.toFixed(3)}, ${meta.p2Name}: ${current.p2.toFixed(3)}</span>
|
|
@@ -665,7 +665,7 @@ function renderStats(caseKey) {
|
|
| 665 |
<span>Model case: ${meta.p1Name}, ${meta.p2Name}</span>
|
| 666 |
<span>Samples: ${m}</span>
|
| 667 |
<span>Current step: ${idx}</span>
|
| 668 |
-
<span>
|
| 669 |
<span>${meta.p1Label}: ${current.p1.toFixed(4)}</span>
|
| 670 |
<span>${meta.p2Label}: ${current.p2.toFixed(4)}</span>
|
| 671 |
`;
|
|
@@ -709,8 +709,8 @@ function renderLandscape(caseKey, grid) {
|
|
| 709 |
colorscale: "Viridis",
|
| 710 |
showscale: showSurface,
|
| 711 |
visible: showSurface || showContours,
|
| 712 |
-
colorbar: { title: "
|
| 713 |
-
hovertemplate: `${meta.p1Name}: %{x:.4f}<br>${meta.p2Name}: %{y:.4f}<br>
|
| 714 |
});
|
| 715 |
|
| 716 |
if (showTrajectory && fullPath.length > 0) {
|
|
@@ -811,8 +811,8 @@ function renderLandscape(caseKey, grid) {
|
|
| 811 |
colorscale: "Viridis",
|
| 812 |
showscale: showSurface,
|
| 813 |
visible: showSurface,
|
| 814 |
-
colorbar: { title: "
|
| 815 |
-
hovertemplate: `${meta.p1Name}: %{x:.4f}<br>${meta.p2Name}: %{y:.4f}<br>
|
| 816 |
});
|
| 817 |
|
| 818 |
const contour3d = buildContourSegments3D(grid);
|
|
@@ -891,7 +891,7 @@ function renderLandscape(caseKey, grid) {
|
|
| 891 |
scene: {
|
| 892 |
xaxis: { title: meta.p1Label, range: [grid.p1Min, grid.p1Max], showspikes: false },
|
| 893 |
yaxis: { title: meta.p2Label, range: [grid.p2Min, grid.p2Max], showspikes: false },
|
| 894 |
-
zaxis: { title: "
|
| 895 |
aspectmode: "manual",
|
| 896 |
aspectratio: { x: 1.14, y: 1.12, z: 0.82 },
|
| 897 |
camera: state.camera3d || cloneCamera(DEFAULT_CAMERA),
|
|
|
|
| 494 |
`Iteration: ${point.step}`,
|
| 495 |
`${meta.p1Name}: ${point.p1.toFixed(4)}`,
|
| 496 |
`${meta.p2Name}: ${point.p2.toFixed(4)}`,
|
| 497 |
+
`Cost function: ${point.cost.toFixed(4)}`,
|
| 498 |
].join("<br>");
|
| 499 |
}
|
| 500 |
|
|
|
|
| 597 |
|
| 598 |
if (state.trajectory.length === 0) {
|
| 599 |
landscapeSummary.innerHTML = `
|
| 600 |
+
<span class="landscape-pill">Start cost: --</span>
|
| 601 |
+
<span class="landscape-pill">Current cost: --</span>
|
| 602 |
+
<span class="landscape-pill">Final cost: --</span>
|
| 603 |
<span class="landscape-pill">Reduction: --</span>
|
| 604 |
<span class="landscape-pill">Iterations: 0 / 0</span>
|
| 605 |
`;
|
|
|
|
| 613 |
const reduction = ((start.cost - final.cost) / Math.max(1e-9, start.cost)) * 100;
|
| 614 |
|
| 615 |
landscapeSummary.innerHTML = `
|
| 616 |
+
<span class="landscape-pill">Start cost: ${start.cost.toFixed(4)}</span>
|
| 617 |
+
<span class="landscape-pill">Current cost: ${current.cost.toFixed(4)}</span>
|
| 618 |
+
<span class="landscape-pill">Final cost: ${final.cost.toFixed(4)}</span>
|
| 619 |
<span class="landscape-pill">Reduction: ${reduction.toFixed(1)}%</span>
|
| 620 |
<span class="landscape-pill">Iterations: ${idx} / ${state.trajectory.length - 1}</span>
|
| 621 |
<span class="landscape-pill">${meta.p1Name}: ${current.p1.toFixed(3)}, ${meta.p2Name}: ${current.p2.toFixed(3)}</span>
|
|
|
|
| 665 |
<span>Model case: ${meta.p1Name}, ${meta.p2Name}</span>
|
| 666 |
<span>Samples: ${m}</span>
|
| 667 |
<span>Current step: ${idx}</span>
|
| 668 |
+
<span>Cost function: ${current.cost.toFixed(4)}</span>
|
| 669 |
<span>${meta.p1Label}: ${current.p1.toFixed(4)}</span>
|
| 670 |
<span>${meta.p2Label}: ${current.p2.toFixed(4)}</span>
|
| 671 |
`;
|
|
|
|
| 709 |
colorscale: "Viridis",
|
| 710 |
showscale: showSurface,
|
| 711 |
visible: showSurface || showContours,
|
| 712 |
+
colorbar: { title: "Cost function", thickness: 14 },
|
| 713 |
+
hovertemplate: `${meta.p1Name}: %{x:.4f}<br>${meta.p2Name}: %{y:.4f}<br>Cost function: %{z:.4f}<extra></extra>`,
|
| 714 |
});
|
| 715 |
|
| 716 |
if (showTrajectory && fullPath.length > 0) {
|
|
|
|
| 811 |
colorscale: "Viridis",
|
| 812 |
showscale: showSurface,
|
| 813 |
visible: showSurface,
|
| 814 |
+
colorbar: { title: "Cost function", thickness: 14 },
|
| 815 |
+
hovertemplate: `${meta.p1Name}: %{x:.4f}<br>${meta.p2Name}: %{y:.4f}<br>Cost function: %{z:.4f}<extra></extra>`,
|
| 816 |
});
|
| 817 |
|
| 818 |
const contour3d = buildContourSegments3D(grid);
|
|
|
|
| 891 |
scene: {
|
| 892 |
xaxis: { title: meta.p1Label, range: [grid.p1Min, grid.p1Max], showspikes: false },
|
| 893 |
yaxis: { title: meta.p2Label, range: [grid.p2Min, grid.p2Max], showspikes: false },
|
| 894 |
+
zaxis: { title: "Cost function J(theta)", range: [grid.min, grid.clipMax], showspikes: false },
|
| 895 |
aspectmode: "manual",
|
| 896 |
aspectratio: { x: 1.14, y: 1.12, z: 0.82 },
|
| 897 |
camera: state.camera3d || cloneCamera(DEFAULT_CAMERA),
|