Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gext
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Show more breadcrumbs
Michele Nottoli
gext
Commits
0f0a4592
Commit
0f0a4592
authored
1 year ago
by
Michele Nottoli
Browse files
Options
Downloads
Patches
Plain Diff
Implemented regularization.
parent
e338089a
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!6
QTR
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gext/fitting.py
+6
-2
6 additions, 2 deletions
gext/fitting.py
tests/test_descriptor_fitting.py
+5
-3
5 additions, 3 deletions
tests/test_descriptor_fitting.py
with
11 additions
and
5 deletions
gext/fitting.py
+
6
−
2
View file @
0f0a4592
...
...
@@ -60,8 +60,12 @@ class LeastSquare(AbstractFitting):
def
fit
(
self
,
vectors
:
List
[
np
.
ndarray
],
target
:
np
.
ndarray
):
"""
Given a set of vectors and a target return the fitting
coefficients.
"""
matrix
=
np
.
vstack
(
vectors
).
T
coefficients
,
_
,
_
,
_
=
np
.
linalg
.
lstsq
(
matrix
,
target
,
rcond
=
None
)
matrix
=
np
.
array
(
vectors
).
T
A
=
matrix
.
T
@
matrix
b
=
matrix
.
T
@
target
if
self
.
options
[
"
regularization
"
]
>
0.0
:
A
+=
np
.
identity
(
len
(
b
))
*
self
.
options
[
"
regularization
"
]
coefficients
=
np
.
linalg
.
solve
(
A
,
b
)
return
np
.
array
(
coefficients
,
dtype
=
np
.
float64
)
class
QuasiTimeReversible
(
AbstractFitting
):
...
...
This diff is collapsed.
Click to expand it.
tests/test_descriptor_fitting.py
+
5
−
3
View file @
0f0a4592
...
...
@@ -10,10 +10,11 @@ import gext.fitting
import
gext.grassmann
import
utils
SMALL
=
1e-
10
SMALL
=
1e-
8
@pytest.mark.parametrize
(
"
datafile
"
,
[
"
urea.json
"
,
"
glucose.json
"
])
def
test_descriptor_fitting
(
datafile
):
@pytest.mark.parametrize
(
"
regularization
"
,
[
0.0
,
0.01
,
0.1
])
def
test_descriptor_fitting
(
datafile
,
regularization
):
# load test data from json file
data
=
utils
.
load_json
(
f
"
tests/
{
datafile
}
"
)
...
...
@@ -23,7 +24,8 @@ def test_descriptor_fitting(datafile):
nframes
=
data
[
"
trajectory
"
].
shape
[
0
]
# initialize an extrapolator
extrapolator
=
gext
.
Extrapolator
(
nelectrons
,
nbasis
,
natoms
,
nsteps
=
nframes
)
extrapolator
=
gext
.
Extrapolator
(
nelectrons
,
nbasis
,
natoms
,
nsteps
=
nframes
,
fitting_regularization
=
regularization
)
# load data in the extrapolator
for
(
coords
,
coeff
,
overlap
)
in
zip
(
data
[
"
trajectory
"
],
...
...
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