What is the best algorithm for optimizing a combination of variables? [closed] - algorithm

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 20 hours ago.
Improve this question
I want to program a software that calculates the best combination of materials to use base on parameters such as its tensile strength, elastic modulus, stiffness, and results from doing certain tests from those materials. Those each factor are going to be weighted differently in a WDM. Is there an algorithm that would allow me to find the best combination without actually going through all the combinations and doing each individual calculations? I will be working with a lot of data, so efficiency is important
I tried researching algorithms like kruskal's and other things, but I'm not very fammiliar with them

First step is to write down an equation to calculate a number that you want to optimize.
If you can do that and the equation has no squares or other exponential terms then this is the classical linear programming problem https://en.wikipedia.org/wiki/Linear_programming
Your equation needs to look something like this:
max O = n1 * p1 + n2 * p2 - n3 * p3 ...
If so, then your best bet is to choose a linear programming package ( ask google ) with a good introductory tutorial and plug your problem into that. After a day or so on a steep learning curve, your problem will become almost trivial.
If you cannot do that, then you will need to use some sort of hill climbing algorithm - probably best to hire an expert to help with that.

Related

Minimum number of Trips [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have latitude and longitude points of N societies, order count of these societies, I also have latitude and longitude points of a warehouse from where the trucks will deploy and will be sent to these various societies(like Amazon deliveries). A truck can deliver maximum 350 orders (order count < 350). So no need to consider items with order count above 350 (We generally would send two trucks there or a bigger truck). Now I need to determine a pattern in which the trucks should be deployed in such a way that a minimum number of trips occur.
Considering that we determine the distance between two societies or warehouses is 'X' from this script is accurate, How do we solve this? I first thought that we could solve it using sum of subset problem, maybe? Seems like dp on graphs to me, traveling salesman problem with infinite number of salemans.
There are no restrictions on the number of trucks.
This is a typical Travelling salesman problem (TSP) which is known as NP-complete. It means that if you are looking for the optimal solution you have to test most of combinatorics. And as you know, !350 is tremendeous.
Nevertheless, as Henry suggests, you can look for a good solution which is not necessarily the best. A lot of algorithm called "heuristic" let you find one good solution in a very efficient way. Just have a look here for some examples https://en.wikipedia.org/wiki/Travelling_salesman_problem.
The most simple heuristic algorithm may be a greedy solution like always take the closest unvisited point as next society.

How will greedy work in this coin change case [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
The problem is here
Say I have just 25-cent, 10-cent and 4-cent coins and my total amount is 41. Using greedy, I'll pick 25-cent and then 10-cent, and then the remaining 6 cents can not be made.
So my question is, does greedy in this case will tell me that there is no solution?
It looks like your problem was answered right in the the Greedy algorithm wiki: http://en.wikipedia.org/wiki/Greedy_algorithm#Cases_of_failure
Imagine the coin example with only 25-cent, 10-cent, and 4-cent coins. The greedy algorithm would not be able to make change for 41 cents, since after committing to use one 25-cent coin and one 10-cent coin it would be impossible to use 4-cent coins for the balance of 6 cents, whereas a person or a more sophisticated algorithm could make change for 41 cents with one 25-cent coin and four 4-cent coins.
The greedy algorithm mentioned in your link assumes the existence of a unit coin. Otherwise there are some integer amounts it can't handle at all.
Regarding optimality - as stated there, it depends on the available coins. For {10,5,1} for example the greedy algorithm is always optimal (i.e. returns the minimum number of coins to use). For {1,3,4} the greedy algorithm is not guaranteed to be optimal (it returns 6=4+1+1 instead of 6=3+3).
It seems that greedy algorithm is not always the best and this case is used as example to illustrate when it doesn't work
See example in Wikipedia

Polynomial Regression - results accuracy between two algorithms [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I know that I can find a polynomial regression's coefficients doing (X'X)^-1 * X'y (where X' is the transpose, see Wikipedia for details).
This is a way of finding the coefficients; now, there is (as far as I know) at least one other way, which is by minimizing a cost function using gradient descent. The former method seems to be the easiest to implement ( I did it in C++, I have the latter in Matlab ).
What I wanted to know is the advantage of one of these methods over the other.
Upon a particular dataset, with very few points, I found that I couldn't find a satisfactory solution using (X'X)^-1 * X'y, but gradient descent worked fine and I could get an estimation function that made sense.
So what's wrong with the matrix resolution over gradient descent ? And how would one test a regression results, having all the details hidden from the user ?
Both methods are equivalent. Iterative method is much more computationally efficient thanks to lower storage and the avoidance of matrix inverse calculation. The method outweighs the closed form (matrix equation) methods especially when X is huge and sparse.
Make sure the row number of X is larger than the column number of X to avoid the underdetermined problem. Also check out the condition number of X'X to see if the problem is ill-posedness. If that is the case, you may add a small regularization factor in the closed form ((X'X + lambda * I)^(-1) * X'y) where lambda is a small value and I is the identity matrix.

Do we really have case in this algorithm [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am having trouble for solving the running time of the following algorithm
Now first my question, is the case really important here(I can not come up with 2 different inputs of the same size that are different from each other) ?
Second, I think this algorithm runs in O(n^2). Am I right?
The comment you wrote in #OBu's answer is about only a quarter right:
1*n + 2*(n-1) + 3*(n-2) + ... +n*1
That equals to:
Sum(i=1..n, i*(n-i+1)) = n*Sum(i) - Sum(i*i) + n = n*[n(n+1)/2] - [n(n+1)(2n+1)/6] + n
If you want, feel free to compute the exact formula, but the overall complexity is O(n^3).
As a rule of thumb (more like a back-of-the-envelope computation trick I've picked up... just to give you a quick idea): if you are unsure about algorithms with multiple for's (with different lengths, but all in relation with n, as you have above) try to compute how many operations are performed around the middle of the algorithm (n/2). This usually gives you an idea on how the running time complexity for the whole thing might looks like - you are basically computing the largest element in the sum, so the overall complexity is always >= than the thing you compute (in most cases it's the same though).
Just to give you some hints:
How many loops do you have and how are they nested?
How often is each loop running (start solving this from the outer to the inner loop)
If in doubt, try it with n=4 or 5 and calculate each step. After this, you'll have a good feeling for what's going on.

Is there some way to bruteforce a mathematical function? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm not sure if this is a stupid question but I couldn't really find anything on Google. Given a few data points for a function f(x) would it be possible to bruteforce what the function f(x) itself might be?
This will rely on some prior knowledge of f(x).
If you know that the function is constant, one point is enough; a line, then two points, etc. for polynomial functions.
But if you have no restrictions, this isn't possible. Assuming function here means something like a real-valued function on the real numbers, there are (uncountably) infinitely many functions which will take the specified values on any finite set of data points.
This is mostly math question. It depends on number of data points that are available. You are basically fitting data to a function. You need two data points for straight line, etc. The commercial solution is TableCurve 2D, http://en.wikipedia.org/wiki/TableCurve_2D. I would search for nonlinear fit on Google.
Fitting algorithms are also described in Numerical Recipes (http://en.wikipedia.org/wiki/Numerical_Recipes). The simplest algorithm would look for deviations between assumed function and data points. If you assume certain error on your data points, you can calculate chi-square and goodness of your fit.

Resources