joel-woodfield commited on
Commit
9292daf
·
1 Parent(s): 0e3a627

Add support for random initial point

Browse files
dist/assets/{index-D3IdV-8S.js → index-xwMlQNfu.js} RENAMED
The diff for this file is too large to render. See raw diff
 
dist/index.html CHANGED
@@ -5,7 +5,7 @@
5
  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
  <title>Optimization</title>
8
- <script type="module" crossorigin src="/assets/index-D3IdV-8S.js"></script>
9
  <link rel="stylesheet" crossorigin href="/assets/index-DiNT9sUn.css">
10
  </head>
11
  <body>
 
5
  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
  <title>Optimization</title>
8
+ <script type="module" crossorigin src="/assets/index-xwMlQNfu.js"></script>
9
  <link rel="stylesheet" crossorigin href="/assets/index-DiNT9sUn.css">
10
  </head>
11
  <body>
frontends/react/src/App.tsx CHANGED
@@ -35,6 +35,15 @@ export default function App() {
35
  api.sendInit({ ...settingsUi, xlim, ylim });
36
  }
37
 
 
 
 
 
 
 
 
 
 
38
  const api = usePyodide(settings);
39
 
40
  if (api.isLoading) {
@@ -53,6 +62,7 @@ export default function App() {
53
  <Sidebar
54
  settings={settingsUi}
55
  setSettings={handleSettingsUiChange}
 
56
 
57
  onReset={() => api.sendReset()}
58
  onNextStep={() => api.sendNextStep()}
 
35
  api.sendInit({ ...settingsUi, xlim, ylim });
36
  }
37
 
38
+ function handleRandomInitialPoint() {
39
+ const xRange = xlimRef.current[1] - xlimRef.current[0];
40
+ const yRange = ylimRef.current[1] - ylimRef.current[0];
41
+ const newX0 = (xlimRef.current[0] + Math.random() * xRange * 0.95).toFixed(2);
42
+ const newY0 = (ylimRef.current[0] + Math.random() * yRange * 0.95).toFixed(2);
43
+ const newSettings = { ...settingsUi, x0: newX0, y0: newY0 };
44
+ handleSettingsUiChange(newSettings);
45
+ }
46
+
47
  const api = usePyodide(settings);
48
 
49
  if (api.isLoading) {
 
62
  <Sidebar
63
  settings={settingsUi}
64
  setSettings={handleSettingsUiChange}
65
+ onRandomInitialPoint={handleRandomInitialPoint}
66
 
67
  onReset={() => api.sendReset()}
68
  onNextStep={() => api.sendNextStep()}
frontends/react/src/Sidebar.tsx CHANGED
@@ -39,6 +39,7 @@ const BIVARIATE_FUNCTION_OPTIONS = {
39
  interface SidebarProps {
40
  settings: SettingsUi,
41
  setSettings: (settings: SettingsUi) => void,
 
42
 
43
  onReset?: () => void,
44
  onNextStep?: () => void,
@@ -50,6 +51,7 @@ interface SidebarProps {
50
  export default function Sidebar({
51
  settings,
52
  setSettings,
 
53
  onReset,
54
  onNextStep,
55
  onPrevStep,
@@ -145,6 +147,10 @@ export default function Sidebar({
145
  </div>
146
 
147
  {/* todo button for random init */}
 
 
 
 
148
 
149
  <div className="grid grid-cols-2 gap-2">
150
  {["Gradient Descent", "Nesterov", "Adam", "Adagrad", "RMSProp", "Adadelta"].includes(settings.algorithm) && (
 
39
  interface SidebarProps {
40
  settings: SettingsUi,
41
  setSettings: (settings: SettingsUi) => void,
42
+ onRandomInitialPoint: () => void,
43
 
44
  onReset?: () => void,
45
  onNextStep?: () => void,
 
51
  export default function Sidebar({
52
  settings,
53
  setSettings,
54
+ onRandomInitialPoint,
55
  onReset,
56
  onNextStep,
57
  onPrevStep,
 
147
  </div>
148
 
149
  {/* todo button for random init */}
150
+ <Button
151
+ label="Random Initial Point"
152
+ onClick={onRandomInitialPoint}
153
+ />
154
 
155
  <div className="grid grid-cols-2 gap-2">
156
  {["Gradient Descent", "Nesterov", "Adam", "Adagrad", "RMSProp", "Adadelta"].includes(settings.algorithm) && (