Good day!

There is a function of two variables (decision function):

def dec_func(self, x, y): res = 0 for i, w in enumerate(self.W): res += w * self.F[i](Point(x, y)) return res 

It is necessary to plot this function when res = 0. That is, you need from the list X for each x to get such y, so that when the function is executed, the result is equal to 0.

UPD:

There is an implemented function that, according to given X, can get approximately true Y (with a certain accuracy):

 def plot_data(self, start=-15, end=15, step=1): X = [i for i in range(start, end, step)] Y = [] x_to_remove = [] for x in X: k = 0 y_old = 0 step = 0.05 old_res = self.dec_func(x, y_old) while abs(old_res) > 0.01: if k > 3000: break k += 1 y = y_old + step res = self.dec_func(x, y) if abs(old_res) > abs(res): y_old = y step *= 1.2 else: y_old = y step = -step / 2 old_res = res if k > 3000: print(y_old, x, old_res) x_to_remove.append(x) else: Y.append(y_old) for x in x_to_remove: X.remove(x) return X, Y 

But the problem is that this implementation does not allow to get several values ​​of y for one x.

  • one
    Can I have more code? What self.W objects self.W and self.F ? Point is a class? What library is it from, or is it your own class or function? And what exactly you can not? - mkkik
  • @mkkik, what is inside a function is not important in principle. I just put it in as an example. The main thing is that there is a function that takes input x, y and returns the result. Unable to plot the dec_func (x, y) = 0 function - Ildan Kiamov
  • To understand why it does not work, you need to look at the area of ​​the code where you build the graph. - mkkik
  • @mkkik, the fact is that I do not know how to build it. - Ildan Kiamov

1 answer 1

This is how you can draw a graph for such functions.

 import matplotlib.pyplot from numpy import arange from numpy import meshgrid delta = 0.025 xrange = arange(-50.0, 50.0, delta) yrange = arange(-50.0, 50.0, delta) X, Y = meshgrid(xrange, yrange) F = dec_func(X, Y) matplotlib.pyplot.contour(X, Y, F, [0])