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
b5b81acc
Commit
b5b81acc
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
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!121
2D: add loss that minimizes the area of the triangle in 3D
Pipeline
#12631
passed
6 years ago
Stage: test
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
adaptive/learner/learner2D.py
+37
-0
37 additions, 0 deletions
adaptive/learner/learner2D.py
with
37 additions
and
0 deletions
adaptive/learner/learner2D.py
+
37
−
0
View file @
b5b81acc
...
...
@@ -99,6 +99,43 @@ 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
]
values
=
values
/
(
ip
.
values
.
ptp
(
axis
=
0
).
max
()
or
1
)
def
_get_vectors
(
points
):
delta
=
points
-
points
[:,
-
1
,
:][:,
None
,
:]
vectors
=
delta
[:,
:
2
,
:]
return
vectors
[:,
0
,
:],
vectors
[:,
1
,
:]
a_xy
,
b_xy
=
_get_vectors
(
points
)
a_z
,
b_z
=
_get_vectors
(
values
)
a
=
np
.
hstack
([
a_xy
,
a_z
])
b
=
np
.
hstack
([
b_xy
,
b_z
])
return
np
.
linalg
.
norm
(
np
.
cross
(
a
,
b
)
/
2
,
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