approximation

How to compare that sequence of doubles are all “approximately equal” in Java?

跟風遠走 提交于 2019-12-03 16:22:18
问题 I have a method in java that returns a double number and I want to compare every double number that is returned every time I call the method(say 5 times), so that I can conclude that the number returned is almost the same every time. How can I do this? 回答1: You must first decide what "almost the same" means. For example, there's a method in java.lang.Math called ulp() which, given a double, returns the distance between that double and the next; i.e., the smallest possible difference between

bin packing with overlapping objects

≯℡__Kan透↙ 提交于 2019-12-03 09:03:32
I have some bins with different capacities and some objects with specified size. The goal is to pack these objects in the bins. Until now it is similar to the bin-packing problem. But the twist is that each object has a partial overlap with another. So while object 1 and 2 has sizes s1 and s2, when I put them in the same bin the filled space is less than s1+s2. Supposing that I know this overlapping value for each pair of objects, is there any approximation algorithm like the ones for original bin-packing for this problem too? Masood_mj The answer is to use a kind of tree that captures the

approximation methods

可紊 提交于 2019-12-03 08:51:29
I attached image: (source: piccy.info ) So in this image there is a diagram of the function, which is defined on the given points. For example on points x=1..N. Another diagram, which was drawn as a semitransparent curve, That is what I want to get from the original diagram, i.e. I want to approximate the original function so that it becomes smooth. Are there any methods for doing that? I heard about least squares method, which can be used to approximate a function by straight line or by parabolic function. But I do not need to approximate by parabolic function. I probably need to approximate

RGB Similar Color Approximation Algorithm

a 夏天 提交于 2019-12-03 07:14:25
Given that in RGB we can represent 256^3 combinations = 16,777,216 colors, and since the human eye can only distinguish roughly 10,000,000, there is obviously a surplus of 6,777,216 RGB combinations that chromatically are indistinguishable from counterpart colors. Compression algorithms work on this basis when approximating out spacial difference in color ranges across a frame I believe. With that in mind, how can one reliably compute whether a given color is within a range of 'similarity' to another? Of course, 'similarity' will be some kind of arbitrary/tunable parameter that can be tweaked,

Approximate, incremental nearest-neighbour algorithm for moving bodies

橙三吉。 提交于 2019-12-03 02:04:16
问题 Bounty This question raises several issues. The bounty will go to an answer which addresses them holistically. Here's a problem I've been playing with. NOTE I'm especially interested in solutions that are not based in Euclidian space. There is a set of Actors which form a crowd of size K. The distance d(ActorA,ActorB) is easily computable for any two actors (solutions should work for various definitions of 'distance') and we can find the set of N nearest neighbours for any given Actor using

Approximation to constant “pi” does not get any better after 50 iterations

半腔热情 提交于 2019-12-02 10:52:51
In R I have written this function ifun <- function(m) { o = c() for (k in 1:m) { o[k] = prod(1:k) / prod(2 * (1:k) + 1) } o_sum = 2 * (1 + sum(o)) # Final result print(o_sum) } This function approximates constant pi , however, after m > 50 the approximation gets stuck, i.e. the approximation is the same value and don't get better. How can I fix this? Thanks. Let's go inside: o <- numeric(100) for (k in 1:length(o)) { o[k] = prod(1:k) / prod(2 * (1:k) + 1) } o # [1] 3.333333e-01 1.333333e-01 5.714286e-02 2.539683e-02 1.154401e-02 # [6] 5.328005e-03 2.486402e-03 1.170072e-03 5.542445e-04 2

Split array basing on chunk weight

痴心易碎 提交于 2019-12-02 08:38:21
问题 I have an array with 2 <= n <= 100 doubles: A = [a1, a2, ... , an], ai > 0 and an integer 2 <= k <= min(n, 20) . I need to split A into k subarrays: B1 = [a1, a2, ... , ap] B2 = [ap+1, ap+2, ... , aq] ... Bk = [aw+1, aw+2, ... , an] such that the sum in each B is almost equal (it's hard to give a strict definition what this means - I'm interested in an approximate solution). Example: Input: A = [1, 2, 1, 2, 1], k=2 Output: [[1, 2, 1], [2, 1]] or [[1, 2], [1, 2, 1]] I tried a probabilistic

Round Up a double to int

荒凉一梦 提交于 2019-12-01 14:59:00
I have a number ("double") from int/int (such as 10/3). What's the best way to Approximation by Excess and convert it to int on C#? Are you asking about System.Math.Ceiling ? Math.Ceiling(0.2) == 1 Math.Ceiling(0.8) == 1 Math.Ceiling(2.6) == 3 Math.Ceiling(-1.4) == -1 EursPravus int scaled = (int)Math.Ceiling( (double) 10 / 3 ) ; By "Approximation by Excess", I assume you're trying to "round up" the number of type double. So, @Doug McClean's "ceiling" method works just fine. Here is a note: If you start with double x = 0.8; and you do the type conversion by (int)x; you get 0 . Or, if you do

float strange imprecision error in c [duplicate]

拜拜、爱过 提交于 2019-12-01 11:41:04
This question already has an answer here: Is floating point math broken? 31 answers today happened to me a strange thing, when I try to compile and execute the output of this code isn't what I expected. Here is the code that simply add floating values to an array of float and then print it out. The simple code: int main(){ float r[10]; int z; int i=34; for(z=0;z<10;z++){ i=z*z*z; r[z]=i; r[z]=r[z]+0.634; printf("%f\n",r[z]); } } the output: 0.634000 1.634000 8.634000 27.634001 64.634003 125.634003 216.634003 343.634003 512.633972 729.633972 note that from the 27 appears numbers after the .634

Approximation Algorithm for non-intersecting paths in a grid

戏子无情 提交于 2019-12-01 08:56:33
I recently came across this question and thought I could share it here, since I wasn't able to get it. We are given a 5*5 grid numbered from 1-25, and a set of 5 pairs of points,that are start and end points of a path on the grid. Now we need to find 5 corresponding paths for the 5 pairs of points, such that no two paths should overlap. Also note that only vertical and horizontal moves are allowed. Also the combined 5 path should cover the entire grid. For example we are given the pair of points as: P={1,22},{4,17},{5,18},{9,13},{20,23} Then the corresponding paths will be 1-6-11-16-21-22 4-3