data-partitioning

How can I maximally partition a set?

独自空忆成欢 提交于 2019-12-03 20:28:08
问题 I'm trying to solve one of the Project Euler problems. As a consequence, I need an algorithm that will help me find all possible partitions of a set, in any order. For instance, given the set 2 3 3 5 : 2 | 3 3 5 2 | 3 | 3 5 2 | 3 3 | 5 2 | 3 | 3 | 5 2 5 | 3 3 and so on. Pretty much every possible combination of the members of the set. I've searched the net of course, but haven't found much that's directly useful to me, since I speak programmer-ese not advanced-math-ese. Can anyone help me out

Replace duplicate values in array with new randomly generated values

陌路散爱 提交于 2019-12-03 20:10:52
问题 I have below a function (from a previous question that went unanswered) that creates an array with n amount of values. The sum of the array is equal to $max. function randomDistinctPartition($n, $max) { $partition= array(); for ($i = 1; $i < $n; $i++) { $maxSingleNumber = $max - $n; $partition[] = $number = rand(1, $maxSingleNumber); $max -= $number; } $partition[] = $max; return $partition; } For example: If I set $n = 4 and $max = 30. Then I should get the following. array(5, 7, 10, 8);

Generating unique sorted partitions in Ruby

心不动则不痛 提交于 2019-12-03 16:28:54
I'm trying to generate the set of sequences as shown below, not in any particularly order, but here its shown as a descending sequence. Note that each sequence also descends as I'm interested in combinations, not permutations. I'd like to store each sequence as an array..or the set of sequences as an array of arrays more preferably, but first things first. 6 5 1 4 2 4 1 1 3 3 3 2 1 3 1 1 1 2 2 2 2 2 1 1 2 1 1 1 1 1 1 1 1 1 1 Right now I am simply focusing on generating these sets and I'm trying to do it recursively. Essentially..these are all the sequences of numbers when combines will give

How to sort an integer array into negative, zero, positive part without changing relative position?

时光怂恿深爱的人放手 提交于 2019-12-02 23:23:25
Give an O(n) algorithm which takes as input an array S, then divides S into three sets: negatives, zeros, and positives. Show how to implement this in place, that is, without allocating new memory. And you have to keep the number's relative sequence. for example: {-1, 4, 0, -2, 1, 2} ==> {-1, -2, 0, 4, 1, 2} I am not sure whether or not such an solution exits. The best solutions I can think out are: Solution 1: Using an extra integer array, then traverse the whole array to get negatives, then 0s, then positives. Solution 2: Do not keep number's relative sequence. Then loop the array two times:

3D clustering Algorithm

余生长醉 提交于 2019-12-02 18:37:26
Problem Statement: I have the following problem: There are more than a billion points in 3D space. The goal is to find the top N points which has largest number of neighbors within given distance R. Another condition is that the distance between any two points of those top N points must be greater than R. The distribution of those points are not uniform. It is very common that certain regions of the space contain a lot of points. Goal: To find an algorithm that can scale well to many processors and has a small memory requirement. Thoughts: Normal spatial decomposition is not sufficient for

How to partition an image to 64 block in matlab

一个人想着一个人 提交于 2019-12-01 00:41:29
I want to compute the Color Layout Descriptor (CLD) for each image.. this algorithm include four stages . in the First stage I must Partition each image into 64 block i(8×8)n order to compute a single representative color from each block .. I try to partition the image into 64 block by using (For loop) but I get 64 ting image. I want to get image with (8×8) block in order to complete the algorithm by apply the DCT transformation then Zigzag scanning Here some pieces of code that I wrote for the exact same problem (8x8 blocks, DCT coefficients, etc) sometime ago... img=imread('filename') [img_x

How can I maximally partition a set?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 16:14:00
I'm trying to solve one of the Project Euler problems. As a consequence, I need an algorithm that will help me find all possible partitions of a set, in any order. For instance, given the set 2 3 3 5 : 2 | 3 3 5 2 | 3 | 3 5 2 | 3 3 | 5 2 | 3 | 3 | 5 2 5 | 3 3 and so on. Pretty much every possible combination of the members of the set. I've searched the net of course, but haven't found much that's directly useful to me, since I speak programmer-ese not advanced-math-ese. Can anyone help me out with this? I can read pretty much any programming language, from BASIC to Haskell, so post in whatever

Algorithm to generate all unique permutations of fixed-length integer partitions?

不问归期 提交于 2019-11-30 15:37:24
问题 I'm searching for an algorithm that generates all permutations of fixed-length partitions of an integer. Order does not matter. For example, for n=4 and length L=3: [(0, 2, 2), (2, 0, 2), (2, 2, 0), (2, 1, 1), (1, 2, 1), (1, 1, 2), (0, 1, 3), (0, 3, 1), (3, 0, 1), (3, 1, 0), (1, 3, 0), (1, 0, 3), (0, 0, 4), (4, 0, 0), (0, 4, 0)] I bumbled about with integer partitions + permutations for partitions whose length is lesser than L; but that was too slow because I got the same partition multiple

Replace duplicate values in array with new randomly generated values

℡╲_俬逩灬. 提交于 2019-11-30 15:27:30
I have below a function (from a previous question that went unanswered) that creates an array with n amount of values. The sum of the array is equal to $max. function randomDistinctPartition($n, $max) { $partition= array(); for ($i = 1; $i < $n; $i++) { $maxSingleNumber = $max - $n; $partition[] = $number = rand(1, $maxSingleNumber); $max -= $number; } $partition[] = $max; return $partition; } For example: If I set $n = 4 and $max = 30. Then I should get the following. array(5, 7, 10, 8); However, this function does not take into account duplicates and 0s. What I would like - and have been

python: Generating integer partitions

半腔热情 提交于 2019-11-30 07:14:08
I need to generate all the partitions of a given integer. I found this algorithm by Jerome Kelleher for which it is stated to be the most efficient one: def accelAsc(n): a = [0 for i in range(n + 1)] k = 1 a[0] = 0 y = n - 1 while k != 0: x = a[k - 1] + 1 k -= 1 while 2*x <= y: a[k] = x y -= x k += 1 l = k + 1 while x <= y: a[k] = x a[l] = y yield a[:k + 2] x += 1 y -= 1 a[k] = x + y y = x + y - 1 yield a[:k + 1] reference: http://homepages.ed.ac.uk/jkellehe/partitions.php By the way, it is not quite efficient. For an input like 40 it freezes nearly my whole system for few seconds before