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
8b774296
Commit
8b774296
authored
1 year ago
by
Askarpour, Zahra
Browse files
Options
Downloads
Patches
Plain Diff
test_fitting works
parent
0c054fa4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gext/fitting.py
+20
-22
20 additions, 22 deletions
gext/fitting.py
with
20 additions
and
22 deletions
gext/fitting.py
+
20
−
22
View file @
8b774296
...
@@ -61,37 +61,35 @@ class DiffFitting(AbstractFitting):
...
@@ -61,37 +61,35 @@ class DiffFitting(AbstractFitting):
def
fit
(
self
,
vectors
:
List
[
np
.
ndarray
],
target
:
np
.
ndarray
):
def
fit
(
self
,
vectors
:
List
[
np
.
ndarray
],
target
:
np
.
ndarray
):
"""
Given a set of vectors and a target return the fitting
"""
Given a set of vectors and a target return the fitting
coefficients.
"""
coefficients.
"""
if
len
(
vectors
)
==
1
:
raise
ValueError
(
"
DiffFit does not work for one vector
"
)
target
=
target
-
vectors
[
-
1
]
target
=
target
-
vectors
[
-
1
]
VECTORS
=
[]
VECTORS
=
[]
print
(
"
lenvector
"
,
len
(
vectors
))
for
i
in
range
(
0
,
len
(
vectors
)
+
1
):
if
len
(
vectors
)
>
1
:
VECTORS
.
append
(
vectors
[
i
]
-
vectors
[
-
1
])
for
i
in
range
(
2
,
len
(
vectors
)
+
1
):
matrix
=
np
.
array
(
VECTORS
).
T
print
(
"
lenvector
"
,
len
(
vectors
))
a
=
matrix
.
T
@
matrix
VECTORS
.
append
(
vectors
[
i
-
2
]
-
vectors
[
-
1
])
b
=
matrix
.
T
@
target
print
(
len
(
VECTORS
))
if
self
.
options
[
"
regularization
"
]
>
0.0
:
matrix
=
np
.
array
(
VECTORS
).
T
a
+=
np
.
identity
(
len
(
b
))
*
self
.
options
[
"
regularization
"
]
a
=
matrix
.
T
@
matrix
coefficients
=
np
.
linalg
.
solve
(
a
,
b
)
b
=
matrix
.
T
@
target
print
(
"
coefficients
"
,
coefficients
)
if
self
.
options
[
"
regularization
"
]
>
0.0
:
return
np
.
array
(
coefficients
,
dtype
=
np
.
float64
)
a
+=
np
.
identity
(
len
(
b
))
*
self
.
options
[
"
regularization
"
]
coefficients
=
np
.
linalg
.
solve
(
a
,
b
)
print
(
"
coefficients
"
,
coefficients
)
return
np
.
array
(
coefficients
,
dtype
=
np
.
float64
)
def
linear_combination
(
self
,
vectors
:
List
[
np
.
ndarray
],
def
linear_combination
(
self
,
vectors
:
List
[
np
.
ndarray
],
coefficients
:
np
.
ndarray
)
->
np
.
ndarray
:
coefficients
:
np
.
ndarray
)
->
np
.
ndarray
:
"""
Given a set of vectors (or matrices) and the corresponding
"""
Given a set of vectors (or matrices) and the corresponding
coefficients, build their linear combination.
"""
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
)
result
=
np
.
zeros
(
vectors
[
0
].
shape
,
dtype
=
np
.
float64
)
VECTORS_DiffFitting
=
[]
VECTORS_DiffFitting
=
[]
if
len
(
vectors
)
>
1
:
for
i
in
range
(
0
,
len
(
vectors
)
+
1
):
for
i
in
range
(
2
,
len
(
vectors
)
+
1
):
VECTORS_DiffFitting
.
append
(
vectors
[
i
]
-
vectors
[
-
1
])
VECTORS_DiffFitting
.
append
(
vectors
[
i
-
2
]
-
vectors
[
-
1
])
for
coeff
,
vector
in
zip
(
coefficients
,
VECTORS_DiffFitting
):
for
coeff
,
vector
in
zip
(
coefficients
,
vectors
):
result
+=
vector
*
coeff
result
+=
vector
*
coeff
result
=
result
+
vectors
[
-
1
]
result
=
result
+
vectors
[
-
1
]
return
result
print
(
result
.
shape
)
return
result
class
LeastSquare
(
AbstractFitting
):
class
LeastSquare
(
AbstractFitting
):
...
...
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