combinatorics

Logistic regression: how to try every combination of predictors in R?

陌路散爱 提交于 2019-12-10 12:24:43
问题 This is a duplicate of https://stats.stackexchange.com/questions/293988/logistic-regression-how-to-try-every-combination-of-predictors. I want to perform a logistic regression: I have 1 dependent variable and ~10 predictors. I want to perform an exhaustive search trying every combination, such as changing order and adding/deleting predictors, etc. For example: y ~ x1 + x2 + x3 + x4 + x5 y ~ x2 + x1 + x3 + x4 + x5 y ~ x1 + x2 + x3 y ~ x5 + x1 + x2 + x3 + x4 y ~ x4 + x2 ...and so on.

enumerating all possible strings of length K from an alphabet in Python [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-10 10:45:39
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: is there any best way to generate all possible three letters keywords how can I enumerate all strings of length K from an alphabet L, where L is simply a list of characters? E.g. if L = ['A', 'B', 'C'] and K = 2 , I'd like to enumerate all possible strings of length 2 that can be made up with the letters 'A' , 'B' , 'C' . They can be reused, so 'AA' is valid. This is essentially permutations with replacement, as

Python itertools.combinations() memory problems

对着背影说爱祢 提交于 2019-12-10 10:35:08
问题 I'm processing a huge number of combinations of items (from League of Legends), about 72 million, all of which are fed into a function that calculates how beneficial they are. We're trying to find the best possible combination. Ignoring the fact that there might be better ways, algorithmically speaking, to do this, can anyone tell me why I'm getting a memory error? allpossiblei = itertools.combinations(items.keys(),5) maxc = 0 i = 0 for combo in allpossiblei: icombo = [items[name] for name in

Proving a set of requirements can be met with a set of values using LINQ

余生颓废 提交于 2019-12-10 10:18:25
问题 This is a subset of the question posted here. Given a set of buckets of volume B={x1, x2, ..., xn} and a set of vials with liquid of volumes V={v1, v2, ..., vn } what is the best way to prove that the number of buckets can be filled with the contents of the vials assuming that vials must be poured all into one bucket. Overflow is permitted. Some obvious invariants here are that the cardinality of the buckets |B| must be less than or equal to the cardinality of the vials |V| and that the

Find permutations by repeatedly cycling 3 elements

三世轮回 提交于 2019-12-09 09:54:18
问题 Is there an algorithm to find all possible permutations of a series of unique elements, that follows this rule? From a given permutation the next permutation must be found by cycling exactly 3 elements. They can be any three elements. With such 3-cycles only a subset of all permutations will be found, but all those that are possible to be reached via 3-cycles should be found, and the same permutation should not be found twice until all reachable permutations have been found. Here is an

Anagram Index Calculation [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-09 06:58:19
问题 This question already has answers here : Find the index of a given permutation in the sorted list of the permutations of a given string (6 answers) Closed 4 years ago . Given an input string up to 25 characters long consisting of characters A-Z, output its index in the alphabetically sorted list of all possible anagrams of the input string. Input string is not case sensitive. Input characters can be repeated. The app must complete in less than 500ms and take less than 1GB of memory. At first

Dynamic T-SQL approach for combinatorics/knapsack

不问归期 提交于 2019-12-09 06:37:42
问题 I guess my question has to do with a variant of the knapsack problem, but I can't really come up with a solution for this: Let's say you are in a hardware store and need to buy 21 screws. They only offer them in bags: Bag X - 16 Screws - 1.56$ per screw - 25$ Total Bag Y - 8 Screws - 2.25$ per screw - 18$ Total Bag Z - 4 Screws - 1.75$ per screw - 7$ Total Now you have to figure out which Bags you should buy to get your 21 screws (or more!) for the lowest possible price. So what I got is a

Finding a number of maximally different binary vectors from a set

耗尽温柔 提交于 2019-12-09 05:22:28
问题 Consider the set, S , of all binary vectors of length n where each contains exactly m ones; so there are n-m zeros in each vector. My goal is to construct a number, k , of vectors from S such that these vectors are as different as possible from each other. As a simple example, take n =4, m =2 and k =2, then a possible solution is: [1,1,0,0] and [0,0,1,1]. It seems that this is an open problem in the coding theory literature (?). Is there any way (i.e. algorithm) to find a suboptimal yet good

Permutations excluding repeated characters

纵然是瞬间 提交于 2019-12-09 04:44:26
问题 I'm working on a Free Code Camp problem - http://www.freecodecamp.com/challenges/bonfire-no-repeats-please The problem description is as follows - Return the number of total permutations of the provided string that don't have repeated consecutive letters. For example, 'aab' should return 2 because it has 6 total permutations, but only 2 of them don't have the same letter (in this case 'a') repeating. I know I can solve this by writing a program that creates every permutation and then filters

In how many ways we can pick K elements from set of n elements to form a number X?

青春壹個敷衍的年華 提交于 2019-12-09 02:04:47
问题 There is one important point - We can pick any element any number of times but the total picked element should be equal to K. For example - If set of elements is 1 2 3 5 and K = 3 and X = 4. Then answer is 1 because there is only one way to pick 3 elements which adds upto 4 and those 3 elements are two 1's and one 2. (1+1+2 = 4) An algorithm can greatly help. :) 回答1: Let's consider DP solution for coin change problem. Usually entries of array A with length (Sum+1) contain integers - number of