Range replicator

Jan Lause's Avatar

Jan Lause

20 Jun, 2013 03:39 PM

Dear MWORKs-team,

I use a range replicator to generate a random number ranging from 1 to my EXP_NumberTrials-variable. This number is not hardcoded but parsed into this variable with the help of a plugin, i.e. it changes from its default value to the "real" value provided by an external textfile.

I noticed, that using this variable in the "to"-field of the range replicator object does not cause any error, but uses the default value instead of the value I assign before. This assignment happens before the block containing the range replicator even starts.
As moving the assignment to another protocol also doesn't work, I presume that the range replicator is initialised at the very beginning of everything.

Is this true and if yes, is there any way to work around this?
 

Thanks in advance!

Jan

PS: I also checked whether my EXP_-variable changes accordingly via my plugin(it does!).

  1. Support Staff 1 Posted by Christopher Sta... on 21 Jun, 2013 01:21 PM

    Christopher Stawarz's Avatar

    Hi Jan,

    I presume that the range replicator is initialised at the very beginning of everything.

    Yes, that's correct. Range replicators are expanded at load time, not run time, so they aren't affected by run-time changes you make to variables used in their parameters.

    To help me suggest an appropriate workaround, can you tell me a little more about how your experiment works? How are you using the values generated by the range replicator? Does your plugin just parse a numeric value from a text file and store it in an MWorks variable? Is EXP_NumberTrials fixed at load time, or does it change dynamically (e.g. between protocol runs)?

    Thanks,
    Chris

  2. 2 Posted by Lause, Jan on 26 Jun, 2013 12:22 PM

    Lause, Jan's Avatar

    Hi!
    Thanks for the reply, although it does not sound very promising :-)

    Regarding your questions:

    The random number of the range replicator is used to determine which of the pre-randomised trials (no 1-EXP_NumberTrials) is used (i.e., which line of the external randomisation text file is read in via the plugin). Because of this, it is important that the range replicator is replicating over the range of available trials - which might be different for different protocols, e.g. for training and experiment(using different input files), but should not vary between runs of the same protocol.
    The plugin works as you presumed: A MWORKS variable is changed to the number that is in a specific position in the text file (the requested position is parsed to the plugin via another MWORKS variable)

    It would be nice to have a dynamic(-ready) solution for this - but otherwise we would simply hardcode the number of trials and change the xml when the randomisation changes...

    Thanks for your help!
    Jan

  3. Support Staff 3 Posted by Christopher Sta... on 08 Jul, 2013 02:51 PM

    Christopher Stawarz's Avatar

    Hi Jan,

    Since you're already using a custom plugin, here's an approach that might work for you: Rather than implementing a new component type to read the value of EXP_NumberTrials out of a file, you can implement a new expression-parser function to do that job. Because the initial value of a variable can be specified as an arbitrary expression, you can use your function to initialize EXP_NumberTrials to the correct value, and that value will then be used by the range replicator.

    I've put together a demonstration of this approach, which implements a function similar to what you need (although it substitutes random-number generation for the actual file-reading code). Check out demo.xml to see how the function can be used in an experiment. If you have any questions about how this works, please don't hesitate to ask.

    Chris

  4. Christopher Stawarz closed this discussion on 12 Nov, 2013 04:50 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac