Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
nam
ProxPython
Commits
bf81d2d1
Commit
bf81d2d1
authored
Jun 18, 2022
by
maximilian.seeber
Browse files
changed the visualization
parent
7a1fe738
Changes
5
Hide whitespace changes
Inline
Side-by-side
demos/MC_ALS.py
View file @
bf81d2d1
import
SetProxPythonPath
from
proxtoolbox.experiments.MC.MC_Experiment
import
MC_Experiment
MC
=
MC_Experiment
(
algorithm
=
'ALS'
,
fraction_known_entrees
=
0.
5
,
rank
=
2
,
anim
=
True
)
MC
=
MC_Experiment
(
algorithm
=
'ALS'
,
fraction_known_entrees
=
0.
3
,
rank
=
6
,
anim
=
True
,
n_2
=
200
)
MC
.
run
()
MC
.
animate
(
MC
.
algorithm
)
MC
.
show
()
\ No newline at end of file
demos/MC_AP.py
View file @
bf81d2d1
import
SetProxPythonPath
from
proxtoolbox.experiments.MC.MC_Experiment
import
MC_Experiment
MC
=
MC_Experiment
(
algorithm
=
'AP'
,
fraction_known_entrees
=
0.4
,
rank
=
2
,
anim
=
True
)
MC
=
MC_Experiment
(
algorithm
=
'AP'
,
fraction_known_entrees
=
0.4
,
rank
=
6
,
anim
=
True
,
n_2
=
200
)
MC
.
run
()
MC
.
animate
(
MC
.
algorithm
)
MC
.
show
()
\ No newline at end of file
demos/MC_DR.py
View file @
bf81d2d1
import
SetProxPythonPath
from
proxtoolbox.experiments.MC.MC_Experiment
import
MC_Experiment
MC
=
MC_Experiment
(
algorithm
=
'DR'
,
fraction_known_entrees
=
0.
5
,
anim
=
True
)
MC
=
MC_Experiment
(
algorithm
=
'DR'
,
fraction_known_entrees
=
0.
3
,
anim
=
True
,
n_2
=
200
)
MC
.
run
()
MC
.
animate
(
MC
.
algorithm
)
MC
.
show
()
\ No newline at end of file
proxtoolbox/experiments/MC/MC_Experiment.py
View file @
bf81d2d1
...
...
@@ -48,14 +48,30 @@ class MC_Experiment(Experiment):
self
.
diagnostic
=
False
self
.
gamma
=
gamma
self
.
lambd
=
lambd
self
.
frob_list
=
[]
self
.
rank_list
=
[]
def
loadData
(
self
):
self
.
mask
=
np
.
random
.
rand
(
self
.
n_1
,
self
.
n_2
)
<
self
.
p
# self.u0 = (np.random.randn(self.n_1, self.r))@(np.random.randn(self.r, self.n_2))
self
.
u0
=
np
.
ones
((
self
.
n_1
,
self
.
n_2
))
self
.
u0
[
10
:
70
,
10
:
20
]
=
0
self
.
u0
[
10
:
70
,
50
:
60
]
=
0
self
.
u0
[
20
:
80
,
10
:
20
]
=
0
self
.
u0
[
30
:
40
,
20
:
30
]
=
0
self
.
u0
[
40
:
60
,
30
:
40
]
=
0
self
.
u0
[
60
:
70
,
40
:
50
]
=
0
self
.
u0
[
20
:
80
,
50
:
60
]
=
0
self
.
u0
[
40
:
80
,
80
:
90
]
=
0.5
self
.
u0
[
20
:
40
,
90
:
100
]
=
0.5
self
.
u0
[
60
:
70
,
90
:
100
]
=
0.5
self
.
u0
[
40
:
80
,
100
:
110
]
=
0.5
self
.
u0
[
20
:
80
,
130
:
140
]
=
0
self
.
u0
[
20
:
30
,
140
:
150
]
=
0
self
.
u0
[
20
:
60
,
150
:
160
]
=
0
self
.
u0
[
20
:
30
,
160
:
170
]
=
0
self
.
u0
[
20
:
80
,
170
:
180
]
=
0
self
.
M
=
np
.
copy
(
self
.
u0
)
if
self
.
algorithm_name
==
'ALS'
:
...
...
@@ -81,24 +97,34 @@ class MC_Experiment(Experiment):
# for key in self.output['stats']:
# print(key)
fig
,
ax
=
plt
.
subplots
(
1
,
3
,
figsize
=
(
16
,
5
))
fig
,
((
ax11
,
ax12
),
(
ax21
,
ax22
))
=
plt
.
subplots
(
2
,
2
,
figsize
=
(
16
,
5
))
ax
[
0
].
imshow
(
self
.
M
)
ax
[
0
].
set
(
title
=
'original matrix'
)
ax
[
1
].
imshow
(
u
)
ax
[
1
].
set
(
title
=
'reconstructed matrix'
)
ax
[
2
].
semilogy
(
ch
)
ax
[
2
].
set
(
xlabel
=
'$k$'
,
ylabel
=
'$|| X_{k-1} - X_k ||$'
,
title
=
'change for each iteration'
)
ax11
.
imshow
(
self
.
M
)
ax11
.
set
(
title
=
'original matrix'
)
ax12
.
imshow
(
self
.
M
*
self
.
mask
)
ax12
.
set
(
title
=
'algorithm input'
)
ax21
.
semilogy
(
self
.
frob_list
)
ax21
.
set
(
xlabel
=
'$k$'
,
ylabel
=
'$|| M - X_k ||$'
,
title
=
'distance to M'
)
ax22
.
semilogy
(
ch
)
ax22
.
set
(
xlabel
=
'$k$'
,
ylabel
=
'$|| X_{k-1} - X_k ||$'
,
title
=
'change for each iteration'
)
plt
.
show
()
def
animate
(
self
,
alg
):
# print(alg.u_new)
# print(alg.u_new)
if
alg
.
u_new
is
not
None
:
if
self
.
algorithm_name
==
'DR'
:
self
.
animateFigure
(
alg
.
proxOperators
[
0
].
eval
(
alg
.
u_new
),
f
'$X_{{
{
alg
.
iter
}
}}$'
)
self
.
frob_list
+=
[
np
.
linalg
.
norm
(
alg
.
proxOperators
[
0
].
eval
(
alg
.
u_new
)
-
self
.
M
)]
self
.
rank_list
+=
[
np
.
linalg
.
matrix_rank
(
alg
.
u_new
)]
else
:
self
.
animateFigure
(
alg
.
u_new
,
f
'$X_{{
{
alg
.
iter
}
}}$'
)
self
.
frob_list
+=
[
np
.
linalg
.
norm
(
alg
.
u_new
-
self
.
M
)]
self
.
rank_list
+=
[
np
.
linalg
.
matrix_rank
(
alg
.
u_new
)]
if
alg
.
iter
<
50
:
time
.
sleep
(
0.3
)
time
.
sleep
(
0.1
)
\ No newline at end of file
time
.
sleep
(
0.1
)
else
:
if
self
.
algorithm_name
==
'ALS'
:
self
.
animateFigure
(
self
.
u0
[
0
].
T
@
self
.
u0
[
1
],
'$X_0$'
)
else
:
self
.
animateFigure
(
self
.
u0
,
'$X_0$'
)
time
.
sleep
(
0.7
)
\ No newline at end of file
proxtoolbox/proxoperators/MC_prox_nuc.py
View file @
bf81d2d1
...
...
@@ -11,8 +11,11 @@ class MC_prox_nuc(ProxOperator):
self
.
gamma
=
experiment
.
gamma
def
eval
(
self
,
u
):
n_1
,
n_2
=
u
.
shape
U
,
sigma
,
V
=
np
.
linalg
.
svd
(
u
)
sigma
=
sigma
-
self
.
gamma
sigma
[
sigma
<
0
]
=
0
E
=
np
.
diag
(
sigma
)
n
=
min
(
n_1
,
n_2
)
E
=
np
.
zeros
((
n_1
,
n_2
))
E
[:
n
,
:
n
]
=
np
.
diag
(
sigma
)
return
U
@
E
@
V
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment