How can we put a varying packet error rate in omnet++ - omnet++

Is there a way to put a varying PER(packet error rate) in the omnet.ini file for a single simulation? I know to simulate for different simulations and compare the graph, but I want one simulation which varies PER. Generally, we put the PER in the ini file as in percentage and have a constant PER but I want is varying one between 1% to 50%.
PER = 0.5 #Generally we do like this to show 50% PER
PER= #(0.1 to 0.5) #I need something like this
Hope I am clear.

There are two ways of achieving your goal.
Method 1
In NED declare PER parameter with volatile:
parameters:
volatile double PER;
In omnetpp.ini use a random distribution, for example a uniform distribution:
**.somemodule.PER = uniform(0.01, 0.50)
In C++ code of your module use par("PER") in every place where that value is read.
Thanks to volatile every time that parameter is read, a new random value is chosen. Reference: OMNeT++ Simulation Manual
Method 2
In NED declare two parameters:
parameters:
double minPER;
double maxPER;
In omnetpp.ini set the values of these parameters:
**.somemodule.minPER = 0.01
**.somemodule.maxPER = 0.50
In initialize() of your C++ class read these parameters, e.g.:
minPER = par("minPER");
maxPER = par("maxPER");
In C++ in the place where PER value is necessary generate the current value using a random distribution, for example:
double per = uniform(minPER, maxPER);

Related

How do I add noise/variability to a dataset in Python, given the CV?

Given a dataset of blood results, say cholesterol level, and knowing that the instrument that produced those results is subject to a known degree of variability, how would I add that variability back into the dataset? i.e. I want to assume the result in the original dataset is the true/mean value, and then produce new results that are subject to the known variability of the instrument.
In Excel you use =NORM.INV(RAND(), mean, std_dev), where RAND() provides a random value between 0 and 1, "mean" will be the original value and I have the CV so I can calculate the SD. NORM.INV then provides the inverse of the cumulative normal distribution function.
I've done the following to create a new column with my new values, but would like to know if it is valid (i.e., will each row have a different random number between 0 and 1 as the probability? and is this formula equivalent to NORM.INV?
df8000['HDL_1'] = norm.ppf(random(), loc = df8000['HDL_0'], scale = TAE_df.loc[0,'HDL'])
Thanks in advance!

Is it possible to pre-assign values to decision variables in CPLEX OPL

I have a large number of variables ( both Binary and Continuous). Therefore I have determined a logic to assign some variables set to 0 so that they do not become part of the optimisation process.
For example I have a binary decision variable y[b][t]:
where b varies from 1 to 100
and t from 1 to 5.
I could determine using some logic that y[20][2] onwards to y[100][2] would be 0. I want to assign the fixed value of 0 to these variables y[20][2] onwards to y[100][2] thereby reducing the number of variables in my optimisation problem. While y is a binary decision variable I have other continuous variable as well which I would like to similarly set to 0 in advance.
Is there a way how this can be achieved ? I haven't used Python with CPEX but hear that this can be probably be achieved by setting a lower and upper bound of the variables. Is there a similar method in OPL.
----Added 13th Aug
May be I was not very clear or I could not understand the solution suggested.
What I wanted is say I have the following decision variable Xbmt ...(I have a few of them)
Originally declared as :
dvar float+ Xbmt[PitBlocks][Plants][TimePeriods];
But for some of the PitBlocks and some time periods I want to define this decision variable as 0. Those time periods for which I want to set the decision variable as 0 are defined in a tuple nullVariables. It has block id same as PitBlocks, and it has time_period same as TimePeriod. Hence I want something like below. But I cannot declare the decision variable twice. I need it 0 only for those ids in the nullVariable set.
dvar float+ Xbmt[NullVariablesSet.block_id][Plants][NullVariablesSet.time_period] in 0..0;
How can this be achieved where some of Xbmt remain as decision variables where as some are removed by setting as 0
see https://github.com/AlexFleischerParis/zooopl/blob/master/zoopreassign.mod
within
Making Decision Optimization Simple
int nbKids=300;
{int} seats={40,30}; // how many seats, {} means this is a set
float costBus[seats]=[500,400];
// Now let s see how preassign some decision variables
// Suppose we know that we have exactly 6 buses 40 seats
{int} preassignedseats={40};
int preassignedvalues[preassignedseats]=[6];
dvar int+ nbBus[s in seats]
in
((s in preassignedseats)?preassignedvalues[s]:0)
..
((s in preassignedseats)?preassignedvalues[s]:maxint);
minimize sum(b in seats) costBus[b]*nbBus[b];
subject to
{
sum(b in seats) b*nbBus[b]>=nbKids;
}

Can different waveforms be used for injection and recovery in bilby?

