Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Erik Strand
nmm_2020_site
Commits
f49d32f3
Commit
f49d32f3
authored
Apr 20, 2020
by
Erik Strand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compute loss
Numbers aren't obviously wrong
parent
69acc484
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
0 deletions
+18
-0
_code/notes/diffsim/main.cpp
_code/notes/diffsim/main.cpp
+18
-0
No files found.
_code/notes/diffsim/main.cpp
View file @
f49d32f3
...
...
@@ -23,11 +23,29 @@ struct LaunchObjective {
}
void
operator
()(
VectorX
<
Scalar
>
const
&
velocity
,
Scalar
&
loss
,
VectorX
<
Scalar
>&
gradient
)
{
// prepare initial conditions
initial_conditions_
.
segment
<
dim_
>
(
3
*
dim_
)
=
velocity
;
// run the simulation
nbody_
.
initialize
(
dim_
,
masses_
,
initial_conditions_
,
delta_t_
);
for
(
uint32_t
i
=
0
;
i
<
n_steps_
;
++
i
)
{
nbody_
.
step
();
}
// compute loss
Vector2
<
Scalar
>
const
goal
=
Vector2
<
Scalar
>
(
0
,
1
);
Vector2
<
Scalar
>
const
difference
=
nbody_
.
state
().
segment
<
dim_
>
(
dim_
)
-
goal
;
loss
=
difference
.
squaredNorm
();
// compute gradient of loss
// loss = difference^T * difference
// d_loss = 2 * difference^T * d_difference
gradient
=
2
*
difference
.
transpose
()
*
nbody_
.
state_jacobian
().
block
<
dim_
,
dim_
>
(
dim_
,
3
*
dim_
);
// print stuff
std
::
cout
<<
"loss = "
<<
loss
<<
"
\n
"
;
std
::
cout
<<
"loss gradient
\n
"
;
std
::
cout
<<
gradient
<<
'\n'
;
std
::
cout
<<
"state jacobian
\n
"
;
std
::
cout
<<
nbody_
.
state_jacobian
()
<<
'\n'
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment