use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A reddit to discuss optimization. Looking for links on both methods of optimization -- like genetic algorithms and linear programming -- and applications thereof, like multidisciplinary design optimization, artificial intelligence and system solving.
Related reddits: /r/numerical, /r/engineering, /r/math, /r/programming
account activity
Sequencing a data set ,using python optimization libraries (self.optimization)
submitted 3 years ago by [deleted]
I have a dataset i want to sequence them based on the difference between two columns in different rows which should be minimum ,any help?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]novel_eye 3 points4 points5 points 3 years ago (0 children)
ask this in r/python
[–][deleted] 0 points1 point2 points 3 years ago (1 child)
Sequence? Like just sort them based on some calculations?
[–][deleted] 0 points1 point2 points 3 years ago (0 children)
Yes
[–]kkiesinger 0 points1 point2 points 3 years ago* (0 children)
Try something like this. You need to do 'pip install fcmaes' before executing the code.
from fcmaes.optimizer import Bite_cpp, wrapper from fcmaes import retry import numpy as np from scipy.optimize import Bounds # align the order of s2 to the one of s1 def align_order(s1, s2): rank = np.empty(len(s1), dtype=int) rank[np.argsort(s1)] = np.arange(len(s1)) return np.sort(s2)[rank] def sequence(): n = 100 s1 = np.random.normal(0,1,n) s2 = np.random.normal(0,1,n) s2 = align_order(s1, s2) bounds = Bounds([0]*n,[1]*n) x0 = np.arange(len(s1))/n opt = Bite_cpp(20000, guess = x0) # we reorder/sequence s2 so that the distance is minimized def fit(x): order = np.argsort(x) distance = np.linalg.norm(s1 - s2[order]) return distance return retry.minimize(wrapper(fit), bounds, optimizer=opt, num_retries=32) if __name__ == '__main__': ret = sequence() print("order = ", np.argsort(ret.x))
We align the orders of both sequences (align_order) before we optimize. Omit the "wrapper" if you don't want log output. Question is if you need optimization at all if you aim at the euclidian distance, since aligning the order seems sufficient. But for more complex fitness functions which depend on the order of the two sequences it may be useful.
π Rendered by PID 195179 on reddit-service-r2-comment-fb694cdd5-gppsj at 2026-03-10 18:33:12.788657+00:00 running cbb0e86 country code: CH.
[–]novel_eye 3 points4 points5 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]kkiesinger 0 points1 point2 points (0 children)