I want to use the bayesreg package within the MATLAB environment, which enables flexible Bayesian penalized regression modelling. I am following a paper, which details the software implementation within the MATLAB environment. I am using the exact instructions available in the paper but do not seem to get the code to work.
I have imported the table containing the data that I want to analyze. I then type the following code:
varnames=finale.Properties.VariableNames;
% count regression
X = finale{:,2:9}
y = finale{:,11}
[beta, beta0, retval] = bayesreg(X,y,'poisson','g','nsamples',1e5,'burnin',1e5,'thin',5,'displayor',true,'varnames',varnames(2:9),'display',true);
X and y are simply my dependent and independent variables, and all arguments of bayesreg are in agreement with the software implementation paper instructions.
I get the below error:
Undefined function or variable 'bayesreg'.
Could anyone shed any light?
In my case, the problem was that I didn't have the Neural Network toolbox installed, as well as another 1-2 packages. Installing those solved the issue.
Related
I'm trying to solve a big quadratic optimization problem using CPLEX (cplexqp) in matlab. Unfortunately by H matrix (or Q matrix as some sources call it) is non-convex in nature and thus I want to set the optimality target from 0 (default) to 3 to tell CPLEX to not terminate when finding out Q is non-convex. However, I'm not sure how to do this. I tried to read the manuals and instructions and they all just said set optimality target = 2 or 3 without any actual examples or general command on how to do it. I tried to do it in options but got an error that CPLEX doesn't recognize 'optimalitytarget'.
options = cplexoptimset('Display','on','TolFun',0.0000001,'TolRLPFun',0.0000001,'MaxNodes',50000,'MaxIter',50000, 'optimalitytarget',3);
I also tried:
Cplex = cplexoptimset('cplex')
Cplex.Param.optimalitytarget = 3;
without any sucess. I know it the API is Cplex.Param.optimalitytarget but I cannot seem to figure out where to set this.
Sorry if this is a trivial or dumb question. I feel like this is one of the things that's very simple and either you do know or you don't know and I don't know how to do it. Any help or advice on going about this is greatly appreciated.
You can find examples of using CPLEX from within MATLAB in the distribution. They are located in [installPath]/cplex/examples/src/matlab.
You mentioned that you are using cplexqp, which is the toolbox API. Looking at https://www.ibm.com/support/knowledgecenter/es/SSSA5P_12.7.0/ilog.odms.cplex.help/CPLEX/MATLAB/topics/gs_param.html, I suspect that the issue with your second example is with your using Param. That structure relates to the Cplex Class API, not the toolbox API. I suppose that the following would work better:
options = cplexoptimset('cplex');
options.optimalitytarget=3;
Model = cplex.Cplex("filename.mps")
Model.parameters.optimalitytarget.set(float(3))
This worked for me!
I want to run MATLAB 2015b algorithm on Android device through NDK. So I need a standalone c code from algorithm. I used Matlab Coder for this, But I get this error:
The function 'bwboundaries' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation.`
I used this function in this way:
[B,L]=bwboundaries(h1);
the h1 is an 280*500 logical array which comes from a Black & White image.
I searched and found this list: Functions and Objects Supported for C and C++ Code Generation
As we see there the bwboundaries declared in the list:
bwboundaries :
The conn and options arguments must be compile-time constants and the return value A can only be a full matrix, not a sparse matrix.
If you choose the generic MATLAB Host Computer target platform, generated code uses a precompiled, platform-specific shared library.
MATLAB Function Block support: No.
I don't understand it!! How should I use this function to have its c code?
OR Is there any function to use instead?
I see this SO questions which didn't help me:
q1 q2 q3
I have few continuous variables that look like this:
durs1=[3,40933 0,033630 0,25103 0,6361 0,71971 1,18311 1,91946 0,12842 0,97639 1,1383 0,46871 3,05241 2,34907 1,03788 0,76434 1,08798 1,462 0,4241 2,32128 0,29017..]
Each has more than 1000 values (all positive). I used
[a, b]=gamfit(durs1)
a =
2.3812 0.4200
b =
2.2316 0.3907
2.5408 0.4514
to find parameters of gamma distribution. Now I want to make a goodness of fit test in order to see how well the model fits my data. Matlab provides the one sample Kolmogorov-Smirnov test to solve the problem (http://www.mathworks.com/help/stats/kstest.html#btnyrvz-1)
But when I run my code (based on their examples):
test_cdf=makedist('Gamma','a',2.38,'b',0.42)
[h, p]=kstest(durs1,'CDF',test_cdf)
I have this error: "Undefined function 'makedist' for input arguments of type 'char'."
Can somebody help me to fix my code?
It seems like the function makedist of the statistics toolbox is available only from Matlab version r2013a. Looking in the documentation of earlier versions, even as late as r2012b, there is no mention of makedist. So I think updating to the latest version of matlab should solve your problem.
we are trying to integrate a simulation model into Simulink as a block. We have a custom continuous block which loads an m file that contains the functions Derivatives, Outputs etc.
My question is: is there a way to find out which solver is used currently and with which parameters? Our model won't be able to support variable time solvers and I would like to give a warning. Similarly, the model requires the fixed step time for initialization.
Thanks in advance.
You can get the current solver name using
get_param('modelName', 'SolverName');
Some of the other common solver parameters are
AbsTol
FixedStep
InitialStep
ZcThreshold
ExtrapolationOrder
MaxStep
MinStep
RelTol
SolverMode
You can find other parameters you may wish to query by opening the .mdl file in your favorite text editor and digging through it.
If I'm understanding your use case correctly, you are trying to determine the type of solver (and other solver params) for the top-level simulink system containing your block.
I think the following should give you what you want:
get_param(bdroot, 'SolverType'); % //Returns 'Variable-step' or 'Fixed-step'
get_param(bdroot, 'FixedStep'); % //Returns the fixed step size
Notice that for purposes of generality/reusability, this uses bdroot to identify the top-level system (rather than explicitly specifying the name of this system).
If you want to find out more about other model parameters that you can get/set, I would check out this doc.
Additionally, I'm interested to know why it is that your model doesn't support a variable-step solver?
In MatLab, "> help bi2de" provides the following example:
B = [0 0 1 1; 1 0 1 0];
D = bi2de(B)
But when I try this on my own, I get the following error:
??? Undefined function or method 'bi2de' for input arguments of type 'double'.
Is there something wrong with this function in MatLab?
I am pretty sure that the reason why this problem happened is because of the license of the toolbox, Communications system toolbook, in which this function belongs in. Write which bi2de and see what will be the result. If it returns path of the function and the comment Has no license available, then the problem is related to the license. That means, license of the toolbox is not set correctly. Mostly it happens if the toolbox is added later, i.e., after installation of the original matlab. Please check and solve the license issue, then it will work fine.
bi2de is a function in the Communications toolbox. You need to have that toolbox to use it. If you do have that toolbox, then the problem is that your B matrix is being treated as double instead of binary (I don't have the toolbox so I can't test this).
Consider using bin2dec, which turns a string representation ('1011001', eg) into a decimal number. This function is not part of a toolbox; it's available as part of the basic MATLAB package.