Comments (4)
Hi @matbord , you can run three separate simulations with three parameter sets, `i.e.,
params1 = { 'nWifi': [1], 'distance': [1], 'simTime': [15], } runs=2
params2 = { 'nWifi': [2], 'distance': [5], 'simTime': [15], } runs=2
params3 = { 'nWifi': [3], 'distance': [10], 'simTime': [15], } runs=2
You can then query the three results separately and aggregate them manually for plotting purposes.
One option is to get results as xarrays, convert them to dataframes, and concatenate them.
You can then use matplotlib, or even better seaborn to plot your results in an easy and elegant way.
from sem.
@mattia-lecci's solution is correct - note that you can also pass a list of dictionaries to run_missing_simulations
, so something like the following should also work:
params1 = { 'nWifi': [1], 'distance': [1], 'simulationTime': [15], channelWidth: [20]}
params2 = { 'nWifi': [2], 'distance': [5], 'simulationTime': [15], channelWidth: [20]}
params3 = { 'nWifi': [3], 'distance': [10], 'simulationTime': [15], channelWidth: [20]}
params = [params1, params2, params3]
campaign.run_missing_simulations(params, runs=2)
If you want something that is a bit more concise and easier to maintain, you can also do this:
nwifi_to_distance = {1: 1, 2: 5, 3: 10}
params = {
'nWifi': [1, 2, 3],
'distance': lambda p: nwifi_to_distance[p['nWifi']],
'simulationTime': 15,
'channelWidth': [20]
}
campaign.run_missing_simulations(params, runs=2)
In other words, you define a dictionary that specifies the value (or values, if you enter a list) of distance
that you want for each value of nWifi
, and use a lambda function in the parameter definition. When SEM expands the parameter definition, if one of the parameter values is a function, it will call that function with the current parameter dictionary as an argument to obtain the values for that key. Since in this case distance
comes after nWifi
in the order of parameters, you can assume that the argument of the lambda function will be a dictionary that only has a single value for the nWifi
, as that key was already expanded.
Without lambda functions, the previous code block is equivalent to:
distance_from_nwifi = {1: 1, 2: 5, 3: 10}
def get_distance_from_nwifi(param):
return nwifi_to_distance[param['nWifi']]
params = {
'nWifi': [1, 2, 3],
'distance': get_distance_from_nwifi,
'simulationTime': [15],
'channelWidth': [20]
}
campaign.run_missing_simulations(params, runs=2)
All code blocks above should give the following output:
print(["nWifi: %s, distance: %s, RngRun: %s" % (r['params']['nWifi'], r['params']['distance'], r['params']['RngRun']) for r in campaign.db.get_results()])
['nWifi: 1, distance: 1, RngRun: 1',
'nWifi: 1, distance: 1, RngRun: 0',
'nWifi: 2, distance: 5, RngRun: 3',
'nWifi: 2, distance: 5, RngRun: 2',
'nWifi: 3, distance: 10, RngRun: 5',
'nWifi: 3, distance: 10, RngRun: 4']
Note that I just now pushed a small change to make run_missing_simulations
more robust when a list of parameter combinations is passed to it - please consider updating!
from sem.
I just realized that there is no mention of using lambda functions for parameter space definition in the examples, as of now. I'll address this by next week.
from sem.
Perfect thank you for all your support! using lambda is very useful but @mattia-lecci's solution is the best one for me since I would have duplicates values for the key if I used the dictionary
from sem.
Related Issues (20)
- Exporting Output Files from campaign HOT 2
- Exception: ns-3 repository is not clean HOT 5
- A small typing error in readme HOT 1
- Logging with SEM HOT 14
- Absolute path to scratch subdirectories not correctly built HOT 3
- Exception: ns-3 repository is not clean HOT 2
- Compilation ended with an error HOT 5
- Multi CPUs parallel execution HOT 1
- error while running simple example HOT 10
- module 'sem.utils' has no attribute HOT 2
- Using DRMAA clusters for parallel execution of simulations HOT 2
- ModuleNotFoundError: No module named 'sem' DEI Account HOT 4
- invalid argument value when using a lambda / function HOT 1
- Delete specific simualtion from result folder HOT 1
- No module named 'poetry.masonry' HOT 1
- Error: "No such file or directory: 'path-to-ns3/build/build-status.py'" HOT 2
- Support other simulation frameworks
- Output Folder Name
- SEM : FileNotFoundError: [Errno 2] No such file or directory: '/home/aks/IB/new/bake/source/ns-3.36/build/optimized/build-status.p
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sem.