Nt = np.ones(K) * 4
    Ns = np.array([2, 2, 2])  # np.ones(K) * 2

    multiuserchannel = MultiUserChannelMatrix()
    modulator = PSK(4)

    SNR = 40
    noise_var = 1 / dB2Linear(SNR)
    print("SNR: {0}".format(SNR))
    print("noise_var: {0}".format(noise_var))

    multiuserchannel.randomize(Nr, Nt, K)
    multiuserchannel.noise_var = noise_var

    ia_solver = algorithms.AlternatingMinIASolver(multiuserchannel)
    ia_solver2 = algorithms.MMSEIASolver(multiuserchannel)
    ia_solver3 = algorithms.MaxSinrIASolver(multiuserchannel)

    ia_solver4 = algorithms.AlternatingMinIASolver(multiuserchannel)

    # ia_solver.initialize_with_closed_form = True
    # ia_solver2.initialize_with_closed_form = True
    # ia_solver3.initialize_with_closed_form = True

    ia_solver.randomizeF(Ns)
    ia_solver.max_iterations = 400
    ia_solver.solve(Ns)

    ia_solver2.randomizeF(Ns)
    ia_solver2.max_iterations = 100
    ia_solver2.solve(Ns)
Exemple #2
0
def main():
    """Main function.
    """
    K = 3
    Nr = 4
    Nt = 4
    Ns = 2
    SNR = 30.0
    P = 1.0

    # Dependent parameters
    noise_var = 1 / dB2Linear(SNR)

    RepMax = 1
    mmse_sinrs = np.empty([RepMax, K, Ns], dtype=float)
    max_sinr_sinrs = np.empty([RepMax, K, Ns], dtype=float)
    mmse_capacity = np.empty(RepMax, dtype=float)
    max_sinr_capacity = np.empty(RepMax, dtype=float)

    pbar = ProgressbarText(RepMax, message="Simulating for SNR: {0}".format(SNR))

    for rep in range(RepMax):
        # Creat the channel
        multiUserChannel = pyphysim.channels.multiuser.MultiUserChannelMatrix()
        multiUserChannel.randomize(Nr, Nt, K)
        multiUserChannel.noise_var = noise_var

        # Creat the IA solver object
        mmse_ia_solver = algorithms.MMSEIASolver(multiUserChannel)
        max_sinr_ia_solver = algorithms.MaxSinrIASolver(multiUserChannel)

        mmse_ia_solver.randomizeF(Ns, P)

        mmse_ia_solver.initialize_with = 'fix'
        max_sinr_ia_solver.initialize_with = 'fix'
        # noinspection PyProtectedMember
        max_sinr_ia_solver._F = mmse_ia_solver._F

        #mmse_ia_solver.initialize_with = 'fix'

        # We wouldn't need to explicitly set ia_solver.noise_var
        # variable if the multiUserChannel object had the correct value at
        # this point.
        # mmse_ia_solver.noise_var = noise_var
        mmse_ia_solver.max_iterations = 200
        mmse_ia_solver.solve(Ns)

        # max_sinr_ia_solver.noise_var = noise_var
        max_sinr_ia_solver.max_iterations = 200

        max_sinr_ia_solver.solve(Ns)

        mmse_sinrs[rep] = list(map(linear2dB, mmse_ia_solver.calc_SINR()))
        max_sinr_sinrs[rep] = list(map(linear2dB, max_sinr_ia_solver.calc_SINR()))

        mmse_capacity[rep] = np.sum(calc_capacity(mmse_ia_solver.calc_SINR()))
        max_sinr_capacity[rep] = np.sum(calc_capacity(max_sinr_ia_solver.calc_SINR()))

        # print "MMSE Alt. SINRs:\n{0}".format(np.vstack(mmse_sinrs[rep]))
        # print "Max SINR Alg. SINRs:\n{0}".format(np.vstack(max_sinr_sinrs[rep]))

        # print "MMSE Alt. Capacity: {0}".format(np.sum(calc_capacity(mmse_sinrs[rep])))
        # print "Max SINR Alg. Capacity: {0}".format(np.sum(calc_capacity(max_sinr_sinrs[rep])))
        # print

        pbar.progress(rep)

    print("MMSE Average SINRs:\n{0}".format(mmse_sinrs.mean(0)))
    print("Max SINR Average SINRs:\n{0}".format(max_sinr_sinrs.mean(0)))
    print("MMSE Average Capacity: {0}".format(mmse_capacity.mean()))
    print("Max SINR Average Capacity: {0}".format(max_sinr_capacity.mean()))

    print("\nEnd!")
