FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
DPCFunctionEncoder/src/Integrator.py at main · geoelements/DPCFunctionEncoder · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
geoelements
/
DPCFunctionEncoder
Public
forked from
hassaniqbal209/DPCFunctionEncoder
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
DPCFunctionEncoder
/
src
/
Integrator.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (26 loc) · 1.15 KB
Breadcrumbs
DPCFunctionEncoder
/
src
/
Integrator.py
Copy path
File metadata and controls
34 lines (26 loc) · 1.15 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from
typing
import
Callable
import
torch
def
create_cross_terms
(
x
:
torch
.
Tensor
)
->
torch
.
Tensor
:
"""Create cross product terms for angular rates."""
wx
,
wy
,
wz
=
x
[...,
9
],
x
[...,
10
],
x
[...,
11
]
cross_terms
=
torch
.
stack
([
wy
*
wz
,
wx
*
wz
,
wx
*
wy
],
dim
=
-
1
)
return
torch
.
cat
([
x
,
cross_terms
],
dim
=
-
1
)
def
rk4_step
(
func
:
Callable
,
x
:
torch
.
tensor
,
u
:
torch
.
tensor
,
dt
:
torch
.
tensor
,
**
ode_kwargs
)
->
torch
.
tensor
:
"""Runge-Kutta 4th order ODE integrator for a single step."""
t
=
torch
.
zeros_like
(
dt
,
device
=
dt
.
device
)
k1
=
func
(
t
,
x
,
u
,
**
ode_kwargs
)
k2
=
func
(
t
+
dt
/
2
,
x
+
(
dt
/
2
).
unsqueeze
(
-
1
)
*
k1
,
u
,
**
ode_kwargs
)
k3
=
func
(
t
+
dt
/
2
,
x
+
(
dt
/
2
).
unsqueeze
(
-
1
)
*
k2
,
u
,
**
ode_kwargs
)
k4
=
func
(
t
+
dt
,
x
+
dt
.
unsqueeze
(
-
1
)
*
k3
,
u
,
**
ode_kwargs
)
return
(
dt
/
6
).
unsqueeze
(
-
1
)
*
(
k1
+
2
*
k2
+
2
*
k3
+
k4
)
class
ODEFunc
(
torch
.
nn
.
Module
):
def
__init__
(
self
,
model
:
torch
.
nn
.
Module
):
super
(
ODEFunc
,
self
).
__init__
()
self
.
model
=
model
def
forward
(
self
,
t
,
x
,
u
):
state
=
torch
.
cat
([
t
.
unsqueeze
(
-
1
),
x
,
u
],
dim
=
-
1
)
return
self
.
model
(
state
)
Back
|
FazBrowse Home
|
New Git URL