Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nmm_2020_site
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Erik Strand
nmm_2020_site
Commits
f49d32f3
Commit
f49d32f3
authored
5 years ago
by
Erik Strand
Browse files
Options
Downloads
Patches
Plain Diff
Compute loss
Numbers aren't obviously wrong
parent
69acc484
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
_code/notes/diffsim/main.cpp
+18
-0
18 additions, 0 deletions
_code/notes/diffsim/main.cpp
with
18 additions
and
0 deletions
_code/notes/diffsim/main.cpp
+
18
−
0
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'
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment