How to do multidimensional scaling by iterative majorization in R manually? Does anyone have an idea how to code Guttman`s transform?
Try smacof, an R package. Be sure to examine the sample data structure str(bread) and figure out how to build it. Guttman's Transform and its matrix algebra is presented in Modern Multidimensional Scaling by Ingwer Borg and Patrick J.F. Groenen, Spring 2005, which was named that by some of the developers of smacof according to Borg and Groenen and also discussed in conjunction with the package (see its Vignette).
Related
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.
I am trying to vectorise a for loop. I have a set of coordinates listed in a [68x200] matrix called plt2, and I have another set of coordinates listed in a [400x1] matrix called trans1. I want to create a three dimensional array called dist1, where in dist1(:,:,1) I have all of the values of plt2 with the first value of trans1 subtracted, all the way through to the end of trans1. I have a for loop like this which works but is very slow:
for i=1:source_points;
dist1(:,:,i)=plt2-trans1(i,1);
end
Thanks for any help.
If I understood correctly, this can be easily solved with bsxfun:
dist1 = bsxfun(#minus, plt2, shiftdim(trans1,-2));
Or, if speed is important, use this equivalent version (thanks to #chappjc), which seems to be much faster:
dist1 = bsxfun(#minus, plt2, reshape(trans1,1,1,[]));
In general, bsxfun is a very useful function for cases like this. Its behaviour can be summarized as follows: for any singleton dimension of any of its two input arrays, it applies an "implicit" for loop to the other array along the same dimension. See the doc for further details.
Vectorizing is a good first optimization, and is usually much easier than going all in writing your own compiled mex-function (in c).
However, the golden middle-way for power users is Matlab Coder (this also applies to slightly harder problems than the one posted, where vectorization is more or less impossible). First, create a small m-file function around the slow code, in your case:
function dist1 = do_some_stuff(source_points,dist1,plt2,trans1)
for i=1:source_points;
dist1(:,:,i)=plt2-trans1(i,1);
end
Then create a simple wrapper function which calls do_some_stuff as well as defines the inputs. This file should really be only 5 rows, with only the bare essentials needed. Matlab Coder uses the wrapper function to understand what typical proper inputs to do_some_stuff are.
You can now fire up the Matlab Coder gui from the Apps section and simply add do_some_stuff under Entry-Point Files. Press Autodefine types and select your wrapper function. Go to build and press build, and you are good to go! This approach usually bumps up the execution speed substantially with almost no effort.
BR
Magnus
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.
i've this photo :
and i'm trying to make Document binarization using niblack algorithm
i've implemented the simple Niblack algorithm
T = mean + K* standardDiviation
and that was it's result:
the problem is there's some parts of the image in which the window doesn't contain any objects so it detects the noise as objects and elaborates them .
i tried to apply blurring filter then global thresholding
that was the result :
which wont be solved by any other filter
i guess the only solution is preventing the algorithm from detecting global noise if the window i free from object
i'm interested to do this using niblack algorithm not using other algorithm so any suggestions ?
i tried sauvola algorithm in this paper Adaptive document image binarization J. Sauvola*, M. PietikaKinen section 3.3
it's a modified version of niblack algorithm which uses a modified equation of niblack
which returned a pretty good answers :
as well as i tried another modification of Niblack which is implemented in this paper
in the 5.5 Algorithm No. 9a: Université de Lyon, INSA, France (C. Wolf, J-M Jolion)
which returned a good results as well :
Did you look here: https://stackoverflow.com/a/9891678/105037
local_mean = imfilter(X, filt, 'symmetric');
local_std = sqrt(imfilter(X .^ 2, filt, 'symmetric'));
X_bin = X >= (local_mean + k_threshold * local_std);
I don't see many options here if you insist to use niblack. You can change the size and type of the filter, and the threshold.
BTW, it seems that your original image has colors. This information can significantly improve black text detection.
There are range of methods that can help in this situation:
Of course, you can change algorithm it self =)
Also it is possible just apply morphology filters: first you apply maximum in the window, and after - minimum. You should tune windows size to achieve a better result, see wiki.
You can choose the hardest but the better way and try to improve Niblack's scheme. It is necessary to increase Niblack's windows size if standard deviation is smaller than some fixed number (should be tuned).
i tried the niblack algorithm with k=-0.99 and windows=990 using optimisation:
Shafait – “Efficient Implementation of Local Adaptive Thresholding
Techniques Using Integral Images”, 2008
with : T = mean + K* standardDiviation; i have this result :
the implementation of algorithm is taken here
http://www.mathworks.com/help/techdoc/ref/fftshift.html
If you check that link - thats what I want to do in the first picture - swap quadrants of a matrix.
However, I cant seem to think of a good way to do this without having several loops to pull out the relevant sub-matrices.
I need it to work with MxN matrices, where M and N can be any combination of even and odd.
Thanks
The following should work
sz = ceil(size(A)/2)
A = A([sz(1)+1:end, 1:sz(1)], [sz(2)+1:end, 1:sz(2)])
That only works for 2d matrices, but can be easily generalized to the Nd case.
If you enter type fftshift.m at MATLAB's command line, you'll see the source code for MATLAB's implementation of the function (use edit fftshift.m if you want to view it in the editor with syntax highlighting). I'm not posting the code here, as it is copyrighted. However, you can try it on your machine and re-implement the same in C. Its up to you to figure out the license terms etc, if you're into any of that.