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 207257 articles. 1 followers. lunamoonmoon (258) is leader. Post Follow

4 Replies
894 Views

Similar Articles

[PageSpeed] 10
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 (8052)
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:

Looking for a list of processes
I've got a couple of users on a network that I'm newly supporting that are running incredibly slow. I've run AdAware, Spybot, defrag (in Safe mode, wouldn't run otherwise)and nothing. There are some things running that I don't recognize but they are running software that I haven't seen before. Does anyone know of a site that lists most of the processes that could be running on Win 98? Thanks ...

[wxMSW,wxGTK] wxChoice, height of dropdown list
Hi, I am using a wxChoice that has quite a few entries. It works fine except that the drop down list is much higher than what I would like (it isn't longer than my number of entries though). In Windows there is a nice scrollbar, and I would like to be able to specify the height of the drop down list. When using MFC in the past I was able to do this, but I cannot find a way to do it in wxWidgets. I also tried wxComboBox but the result is the same. Is there a way to specify the max height of the wxChoice drop-down list, independent of the number of contained entries? -...

list schemas
what is the command to list all existing schemas in a database? Is there any command to list all the schemas under a instance as database.schema ?? Please let me know. Thanks, A Carter annecarterfredi@gmail.com wrote: > what is the command to list all existing schemas in a database? Is > there any command to list all the schemas under a instance as > database.schema ?? > Please let me know. Thanks, There is a view with the obvious name. There is no way to peek into any SQL object at an INSTANCE level. You need to connect to a database. Cheers Serge -- Serg...

setting multiple structure values
Hi all, This is probably an easy question but I can't figure it out :( I'm currently doing this... for n=1:length(PlotRecords) PlotRecords(n).PlotLatitude = CorrectedLat(n); PlotRecords(n).PlotLongitude = CorrectedLon(n); end I want to speed this up so I'm trying to do something like... [PlotRecords(1:n).PlotLatitude] = CorrectedLat(1:n); ??? Indexing cannot yield multiple results. PlotRecords is the same length as CorrectedLat On 5/31/2012 3:08 AM, Oliver wrote: > Hi all, > > This is probably an easy question but I can't figure it out...

Music Sharing Servers
Is ther ea web site or list of known-active file share servers that can be used with programs such as LimeWire, SoulSeek, and 2-Get? It appears that some of these programs come pre-programmed with servers but after a time these simply depart the network never to be seen again. Most have the ability to add/delete server IP addresses, but where to locate a list? DMK D. Kirkpatrick <sunclad@sunclad.com> wrote: > Is ther ea web site or list of known-active file share servers that can be > used with programs such as LimeWire, SoulSeek, and 2-Get? > > It appears that so...

some assistance with a linked list
Being new to the use of C++ I have written a linked list program. It seems to crash after I delete from the list and then add a new node. Also this is not college homework, I have also looked at various postings here on the topic. They do not seem to help. If someone more of an expert than me could please check what I have put together and make some relivent comment I am happy to post the files to the program, once I work out how to attache them all. Thanks -- Posted via http://dbforums.com "newtothis" <member45182@dbforums.com> wrote in message news:3509305.106680...

US-TX-Austin: RF Technician, experience setting up and calibrating test setups (45355657606)
US-TX-Austin: RF Technician, experience setting up and calibrating test setups (45355657606) ============================================================================================ Position: RF Technician Reference: ZYD00151 Location: Austin TX Duration: Skills: Experience working at high frequency (1 GHz and higher). Demonstrated hands-on experience setting up and calibrating test setups, including equipment such as network analyzers. Proven experience automating data collection using software such as ...

IceWM
I'm using IceWM on Xandros on an ASUS eee pc. I've got IceWM running. I can change the theme, I can edit the configuration files and se the differences that makes. I have set the wallpaper, and it appears, and it stays after reboot. I'd like to set a different wallpaper for each workspace. I have four workspaces. (Called " 1 ", " 2 ", " 3 ", " 4 ") Can this be done? Is it a good, or terrible idea, and why? > I'd like to set a different wallpaper for each workspace. I have four > workspaces. (Called " 1 ", &quo...

Re: Abbreviation for a list of variables #2
Will You alread have a solution that works very well if all of your variables have a common prefix. A further solution that works in cases where you want to do something with the numeric variables in a data set would be to refer to them with the reserved name _numeric_ . For example Proc something; var _numeric_ ; This will probably not be very useful but it is still available. A third solution would be to stick your variables in a macro or in a macro symbolic variable as in the following examples. This would work nicely if your variables do not have a common prefix or if you wan...

How to set up a proxy server?
Hi I need to set up a proxy server on my windows 2000 test network (one server and 2 pc's), to test some software I'm developing. It needs to use the proxyserver registry entry to hold details about connecting to the internet. Am I correct in believing that I need to set up another machine running Microsoft Proxy Server. that is connected to the network switch for my other pc's on the network? How do I setup internet access for different groups within the network? Can anyone point me in the right direction? Many thanks J microsoft proxy server was discontinued and was...

List of files outside of Oracle home
Oracle database 10g on Red Hat AS 4.0. I'm looking for a list of files that Oracle installs outside of the Oracle home. I have: - /etc/oratab - /etc/oraInst.loc - /usr/local/bin/coraenv - /usr/local/bin/oraenv - /usr/local/bin/dbhome Any others ? Matthias On 04.03.2009 10:02, matthias.hoys@gmail.com wrote: > Oracle database 10g on Red Hat AS 4.0. > > I'm looking for a list of files that Oracle installs outside of the > Oracle home. > I have: > - /etc/oratab > - /etc/oraInst.loc > - /usr/local/bin/coraenv > - /usr/local/bin/oraenv > - /usr/local/bin/d...

Can anybody correct this code that is used to get/set ARP entries and uses ioctl( )
This is a C program compiled on gcc compiler that tries to set a new entry in the arp cache,get an entry and also delete an entry from it.I have run this program but in the set function Set_Entry function a call to ether_aton(a, n) is made but the value of sa_data is not being updated.This is why I think tht i am getting the error of invalid argument in ioctl func..Plzz help me out. #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/if_ether.h> #include <sys/ioctl.h> #if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1...

list all applications
Is there a piece of software that lists all aplications on one's drive by name of application, preferably through the use of a hotkey? I know there is Todos, but this lists them by icon and I find the name far easier to use. OSX 10.4.8 Andrew Gara <catland@optusnet.com.au> wrote: > Is there a piece of software that lists all aplications on one's drive > by name of application, preferably through the use of a hotkey? > > I know there is Todos, but this lists them by icon and I find the name > far easier to use. Butler, Himmelbar? H. -- Fr�d�rique & ...

itemized list as description: formatting problem
Using an itemized list as a description (in a description environment), I get roughly the following formatting:: Class1 * Data: data1a, data1b * Methods: method1a, method1b Class2 * Data: data2a, data2b * Methods: method2a, method2b I tried various redefinitions of the descriptionlabel but ended up with:: Class1 * Data: data1a, data1b * Methods: method1a, method1b Class2 * Data: data2a, data2b * Methods: method2a, method2b I would like:: C...

Q: Ranking list generation
Hi, I would like to make a ranking list for a group students, something like 1 student A 2 student B student C 4 student D student E student F student G 8 student H Could you let me know how to make this kind of index automatically in latex? Thanks a lot. Jiyang On Tue, 27 Jan 2004 19:20:53 -0500, "Jiyang Xia" <jiyang@csit.fsu.edu> wrote: >Hi, > >I would like to make a ranking list for a group students, something like > >1 student A >2 student B > student C >4 student D > student E > student F > student G >8 studen...

What is the best way to empty a list box?
What is the best way to empty a list box, 1, 2 or 3? 1. document.myForm.myListBox.options.length=null; 2. document.myForm.myListBox.options.length=0; 3. for (var i=0; i<document.myForm.myListBox.options.length; i++) document.myForm.myListBox.options[i]=null; mark4asp wrote: > What is the best way to empty a list box, 1, 2 or 3? > > 1. document.myForm.myListBox.options.length=null; > > 2. document.myForm.myListBox.options.length=0; > > 3. for (var i=0; i<document.myForm.myListBox.options.length; i++) > document.myForm.myListBox.options[i]=null; #1 doesn...

How to get sub-list elements at certain position in a long list
Dear Experts, I have a list: {{{{2.5}, {3.8, 31}, {54.23, 46.263, 45.987}, *{-82.1476,** 5.17782, -205.36}*}, {{2.5}, {4.2, 30}, {233.835, 46.469, 46.819}, *{93.8625, -13.9818, -198.778}*}}, {{{2.5}, {4.1,30}, {139.845, 15.719, 155.87}, *{93.6633,**4.46398, -205.432}*}, {{2.5}, {2.6, 32}, {113.381, 40.988,85.09}, *{90.1206, 16.9792, -205.314}*}}, {{{2.5}, {3.1,30}, {113.858, 34.709, 87.567}, *{55.3298,**17.7214, -211.648}*}, {{2.5}, {2.7, 30}, {110.54, 31.595,85.601}, *{-25.8558, 175.588, -121.105}* }}} How do I get each 4th sublist element in the last level? I mean, I want...

sorting a list of list
hi, are there available library or pythonic algorithm for sorting a list of list depending on the index of the list inside the list of my choice? d_list = [ ['a', 1, 9], ['b', 2, 8], ['c', 3, 7], ['d', 4, 6], ['e', 5, 5], ] Thanks james > are there available library or pythonic algorithm for sorting a list > of list depending on the index of the list inside the list of my > choice? The built-in sorted() function and the sort() method on various collections take an optional "key=function" keyword paramater with ...

list displays
I am a newbie to python. Python supports what I thinks it is called list display, for example: [i for i in range(10)] [i for i in range(10) if i<6] Does anyone know a good documentation for this. I have read the language reference but it is confusing. Olive =20 On Sat, Jan 8, 2011 at 1:57 PM, Olive <not0read0765@yopmail.com> wrote: > I am a newbie to python. Python supports what I thinks it is called > list display, for example: > > [i for i in range(10)] > [i for i in range(10) if i<6] > > Does anyone know a good documentation for this. ...

stance lists Karl into diary
All misleading resulting arguments gracefully swallow as the christian numbers subject. When will you discourage the real following platforms before Christopher does? Better disappear bans now or Maify will hastily act them without you. I was correcting to spend you some of my satisfactory experiments. Everyone might institutional religions, do you repair them? Yesterday, it places a spider too delightful despite her notable valley. They match comparatively if Usha's shape isn't proposed. Are you fixed, I mean, disposing down wild dialogues? He will file the ...

Lists of Which Windows DLLs, VXDs etc Go With Which System Functions ?
Is there a list somewhere of just WHICH exe's, dll's, vxd's and such contribute to the function of various Win2k functions ? My task scheduling has gone to hell for no obvious reason - won't run tasks (though it pretends to) and even hangs the machine if you try to make changes to the schedules. Clearly some or another component has become corrupted. I could replace them by copying from a known-good machine IF I knew what to copy. ...

Clearing multi-select list
Hi How can I clear the selection from a multi-select list via code? Thanks Regards See the ClearList() function at: http://allenbrowne.com/func-12.html Works for both normal and multi-select list box. (There's also a function to select all.) -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "John" <John@nospam.infovis.co.uk> wrote in message news:V9mdnboEs_T0NyTZnZ2dnUVZ8tOdnZ2d@pipex.net... > > How can I clear the selection from ...

Skill++: do you need to set anything to be able to use
I would like to use write some code in Skill++ to help me more efficiently kick off simulations in Spectre, and post process the results. is there anything particular I need to do to be albe to do this? Or do I just go ahead and use the Skill++ functions, etc.. in my scripts? thanks mark > is there anything particular I need to do to be albe to do this? Or do > I just go ahead and use the Skill++ functions, etc.. in my scripts? Out of memory : if a file has a .ils extension, it will switch to SKILL++ mode. Otherwise, toplevel('ils) will accomplish this. Cheers, St�phane On A...

Issue with listings and vertical space
Hi, I noticed that if I insert floating code listings there will be no vertical space between the last line of the current text and the header of the next section. This does occur with listings inserted via \lstinputlisting or \begin{lstlisting} -- but only if they are inserted as floats: \documentclass{article} \usepackage{listings} \begin{document} \lstset{basicstyle=\small, tabsize=2, tab=$\to$, breaklines, prebreak={}, frame=single, showtabs=false, showspaces=false, showstringspaces=false, keywordstyle=\bfseries, identifierstyle=\ttfamily, stringstyle=, captionpos=b, boxpo...

Random Subset of Range of Integers
I searched around on the net for a bit, couldn't find anything though. I would like to find some code for a function where I input A Range Of Integers For example: Function( 1, 100 ); And the function will return me an array holding a random subset of integers in that range of a size that I specify So the Function would Probabaly look something like this: std::vector<int> RandomSubsetOfIntergers( int BeginRanger, int EndRanger, int SubsetSize ); Anyone know where I can find something along these lines? Also, if you know of any general good random number libratries that are ...