Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A test for local convexity
using LinearAlgebra
using Random
function local_convex_test(N)
#srand(1234)
sum = 0.0
for i=1:100
beta = rand()
## the input signal
X = rand(3,1)*2 .-1.0
Z_1 = rand(3,3)*sqrt(2/3)
Z_2 = rand(3,3)*sqrt(2/3)
out_1 = (beta*Z_1 + (1-beta)*Z_2)*X .+ 0.1
out_2 = Z_1*X .+ 0.1
out_3 = Z_2*X .+ 0.1
## the main calculation
for j=1:N-1
## two sets of matrices:
W_1 = rand(3,3)*sqrt(2/3)
W_2 = rand(3,3)*sqrt(2/3)
out_1 = (beta*W_1 + (1-beta)*W_2)*out_1 .+ 0.1
out_2 = W_1*out_2 .+ 0.1
out_3 = W_2*out_3 .+ 0.1
end
## the infinity norm is actually a much weaker convexity test:
sum += minimum(beta*out_2 + (1-beta)*out_3 .- out_1 .+ 1e-10 .> 0.0)*1.0
end
return sum/100
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.