aboutsummaryrefslogtreecommitdiffstats
path: root/jpa_test/make_plots.py
blob: ed7bb100a39d4f1acda3a130063046522dea2fc9 (plain)
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
import matplotlib.pyplot as plt
import numpy as np
import cascade_creation
import rip_condition


def plot_rip_numberofnodes(max_proba, n_min, n_max, p_init, n_cascades, K_max):
    """
    Plots the RIP constant for varying number of nodes (n_max included)
    """
    x = np.arange(n_min, n_max+1)
    y = []

    for n_nodes in x:
        print n_nodes
        G = cascade_creation.InfluenceGraph(max_proba=.3)
        G.erdos_init(n=n_nodes, p=.5) #TODO: handle different inits!
        cascades = cascade_creation.generate_cascades(G, p_init=p_init,
                                                      n_cascades=n_cascades)
        M, __ = cascade_creation.icc_matrixvector_for_node(cascades, None)
        M = cascade_creation.normalize_matrix(M)
        y.append(rip_condition.find_kth_rip_constants(M, 5))

    plt.clf()
    plt.plot(x, y)
    plt.show()

    return x, y


def test():
    """
    unit test
    """
    plot_rip_numberofnodes(max_proba=.3, n_min=10, n_max=15,
                            p_init=.3, n_cascades=10, K_max=5)

if __name__=="__main__":
    test()