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
Commits
cf50f260
Commit
cf50f260
authored
4 months ago
by
Michele Nottoli
Browse files
Options
Downloads
Patches
Plain Diff
Lagrange.
parent
8b4a8c08
No related branches found
No related tags found
No related merge requests found
Pipeline
#2260
failed
4 months ago
Stage: test
Stage: lint
Stage: coverage
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
gext/fitting.py
+28
-1
28 additions, 1 deletion
gext/fitting.py
gext/main.py
+31
-1
31 additions, 1 deletion
gext/main.py
with
59 additions
and
2 deletions
gext/fitting.py
+
28
−
1
View file @
cf50f260
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
abc
import
abc
from
typing
import
List
from
typing
import
List
import
numpy
as
np
import
numpy
as
np
import
scipy
class
AbstractFitting
(
abc
.
ABC
):
class
AbstractFitting
(
abc
.
ABC
):
...
@@ -13,7 +14,6 @@ class AbstractFitting(abc.ABC):
...
@@ -13,7 +14,6 @@ class AbstractFitting(abc.ABC):
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
**
kwargs
):
self
.
set_options
(
**
kwargs
)
self
.
set_options
(
**
kwargs
)
@abc.abstractmethod
def
set_options
(
self
,
**
kwargs
):
def
set_options
(
self
,
**
kwargs
):
"""
Base method for setting options.
"""
"""
Base method for setting options.
"""
self
.
options
=
{}
self
.
options
=
{}
...
@@ -341,3 +341,30 @@ class PolynomialRegression(AbstractFitting):
...
@@ -341,3 +341,30 @@ class PolynomialRegression(AbstractFitting):
if
self
.
options
[
"
ref
"
]:
if
self
.
options
[
"
ref
"
]:
gamma
+=
self
.
gamma_ref
gamma
+=
self
.
gamma_ref
return
np
.
reshape
(
gamma
,
self
.
gamma_shape
)
return
np
.
reshape
(
gamma
,
self
.
gamma_shape
)
class
LagrangeFitting
(
AbstractFitting
):
supported_options
=
{}
def
__init__
(
self
):
super
().
__init__
()
self
.
gammas
=
[]
def
train
(
self
,
descriptor_list
:
List
[
np
.
ndarray
],
gamma_list
:
List
[
np
.
ndarray
]):
self
.
gammas
=
gamma_list
def
extrapolate
(
self
,
_
):
tokens
=
[]
q
=
len
(
self
.
gammas
)
tokens
=
np
.
array
(
tokens
)
result
=
np
.
zeros
(
self
.
gammas
[
0
].
shape
)
for
i
,
gamma
in
enumerate
(
self
.
gammas
):
l
=
1.0
for
m
in
range
(
1
,
q
+
1
):
if
m
==
i
+
1
:
continue
l
*=
(
q
+
1
-
m
)
/
(
i
+
1
-
m
)
result
+=
l
*
gamma
return
result
This diff is collapsed.
Click to expand it.
gext/main.py
+
31
−
1
View file @
cf50f260
...
@@ -4,7 +4,7 @@ from typing import Optional
...
@@ -4,7 +4,7 @@ from typing import Optional
import
numpy
as
np
import
numpy
as
np
from
.
import
grassmann
from
.
import
grassmann
from
.fitting
import
LeastSquare
,
QuasiTimeReversible
,
PolynomialRegression
,
DiffFitting
from
.fitting
import
LeastSquare
,
QuasiTimeReversible
,
PolynomialRegression
,
DiffFitting
,
LagrangeFitting
from
.descriptors
import
Distance
,
Coulomb
,
Flatten
from
.descriptors
import
Distance
,
Coulomb
,
Flatten
from
.buffer
import
CircularBuffer
from
.buffer
import
CircularBuffer
...
@@ -92,6 +92,8 @@ class Extrapolator:
...
@@ -92,6 +92,8 @@ class Extrapolator:
self
.
fitting_calculator
=
QuasiTimeReversible
()
self
.
fitting_calculator
=
QuasiTimeReversible
()
elif
self
.
options
[
"
fitting
"
]
==
"
polynomialregression
"
:
elif
self
.
options
[
"
fitting
"
]
==
"
polynomialregression
"
:
self
.
fitting_calculator
=
PolynomialRegression
()
self
.
fitting_calculator
=
PolynomialRegression
()
elif
self
.
options
[
"
fitting
"
]
==
"
lagrange
"
:
self
.
fitting_calculator
=
LagrangeFitting
()
else
:
else
:
raise
ValueError
(
"
Unsupported fitting
"
)
raise
ValueError
(
"
Unsupported fitting
"
)
self
.
fitting_calculator
.
set_options
(
**
fitting_options
)
self
.
fitting_calculator
.
set_options
(
**
fitting_options
)
...
@@ -118,6 +120,34 @@ class Extrapolator:
...
@@ -118,6 +120,34 @@ class Extrapolator:
c_guess
=
self
.
guess_coefficients
(
coords
,
overlap
)
c_guess
=
self
.
guess_coefficients
(
coords
,
overlap
)
return
c_guess
@
c_guess
.
T
return
c_guess
@
c_guess
.
T
def
guess_no_mapping
(
self
,
coords
:
np
.
ndarray
,
overlap
):
# check if we have enough data points to perform an extrapolation
count
=
self
.
descriptors
.
count
if
self
.
options
[
"
allow_partially_filled
"
]:
if
count
==
0
:
raise
ValueError
(
"
Not enough data loaded in the extrapolator
"
)
n
=
min
(
self
.
options
[
"
nsteps
"
],
count
)
else
:
n
=
self
.
options
[
"
nsteps
"
]
if
count
<
n
:
raise
ValueError
(
"
Not enough data loaded in the extrapolator
"
)
if
overlap
is
None
and
not
self
.
options
[
"
store_overlap
"
]:
raise
ValueError
(
"
Guessing without overlap requires `store_overlap` true.
"
)
# get the required quantities
prev_descriptors
=
self
.
descriptors
.
get
(
n
)
coefficients
=
self
.
coefficients
.
get
(
n
)
ds
=
[
c
@
c
.
T
for
c
in
coefficients
]
descriptor
=
self
.
_compute_descriptor
(
coords
)
self
.
fitting_calculator
.
train
(
prev_descriptors
,
ds
)
inverse_sqrt_overlap
=
self
.
_inverse_sqrt_overlap
(
overlap
)
d
=
self
.
fitting_calculator
.
extrapolate
(
descriptor
)
return
inverse_sqrt_overlap
@
d
@
inverse_sqrt_overlap
def
guess_coefficients
(
self
,
coords
:
np
.
ndarray
,
overlap
=
None
)
->
np
.
ndarray
:
def
guess_coefficients
(
self
,
coords
:
np
.
ndarray
,
overlap
=
None
)
->
np
.
ndarray
:
"""
Get a new coefficient matrix to be used as a guess.
"""
"""
Get a new coefficient matrix to be used as a guess.
"""
...
...
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