Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pyVis
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
Model registry
Operate
Environments
Monitor
Incidents
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
Julian Lenz
pyVis
Commits
775b47b5
Commit
775b47b5
authored
5 years ago
by
Julian Lenz
Browse files
Options
Downloads
Patches
Plain Diff
Added Chi-Square routine
parent
c088b9a4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aux.py
+27
-0
27 additions, 0 deletions
aux.py
with
27 additions
and
0 deletions
aux.py
+
27
−
0
View file @
775b47b5
...
...
@@ -41,6 +41,33 @@ class Cycler:
return
self
.
getCurrent
()
def
chisq
(
r
,
sigma
,
redFreedom
=
0
,
normalized
=
False
):
'''
Calculates the chi^2 value of residuals r with standard deviations sigma as
is minimized by scipy.optimize.curve_fit. This means it calculates
sum( (r/sigma)**2 )
if r and sigma are one-dimensional and
r.T . sigma^-1 . r
if sigma the two-dimensional covariance matrix.
If normalized=True, the result is divided by the length of r (Default: False).
If redFreedom>0, then normalized=True and the result is divided by len(r)-redFreedom.
'''
factor
=
1
if
redFreedom
>
0
or
normalized
:
factor
=
1
/
(
len
(
r
)
-
redFreedom
)
if
len
(
np
.
shape
(
sigma
))
==
1
:
return
np
.
sum
((
r
/
sigma
)
**
2
)
*
factor
elif
len
(
np
.
shape
(
sigma
)
==
2
)
and
np
.
shape
(
sigma
)[
0
]
==
np
.
shape
(
sigma
)[
1
]:
return
np
.
dot
(
r
.
T
,
np
.
dot
(
np
.
linalg
.
inv
(
sigma
),
r
))
*
factor
else
:
raise
Exception
(
'
Shape of sigma is wrong.
'
)
def
makeTuples
(
iterable
):
ret
=
[]
...
...
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