A
I think you've lost some physical meaning to the task. I understand that in the economic geography, the forces of attraction and pushing are not reduced to the evclide distance on the plane.Let's take the task of choosing a rented apartment for certain. There's a supermarket at point 0.0 where it's all there (the strong retracting point), but people are constantly being pushed. There's a store at a point (10.1) where food is sold on a daily basis, but it's not negative. And there's a factory where noise, gam, and laborers (a strong pushing point).The extent to which objects are pushed and attracted must tell us by sociologists. In order to calculate the potential for attraction and pushing from the bald, I took a fine mechanism: the further you from the attracting point, the more you're sorry to get away from it, the closer you're to the pushing point, the more you're getting closer to it.For the retracting point, I put a fine of infinity, or we'd have had a long time torn from a whispering Wall-Mart in a hypothetical Kansas City.# Штраф для функции притяжения - сначала нарастает, потом убывает. На большом расстоянии уже пофиг, что там притягивает.
def attract(power, distance):
# притягивающая часть - квадратичная сигмоидная функция
p1 = power*distance/np.sqrt(distance+1)
# забывание - степенная функция
p2 = p1*(1/(distance+1))
return p2
# Штраф для отталкивания - постепенно убывает.
def repell(power, distance):
return power*(1/(distance+1))
I've just made up a specific type of pushing potential. It seems that there is a need to conduct research among the real people as their relationship to the tractoral and pushing places with distance.I see. Ask for the number of points and find a local minimum. The global minimum with such potentials is useless, it is infinite.class Point:
def __init__(self, coords, attracting, repelling):
self.coords = np.atleast_2d(coords)
self.attracting_power = attracting
self.repelling_power = repelling
def potential(self, point):
point = np.atleast_2d(point)
distance = np.linalg.norm(point-self.coords)
attracting_penalty = attract(self.attracting_power, distance) if self.attracting_power > 0 else 0
repelling_penalty = repell(self.repelling_power, distance)
return attracting_penalty + repelling_penalty
class Potential:
def init(self, points):
self.points = points
def potential(self, v):
resPot = 0.0
for p in self.points:
potential = p.potential(v)
resPot += potential
return resPot
def __call__(self, v):
return self.potential(v)
Let's go back for example.supermarket = Point((0.0), attracting=10, repelling=0.5)
factory = Point((10, -1), attracting=0, repelling=5)
minishop = Point((10,1), attracting=3, repelling=0)
fn = Potential((supermarket, minishop, factory))
The supermarket and the store create local minimums, the factory creates a local maximum.Next, we're looking for a limited local max and a voie la! Live at the supermarket )spo.minimize(fn, x0=(1,0), bounds=((-5, 15), (-10, 10)))
Outcome fun: 1.7733099211366816
hess_inv: <2x2 LbfgsInvHessProduct with dtype=float64>
jac: array([1.54659745, 0.5809764 ])
message: b'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'
nfev: 210
nit: 20
status: 0
success: True
x: array([-3.93721209e-09, -4.60977379e-09])
https://github.com/pakuula/StackOverflow/blob/main/python/1259494/repelling_points.ipynb UPDATEReply to questions raised in the reference post and in the comments.It is my understanding that you have come to the task of Weber, where the cost of location is determined by a weighted amount of distance to fixed points and asks about a universal receptor.♪ scipy.optimize is a function. https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html which implements several common methods of finding a minimum multi-dimensional function. By virtue of its universality, function minimize It does not guarantee the existence of a global minimum even without pushing points. For example, in the structure of the close-up clasters and the remote super-contracting point, the general method can be "struck" at a local minimum in the center of the cluster, not in a global area near the super-contracting point.With pushing points in Weber ' s task, the global minimum may exist only if the amount of positive weights by module is greater than the amount of negative. Otherwise, the negative weights will be overweight and the global minimum will be -inf Infinity. That would suggest that even a specialized method of finding minimums in Weber's task might be "stop." The addition of pushing points completely changes the challenge.Anyway. I categorically disagree with the use of a simple linear evaluation function for the real tasks of a “space economy”. The evaluation function, IMOW, must strive for an endless constant, and it doesn't matter what's out there. It's like a background. So I'm in favour of using sygmoid functions, and that's a very different way of finding minimums. But in this case, universal minimizers from scipy.optimize.minimize They can be stuck in local minimums.There are no universal methods that are guaranteed a global minimum. Global minimums can only find specialized methods that are targeted. But these methods stop working as soon as the shape of the evaluation function changes. The same Wisefeld method works with retracting points, but it breaks with pushers. The sygmoid evaluation functions may be performed, but for a more specific response, it is necessary to look at the convenience of the method, which it demands.Accordingly, I suggest you try to use common methods from scipy.optimizeand move to specialized only when you're going to get into clear gaps.