Is it possible to inject a signal with waveform A and then recover it with a different waveform?
*Question asked by Nirban Bose on the bilby slack channel.
Yes, a good example of this is the Reduced Order Quadrature example. The key is to generate the data with a different waveform_generator to the one used in the search. Practically, this amounts to passing a different waveform_generator to the interferometer data generated and to the likelihood.
Here is a pseudo code demonstration which injects a binary black hole and recovers a binary neutron star waveform
# Make some injection parameters
injection_parameters = dict(
chirp_mass=36., mass_ratio=0.9, a_1=0.4, a_2=0.3, tilt_1=0.0, tilt_2=0.0,
phi_12=1.7, phi_jl=0.3, luminosity_distance=1000., iota=0.4, psi=0.659,
phase=1.3, geocent_time=1126259642.413, ra=1.375, dec=-1.2108)
# Make the injection waveform generator
waveform_arguments = dict(waveform_approximant='IMRPhenomPv2',
reference_frequency=20., minimum_frequency=20.)
injection_waveform_generator = bilby.gw.WaveformGenerator(
duration=duration, sampling_frequency=sampling_frequency,
frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole,
waveform_arguments=waveform_arguments)
# Setup the interferometer list
ifos = bilby.gw.detector.InterferometerList(['H1', 'L1', 'V1'])
ifos.set_strain_data_from_power_spectral_densities(
sampling_frequency=sampling_frequency, duration=duration,
start_time=injection_parameters['geocent_time'] - 3)
# Here we inject a signal using the injection_waveform_generator
ifos.inject_signal(waveform_generator=injection_waveform_generator,
parameters=injection_parameters)
# Now create a search waveform generator (i.e. the one used for PE)
# Here you can specify anything you like, e.g. a different waveform approximant,
# in this example, I've just used a binary neutron star instead
waveform_arguments = dict(waveform_approximant='IMRPhenomPv2',
reference_frequency=20., minimum_frequency=20.)
search_waveform_generator = bilby.gw.WaveformGenerator(
duration=duration, sampling_frequency=sampling_frequency,
frequency_domain_source_model=bilby.gw.source.lal_binary_neutron_star,
waveform_arguments=waveform_arguments)
# Set up your priors
priors = ...
# Now set up the likelihood - here we pass in the search waveform generator
likelihood = bilby.gw.likelihood.GravitationalWaveTransient(
interferometers=ifos, waveform_generator=search_waveform_generator,
prior=priors)
# Run the sampler
result = bilby.run_sampler(
likelihood=likelihood, priors=priors, ...)
This should be adaptable to a good number of situations.

Printing Noise Seed of Processing Sketch

There is a function noiseSeed(int) to set the seed for a program, but is there any way to print the seed of a program when it begins?
I am making generative art sketches and it would be more convenient to store just a seed number for a result than an entire image.
You can't get the default random seed value.
Check out Processing's source code (specifically the random() and randomSeed() functions) to see that Processing uses an instance of the Random class to generate random numbers. That class does not have a public way to access its seed value, and even if it did, the internalRandom used by Processing isn't accessible to you anyway.
What you can do is create your own seed value and then store that in your own variable. Something like this:
long seed;
void setup(){
seed = (long)random(1000);
randomSeed(seed);
println("Seed value: " + seed);
}
How you come up with that seed is up to you. Here I'm generating a random seed between 0 and 1000, but in real life it can be any long value.
You could then also input this from the user in order to have repeatable random behavior based on the input value.

Assignment problems with simple random number generation in Modelica

I am relatively new to Modelica (Dymola-environment) and I am getting very desperate/upset that I cannot solve such a simple problem as a random number generation in Modelica and I hope that you can help me out.
The simple function random produces a random number between 0 and 1 with an input seed seedIn[3] and produces the output seed seedOut[3] for the next time step or event. The call
(z,seedOut) = random(seedIn);
works perfectly fine.
The problem is that I cannot find a way in Modelica to compute this assignment over time by using the seedOut[3] as the next seedIn[3], which is very frustrating.
My simple program looks like this:
*model Randomgenerator
Real z;
Integer seedIn[3]( start={1,23,131},fixed=true), seedOut[3];
equation
(z,seedOut) = random(seedIn);
algorithm
seedIn := seedOut;
end Randomgenerator;*
I have tried nearly all possibilities with algorithm assignments, initial conditions and equations but none of them works. I just simply want to use seedOut in the next time step. One problem seems to be that when entering into the algorithm section, neither the initial conditions nor the values from the equation section are used.
Using the 'sample' and 'reinit' functions the code below will calculate a new random number at the frequency specified in 'sample'. Note the way of defining the "start value" of seedIn.
model Randomgenerator
Real seedIn[3] = {1,23,131};
Real z;
Real[3] seedOut;
equation
(z,seedOut) = random(seedIn);
when sample(1,1) then
reinit(seedIn,pre(seedOut));
end when;
end Randomgenerator;
The 'pre' function allows the use of the previous value of the variable. If this was not used, the output 'z' would have returned a constant value. Two things regarding the 'reinint' function, it requires use of 'when' and requires 'Real' variables/expressions hence seedIn and seedOut are now defined as 'Real'.
The simple "random" generator I used was:
function random
input Real[3] seedIn;
output Real z;
output Real[3] seedOut;
algorithm
seedOut[1] :=seedIn[1] + 1;
seedOut[2] :=seedIn[2] + 5;
seedOut[3] :=seedIn[3] + 10;
z :=(0.1*seedIn[1] + 0.2*seedIn[2] + 0.3*seedIn[3])/(0.5*sum(seedIn));
end random;
Surely there are other ways depending on the application to perform this operation. At least this will give you something to start with. Hope it helps.

Resources