Simulation Results for Interference Alignment

This notebook shows BER and Sum Capacity results for different IA algorithms when the maximum number of allowed iterations is limited. Note that the algorithm might run less iterations than the allowed maximum if the precoders do not change significantly from one iteration to the next one. The maximum number of allowed iterations vary from 5 to 60, except for the closed form algorithm, which is not iterative. The solid lines indicate the BER or Sum Capacity in the left axis, while the dashed lines indicate the mean number of iterations that algorithm used.

Let's perform some initializations.

First we enable the "inline" mode for plots.


In [ ]:
%matplotlib inline

In [ ]:
from matplotlib import pyplot as plt

Now we import some modules we use and add the PyPhysim to the python path.


In [ ]:
import sys
sys.path.append("../")
# xxxxxxxxxx Import Statements xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
from pyphysim.simulations.core import SimulationRunner, SimulationParameters, SimulationResults, Result
from pyphysim.comm import modulators, channels
from pyphysim.util.conversion import dB2Linear
from pyphysim.util import misc
# from pyphysim.ia import ia

import numpy as np
from pprint import pprint

from IPython.html.widgets import interact, interactive
from IPython.display import clear_output, display, HTML
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Function definitions

This section defines several functions used in this notebook. First let's define helper methods to get mean number of IA iterations from a simulation results object.


In [ ]:
# Helper function to get the number of repetitions for a given set of transmit parameters
def get_num_runned_reps(sim_results_object, fixed_params=dict()):
    all_runned_reps = np.array(sim_results_object.runned_reps)
    indexes = sim_results_object.params.get_pack_indexes(fixed_params)
    return all_runned_reps[indexes]

# Helper function to get the number of IA runned iterations for a given set of transmit parameters
def get_num_mean_ia_iterations(sim_results_object, fixed_params=dict()):
    return sim_results_object.get_result_values_list('ia_runned_iterations', fixed_params)

Define a function to read the results.


In [ ]:
def read_results(scenario_string):
    # Examples for scenario_string
    # "2x2_(1)"
    # "3x3_([1,1,2])"
    Nr = scenario_string[0]
    Nt = scenario_string[2]
    Ns = scenario_string[5:-1]
    
    #Nr = 2
    #Nt = 2
    #Ns = 1
    K = 3
    M = 4
    modulator = "PSK"
    max_iterations_string = "[1_(1)_4,5_(5)_120,200]"
    initizalize_with_string = "['random', 'alt_min']"

    base_name = 'results_{M}-{modulator}_{Nr}x{Nt}_({Ns})_MaxIter_{max_iterations}_{initizalize_with}'.format(M=M, modulator=modulator, Nr=Nr, Nt=Nt, Ns=Ns, max_iterations=max_iterations_string, initizalize_with=initizalize_with_string)
    base_name2 = 'results_{M}-{modulator}_{Nr}x{Nt}_({Ns})_MaxIter_{max_iterations}'.format(M=M, modulator=modulator, Nr=Nr, Nt=Nt, Ns=Ns, max_iterations=max_iterations_string)
    
    alt_min_results = SimulationResults.load_from_file('ia_alt_min_{0}.pickle'.format(base_name2))
    max_sinrn_results = SimulationResults.load_from_file('ia_max_sinr_{0}.pickle'.format(base_name))
    mmse_results = SimulationResults.load_from_file('ia_mmse_{0}.pickle'.format(base_name))
    
    return (alt_min_results, max_sinrn_results, mmse_results)

Define a function that we can call to plot the BER. This function will plot the BER for all SNR values for the four IA algorithms, given the desired "max_iterations" parameter value.


In [ ]:
#def plot_ber(alt_min_results, max_sinrn_results, mmse_results, max_iterations, ax=None):
def plot_ber(max_iterations=5, ax=None, alt_min_results=None, max_sinrn_results=None, mmse_results=None):
    SNR_alt_min = np.array(alt_min_results.params['SNR'])
    SNR_max_SINR = np.array(max_sinrn_results.params['SNR'])
    # SNR_min_leakage = np.array(min_leakage_results.params['SNR'])
    SNR_mmse = np.array(mmse_results.params['SNR'])
    
    # Alt. Min. Algorithm
    ber_alt_min = alt_min_results.get_result_values_list(
        'ber',
        fixed_params={'max_iterations': max_iterations})
    ber_CF_alt_min = alt_min_results.get_result_values_confidence_intervals(
        'ber',
        P=95,
        fixed_params={'max_iterations': max_iterations})
    ber_errors_alt_min = np.abs([i[1] - i[0] for i in ber_CF_alt_min])

    # Max SINR Algorithm (random init)
    ber_max_sinr = max_sinrn_results.get_result_values_list(
        'ber',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    ber_CF_max_sinr = max_sinrn_results.get_result_values_confidence_intervals(
        'ber',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    ber_errors_max_sinr = np.abs([i[1] - i[0] for i in ber_CF_max_sinr])

    # Max SINR Algorithm (alt_min init)
    ber_max_sinr2 = max_sinrn_results.get_result_values_list(
        'ber',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    ber_CF_max_sinr2 = max_sinrn_results.get_result_values_confidence_intervals(
        'ber',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    ber_errors_max_sinr2 = np.abs([i[1] - i[0] for i in ber_CF_max_sinr2])
    
    # MMSE Algorithm (random init)
    ber_mmse = mmse_results.get_result_values_list(
        'ber',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    ber_CF_mmse = mmse_results.get_result_values_confidence_intervals(
        'ber',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    ber_errors_mmse = np.abs([i[1] - i[0] for i in ber_CF_mmse])
    
    # MMSE Algorithm (alt_min init)
    ber_mmse2 = mmse_results.get_result_values_list(
        'ber',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    ber_CF_mmse2 = mmse_results.get_result_values_confidence_intervals(
        'ber',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    ber_errors_mmse2 = np.abs([i[1] - i[0] for i in ber_CF_mmse2])

    if ax is None:
        fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(12,9))
    
    ax.errorbar(SNR_alt_min, ber_alt_min, ber_errors_alt_min, fmt='-r*', elinewidth=2.0, label='Alt. Min.')
    ax.errorbar(SNR_max_SINR, ber_max_sinr, ber_errors_max_sinr, fmt='-g*', elinewidth=2.0, label='Max SINR (random)')
    ax.errorbar(SNR_max_SINR, ber_max_sinr2, ber_errors_max_sinr2, fmt='-y*', elinewidth=2.0, label='Max SINR (alt_min)')
    ax.errorbar(SNR_mmse, ber_mmse, ber_errors_mmse, fmt='-m*', elinewidth=2.0, label='MMSE (random)')
    ax.errorbar(SNR_mmse, ber_mmse2, ber_errors_mmse2, fmt='-b*', elinewidth=2.0, label='MMSE (alt_min)')

    ax.set_xlabel('SNR')
    ax.set_ylabel('BER')
    title = 'BER for Different Algorithms ({max_iterations} Max Iterations)\nK={K}, Nr={Nr}, Nt={Nt}, Ns={Ns}, {M}-{modulator}'.replace("{max_iterations}", str(max_iterations))
    ax.set_title(title.format(**alt_min_results.params.parameters))

    ax.set_yscale('log')
    leg = ax.legend(fancybox=True, shadow=True, loc='lower left', bbox_to_anchor=(0.01, 0.01), ncol=4)
    ax.grid(True, which='both', axis='both')
    
    # Lets plot the mean number of ia iterations
    ax2 = ax.twinx()
    mean_alt_min_ia_terations = get_num_mean_ia_iterations(alt_min_results, {'max_iterations': max_iterations})
    mean_max_sinrn_ia_terations = get_num_mean_ia_iterations(max_sinrn_results, {'max_iterations': max_iterations, 'initialize_with': 'random'})
    mean_max_sinrn_ia_terations2 = get_num_mean_ia_iterations(max_sinrn_results, {'max_iterations': max_iterations, 'initialize_with': 'alt_min'})    
    mean_mmse_ia_terations = get_num_mean_ia_iterations(mmse_results, {'max_iterations': max_iterations, 'initialize_with': 'random'})
    mean_mmse_ia_terations2 = get_num_mean_ia_iterations(mmse_results, {'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    ax2.plot(SNR_alt_min, mean_alt_min_ia_terations, '--r*')
    ax2.plot(SNR_max_SINR, mean_max_sinrn_ia_terations, '--g*')
    ax2.plot(SNR_max_SINR, mean_max_sinrn_ia_terations2, '--y*')
    ax2.plot(SNR_mmse, mean_mmse_ia_terations, '--m*')
    ax2.plot(SNR_mmse, mean_mmse_ia_terations2, '--b*')
    
    # Horizontal line with the max alowed ia iterations
    ax2.hlines(max_iterations, SNR_alt_min[0], SNR_alt_min[-1], linestyles='dashed')
    ax2.set_ylim(0, max_iterations*1.1)
    ax2.set_ylabel('IA Mean Iterations')

    # Set the X axis limits
    ax.set_xlim(SNR_alt_min[0], SNR_alt_min[-1])
    # Set the Y axis limits
    ax.set_ylim(1e-6, 1)
    
    fig = ax.figure
    
    return fig

In [ ]:
# scenario = "2x2_(1)"
# alt_min_results, max_sinr_results, mmse_results = read_results(scenario)
# fig = plot_ber(max_iterations=80, ax=None, alt_min_results=alt_min_results,
#              max_sinrn_results=max_sinr_results, mmse_results=mmse_results)
# a=10
# a

Define a function that we can call to plot the Sum Capacity. This function will plot the Sum Capacity for all SNR values for the four IA algorithms, given the desired "max_iterations" parameter value.


In [ ]:
def plot_capacity(max_iterations, ax=None, alt_min_results=None, max_sinrn_results=None, mmse_results=None):
    SNR_alt_min = np.array(alt_min_results.params['SNR'])
    SNR_max_SINR = np.array(max_sinrn_results.params['SNR'])
    # SNR_min_leakage = np.array(min_leakage_results.params['SNR'])
    SNR_mmse = np.array(mmse_results.params['SNR'])
    
    # xxxxx Plot Sum Capacity (all) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    sum_capacity_alt_min = alt_min_results.get_result_values_list(
        'sum_capacity',
        fixed_params={'max_iterations': max_iterations})
    sum_capacity_CF_alt_min = alt_min_results.get_result_values_confidence_intervals(
        'sum_capacity',
        P=95,
        fixed_params={'max_iterations': max_iterations})
    sum_capacity_errors_alt_min = np.abs([i[1] - i[0] for i in sum_capacity_CF_alt_min])
    
#     sum_capacity_closed_form = closed_form_results.get_result_values_list(
#         'sum_capacity',
#         fixed_params={'max_iterations': max_iterations})
#     sum_capacity_CF_closed_form = closed_form_results.get_result_values_confidence_intervals(
#         'sum_capacity',
#         P=95,
#         fixed_params={'max_iterations': max_iterations})
#     sum_capacity_errors_closed_form = np.abs([i[1] - i[0] for i in sum_capacity_CF_closed_form])
    
    # Max SINR Algorithm (random)
    sum_capacity_max_sinr = max_sinrn_results.get_result_values_list(
        'sum_capacity',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    sum_capacity_CF_max_sinr = max_sinrn_results.get_result_values_confidence_intervals(
        'sum_capacity',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    sum_capacity_errors_max_sinr = np.abs([i[1] - i[0] for i in sum_capacity_CF_max_sinr])
    
    # Max SINR Algorithm (alt_min)
    sum_capacity_max_sinr2 = max_sinrn_results.get_result_values_list(
        'sum_capacity',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    sum_capacity_CF_max_sinr2 = max_sinrn_results.get_result_values_confidence_intervals(
        'sum_capacity',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    sum_capacity_errors_max_sinr2 = np.abs([i[1] - i[0] for i in sum_capacity_CF_max_sinr2])

    # MMSE Algorithm (random)
    sum_capacity_mmse = mmse_results.get_result_values_list(
        'sum_capacity',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    sum_capacity_CF_mmse = mmse_results.get_result_values_confidence_intervals(
        'sum_capacity',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    sum_capacity_errors_mmse = np.abs([i[1] - i[0] for i in sum_capacity_CF_mmse])
    
    # MMSE Algorithm (alt_min)
    sum_capacity_mmse2 = mmse_results.get_result_values_list(
        'sum_capacity',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    sum_capacity_CF_mmse2 = mmse_results.get_result_values_confidence_intervals(
        'sum_capacity',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    sum_capacity_errors_mmse2 = np.abs([i[1] - i[0] for i in sum_capacity_CF_mmse2])

    
    if ax is None:
        fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(12,9))
    # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    ax.errorbar(SNR_alt_min, sum_capacity_alt_min, sum_capacity_errors_alt_min, fmt='-r*', elinewidth=2.0, label='Alt. Min.')
    #ax.errorbar(SNR_closed_form, sum_capacity_closed_form, sum_capacity_errors_closed_form, fmt='-b*', elinewidth=2.0, label='Closed Form')
    ax.errorbar(SNR_max_SINR, sum_capacity_max_sinr, sum_capacity_errors_max_sinr, fmt='-g*', elinewidth=2.0, label='Max SINR (random)')
    ax.errorbar(SNR_max_SINR, sum_capacity_max_sinr2, sum_capacity_errors_max_sinr2, fmt='-y*', elinewidth=2.0, label='Max SINR (alt_min)')
    ax.errorbar(SNR_mmse, sum_capacity_mmse, sum_capacity_errors_mmse, fmt='-m*', elinewidth=2.0, label='MMSE (random)')
    ax.errorbar(SNR_mmse, sum_capacity_mmse2, sum_capacity_errors_mmse2, fmt='-b*', elinewidth=2.0, label='MMSE (alt_min)')
    # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    ax.set_xlabel('SNR')
    ax.set_ylabel('Sum Capacity')
    title = 'Sum Capacity for Different Algorithms ({max_iterations} Max Iterations)\nK={K}, Nr={Nr}, Nt={Nt}, Ns={Ns}, {M}-{modulator}'.replace("{max_iterations}", str(max_iterations))
    ax.set_title(title.format(**alt_min_results.params.parameters))

    #leg = ax.legend(fancybox=True, shadow=True, loc=2)
    leg = ax.legend(fancybox=True, shadow=True, loc='lower right', bbox_to_anchor=(0.99, 0.01), ncol=4)
    
    ax.grid(True, which='both', axis='both')
    
    # Lets plot the mean number of ia iterations
    ax2 = ax.twinx()
    mean_alt_min_ia_terations = get_num_mean_ia_iterations(alt_min_results, {'max_iterations': max_iterations})
    mean_max_sinrn_ia_terations = get_num_mean_ia_iterations(max_sinrn_results, {'max_iterations': max_iterations, 'initialize_with': 'random'})
    mean_max_sinrn_ia_terations2 = get_num_mean_ia_iterations(max_sinrn_results, {'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    mean_mmse_ia_terations = get_num_mean_ia_iterations(mmse_results, {'max_iterations': max_iterations, 'initialize_with': 'random'})
    mean_mmse_ia_terations2 = get_num_mean_ia_iterations(mmse_results, {'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    ax2.plot(SNR_alt_min, mean_alt_min_ia_terations, '--r*')
    ax2.plot(SNR_max_SINR, mean_max_sinrn_ia_terations, '--g*')
    ax2.plot(SNR_max_SINR, mean_max_sinrn_ia_terations2, '--y*')
    ax2.plot(SNR_mmse, mean_mmse_ia_terations, '--m*')
    ax2.plot(SNR_mmse, mean_mmse_ia_terations2, '--b*')
    
    # Horizontal line with the max alowed ia iterations
    ax2.hlines(max_iterations, SNR_alt_min[0], SNR_alt_min[-1], linestyles='dashed')
    ax2.set_ylim(0, max_iterations*1.1)
    ax2.set_ylabel('IA Mean Iterations')

    # Set the X axis limits
    ax.set_xlim(SNR_alt_min[0], SNR_alt_min[-1])
    # Set the Y axis limits
    #ax.set_ylim(1e-6, 1)
    
    fig = ax.figure
    return fig

In [ ]:
# fig = plot_capacity(max_iterations=200, ax=None, alt_min_results=alt_min_results,
#              max_sinrn_results=max_sinr_results, mmse_results=mmse_results)

In [ ]:
def read_results_and_plot_ber(scenario_string="2x2_(1)", max_iterations=5):
    (alt_min_results, max_sinrn_results, mmse_results) = read_results(scenario_string)
    
    fig = plot_ber(max_iterations=max_iterations,
             ax=None,
             alt_min_results=alt_min_results, 
             max_sinrn_results=max_sinrn_results, 
             mmse_results=mmse_results)
    return fig

In [ ]:
def read_results_and_plot_capacity(scenario_string="2x2_(1)", max_iterations=5):
    (alt_min_results, max_sinrn_results, mmse_results) = read_results(scenario_string)
    
    fig = plot_capacity(max_iterations=max_iterations,
             ax=None,
             alt_min_results=alt_min_results, 
             max_sinrn_results=max_sinrn_results, 
             mmse_results=mmse_results)
    return fig

Scenarios to be ploted


In [ ]:
#read_results_and_plot_capacity(scenario_string="2x2_(1)", max_iterations=120)
scenarios = ["2x2_(1)", 
             #"3x3_(1)",
             #"3x3_(2)",
             #"3x3_([1,1,2])",
             #"3x3_([1,2,2])",
             "4x4_(2)",
             #"4x4_([2,2,3])",
             #"4x4_([2,3,3])"
             ]

Plot the BER


In [ ]:
read_results_and_plot_ber("2x2_(1)", 200)

In [ ]:
from IPython.html import widgets
from IPython.html.widgets import interact
interact(read_results_and_plot_ber, 
         scenario_string=['2x2_(1)', '4x4_(2)'],
         max_iterations=[5, 120, 5])

Plot the Sum Capacity


In [ ]:
from IPython.html import widgets
from IPython.html.widgets import interact
interact(read_results_and_plot_capacity, 
         scenario_string=['2x2_(1)', '4x4_(2)'],
         max_iterations=[5, 120, 5])

Apagar depois


In [ ]:
from pyphysim.plot.pgfplotshelper import generate_pgfplots_plotline

In [ ]:
#def plot_ber(alt_min_results, max_sinrn_results, mmse_results, max_iterations, ax=None):
def plot_ber_tikz(max_iterations=5, ax=None, alt_min_results=None, max_sinrn_results=None, mmse_results=None):
    SNR_alt_min = np.array(alt_min_results.params['SNR'])
    SNR_max_SINR = np.array(max_sinrn_results.params['SNR'])
    # SNR_min_leakage = np.array(min_leakage_results.params['SNR'])
    SNR_mmse = np.array(mmse_results.params['SNR'])
    
    # Alt. Min. Algorithm
    ber_alt_min = alt_min_results.get_result_values_list(
        'ber',
        fixed_params={'max_iterations': max_iterations})
    ber_CF_alt_min = alt_min_results.get_result_values_confidence_intervals(
        'ber',
        P=95,
        fixed_params={'max_iterations': max_iterations})
    ber_errors_alt_min = np.abs([i[1] - i[0] for i in ber_CF_alt_min])

    # Max SINR Algorithm (random init)
    ber_max_sinr = max_sinrn_results.get_result_values_list(
        'ber',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    ber_CF_max_sinr = max_sinrn_results.get_result_values_confidence_intervals(
        'ber',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    ber_errors_max_sinr = np.abs([i[1] - i[0] for i in ber_CF_max_sinr])

    # Max SINR Algorithm (alt_min init)
    ber_max_sinr2 = max_sinrn_results.get_result_values_list(
        'ber',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    ber_CF_max_sinr2 = max_sinrn_results.get_result_values_confidence_intervals(
        'ber',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    ber_errors_max_sinr2 = np.abs([i[1] - i[0] for i in ber_CF_max_sinr2])
    
    # MMSE Algorithm (random init)
    ber_mmse = mmse_results.get_result_values_list(
        'ber',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    ber_CF_mmse = mmse_results.get_result_values_confidence_intervals(
        'ber',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    ber_errors_mmse = np.abs([i[1] - i[0] for i in ber_CF_mmse])
    
    # MMSE Algorithm (alt_min init)
    ber_mmse2 = mmse_results.get_result_values_list(
        'ber',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    ber_CF_mmse2 = mmse_results.get_result_values_confidence_intervals(
        'ber',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    ber_errors_mmse2 = np.abs([i[1] - i[0] for i in ber_CF_mmse2])

#     if ax is None:
#         fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(12,9))
    
#     ax.errorbar(SNR_alt_min, ber_alt_min, ber_errors_alt_min, fmt='-r*', elinewidth=2.0, label='Alt. Min.')
#     ax.errorbar(SNR_max_SINR, ber_max_sinr, ber_errors_max_sinr, fmt='-g*', elinewidth=2.0, label='Max SINR (random)')
#     ax.errorbar(SNR_max_SINR, ber_max_sinr2, ber_errors_max_sinr2, fmt='-y*', elinewidth=2.0, label='Max SINR (alt_min)')
#     ax.errorbar(SNR_mmse, ber_mmse, ber_errors_mmse, fmt='-m*', elinewidth=2.0, label='MMSE (random)')
#     ax.errorbar(SNR_mmse, ber_mmse2, ber_errors_mmse2, fmt='-b*', elinewidth=2.0, label='MMSE (alt_min)')

#     ax.set_xlabel('SNR')
#     ax.set_ylabel('BER')
#     title = 'BER for Different Algorithms ({max_iterations} Max Iterations)\nK={K}, Nr={Nr}, Nt={Nt}, Ns={Ns}, {M}-{modulator}'.replace("{max_iterations}", str(max_iterations))
#     ax.set_title(title.format(**alt_min_results.params.parameters))

#     ax.set_yscale('log')
#     leg = ax.legend(fancybox=True, shadow=True, loc='lower left', bbox_to_anchor=(0.01, 0.01), ncol=4)
#     ax.grid(True, which='both', axis='both')
    
#     Lets plot the mean number of ia iterations
#     ax2 = ax.twinx()
    mean_alt_min_ia_terations = get_num_mean_ia_iterations(alt_min_results, {'max_iterations': max_iterations})
    mean_max_sinrn_ia_terations = get_num_mean_ia_iterations(max_sinrn_results, {'max_iterations': max_iterations, 'initialize_with': 'random'})
    mean_max_sinrn_ia_terations2 = get_num_mean_ia_iterations(max_sinrn_results, {'max_iterations': max_iterations, 'initialize_with': 'alt_min'})    
    mean_mmse_ia_terations = get_num_mean_ia_iterations(mmse_results, {'max_iterations': max_iterations, 'initialize_with': 'random'})
    mean_mmse_ia_terations2 = get_num_mean_ia_iterations(mmse_results, {'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
#     ax2.plot(SNR_alt_min, mean_alt_min_ia_terations, '--r*')
#     ax2.plot(SNR_max_SINR, mean_max_sinrn_ia_terations, '--g*')
#     ax2.plot(SNR_max_SINR, mean_max_sinrn_ia_terations2, '--y*')
#     ax2.plot(SNR_mmse, mean_mmse_ia_terations, '--m*')
#     ax2.plot(SNR_mmse, mean_mmse_ia_terations2, '--b*')
    
#     # Horizontal line with the max alowed ia iterations
#     ax2.hlines(max_iterations, SNR_alt_min[0], SNR_alt_min[-1], linestyles='dashed')
#     ax2.set_ylim(0, max_iterations*1.1)
#     ax2.set_ylabel('IA Mean Iterations')

#     # Set the X axis limits
#     ax.set_xlim(SNR_alt_min[0], SNR_alt_min[-1])
#     # Set the Y axis limits
#     ax.set_ylim(1e-6, 1)
    
#     fig = ax.figure
    
    # Plot the BER
    alt_min_line = generate_pgfplots_plotline(
        SNR_alt_min, ber_alt_min, #ber_errors_alt_min,
        options='alt min style', 
        legend="IA-Alternating")
    max_sinr_random_init_line = generate_pgfplots_plotline(
        SNR_max_SINR, ber_max_sinr, #ber_errors_alt_min,
        options='max sinr random init style',
        legend="IA-Max SINR (random)")
    max_sinr_alt_init_line = generate_pgfplots_plotline(
        SNR_max_SINR, ber_max_sinr2, #ber_errors_alt_min,
        options='max sinr alt init style',
        legend="IA-Max SINR (alt init)")
    mmse_random_init_line = generate_pgfplots_plotline(
        SNR_mmse, ber_mmse, #ber_errors_alt_min,
        options='mmse random init style',
        legend="IA-MMSE (random)")
    mmse_alt_init_line = generate_pgfplots_plotline(
        SNR_mmse, ber_mmse2, #ber_errors_alt_min,
        options='mmse alt init style',
        legend="IA-MMSE (alt init)")
    
    # Plot mean IA iterations
    alt_min_iter_line = generate_pgfplots_plotline(
        SNR_alt_min, mean_alt_min_ia_terations, #ber_errors_alt_min,
        options='alt min iter style')
    max_sinr_random_init_iter_line = generate_pgfplots_plotline(
        SNR_max_SINR, mean_max_sinrn_ia_terations, #ber_errors_alt_min,
        options='max sinr random init iter style')
    max_sinr_alt_init_iter_line = generate_pgfplots_plotline(
        SNR_max_SINR, mean_max_sinrn_ia_terations2, #ber_errors_alt_min,
        options='max sinr alt init iter style')
    mmse_random_init_iter_line = generate_pgfplots_plotline(
        SNR_mmse, mean_mmse_ia_terations, #ber_errors_alt_min,
        options='mmse random init iter style')
    mmse_alt_init_iter_line = generate_pgfplots_plotline(
        SNR_mmse, mean_mmse_ia_terations2, #ber_errors_alt_min,
        options='mmse alt init iter style')
    
    ber_plots = (alt_min_line, max_sinr_random_init_line, max_sinr_alt_init_line, mmse_random_init_line, mmse_alt_init_line)
    mean_iterations_plots = (alt_min_iter_line, max_sinr_random_init_iter_line, max_sinr_alt_init_iter_line, mmse_random_init_iter_line, mmse_alt_init_iter_line)
    return ber_plots, mean_iterations_plots

In [ ]:
scenario = "4x4_(2)"
max_iterations = 80

alt_min_results, max_sinr_results, mmse_results = read_results(scenario)
ber_plots, mean_iterations_plots = plot_ber_tikz(max_iterations=max_iterations, 
                                                 ax=None, 
                                                 alt_min_results=alt_min_results,
                                                 max_sinrn_results=max_sinr_results, 
                                                 mmse_results=mmse_results)

print("% Max Iterations: {0}\n".format(max_iterations))

print("% xxxxxxxxxxxxxxxxxxxx BER PLOTS xxxxxxxxxxxxxxxxxxxx")
for p in ber_plots:
    print(p)
    print()
    
print()
print("% xxxxxxxxxxxxxxxxxxxx Mean Iterations PLOTS xxxxxxxxxxxxxxxxxxxx")
for p in mean_iterations_plots:
    print(p)
    print()

In [ ]:
def plot_capacity_tikz(max_iterations, ax=None, alt_min_results=None, max_sinrn_results=None, mmse_results=None):
    SNR_alt_min = np.array(alt_min_results.params['SNR'])
    SNR_max_SINR = np.array(max_sinrn_results.params['SNR'])
    # SNR_min_leakage = np.array(min_leakage_results.params['SNR'])
    SNR_mmse = np.array(mmse_results.params['SNR'])
    
    # xxxxx Plot Sum Capacity (all) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    sum_capacity_alt_min = alt_min_results.get_result_values_list(
        'sum_capacity',
        fixed_params={'max_iterations': max_iterations})
    sum_capacity_CF_alt_min = alt_min_results.get_result_values_confidence_intervals(
        'sum_capacity',
        P=95,
        fixed_params={'max_iterations': max_iterations})
    sum_capacity_errors_alt_min = np.abs([i[1] - i[0] for i in sum_capacity_CF_alt_min])
    
#     sum_capacity_closed_form = closed_form_results.get_result_values_list(
#         'sum_capacity',
#         fixed_params={'max_iterations': max_iterations})
#     sum_capacity_CF_closed_form = closed_form_results.get_result_values_confidence_intervals(
#         'sum_capacity',
#         P=95,
#         fixed_params={'max_iterations': max_iterations})
#     sum_capacity_errors_closed_form = np.abs([i[1] - i[0] for i in sum_capacity_CF_closed_form])
    
    # Max SINR Algorithm (random)
    sum_capacity_max_sinr = max_sinrn_results.get_result_values_list(
        'sum_capacity',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    sum_capacity_CF_max_sinr = max_sinrn_results.get_result_values_confidence_intervals(
        'sum_capacity',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    sum_capacity_errors_max_sinr = np.abs([i[1] - i[0] for i in sum_capacity_CF_max_sinr])
    
    # Max SINR Algorithm (alt_min)
    sum_capacity_max_sinr2 = max_sinrn_results.get_result_values_list(
        'sum_capacity',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    sum_capacity_CF_max_sinr2 = max_sinrn_results.get_result_values_confidence_intervals(
        'sum_capacity',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    sum_capacity_errors_max_sinr2 = np.abs([i[1] - i[0] for i in sum_capacity_CF_max_sinr2])

    # MMSE Algorithm (random)
    sum_capacity_mmse = mmse_results.get_result_values_list(
        'sum_capacity',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    sum_capacity_CF_mmse = mmse_results.get_result_values_confidence_intervals(
        'sum_capacity',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'random'})
    sum_capacity_errors_mmse = np.abs([i[1] - i[0] for i in sum_capacity_CF_mmse])
    
    # MMSE Algorithm (alt_min)
    sum_capacity_mmse2 = mmse_results.get_result_values_list(
        'sum_capacity',
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    sum_capacity_CF_mmse2 = mmse_results.get_result_values_confidence_intervals(
        'sum_capacity',
        P=95,
        fixed_params={'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    sum_capacity_errors_mmse2 = np.abs([i[1] - i[0] for i in sum_capacity_CF_mmse2])
    
    # Lets plot the mean number of ia iterations
    mean_alt_min_ia_terations = get_num_mean_ia_iterations(alt_min_results, {'max_iterations': max_iterations})
    mean_max_sinrn_ia_terations = get_num_mean_ia_iterations(max_sinrn_results, {'max_iterations': max_iterations, 'initialize_with': 'random'})
    mean_max_sinrn_ia_terations2 = get_num_mean_ia_iterations(max_sinrn_results, {'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
    mean_mmse_ia_terations = get_num_mean_ia_iterations(mmse_results, {'max_iterations': max_iterations, 'initialize_with': 'random'})
    mean_mmse_ia_terations2 = get_num_mean_ia_iterations(mmse_results, {'max_iterations': max_iterations, 'initialize_with': 'alt_min'})
        
    # Plot the Sum Capacity
    alt_min_line = generate_pgfplots_plotline(
        SNR_alt_min, sum_capacity_alt_min, #ber_errors_alt_min,
        options='alt min style', 
        legend="IA-Alternating")
    max_sinr_random_init_line = generate_pgfplots_plotline(
        SNR_max_SINR, sum_capacity_max_sinr, #ber_errors_alt_min,
        options='max sinr random init style',
        legend="IA-Max SINR (random)")
    max_sinr_alt_init_line = generate_pgfplots_plotline(
        SNR_max_SINR, sum_capacity_max_sinr2, #ber_errors_alt_min,
        options='max sinr alt init style',
        legend="IA-Max SINR (alt init)")
    mmse_random_init_line = generate_pgfplots_plotline(
        SNR_mmse, sum_capacity_mmse, #ber_errors_alt_min,
        options='mmse random init style',
        legend="IA-MMSE (random)")
    mmse_alt_init_line = generate_pgfplots_plotline(
        SNR_mmse, sum_capacity_mmse2, #ber_errors_alt_min,
        options='mmse alt init style',
        legend="IA-MMSE (alt init)")
    
    # Plot mean IA iterations
    alt_min_iter_line = generate_pgfplots_plotline(
        SNR_alt_min, mean_alt_min_ia_terations, #ber_errors_alt_min,
        options='alt min iter style')
    max_sinr_random_init_iter_line = generate_pgfplots_plotline(
        SNR_max_SINR, mean_max_sinrn_ia_terations, #ber_errors_alt_min,
        options='max sinr random init iter style')
    max_sinr_alt_init_iter_line = generate_pgfplots_plotline(
        SNR_max_SINR, mean_max_sinrn_ia_terations2, #ber_errors_alt_min,
        options='max sinr alt init iter style')
    mmse_random_init_iter_line = generate_pgfplots_plotline(
        SNR_mmse, mean_mmse_ia_terations, #ber_errors_alt_min,
        options='mmse random init iter style')
    mmse_alt_init_iter_line = generate_pgfplots_plotline(
        SNR_mmse, mean_mmse_ia_terations2, #ber_errors_alt_min,
        options='mmse alt init iter style')
    
    sum_capacity_plots = (alt_min_line, max_sinr_random_init_line, max_sinr_alt_init_line, mmse_random_init_line, mmse_alt_init_line)
    mean_iterations_plots = (alt_min_iter_line, max_sinr_random_init_iter_line, max_sinr_alt_init_iter_line, mmse_random_init_iter_line, mmse_alt_init_iter_line)
    
    return sum_capacity_plots, mean_iterations_plots

In [ ]:
scenario = "4x4_(2)"
max_iterations = 80

alt_min_results, max_sinr_results, mmse_results = read_results(scenario)
sum_capacity_plots, mean_iterations_plots = plot_capacity_tikz(max_iterations=max_iterations, ax=None, alt_min_results=alt_min_results,
                 max_sinrn_results=max_sinr_results, mmse_results=mmse_results)

print("% Max Iterations: {0}\n".format(max_iterations))

print("% xxxxxxxxxxxxxxxxxxxx Capacity PLOTS xxxxxxxxxxxxxxxxxxxx")
for p in sum_capacity_plots:
    print(p)
    print()
    
print()
print("% xxxxxxxxxxxxxxxxxxxx Mean Iterations PLOTS xxxxxxxxxxxxxxxxxxxx")
for p in mean_iterations_plots:
    print(p)
    print