f



listing all subsets of a given set

Hi All,

Is there a function in MATLAB that produces all subsets of a given
set?

Or alternatively, what is an efficient way to list all subsets in
MATLAB?

The original set is a vector of indices (integers).

(context: I need this for some model-selection experiments in
regression analysis.)
0
mahani (4)
9/4/2004 8:47:27 PM
comp.soft-sys.matlab 210158 articles. 11 followers. lunamoonmoon (258) is leader. Post Follow

4 Replies
1173 Views

Similar Articles

[PageSpeed] 12

I wrote a simple recursive function that does the job with the
following performance compared to "perms" in MATLAB:

Number Number
of of time time
elements repetitions perms my-function
------------------------------------------
% 4 1000 0.2 0.23
% 5 1000 0.36 0.491
% 6 1000 0.851 1.022
% 7 1000 7.291 2.013
% 8 100 6.119 0.41
% 9 10 7.041 0.09

(Of course, for n>4 the two are not directly comparable: 2^5=32
5!=120)

If there are faster algorithms please let me know.

reza

reza mahani wrote:
>
>
> Hi All,
>
> Is there a function in MATLAB that produces all subsets of a given
> set?
>
> Or alternatively, what is an efficient way to list all subsets in
> MATLAB?
>
> The original set is a vector of indices (integers).
>
> (context: I need this for some model-selection experiments in
> regression analysis.)
0
mahani (4)
9/5/2004 2:17:23 AM
reza:
<SNIP favorably compares his/her algo to ML's <perms> and
asks for even better ways of doing it...

well, could you show CSSM your code?
us
0
us1 (8051)
9/5/2004 2:23:17 AM
function S = AllSubsets(V)
% 9/4/04: [Reza Mahani]

% Lists all subsets of a set given by the vector V of length
n.

% Assumption: No "nan" in V.

% I use a "recursive" algorithm, AllSubsets call itself on
one-element-smaller subsets.

% CALL: S = AllSubsets(V)

[m n] = size(V);

if m>n, n=m; V=V'; end % makes V a row vector

S = nan*zeros(2^n,n); % initialization

%

i0 = 1;

%

if max(m,n)==1

    S(i0,:) = V;

    return

end

if n==2

    S(i0:i0+2,:) = [V ; V(1) nan ; nan V(2)];

    return

end

for i=1:(n-1)

    S1 = AllSubsets(V(i+1:n));

    S(i0:i0+2^(n-i)-1,i:n) = [ones(2^(n-i),1)*V(i) , S1];

    i0 = i0 + 2^(n-i);

end

S(i0,n) = V(n);

return
0
mahani (4)
9/5/2004 2:33:59 AM
I just found out how stupid was my question. The following line gives
the result:

---------------------------------------

function SI = AllSubsets2(n)

SI = dec2bin(0:2^n-1,n);

---------------------------------------

Yes, just one line. However, my previous code was not very bad, see
how the two are compared:

      n repetitions first second
    3.0000 100.0000 0.0100 0.0100
    4.0000 100.0000 0.0200 0.0200
    5.0000 100.0000 0.0500 0.0100
    6.0000 100.0000 0.1010 0.0200
    7.0000 100.0000 0.2010 0.0400
    8.0000 100.0000 0.4110 0.0600
0
mahani (4)
9/5/2004 8:22:16 PM
Reply:

Similar Artilces:

List of lists of lists of lists...
I would like to have a list of lists N times deep, and my solution is (in pseudocode): def deep(x): a=[x] return a mylist=[] for N: mylist=deep(mylist) Is there a more elegant way to do it? The maine idea is: from a list having the numbre of steps along N dimensions, generate a list with an item at each possible point. Example 1: N=2 list=[2,3] result=[[1,2],[1,2],[1,2]] Example 2: N=3 list=[3,1,2] result=[[[1,2,3]],[[1,2,3]]] -- Ángel Gutiérrez Rodríguez - agr@fq.uniovi.es Instituto de Ciencia de los Materiales de Madrid - CSIC SpLine - European Syncrothorn Radiat...

