コード例 #1
0
ファイル: exercise2.py プロジェクト: bertramr/Hopfield_VR
def exercise2(N_lst=(100, 250, 500), tests=10, confidence=0.95):
    print 'Exercise 2:'
    with open('../tex/dat/ex2-table-N%d-Q%d-C%d.tex' % 
        (N_lst[-1], tests , confidence*100),'w') as fp:
        fp.write(
            '\\begin{tabular}{|l|l|l|l|l|l|l|} \n'
            '\\hline \n'
            'N & tests & C-level & $\alpha_{N,max}$ &  $\alpha_{N,max}+CI$ & '
            '$\alpha_{N,max}-CI$ & $P_{N,max}$\\\\ \n'
            ' \\hline \\hline \n'
            ) 
        for N in N_lst:
            print N
            [load_mean, load_mean_lb, load_mean_ub, pmax_mean, 
                load_std] = load_max(
                    N=N, flip_ratio=0.1, pcut=0, 
                    tests=tests, confidence=confidence)
            fp.write('%d & %d & %0.1f $ \\%% $& %0.4f & %0.4f & %0.4f & %0.2f \\\\ \n' % \
                (N, tests, confidence*100, \
                load_mean, load_mean_lb, load_mean_ub, \
                pmax_mean))
        fp.write(
            '\\hline \n'
            '\\end{tabular} \n'
            )
    fp.closed

    print 'The maximal load of the Hopfield Network' \
        'with N=%d is %.5f with a 0.95 confidence intervall ' \
        'of [%.5f,%.5f].\nThe capacity of the network is %.5f' \
        % (N, load_mean,load_mean_lb ,load_mean_ub,pmax_mean)        
コード例 #2
0
ファイル: exercise4.py プロジェクト: moensv/Hopfield_VR
def exercise4(N=200, c=0.1, numint=11, tests=10, confidence=0.95):
    print('Exercise 4:')
    i = 0
    load_mean = zeros(numint,float)
    load_std = zeros(numint,float)
    for e in np.linspace(0,1,numint):
        [load_mean[i], load_mean_lb, load_mean_ub, pmax_mean,
             load_std[i]] = load_max(
                N=N, flip_ratio=c, pcut=0, tests=tests,
                confidence=confidence, excitatory=e)
        i += 1

    alpha_null = 0.1278

    fig = figure()
    ax1 = fig.add_subplot(111)
    lp = errorbar(np.linspace(0,1,num=numint),load_mean/alpha_null,load_std/alpha_null)
    
    ax1.set_ylim(0,1)
    ax1.yaxis.grid(True, linestyle='-', which='major', 
        color=(0.2,0.2,0.2), alpha=0.5)
    ax1.set_axisbelow(True)
    ax1.set_title('Mean maximal load over different E (N=%d, Q=%d)' % 
        (N, tests))
    ax1.set_ylabel('mean maximal load')
    ax1.set_xlabel('E')
    savefig('../tex/dat/ex4-mean_max_load-N%d-Q%d-C%d.png' %
        (N, tests , confidence*100))
    close()
コード例 #3
0
ファイル: exercise3.py プロジェクト: bertramr/Hopfield_VR
def exercise3(N = 200, c= 0.1, confidence=0.95, numint = 11, tests=10):
    print 'Exercise 3:'

    i = 0
    load_mean = zeros(numint,float)
    load_std = zeros(numint,float)
    with open('../tex/dat/ex3-table-N%d-Q%d-C%d.tex' % 
        (N, tests , confidence*100),'w') as fp:
        fp.write(
            
            '\\begin{tabular}{|l|l|l|l|l|l|l|l|} \n'
            '\\hline \n'
            '$P_{cut}$ & N & tests & C-level & maximal load & lower bound & '
            'upper bound & $P_{N,max}$\\\\ \n'
            ' \\hline \\hline \n'
            ) 
        for pcut in np.linspace(0,1,num=numint):
            [load_mean[i], load_mean_lb, load_mean_ub, pmax_mean, 
                load_std[i]] = load_max(N=N, flip_ratio=c, pcut=pcut,
                    tests=tests, confidence=confidence)
            fp.write('%0.1f & %d & %d & %0.1f $\\%%$ '
                ' & %0.2f & %0.2f & %0.2f & %0.2f \\\\ \n' % 
                (pcut, N, tests, confidence*100, 
                load_mean[i], load_mean_lb, load_mean_ub, pmax_mean))
            i += 1
        fp.write('\hline'
                 '\end{tabular}'
                 )

    fp.closed
    
    alpha_null = 0.128    

    fig = figure()
    ax1 = fig.add_subplot(111)
    lp = errorbar(np.linspace(0,1,num=numint),load_mean/alpha_null,load_std/alpha_null)
    
    axhline(y=0.5,linewidth=1, color='r')
    ax1.set_ylim(0,1)
    ax1.yaxis.grid(True, linestyle='-', which='major', 
        color=(0.2,0.2,0.2), alpha=0.5)
    ax1.set_axisbelow(True)
    ax1.set_title('Mean maximal load over different P_cut (N=%d, Q=%d)' % 
        (N, tests))
    ax1.set_ylabel('mean maximal load (alpha_max/alpha_null)')
    ax1.set_xlabel('P_cut')
    savefig('../tex/dat/ex3-mean_max_load-N%d-Q%d-C%d.png' % 
        (N, tests , confidence*100))
    close()