First of all, I want to mention that this is my homework. However, to solve my problem I can use any literature I want.
Even though I think that problem is clear from its name, I will give it description: "For given undirected graph G and given integer k, does G contain totally connected (clique) subgraph of size k or totally disconnected subgraph (independent set) of size k."
I know about polynomial reductions from 3-SAT to CLIQUE and from 3-SAT to INDEPENDENT-SET. (http://mlnotes.com/2013/04/29/npc.html) However, I have problem with this one because I cannot combine those two reductions. I also tried reduction from CLIQUE to CLIQUE-OR-INDEPENDENT-SET but without much success.
So I would really appreciate any hints!
Thanks in advance.
I found out reduction from problem INDEPENDENT-SET to CLIQUE-OR-INDEPENDENT-SET. All you need to do is to add n isolated vertices to graph G (which is an instance of INDEPENDENT-SET and has n vertices). Let call this newly created graph G' (instance of CLIQUE-OR-INDEPENDENT-SET). Then it is not hard to prove that G has k independent-set iff G' has n+k independent-set of clique (since, by construction, it cannot have n+kclique).
Related
I have two matrices S and T which have n columns and a row vector v of length n. By my construction, I know that S does not have any duplicates. What I'm looking for is a fast way to find out whether or not the row vector v appears as one of the rows of S. Currently I'm using the test
if min([sum(abs(S - repmat(f,size(S,1),1)),2);sum(abs(T - repmat(v,size(dS_new,1),1)),2)]) ~= 0 ....
When I first wrote it, I had a for loop testing each (I knew this would be slow, I was just making sure the whole thing worked first). I then changed this to defining a matrix diff by the two components above and then summing, but this was slightly slower than the above.
All the stuff I've found online says to use the function unique. However, this is very slow as it orders my matrix after. I don't need this, and it's a massively waste of time (it makes the process really slow). This is a bottleneck in my code -- taking nearly 90% of the run time. If anyone has any advice as how to speed this up, I'd be most appreciative!
I imagine there's a fairly straightforward way, but I'm not that experienced with Matlab (fairly, just not lots). I know how to use basic stuff, but not some of the more specialist functions.
Thanks!
To clarify following Sardar_Usama's comment, I want this to work for a matrix with any number of rows and a single vector. I'd forgotten to mention that the elements are all in the set {0,1,...,q-1}. I don't know whether that helps or not to make it faster!
You may want this:
ismember(v,S,'rows')
and replace arguments S and v to get indices of duplicates
ismember(S,v,'rows')
Or
for test if v is member of S:
any(all(bsxfun(#eq,S,v,2))
this returns logical indices of all duplicates
all(bsxfun(#eq,S,v),2)
I have a linear system to solve, written as Ax=b
A is a 175 by 175 symmetric square, with ones at it's diagonal (i.e., aii=1), and other entries ranges from 0 to 1(i.e., 0
A is very ill conditioned, and not positive definite, its rank is 162 and its condition number is 3.5869e+16
I spent several days to solve this in MATLAB, I've tried almost every method I can find, including \, pcg, bicg, bicgstab, bicgstabl, cgs, gmres, lsqr, minres, qmr, symmlq, tfqmr
These methods gave me some solutions. But I don't know how to trust them, or which solution to trust. Is there a criteria to determine?
I'll appreciate someone who can give me a solution that I can trust.
Thanks!
A and b are stored in .mat files and can be download from dropbox links:
https://www.dropbox.com/s/s6xlbq68juqs6xi/A.mat?dl=0
https://www.dropbox.com/s/pxl0hdup20hf2lr/b.mat?dl=0
use like this:
load('A.mat');
load('b.mat');
x = A\b;
Not sure if this will help, but give it a go:
Tikhonov regularization
Basically, when the following is hard to compute due to ill-conditiones:
You minimize the following instead
Being \Gamma generally the identity matrix.
In the end, you get the following equation for x:
To add to that, you will generally want to add an "hyperparameter", to control how much you regularize the problem. So \Gamma instead of being just the identity matrix, it will be a number (i.e. 0.001) multiplied by the identity matrix of size(A).
The last equation should be straightforward to try in Matlab. Give it a go.
NOTE: this is not the answer. Actually probably there is no unique answer to solving an ill posed problem. This is just a way to go.
I'm having a problem trying to use YALMIP; I suspect I'm doing something silly and I would greatly appreciate if someone pointed out what it is.
I'm trying to solve some SDPs. When I don't define an objective, YALMIP returns a solution (implying that the problem is feasible). However, when I attach an objective to it, YALMIP returns that the problem is infeasible, which has left me a bit perplexed.
Here's the code for the simplest SDP I could cook up in which the above happens. Declaring the variables and setting the constraints is as follows:
y = sdpvar(6,1);
M = sdpvar(3,3);
C = [0,0,0,0,0,0; 0,0,0,0,0,0; -2,0,1.8,0,2,1; 0,0,0,0,0,0; 1,0,-1,0,-1.2,0;
0,0,0,0,0,0;];
F = [C*y==0, y(6) == 1, M>=0];
F = [F,M(1,1) == y(1), M(2,1) == y(2), M(3,1) == y(3),...
M(2,2) == y(4), M(3,2) == y(5), M(3,3) == y(6)];
Now if I merely ask YALMIP to find a feasible solution with
solvesdp(F)
it returns
info: 'Successfully solved (LMILAB)'
problem: 0
and some feasible M and y (I've checked that they indeed are). However, if I append the objective "minimise y(3)" (or indeed any linear combination of the entries of y) with
solvesdp(F,y(3))
it returns that the problem is infeasible:
info: 'Infeasible problem (LMILAB)'
problem: 1
and y and M are full of "NaN" tokens.
Many thanks in advance.
LMILAB should not be used together with YALMIP.
http://users.isy.liu.se/johanl/yalmip/pmwiki.php?n=Solvers.LMILAB
The solver in LMILAB has many deficiencies, and one which becomes crucial here is the fact that the solver lacks support for inequalities. To circumvent this, YALMIP adds double-sided inequalities, which completely destroys the numerical procedures of LMILAB.
Install a more general (and modern) solver such as SeDuMi, SDPT3, or Mosek
http://users.isy.liu.se/johanl/yalmip/pmwiki.php?n=Category.SemidefiniteProgrammingSolver
BTW, you are redundantly defining additional variables y. No reason to have them as separate decision variables and then encode how they relate to M. Simply extract them
y = M(find(tril(ones(3))));
I have 2 sets of data of float numbers, set A and set B. Both of them are matrices of size 40*40. I would like to find out which set is closer to the normal distribution. I know how to use probplot() in matlab to plot the probability of one set. However, I do not know how to find out the level of the fitness of the distribution is.
In python, when people use problot, a parameter ,R^2, shows how good the distribution of the data is against to the normal distribution. The closer the R^2 value to value 1, the better the fitness is. Thus, I can simply use the function to compare two set of data by their R^2 value. However, because of some machine problem, I can not use the python in my current machine. Is there such parameter or function similar to the R^2 value in matlab ?
Thank you very much,
Fitting a curve or surface to data and obtaining the goodness of fit, i.e., sse, rsquare, dfe, adjrsquare, rmse, can be done using the function fit. More info here...
The approach of #nate (+1) is definitely one possible way of going about this problem. However, the statistician in me is compelled to suggest the following alternative (that does, alas, require the statistics toolbox - but you have this if you have the student version):
Given that your data is Normal (not Multivariate normal), consider using the Jarque-Bera test.
Jarque-Bera tests the null hypothesis that a given dataset is generated by a Normal distribution, versus the alternative that it is generated by some other distribution. If the Jarque-Bera test statistic is less than some critical value, then we fail to reject the null hypothesis.
So how does this help with the goodness-of-fit problem? Well, the larger the test statistic, the more "non-Normal" the data is. The smaller the test statistic, the more "Normal" the data is.
So, assuming you have converted your matrices into two vectors, A and B (each should be 1600 by 1 based on the dimensions you provide in the question), you could do the following:
%# Build sample data
A = randn(1600, 1);
B = rand(1600, 1);
%# Perform JB test
[ANormal, ~, AStat] = jbtest(A);
[BNormal, ~, BStat] = jbtest(B);
%# Display result
if AStat < BStat
disp('A is closer to normal');
else
disp('B is closer to normal');
end
As a little bonus of doing things this way, ANormal and BNormal tell you whether you can reject or fail to reject the null hypothesis that the sample in A or B comes from a normal distribution! Specifically, if ANormal is 1, then you fail to reject the null (ie the test statistic indicates that A is probably drawn from a Normal). If ANormal is 0, then the data in A is probably not generated from a Normal distribution.
CAUTION: The approach I've advocated here is only valid if A and B are the same size, but you've indicated in the question that they are :-)
I would like to obtain all the permutations with replacement of d elements chosen in a set of n elements (which are numbers from 0 to n-1) in MATLAB. I noticed that on MATLAB Central the method npermutek is available, but I would like to try another implementation.
My idea is to make d for loops, one inside the other, each varying an index from 0 to n-1: i.e., d recursions over a line (from 0 to n-1). However, n and d should be parameters of my code, so I cannot implement my idea of d for loops one inside the other... or could I? Do you have any suggestions?
Thank you for your attention.
I'd suggest you use combn on the File Exchange.
I use combinator. Perhaps somebody should run a benchmark to see which implementation is best.