Feeding arguments to predict_y in gpflow trough feed_dict - gpflow

Is it possible to feed inputs to m.predict_y trough a dictionary? Something similar like in the examples for computing the log likelihood:
model.compute_log_likelihood(feed_dict={x_tensor: x_new, y_tensor: y_new})
#this
model.predict_y(feed_dict={Xnew: x_new})

No, predict_y() expects numpy arrays for the new X, as the new X parameter is handled inside autoflow, which automatically calls session.run(). You can pass in tensors and their values for any other inputs to the graph.
To do what you want to do, you could manually follow what is done in predict_y() [1].
[1] https://github.com/GPflow/GPflow/blob/develop/gpflow/models/model.py#L201

Related

How to find all MATLAB function blocks in a Simulink model

I would like to know how to find all MATLAB function blocks in a Simulink model.
In a model in which I know there are a lot of MATLAB function blocks, I tried the following command:
find_system(myModel,'LookUnderMasks','on','FollowLinks','on','BlockType','MATLAB Function')
However, this command returns an empty cell array. If I try something like this:
find_system(myModel,'LookUnderMasks','on','FollowLinks','on','BlockType','Gain')
, I'm getting many results. Is the "MATLAB Function" an actual BlockType or is there another term to use?
You can use the following code to find all MATLAB function blocks.
S = sfroot();
% Get block handles
B = find(sfroot, '-isa','Stateflow.EMChart');
This will search all open models and returns a list of objects of type Stateflow.EMChart. You can look at the Path property of these objects to reduce the list to the model you want.
You will need to define the search depth use the below:
h=find_system(myModel,'SearchDepth',N, 'regexp', 'on', 'FollowLinks','on','Findall','on','LookUnderMasks','all', 'BlockType','Gain');
Specify N, the higher the N the deeper into the blocks the search will be.
Let me know if this doesn't work.

MATLAB - EEGLAB: surpress GUI for pop_eegfiltnew()

I am working on some scripts for which I use several functions from the EEGLAB package for matlab. Most of these functions make it possible to surpress the GUI from showing, for example using f( ... 'gui','off'), or by using a different version of the same function. However, I can not figure out how to do this for the function pop_eegfiltnew(). Two similar functions are eegfilt(), which seems to be an outdated version of the function, and firfilt() however, pop_eegfiltnew() has more arguments than these other two, so they are certainly not the same in functional terms.
Anyone knows how to get around this?
If you supply enough arguments to pop_eegfiltnew it does not pop up a GUI.
For example if you wanted to filter your signal 1 Hz highpass you would:
EEG = pop_eegfiltnew(EEG, 1, 0);
This is because the first argument of pop_eegfilt is EEG structure, the second is locutoff (lower edge of the passband) and the third is hicutoff (higher edge of the passband).

Why is this error happening: Index exceeds matrix dimensions

I am running a GUI system in MATLAB and I am a beginner with working with GUI's.
The code is extensively long and so I am going to just put in what and where I have things and see if it is enough information for help to be given, thanks.
in my first GUi I have this in the opening function:
HW12_result_bhanford(handles.scan_age, handles.check_athlete, handles.radio_male, handles.radio_female)
this is supposed to be transferring these four variables over to my third GUI named
HW12_result_bhanford
In my second GUI I have this written in the opening function:
age = varargin{1}
athlete = varargin{2}
male = varargin{3}
female = varargin{4}
I then use these four variables(age, athlete, male, female) later in the second GUI and I
assume them to be the equivalent value of the corresponding variable passed from the first
GUI.
When I run everything the error that comes back is Index exceeds matrix dimensions.
if anyone could help me, that would be awesome. If you cannot help without the entire code I understand.
You use varargin if your argument list is variable, and varargin has to be in your function definition.
function HW12_result_bhanford(varargin)
In this case function receive a cell array as an input, so you can get individual arguments with varargin{1} etc.
If you put your arguments together as a structure, you can pass this structure as an argument along.
function HW12_result_bhanford(handles)
But if the function definition has individual arguments, for example,
function HW12_result_bhanford(age, athlete, male, female)
you cannot use varargin, just process the arguments as is.
Read more on how to use VARARGIN.

S-function documentation that "S-function level-1 supports vector inputs and outputs. DOES NOT support multiple input and output ports"

I read in S-function documentation that "S-function level-1 supports vector inputs and outputs. DOES NOT support multiple input and output ports".
Does the second sentence mean the input and output dimension must be the same?
I have been using S-function level-1 to do the following:
[a1, b1] = choose_cells(c, d);
where a1 and b1 are outputs, c and d are inputs. All the variables are having a single value, except d is an array with 6 values.
Referring to the image attached, we all know that in S-function block, the input dimension must be SAME as output dimension, else we will get error, in this case, the input dimension is 7 while the output dimension is 2, so I have to include the "Terminator" blocks in the diagram for it to work perfectly, otherwise, I will get an error.
My problem is, when the system gets bigger, the array d could contain hundreds of variables, using this method, it means I would have to add hundreds of "Terminator" blocks in order to get this work, this definitely does not sound practical.
Could you please suggest me a wise way to implement this?
http://imgur.com/ib6BTTp
http://imageshack.us/content_round.php?page=done&id=4tHclZ2klaGtl66S36zY2KfO5co
Updated: actually I have been trying to convert my level-1 S-function to level-2 but I got stuck at calling another sub function at function Output(block) trying to look for other threads but to no avail, do you mind to provide related links?
My output depends on a lot processing with the inputs, this is the reason I need to call the sub-function in order to calculate and then return output values, all the examples that I can see are calculating their outputs directly in "function Output(block)", in my case I thought it is not possible.
I then tried to use Interpreted Matlab Function block but failed due to the output dimension is NOT the same as input dimension, also it does not support the return of more than ONE output................
Level-1 s-function supports single input and single output port. These ports must be vectors. But there is no restriction on the length. Input and output can have different lengths. You can use selector block to select only relevant data. You do not need to use Bus in the output.
There is also no restriction on calling other sub-functions from Output. If your sub-function is not in the same file it must be in the path or in the current directory.
If your MATLAB code is compatible with MATLAB Function block, I recommend using that block. It is simpler to setup and use.

When using a multiple-output matlab function, do i need to callback all variables?

When using a multiple-output matlab function, do i need to callback all variables? or can I just take the first two variables? (if so..is it not recommended?)
lets say in function.m
[a, b, c] = function( )
in main.m
[var1, var2] = function;
When calling (almost) any function in matlab you can request fewer outputs than it specifies. So, yes the example you give should work perfectly fine.
There are some clever things you can do with this, such as using nargout within a function to see how many output arguments have been requested and only calculating the values that have been requested as an optimisation trick.
It depends on the definition of the function, and exactly which of the outputs you want to get.
Not all the function allow to do it, you can find all the options for each function in the beginning of the help documentation on the specific function.
If you want only the 2nd, or 3rd outputs, and you want also to save the computation-time of the results that does not interesting, you can use ~ option, like this (for versions 2009b and later):
[~, var1, var2]=function
Many functions allow for options to passed that change how the function behaves. I used/wrote various numerical solving functions a bit and one that nice amount of option, for instance is the LSMR function(s).
Otherwise, if you can manipulate the original either introduce an input(s) to do so before or at the end with an inline subroutine to generate the outputs you want.
Or if you can't it will return as either a cell array or a vector and you can pass an anonymous function to generate the desired outputs that way.
Really, can be done many ways. Very contextual.