Exemple #3
0
    def __init__(self, default_config_file, read_command_line_args=True):
        """
        Constructor of the IASimulationRunner class.
        """

        spec = """[Grid]
        cell_radius=float(min=0.01, default=1.0)
        num_cells=integer(min=3,default=3)
        num_clusters=integer(min=1,default=1)
        [Scenario]
        NSymbs=integer(min=10, max=1000000, default=200)
        SNR=real_numpy_array(min=-50, max=100, default=0:5:31)
        M=integer(min=4, max=512, default=4)
        modulator=option('QPSK', 'PSK', 'QAM', 'BPSK', default="PSK")
        Nr=integer_scalar_or_integer_numpy_array_check(min=2,default=3)
        Nt=integer_scalar_or_integer_numpy_array_check(min=2,default=3)
        Ns=integer_scalar_or_integer_numpy_array_check(min=1,default=3)
        N0=float(default=-116.4)
        scenario=string_list(default=list('Random', 'NoPathLoss'))
        [IA Algorithm]
        max_iterations=integer(min=1, default=120)
        initialize_with=string_list(default=list('random'))
        stream_sel_method=string_list(default=list('greedy', 'brute'))
        [General]
        rep_max=integer(min=1, default=2000)
        max_bit_errors=integer(min=1, default=3000)
        unpacked_parameters=string_list(default=list('SNR','stream_sel_method','scenario','initialize_with'))
        """.split("\n")

        SimulationRunner.__init__(self, default_config_file, spec,
                                  read_command_line_args)

        # xxxxxxxxxx General Parameters xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        # Maximum number of repetitions for each unpacked parameters set
        self.rep_max = self.params['rep_max']

        # # max_bit_errors is used in the _keep_going method to stop the
        # # simulation earlier if possible. We stop the simulation if the
        # # accumulated number of bit errors becomes greater then 5% of the
        # # total number of simulated bits
        # self.max_bit_errors = self.params['max_bit_errors']
        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        # xxxxxxxxxx Channel and Path Loss Parameters xxxxxxxxxxxxxxxxxxxxx
        # Create the channel object
        self.multiUserChannel = multiuser.MultiUserChannelMatrix()

        # Create the Path loss object
        self.path_loss_obj = pathloss.PathLoss3GPP1()
        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        # xxxxxxxxxx RandomState objects seeds xxxxxxxxxxxxxxxxxxxxxxxxxxxx
        # This is only useful to reproduce a simulation for debugging
        # purposed
        self.channel_seed = None  # 22522
        self.noise_seed = None  # 4445
        self.data_gen_seed = np.random.randint(10000)  # 2105
        #
        self.multiUserChannel.set_channel_seed(self.channel_seed)
        self.multiUserChannel.set_noise_seed(self.noise_seed)
        self.data_RS = np.random.RandomState(self.data_gen_seed)
        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        # xxxxxxxxxx Create the modulator object xxxxxxxxxxxxxxxxxxxxxxxxxx
        M = self.params['M']
        modulator_options = {
            'PSK': fundamental.PSK,
            'QPSK': fundamental.QPSK,
            'QAM': fundamental.QAM,
            'BPSK': fundamental.BPSK
        }
        self.modulator = modulator_options[self.params['modulator']](M)
        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        # xxxxxxxxxx Progress Bar xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        # This can be either 'screen' or 'file'. If it is 'file' then the
        # progressbar will write the progress to a file with appropriated
        # filename
        self.progress_output_type = 'screen'

        # Set the progressbar message
        self.progressbar_message = "SNR: {{SNR}}".format(self.modulator.name)
        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        # xxxxxxxxxx Dependent parameters (don't change these) xxxxxxxxxxxx
        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        # Cell Grid
        self.cell_grid = cell.Grid()
        self.cell_grid.create_clusters(self.params['num_clusters'],
                                       self.params['num_cells'],
                                       self.params['cell_radius'])

        # Note that the Noise variance will be set in the
        # _on_simulate_current_params_start method. In the NoPathLoss
        # scenario it will be set as 1.0 regardless of the value of
        # params['N0'] to avoid problems in the IA algorithms. In the other
        # scenarios it will be set to self.params['N0'].
        #
        # In any case the transmit power will be calculated accordingly in
        # the _run_simulation method and the simulation results will still
        # be correct.
        self.noise_var = None

        # Linear path loss from cell center to cell border.
        self._path_loss_border = self.path_loss_obj.calc_path_loss(
            self.params['cell_radius'])
        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        # TODO: Move code below to the _on_simulate_current_params_start
        # method
        # xxxxxxxxxx Interference Alignment objects xxxxxxxxxxxxxxxxxxxxxxx
        # Create the basic IA Solver object
        self.ia_solver = algorithms.MMSEIASolver(self.multiUserChannel)
        # This will be created in the _on_simulate_current_params_start
        # method. The class of self.ia_top_object will depend on the value
        # of the 'stream_sel_method' parameter
        self.ia_top_object = None