Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
adaptive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Quantum Tinkerer
adaptive
Commits
ec32933a
Commit
ec32933a
authored
6 years ago
by
Bas Nijholt
Browse files
Options
Downloads
Patches
Plain Diff
2D: add loss that minimized the area of the triangle in 3D
parent
30ab0b31
No related branches found
No related tags found
No related merge requests found
Pipeline
#12595
passed
6 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
adaptive/learner/learner2D.py
+38
-0
38 additions, 0 deletions
adaptive/learner/learner2D.py
with
38 additions
and
0 deletions
adaptive/learner/learner2D.py
+
38
−
0
View file @
ec32933a
...
...
@@ -99,6 +99,44 @@ def resolution_loss(ip, min_distance=0, max_distance=1):
return
loss
def
minimize_triangle_surface_loss
(
ip
):
"""
Loss function that is similar to the default loss function in the
`Learner1D`. The loss is the area spanned by the 3D vectors of the
vertices.
Works with `~adaptive.Learner2D` only.
Examples
--------
>>>
from
adaptive.learner.learner2D
import
minimize_triangle_surface_loss
>>>
def
f
(
xy
):
...
x
,
y
=
xy
...
return
x
**
2
+
y
**
2
>>>
>>>
learner
=
adaptive
.
Learner2D
(
f
,
bounds
=
[(
-
1
,
-
1
),
(
1
,
1
)],
...
loss_per_triangle
=
minimize_triangle_surface_loss
)
>>>
"""
tri
=
ip
.
tri
points
=
tri
.
points
[
tri
.
vertices
]
values
=
ip
.
values
[
tri
.
vertices
]
delta_pts
=
points
-
points
[:,
-
1
,
:][:,
None
,
:]
vectors
=
delta_pts
[:,
:
2
,
:]
a_xy
=
vectors
[:,
0
,
:]
b_xy
=
vectors
[:,
1
,
:]
delta_vals
=
values
-
values
[:,
-
1
,
:][:,
None
,
:]
vectors
=
delta_vals
[:,
:
2
,
:]
a_z
=
vectors
[:,
0
,
:]
b_z
=
vectors
[:,
1
,
:]
a
=
np
.
hstack
([
a_xy
,
a_z
])
b
=
np
.
hstack
([
b_xy
,
b_z
])
return
np
.
linalg
.
norm
(
np
.
cross
(
a
,
b
),
axis
=
1
)
def
default_loss
(
ip
):
dev
=
np
.
sum
(
deviations
(
ip
),
axis
=
0
)
A
=
areas
(
ip
)
...
...
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