Giter VIP home page Giter VIP logo

Comments (4)

mattia-lecci avatar mattia-lecci commented on August 26, 2024

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.

DvdMgr avatar DvdMgr commented on August 26, 2024

@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.

DvdMgr avatar DvdMgr commented on August 26, 2024

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.

matbord avatar matbord commented on August 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.