Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DataTools_Tutorial_Demo_fixing_issue_tpot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
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
casalet3
DataTools_Tutorial_Demo_fixing_issue_tpot
Commits
d9b3d1ed
Commit
d9b3d1ed
authored
2 years ago
by
Colbry, Dirk
Browse files
Options
Downloads
Patches
Plain Diff
First Commit
parent
fb75cdb9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+14
-0
14 additions, 0 deletions
.gitignore
_Template.ipynb
+277
-0
277 additions, 0 deletions
_Template.ipynb
answercheck.py
+163
-0
163 additions, 0 deletions
answercheck.py
with
454 additions
and
0 deletions
.gitignore
0 → 100644
+
14
−
0
View file @
d9b3d1ed
# Original file copied From: https://gist.github.com/kjaanson/de713cff4ab7d493563fd9731a232534
/*.egg-info
/.spyderproject
.spyderproject
.idea/*
/**/.DS_Store
/**/__pycache__
/**/.ipynb_checkpoints
/.doit.db.bak
/.doit.db.dat
/.doit.db.dir
*.mp4
*.mpg
*.html
This diff is collapsed.
Click to expand it.
_Template.ipynb
0 → 100644
+
277
−
0
View file @
d9b3d1ed
This diff is collapsed.
Click to expand it.
answercheck.py
0 → 100644
+
163
−
0
View file @
d9b3d1ed
import
hashlib
import
numpy
as
np
import
sympy
as
sym
import
sys
import
textwrap
# detailedwarnings = True
# Things I fixed. Fixed Matrix rounding error
# Added more print warnings
# TODO: Fix Printwarnings
def
printwarning
(
message
):
if
checkanswer
.
detailedwarnings
:
print
(
message
)
class
checkanswer
():
detailedwarnings
=
True
def
__init__
(
self
,
var
,
hashtag
=
None
):
checkanswer
.
basic
(
var
,
hashtag
)
def
basic
(
var
,
hashtag
=
None
):
"""
Fuanction that encodes answers in a string called a Hash.
This is a one way function so a correct answer will generate the
correct has. An incorrect answer will generate an incorrect hash.
"""
if
checkanswer
.
detailedwarnings
:
print
(
f
"
Testing
{
var
}
"
)
else
:
print
(
f
"
Testing Answer
"
)
curr_printopts
=
np
.
get_printoptions
()
np
.
set_printoptions
(
threshold
=
sys
.
maxsize
)
varstr
=
f
"
{
var
}
"
np
.
set_printoptions
(
threshold
=
curr_printopts
[
'
threshold
'
])
t2
=
varstr
.
encode
(
"
utf-8
"
)
m
=
hashlib
.
md5
(
t2
)
checktag
=
m
.
hexdigest
()
if
hashtag
:
if
checktag
==
hashtag
:
print
(
"
Answer seems to be correct
\n
"
)
else
:
print
(
"
Answer seems to be incorrect
\n
"
)
assert
checktag
==
hashtag
,
f
"
Answer is incorrect
{
checktag
}
"
else
:
raise
TypeError
(
f
"
No answer hastag provided:
{
checktag
}
"
)
def
float
(
A
,
hashtag
=
None
,
decimal_accuracy
=
5
):
"""
Function to check matrix type before hashing.
"""
if
(
type
(
A
)
is
not
float
):
if
(
type
(
A
)
is
list
):
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: passed variable is a list and not a float...
Cannot convert list to float directly. We will assume this
list has only one element and covert to a numpy matrix
using ```A = np.matrix(A)```.
\n
"""
))
A
=
np
.
matrix
(
A
)
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: passed variable is
{
type
(
A
)
}
and not a float.
Trying to convert to a float using ```A = float(A)```.
\n
"""
))
A
=
float
(
A
)
A
=
np
.
round
(
A
,
decimals
=
decimal_accuracy
)
if
A
==
-
0.00
:
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: Value is negative zero...
Converting to positive zero before checking using ```A = 0.00```.
\n
"""
))
A
=
0.00
return
checkanswer
.
basic
(
A
,
hashtag
)
def
make_vector
(
A
,
decimal_accuracy
=
5
):
"""
Function to check matrix type before hashing.
"""
if
(
type
(
A
)
is
not
np
.
matrix
):
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: passed variable is
{
type
(
A
)
}
and not a numpy.matrix.
Trying to convert to a array matrix using ```A = np.matrix(A)```.
\n
"""
))
A
=
np
.
matrix
(
A
)
if
not
np
.
issubdtype
(
A
.
dtype
,
np
.
dtype
(
float
).
type
):
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: passed matrix is
{
A
.
dtype
}
and not
{
np
.
dtype
(
float
).
type
}
...
Trying to convert to float using ```A = A.astype(float)```.
\n
"""
))
A
=
A
.
astype
(
float
)
if
(
A
.
shape
[
0
]
!=
1
and
A
.
shape
[
1
]
!=
1
):
assert
A
.
shape
[
0
]
!=
1
and
A
.
shape
[
1
]
!=
1
,
\
f
"
Matrix is not of vector format
{
A
}
"
if
(
A
.
shape
[
0
]
!=
1
):
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: numpy.matrix is row vector...
Trying to convert to a column vector using ```A = A.T```.
\n
"""
))
A
=
A
.
T
A
=
np
.
round
(
A
,
decimals
=
decimal_accuracy
)
if
not
A
[
A
==
-
0
].
size
==
0
:
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: Vector contains negative values for zero...
Converting to positive values of zero using ```A[A==-0] = 0```.
\n
"""
))
A
[
A
==
-
0
]
=
0.00
return
A
def
vector
(
A
,
hashtag
=
None
,
decimal_accuracy
=
5
):
A
=
checkanswer
.
make_vector
(
A
,
decimal_accuracy
)
return
checkanswer
.
basic
(
A
,
hashtag
)
def
eq_vector
(
A
,
hashtag
=
None
,
decimal_accuracy
=
5
):
A
=
checkanswer
.
make_vector
(
A
,
decimal_accuracy
)
vecsum
=
np
.
sqrt
(
np
.
sum
(
np
.
dot
(
A
,
A
.
T
)))
if
not
vecsum
==
1
:
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: Vector sum of
{
A
}
has total value of
{
vecsum
}
...
Trying to normalize to unit vector to check answer using
using ```A = A/
{
vecsum
}
```.
\n\n
"""
))
A
=
A
/
vecsum
if
(
A
[
0
,
0
]
<
0
):
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: First element of
{
A
}
is negative (
{
A
[
0
,
0
]
}
.
Trying to normalize by making this value positive using ```A = -A```.
\n
"""
))
A
=
-
A
A
=
np
.
round
(
A
,
decimals
=
decimal_accuracy
)
if
not
A
[
A
==
-
0
].
size
==
0
:
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: Vector contains negative values for zero...
Converting to positive values of zero using ```A[A==-0] = 0```.
\n
"""
))
A
[
A
==
-
0
]
=
0.00
return
checkanswer
.
basic
(
A
,
hashtag
)
def
make_matrix
(
A
,
decimal_accuracy
=
5
):
if
(
type
(
A
)
is
not
np
.
matrix
):
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: passed variable is
{
type
(
A
)
}
and not a numpy.matrix...
Trying to convert to a array matrix using ```A = np.matrix(A)```.
\n
"""
))
A
=
np
.
matrix
(
A
)
if
not
np
.
issubdtype
(
A
.
dtype
,
np
.
dtype
(
float
).
type
):
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: passed matrix is
{
A
.
dtype
}
and not
{
np
.
dtype
(
float
).
type
}
...
Trying to convert to float using ```A = A.astype(float)```.
\n
"""
))
A
=
A
.
astype
(
float
)
A
=
np
.
round
(
A
,
decimals
=
decimal_accuracy
)
if
not
A
[
A
==
-
0
].
size
==
0
:
printwarning
(
textwrap
.
dedent
(
f
"""
CheckWarning: Matrix contains negative values for zero...
Converting to positive values of zero using ```A[A==-0] = 0```.
\n
"""
))
A
[
A
==
-
0
]
=
0.00
return
A
def
matrix
(
A
,
hashtag
=
None
,
decimal_accuracy
=
5
):
"""
Function to check matrix type before hashing.
"""
A
=
checkanswer
.
make_matrix
(
A
,
decimal_accuracy
)
return
checkanswer
.
basic
(
A
,
hashtag
)
# TODO: Not complete or tested.
def
eq_matrix
(
A
,
hashtag
=
None
,
decimal_accuracy
=
5
):
"""
Function to convert matrix to reduced row echelon form
and then run hashing.
"""
A
=
checkanswer
.
make_matrix
(
A
,
decimal_accuracy
)
symA
=
sym
.
Matrix
(
A
)
symA
=
symA
.
rref
()[
0
]
A
=
np
.
matrix
(
symA
)
A
=
checkanswer
.
make_matrix
(
A
)
return
checkanswer
.
basic
(
A
,
hashtag
)
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