Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CSNMF
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
TrafficPatterns
CSNMF
Commits
e23934c6
There was an error fetching the commit references. Please try again later.
Commit
e23934c6
authored
7 years ago
by
vkarve2
Browse files
Options
Downloads
Patches
Plain Diff
Added functionality to identify extreme events and to make graph of spikeyness vs. error.
parent
b7e33116
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
Multiplicative Algorithm/Visualizations.py
+36
-5
36 additions, 5 deletions
Multiplicative Algorithm/Visualizations.py
with
36 additions
and
5 deletions
Multiplicative Algorithm/Visualizations.py
+
36
−
5
View file @
e23934c6
...
@@ -18,11 +18,27 @@ def find_mean_trend_particular_weekday(w, weekday):
...
@@ -18,11 +18,27 @@ def find_mean_trend_particular_weekday(w, weekday):
return
np
.
mean
(
w2
,
axis
=
0
)
return
np
.
mean
(
w2
,
axis
=
0
)
def
plot_particular_weekday
(
w
,
weekday
,
mean
=
False
):
def
find_extreme_events
(
w
,
weekday
):
mean_trend
=
find_mean_trend_particular_weekday
(
w
,
weekday
)
w
=
w
.
reshape
(
365
,
24
)
w
=
w
[
weekday
::
7
]
deviation
=
np
.
mean
(
abs
(
w
-
mean_trend
),
axis
=
1
)
/
np
.
mean
(
w
)
extreme_weeks
=
[]
for
week
in
range
(
len
(
deviation
)):
if
deviation
[
week
]
>
0.6
:
extreme_weeks
.
append
(
week
)
return
extreme_weeks
def
plot_particular_weekday
(
w
,
weekday
,
mean
=
False
,
extreme
=
False
):
for
day
in
range
(
weekday
,
365
,
7
):
for
day
in
range
(
weekday
,
365
,
7
):
plot_particular_day
(
w
,
day
)
plot_particular_day
(
w
,
day
)
if
mean
:
if
mean
:
plt
.
plot
(
find_mean_trend_particular_weekday
(
w
,
weekday
),
'
ro
'
)
plt
.
plot
(
find_mean_trend_particular_weekday
(
w
,
weekday
),
'
ro
'
)
if
extreme
:
extreme_weeks
=
find_extreme_events
(
w
,
weekday
)
for
week
in
extreme_weeks
:
plt
.
plot
(
w
[
24
*
7
*
week
+
24
*
weekday
:
24
*
7
*
week
+
24
*
weekday
+
24
],
'
k-
'
)
def
plot_all_weekdays
(
w
,
mean
=
False
,
signature
=
'
??
'
):
def
plot_all_weekdays
(
w
,
mean
=
False
,
signature
=
'
??
'
):
...
@@ -35,16 +51,16 @@ def plot_all_weekdays(w, mean = False, signature = '??'):
...
@@ -35,16 +51,16 @@ def plot_all_weekdays(w, mean = False, signature = '??'):
plt
.
clf
()
plt
.
clf
()
def
plot_all_signatures_particular_weekday
(
W
,
weekday
,
mean
=
False
):
def
plot_all_signatures_particular_weekday
(
W
,
weekday
,
mean
=
False
,
extreme
=
False
):
plt
.
ioff
()
plt
.
ioff
()
fig
=
plt
.
figure
(
figsize
=
(
16
,
9
))
# size in inches
fig
=
plt
.
figure
(
figsize
=
(
16
,
9
))
# size in inches
for
signature
in
range
(
config
.
RANK
):
for
signature
in
range
(
config
.
RANK
):
plot_particular_weekday
(
W
[:,
signature
],
weekday
,
mean
=
mean
)
plot_particular_weekday
(
W
[:,
signature
],
weekday
,
mean
=
mean
,
extreme
=
extreme
)
imagename
=
'
./Images/Signature_Trends/
'
+
str
(
signature
).
zfill
(
2
)
+
days_of_week
[
weekday
][
0
:
3
]
+
'
.png
'
imagename
=
'
./Images/Signature_Trends/
'
+
str
(
signature
).
zfill
(
2
)
+
days_of_week
[
weekday
][
0
:
3
]
+
'
.png
'
plt
.
savefig
(
imagename
,
dpi
=
300
,
bbox_inches
=
'
tight
'
)
# dpi ideal for viewing on laptop fullscreen
plt
.
savefig
(
imagename
,
dpi
=
300
,
bbox_inches
=
'
tight
'
)
# dpi ideal for viewing on laptop fullscreen
plt
.
clf
()
plt
.
clf
()
def
Heatmap
(
W1
,
W2
):
def
Heatmap
(
W1
,
W2
):
assert
W1
.
shape
==
W2
.
shape
assert
W1
.
shape
==
W2
.
shape
Ro
=
np
.
corrcoef
(
W1
.
T
,
W2
.
T
)[
len
(
W1
.
T
):,:
len
(
W2
.
T
)]
Ro
=
np
.
corrcoef
(
W1
.
T
,
W2
.
T
)[
len
(
W1
.
T
):,:
len
(
W2
.
T
)]
...
@@ -215,9 +231,24 @@ def permute_and_sort(W1, H1, W2, permute = False):
...
@@ -215,9 +231,24 @@ def permute_and_sort(W1, H1, W2, permute = False):
return
w1
,
h1
,
W2
,
permutation
return
w1
,
h1
,
W2
,
permutation
def
spikeyness_vs_error
():
D
=
np
.
loadtxt
(
'
D_trips.txt
'
)
W
=
np
.
loadtxt
(
'
W_trips.txt
'
)
H
=
np
.
loadtxt
(
'
H_trips.txt
'
)
def
spikeyness
(
link
):
trend
=
D
[:
52
*
24
*
7
,
link
].
reshape
(
52
,
24
*
7
)
return
np
.
mean
(
np
.
nanstd
(
trend
,
axis
=
0
))
/
np
.
nanmean
(
D
[:,
link
])
def
errors
():
return
np
.
linalg
.
norm
(
np
.
nan_to_num
(
D
-
W
@H
),
axis
=
0
)
/
np
.
linalg
.
norm
(
np
.
nan_to_num
(
D
),
axis
=
0
)
plt
.
figure
(
figsize
=
(
10
,
10
))
plt
.
plot
([
spikeyness
(
link
)
for
link
in
range
(
2302
)],
errors
(),
'
+
'
)
plt
.
xlabel
(
'
Deviation from weekly periodicity
'
)
plt
.
ylabel
(
'
Error per link
'
)
plt
.
savefig
(
'
Spikeyness_vs_Error
'
)
return
None
\ No newline at end of file
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