-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblems.jl
83 lines (60 loc) · 1.7 KB
/
Problems.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
export lrcomp_model, mat_rand_model
reshape2(a, dims) = invoke(Base._reshape, Tuple{AbstractArray,typeof(dims)}, a, dims)
function lrcomp_data(m::Int, n::Int)
A = Array(rand(Float64,(m, n)))
A
end
function lrcomp_model(m::Int, n::Int)
A = lrcomp_data(m, n)
r = vec(similar(A))
function resid!(r, x, A)
r .= x .- vec(reshape2(A, (m*n,1)))
r
end
function obj(x)
resid!(r, x, A)
dot(r, r) / 2
end
function grad!(r, x)
resid!(r, x, A)
r
end
return FirstOrderModel(obj, grad!, rand(Float64, m*n), name = "LRCOMP"), A
end
# Preallouer r dans l'algo ci-haut meme avec vec il sera plus exact.
using Distributions
using Noise
# Ω désigne le sous ensemble des points connus et alea
#xl = Array(rand(Uniform(-0.3,0.1), 30, 5))
#xr = Array(rand(Uniform(-0.3,0.1), 30, 5))
#xs = xl*xr'
function mat_rand(m::Int, n::Int, r::Int, sr::Float64, va::Float64, vb::Float64, c::Float64)
xl = Array(rand(Uniform(-0.3,0.1),m, r))
xr = Array(rand(Uniform(-0.3,0.1),n, r))
xs = xl*xr'
Ω = findall(<(sr), rand(m,n));
B=xs[Ω];
B = (1-c)*add_gauss(B, va, 0) + c*add_gauss(B, vb, 0);
return xs, B, Ω
end
function mat_rand_model(m::Int, n::Int, r::Int, sr::Float64, va::Float64, vb::Float64, c::Float64)
T = mat_rand(m, n, r, sr, va, vb, c)
res = zeros(m,n)
function resid!(res, x)
res[T[3]] .= vec(T[2] - reshape2(x, (m,n))[T[3]])
vec(res)
end
function obj(x)
resid!(res, x)
dot(res, res) / 2
end
function grad!(g, x)
resid!(res,x)
res
end
function REL(x)
rel=sqrt(norm(x-reshape2(T[1],(m*n,1)))/(m*n));
rel
end
return FirstOrderModel(obj, grad!, rand(Float64, m*n), name = "LRCOMP"), REL, T[1] # T otain xs and compute RMSE
end