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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michele Nottoli
gext
Compare revisions
0c054fa47d325cdb78af827e83e90778c9044892 to 84b04f6803cccf1133dea8755d4f44eec00b9348
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
nottolme/gext
Select target project
No results found
84b04f6803cccf1133dea8755d4f44eec00b9348
Select Git revision
Branches
askarpza-main-patch-76094
main
optimization
polynomial_regression
Tags
v0.2.0
v0.3.0
v0.4.0
v0.4.1
v0.5.0
v0.6.0
v0.7.0
v0.7.1
v0.8.0
13 results
Swap
Target
nottolme/gext
Select target project
nottolme/gext
1 result
0c054fa47d325cdb78af827e83e90778c9044892
Select Git revision
Branches
askarpza-main-patch-76094
main
optimization
polynomial_regression
Tags
v0.2.0
v0.3.0
v0.4.0
v0.4.1
v0.5.0
v0.6.0
v0.7.0
v0.7.1
v0.8.0
13 results
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source
2
test_fitting works
· 8b774296
Askarpour, Zahra
authored
Feb 15, 2024
8b774296
test_fitting works
· 84b04f68
Askarpour, Zahra
authored
Feb 15, 2024
84b04f68
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
gext/fitting.py
+20
-22
20 additions, 22 deletions
gext/fitting.py
test_diff_fitting.py
+54
-0
54 additions, 0 deletions
test_diff_fitting.py
with
74 additions
and
22 deletions
gext/fitting.py
View file @
84b04f68
...
...
@@ -61,14 +61,12 @@ class DiffFitting(AbstractFitting):
def
fit
(
self
,
vectors
:
List
[
np
.
ndarray
],
target
:
np
.
ndarray
):
"""
Given a set of vectors and a target return the fitting
coefficients.
"""
if
len
(
vectors
)
==
1
:
raise
ValueError
(
"
DiffFit does not work for one vector
"
)
target
=
target
-
vectors
[
-
1
]
VECTORS
=
[]
print
(
"
lenvector
"
,
len
(
vectors
))
if
len
(
vectors
)
>
1
:
for
i
in
range
(
2
,
len
(
vectors
)
+
1
):
print
(
"
lenvector
"
,
len
(
vectors
))
VECTORS
.
append
(
vectors
[
i
-
2
]
-
vectors
[
-
1
])
print
(
len
(
VECTORS
))
for
i
in
range
(
0
,
len
(
vectors
)
+
1
):
VECTORS
.
append
(
vectors
[
i
]
-
vectors
[
-
1
])
matrix
=
np
.
array
(
VECTORS
).
T
a
=
matrix
.
T
@
matrix
b
=
matrix
.
T
@
target
...
...
@@ -82,15 +80,15 @@ class DiffFitting(AbstractFitting):
coefficients
:
np
.
ndarray
)
->
np
.
ndarray
:
"""
Given a set of vectors (or matrices) and the corresponding
coefficients, build their linear combination.
"""
if
len
(
vectors
)
==
1
:
raise
ValueError
(
"
DiffFit does not work for one vector
"
)
result
=
np
.
zeros
(
vectors
[
0
].
shape
,
dtype
=
np
.
float64
)
VECTORS_DiffFitting
=
[]
if
len
(
vectors
)
>
1
:
for
i
in
range
(
2
,
len
(
vectors
)
+
1
):
VECTORS_DiffFitting
.
append
(
vectors
[
i
-
2
]
-
vectors
[
-
1
])
for
coeff
,
vector
in
zip
(
coefficients
,
vectors
):
for
i
in
range
(
0
,
len
(
vectors
)
+
1
):
VECTORS_DiffFitting
.
append
(
vectors
[
i
]
-
vectors
[
-
1
])
for
coeff
,
vector
in
zip
(
coefficients
,
VECTORS_DiffFitting
):
result
+=
vector
*
coeff
result
=
result
+
vectors
[
-
1
]
print
(
result
.
shape
)
return
result
class
LeastSquare
(
AbstractFitting
):
...
...
This diff is collapsed.
Click to expand it.
test_diff_fitting.py
0 → 100644
View file @
84b04f68
import
os
import
sys
import
numpy
as
np
import
gext
import
gext.descriptors
import
gext.fitting
import
gext.grassmann
from
tests
import
utils
SMALL
=
1e-8
THRESHOLD
=
5e-2
regularization
=
0.0
# load test data from json file
data
=
utils
.
load_json
(
f
"
tests/urea.json
"
)
nelectrons
=
data
[
"
nelectrons
"
]
natoms
=
data
[
"
trajectory
"
].
shape
[
1
]
nbasis
=
data
[
"
overlaps
"
].
shape
[
1
]
nframes
=
data
[
"
trajectory
"
].
shape
[
0
]
# initialize an extrapolator
extrapolator
=
gext
.
Extrapolator
(
nelectrons
,
nbasis
,
natoms
,
nsteps
=
nframes
,
fitting_regularization
=
regularization
,
fitting
=
"
diff
"
)
# load data in the extrapolator
for
(
coords
,
coeff
,
overlap
)
in
zip
(
data
[
"
trajectory
"
],
data
[
"
coefficients
"
],
data
[
"
overlaps
"
]):
extrapolator
.
load_data
(
coords
,
coeff
,
overlap
)
descriptors
=
extrapolator
.
descriptors
.
get
(
10
)
target
=
descriptors
[
-
1
]
fitting_calculator
=
extrapolator
.
fitting_calculator
# check if things are reasonable
for
start
in
range
(
0
,
8
):
vectors
=
descriptors
[
start
:
-
1
]
fit_coefficients
=
fitting_calculator
.
fit
(
vectors
,
target
)
fitted_target
=
fitting_calculator
.
linear_combination
(
vectors
,
fit_coefficients
)
error
=
np
.
linalg
.
norm
(
target
-
fitted_target
,
ord
=
np
.
inf
)
assert
error
<
THRESHOLD
# if we put the target in the vectors used for the fitting,
# check that we get an error smaller than the regularization
vectors
=
descriptors
[:
-
1
]
vectors
[
0
]
=
target
fit_coefficients
=
fitting_calculator
.
fit
(
vectors
,
target
)
fitted_target
=
fitting_calculator
.
linear_combination
(
vectors
,
fit_coefficients
)
print
(
np
.
linalg
.
norm
(
target
-
fitted_target
,
ord
=
np
.
inf
),
max
(
SMALL
,
regularization
))
assert
np
.
linalg
.
norm
(
target
-
fitted_target
,
ord
=
np
.
inf
)
<
max
(
SMALL
,
regularization
)
This diff is collapsed.
Click to expand it.