list of all possible subsets of a set
I want to divide an array [1 .. N] all integers and array is sorted into k segments. The output should be a list of all possible k-subset no permutation allowed All subsets should have at least two elements but this is easy to do. f.e. k=2, N=5 ===> a=[1 2 3 4 5] [1] [2 3 4 5] less than 2 elements in set - delete [1 2 3 4] [5] less than 2 elements in set - delete [1 2] [3 4 5] [1 2 3] [4 5] k=3 [1] [2 3] [4 5] [1] [2 3 4] [5] [1] [2] [3 4 5] [1 2] [3] [4 5] [1 2 3] [ 4] [5] (actually for this case there is no solution - all cases have one subset of one element. ...

Breaking Python list into set-length list of lists
Hey everyone-- I'm pretty new to Python, & I need to do something that's incredibly simple, but combing my Python Cookbook & googling hasn't helped me out too much yet, and my brain is very, very tired & flaccid @ the moment.... I have a list of objects, simply called "list". I need to break it into an array (list of lists) wherein each sublist is the length of the variable "items_per_page". So array[0] would go from array[0][0] to array[0][items_per_page], then bump up to array[1][0] - array[1] [items_per_page], until all the items in the origin...

Find all subset of given set in a table
Hi all, i have a problem, i have a table like this: A | B ------------ 1 | 1 1 | 2 2 | 1 2 | 4 2 | 5 3 | 3 and a given set like C=('1', '2', '3'). I would to retrieve all A where B of A is a subset of the set C, in this example the result will be 1 and 3. Is this possible with low complexity and with a single query? Thanks, Igor Igor wrote: > Hi all, > > i have a problem, i have a table like this: > > A | B > ------------ > 1 | 1 > 1 | 2 > 2 | 1 > 2 | 4 > 2 | 5 > 3 | 3 >...

list of unique non-subset sets
Hi, I have many set objects some of which can contain same group of object while others can be subset of the other. Given a list of sets, I need to get a list of unique sets such that non of the set is an subset of another or contain exactly the same members. Tried to do the following: s1=set(['a','b','c']) s2=set(['a','c']) s3=set(['a','d','e','f']) s4=set(['r','k','l']) s5=set(['r','k','l']) L=[s1,s2,s3,s4,s5] ----------------------- > cleaned-up list should contain s1,...

Calculate the Correlation Coefficient of Subsets of a given set
Hi guys I wanna calculate the correlation coefficient of all subsets of a given sets. I know how I can calculate the CC of each subset but the problem is that how I can extract all the subsets and found each subset contains which members of set. Best Regards Mojgan "Mojgan " <ariamahsa@yahoo.com> wrote in message <kkd1fk$i0u$1@newscl01ah.mathworks.com>... > Hi guys > > I wanna calculate the correlation coefficient of all subsets of a given sets. > I know how I can calculate the CC of each subset but the problem is that how I can extract all the ...

list of lists of lists ....
Hi, I have a list of data (type A) my list can includes element of type A or a lists, these list can includes element of type A or a lists, and so on ... is there a simple way to obtain a single list of all the elemets of type A ? thanks yomgui I forgot the most important, I am looking for a non recursive method. thanks yomgui yomgui wrote: > > Hi, > > I have a list of data (type A) > my list can includes element of type A or a lists, > these list can includes element of type A or a lists, and so on ... > > is there a simple way to obtain a single list of all the elemets > of type A ? > > thanks > > yomgui recursion. def get_As(L): res = [] for elem in L: if isinstance(elem, A): res.append(elem) elif isinstance(elem, list): res += get_As(elem) return res i also have a Tree class in my rc: http://home.comcast.net/~faulkner612/programming/python/pythonrc.py yomgui wrote: > Hi, > > I have a list of data (type A) > my list can includes element of type A or a lists, > these list can includes element of type A or a lists, and so on ... > > is there a simple way to obtain a single list of all the elemets > of type A ? > > thanks > > yomgui doh. ok, so, recursion is just functional programming sugar for a loop. def get_As(L): checking = [elem for elem in L if isinstance(elem, list)] # the equivalent of elem in recursion all_As =...

set a attribute to random values in a given list
Hi, I like to have a SQL script which could update a table to set one attribute to a random value picked from a given list. The prototyping code is as below: select @value_list = ('John', 'David', 'Mathew', 'Paul') .... update EMP set emp_name = @random_name where ... where random name is randomly got from the given list. Of course there will be a cursor so that different row may have different random name but not necessary unique. Also the attribute and the list could be any valid common SQL data types Thanks! Ximing "Ximing Zheng" <xz...

Sort a List, in a List of Lists of Lists
Dear Mathgroup, I have a lsit of Lists of Lists: {{{1,2},{2,1},{1,1}},{{1,1},{1,1},{1,2}},{{2,1},{2,2},{1,2}},{{2,2},{1,2},{2,2}},{{1,1},{2,1},{1,2}},{{1,2},{2,2},{2,2}}} I would like to sort the elements in the lowest level of brackets to give {{{1, 2}, {1, 2}, {1, 1}}, {{1, 1}, {1, 1}, {1, 2}}, {{1, 2}, {2, 2}, {1, 2}}, {{2, 2}, {1, 2}, {2, 2}}, {{1, 1}, {1, 2}, {1, 2}}, {{1, 2}, {2, 2}, {2, 2}}} i.e retaining the same structure with the paired elements in the original order. I can't seem to get the syntax right to do this apart from the obvious {{Sort[{1,...

Algorithm to combine or-sets of and-sets, where each element of an and-set is an or-set of and-sets
As part of an abduction procedure, see http://code.google.com/p/biohacker/source/browse/trunk/BPS/ltms/abduction.lisp if interested, I need to efficiently solve the following problem: Given an or-set of and-sets, for example, (:OR (:AND A B C) (:AND D E A)) and given a dictionary, where each element of an and-set is listed, with another or-set of and-sets as value, for example, A -> (:OR (:AND 1 2) (:AND 3 4)) B -> (:OR (:AND 2 3) (:AND 4)) C -> (:OR (:AND 1) (:AND 3)) D -> (:OR (:AND 1) (:AND 3 4)) E -> (:OR (:AND 1 2) (:AND 3)) find a new minimal or-set of and-set consistent,...

Re: Sort a List, in a List of Lists of Lists
On 11/13/10 at 12:59 AM, leigh.pascoe@inserm.fr wrote: >I have a lsit of Lists of Lists: >{{{1,2},{2,1},{1,1}},{{1,1},{1,1},{1,2}},{{2,1},{2,2},{1,2}},{{2,2}, >{1,2},{2,2}},{{1,1},{2,1},{1,2}},{{1,2},{2, 2},{2,2}}} >I would like to sort the elements in the lowest level of brackets to >give >{{{1, 2}, {1, 2}, {1, 1}}, {{1, 1}, {1, 1}, {1, 2}}, {{1, 2}, {2, >2}, {1, 2}}, {{2, 2}, {1, 2}, {2, 2}}, {{1, 1}, {1, 2}, {1, 2}}, >{{1, 2}, {2, 2}, {2, 2}}} >i.e retaining the same structure with the paired elements in the >original order. I can't seem...

How to list all files with an ACL and also list the ACL settings
Hi, I am using AIX 5.3 with MP 7 and I am investigating the use of ACL=92s to assist in setting various security constraints. I have found that you can use ls and find to obtain a list of the objects that have ACL=92s applied to them. The command =93find=94 with the =93-ea=94 option appears to be the better option of the two. My question is: Is there any tool available on AIX that will keep a list of the objects and their applied ACL=92s in a file or files. I could write a script to do all of this by making use of find and aclget. However if there is already a tool or script etc that is...

Set matlab = GetObject(, "Matlab.Application")
How can I address via COM interface to existing instance of MATLAB from VBA. This construction doesnt work: Set matlab = GetObject(, "Matlab.Application") It is a bug or a feature? JackFrost wrote: > > > How can I address via COM interface to existing instance of MATLAB > from VBA. > > This construction doesnt work: > Set matlab = GetObject(, "Matlab.Application") > > It is a bug or a feature? Try to use FindWindow. > > Try to use FindWindow. HWND = FindWindowA("0", "MATLAB") it is possible to find handle of MATLAB ...

function for searching a given path list for a given file
Hi, I am looking for a c callable function to search a path list for a given file. Many thanks in advance, Aaron On 7/28/2010 5:22 PM, Aaron Gray wrote: > Hi, > > I am looking for a c callable function to search a path list for a given > file. I think what you are after is globbing capabilities. http://www.gnu.org/s/libc/manual/html_node/Globbing.html#Globbing Does that link give you a head start for what you want? ...

Copying a List to a List of Lists
Hi, I am having trouble with the following: I wish to have a list of lists of type Double called A. I then have a separate List of Doubles called B which i wish to add to A. I then want to be able to clear B and reuse it without clearing what I have added to A. Currently my code looks like: for(int i=0;i<seqLength;i++) { B.clear(); for(int j=i+1;j<seqLength;j++) { if(fourGameteTest(i,j)) { B.add(segPositions.get(j)); } } A.get(i).add(B); } However, it seems that due to, I guess the element held in A being a reference to the same pl...

List of Atom or List of List??
how can detect some element of list is list o Atom?? for example when i try head (head p1) where p1=[[1,2],2] return 1 but when try head (head p1) where p1=[1,2] it returns Error plz help me..it my project and i have just 2 hours..:( i want to replace on Atom by another in list..for example: replace 1 2 [1,2] => [2,2] but sometime i have replace 1 2 [[1,2],2]=>[[2,2],2] i want to detect if first element of list is list then recurcively call head on that element.. is there any solutions?? On 8 Apr 2007 02:46:25 -0700, kheirandish.amin@gmail.com wrote: >how can detect some element of list is list o Atom?? (list? 42) --> #f (list? '(42 37)) --> #t Steve Schafer Fenestra Technologies Corp. http://www.fenestra.com/ in Haskell plz, not Scheme In article <1176025585.229021.233310@w1g2000hsg.googlegroups.com>, <kheirandish.amin@gmail.com> wrote: > how can detect some element of list is list o Atom?? What is an atom? That is term is not commonly used with Haskell. > for example > when i try head (head p1) where p1=[[1,2],2] return 1 > but when try head (head p1) where p1=[1,2] it returns Error It doesn't _return_ an error, but your expression fails to type-check. Haskell's lists are homogeneous, i.e. all the elements are of the same type. So either _all_ elements are lists (in which case the list of lists has type [[a]] for some type a), or none of them are (in which case the list has type [b] for some type ...

How to have a list of lists (or array of lists)
Hi, I want to have many lists, such as list0, list1, list2, ..., each one holding different number of items. Is there something like list[0] list[1] list[2] so that I can iterate through this list of lists? Thanks! bahoo On Apr 3, 7:12 pm, "bahoo" <b83503...@yahoo.com> wrote: > Hi, > > I want to have many lists, such as list0, list1, list2, ..., each one > holding different number of items. > Is there something like > list[0] > list[1] > list[2] > > so that I can iterate through this list of lists? > > Thanks! > bahoo listOfLists = [...

Extracting a List from a List of lists
Hi, I have an ArrayList of ArrayLists. I want to extract all the lists, but I dont know how many ArrayLists will be in the ArrayList. I know I can do it if i know how many lists are there using the ArrayList get() method. this is how i'm doing it List<String> list1 = new ArrayList<String>(); list1 = res.get(0); List<String> list1 = new ArrayList<String>(); list2 = res.get(1); List<String> list1 = new ArrayList<String>(); list3 = res.get(2); But if theres only two lists in the list i get a NullPointerException Is there any way i can loop through the l...

convert list of lists to list
Is there a way to convert list_of_listsA to list_of_listsB, where one list in listof lists A is one element of listB? list_of_listsA: [['klas*', '*', '*'], ['mooi*', '*', '*', '*'], ['koe'], ['arm*', '*', '*(haar)'], ['groei*', '*', '*', '*', '*']] listB: ['klas* * *', 'mooi* * * *, 'koe', 'arm* * * (haar)', 'groei* * * * *'] Thankx! antar2 wrote: > Is there a way to convert list_of_listsA to list_of_listsB, where one >...

list*list
There must be a better way to multiply the elements of one list by another: a = [1,2,3] b = [1,2,3] c = [] for i in range(len(a)): c.append(a[i]*b[i]) a = c print a [1, 4, 9] Perhaps a list comprehension or is this better addressed by NumPy? Thanks, jab > There must be a better way to multiply the elements of one list by > another: > > a = [1,2,3] > b = [1,2,3] > c = [] > for i in range(len(a)): > c.append(a[i]*b[i]) > a = c > print a > [1, 4, 9] > > Perhaps a list comprehension or is this better addressed by NumPy? First of all: it's ...

List of lists
How do I extract a list of lists from a user defined function and print the results as strings for each list? On Fri, 27 Jun 2003 01:44:42 GMT, Mike wrote: > How do I extract a list of lists from a user defined function Depends how that function is returning its values. The most obvious, and simplest way to do what you describe, is to have the function return a list of lists, as its return value. If you mean something else, you'll have to be more descriptive of what you actually want to do. > and print the results as strings for each list? The 'repr()' method of any o...

Lists of lists
I've written a simple forum. The posts are lists of lists of lists... Each new list steps out the left margin. What happens is that after so many replies the lists get pushed too far right. I'd like to reset the list margin back to the beginning. for ex: ul > ul>ul> ul > ul... { margin-left: original thread left position; ??? position: absolute; left 0; } For ex: http://earlymorningreport.com/test_zig_zag_lists.html I would think this would not be an uncommon request. How now can we do this (other than that)? Jeff In article <jpom3b...

Lists from Lists
Can anyone tell me how can I make a list from all the first elements of the following pairs? l:=[[1,2],[3,4],[5,6],[7,8]] ; to get, m:=[1,3,5,7]; Thanks, Tony Connell "Tony Connell" <a.connell@galileo.karoo.co.uk> wrote in message news:vfk59prj7bp0fb@corp.supernews.com... > Can anyone tell me how can I make a list from all the first elements of the > following pairs? > > l:=[[1,2],[3,4],[5,6],[7,8]] ; > > to get, > > m:=[1,3,5,7]; > If you know the length of the list you could do like this: > m:=[seq(l[i][1], i=1..4)]; -Reidar Kind Tony Connell" <a.connell@galileo.karoo.co.uk> wrote: > Can anyone tell me how can I make a list from all the first elements of > the following pairs? > l:=[[1,2],[3,4],[5,6],[7,8]] ; map2(op, 1, l); "Tony Connell" <a.connell@galileo.karoo.co.uk> wrote in message news:vfk59prj7bp0fb@corp.supernews.com... > Can anyone tell me how can I make a list from all the first elements of the > following pairs? > > l:=[[1,2],[3,4],[5,6],[7,8]] ; > > to get, > > m:=[1,3,5,7]; m:=l[1..-1,1]; Alec Mihailovs http://webpages.shepherd.edu/amihailo/ "Reidar Kind" <s989788@stud.nhh.no> wrote in message news:A%oKa.13616$KF1.276672@amstwist00... > > "Tony Connell" <a.connell@galileo.karoo.co.uk> wrote in message > news:vfk59prj7bp0fb@cor...

list with Matlab
HI, is it possible to have a list with Matlab ? for instance, distance = ['euclidean', 'seuclidean', 'cityblock', 'mahalanobis', 'minkowski', 'cosine', 'correlation', 'hamming', 'jaccard'] linkage =['single', 'complete', 'average', 'centroid', 'ward'] Late on I have to use commends like, for i=1:9 for j=1:5 Y=pdist(X, distance); Z=linkage(Y, linkage); %% to verify cluster tree using cophenet correlation coefficient c = cophenet(Z, Y) end end Bin Jiang wrote > HI, is i...

Web resources about - listing all subsets of a given set - comp.soft-sys.matlab

Listing - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Heritage listing push for Sydney's iconic Sirius building
The NSW Environment Minister says he will consider a recommendation from the state's Heritage Council to protect the iconic Sirius building on ...

'Cape Breton if Trumps Wins' draws thousands to real estate listings
The web site 'Cape Breton if Donald Trump Wins' continues to gain momentum, attracting international attention and drawing tens of thousands ...

Australian Grains Champion's secret plot for CBH listing
Country Western Australia isn't the easiest place to secretly plot a potential $3 billion deal to list the nation's biggest grains exporter, ...

Why a back-door listing on the Australian Stock Exchange isn't right for all startups
When Buddy Platform chose the Australian Stock Exchange (ASX) over U.S. venture capital firms, the Seattle startup raised more money at a higher ...

Reseller Listing From Dubai Provides Best Shots of LG G5 Yet
A listing on a reseller site out of Dubai has provided a few unique, close and personal photos of the LG G5 . Until today, we have seen the device ...

NYU says Craigslist sucks at spotting fake rental listings
Researchers at New York University claim that Craigslist has a serious problem identifying fraudulent listings. After digging through two million ...

Airbnb Deleted Listings Before Posting Data In New York City
The listings "did not reflect Airbnb's vision for our community," Airbnb says. Airbnb admitted on Wednesday that it had deleted about 1,500 ...

At $92 Million, Del Dios Ranch Debuts As San Diego's Most Expensive Listing Ever
... has just hit the market for $92 million. It is the most expensive asking price for a residence in San Diego County ever, according to the listing ...

Airbnb Finally Admits to Purging Listings to Make It Look Less Commercialized
... New York City hosts were innocently renting out their personal homes, Airbnb admitted yesterday that it did indeed remove “roughly 1,500” listings ...

Resources last updated: 3/9/2016 6:46:34 AM