-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsparsities_kkt.py
32 lines (29 loc) · 1.24 KB
/
sparsities_kkt.py
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
"""
Script used to obtain sparsities of KKT systems for RandomQP instances generated using different sparsitz
parameters rho.
"""
from qps import RandomQP, ControlQP
import numpy as np
n = 100
sparse_M_sym_08 = np.zeros(10)
sparse_M_08 = np.zeros(10)
sparse_M_sym_15 = np.zeros(10)
sparse_M_15 = np.zeros(10)
sparse_M_sym_30 = np.zeros(10)
sparse_M_30 = np.zeros(10)
for i in range(10):
qp = RandomQP(n, i, sparsity=0.08)
sparse_M_08[i] = qp.get_M_sparsity()
sparse_M_sym_08[i] = qp.get_M_sym_sparsity()
qp = RandomQP(n, i, sparsity=0.15)
sparse_M_15[i] = qp.get_M_sparsity()
sparse_M_sym_15[i] = qp.get_M_sym_sparsity()
qp = RandomQP(n, i, sparsity=0.3)
sparse_M_30[i] = qp.get_M_sparsity()
sparse_M_sym_30[i] = qp.get_M_sym_sparsity()
print(f"rho=0.08 M: mean {np.mean(sparse_M_08)} std {np.std(sparse_M_08)}")
print(f"rho=0.08 M_sym: mean {np.mean(sparse_M_sym_08)} std {np.std(sparse_M_sym_08)}")
print(f"rho=0.15 M: mean {np.mean(sparse_M_15)} std {np.std(sparse_M_15)}")
print(f"rho=0.15 M_sym: mean {np.mean(sparse_M_sym_15)} std {np.std(sparse_M_sym_15)}")
print(f"rho=0.30 M: mean {np.mean(sparse_M_30)} std {np.std(sparse_M_30)}")
print(f"rho=0.30 M_sym: mean {np.mean(sparse_M_sym_30)} std {np.std(sparse_M_sym_30)}")