I am trying to create function using numpy something like f=(x-a1)^2+(y-a2)^2+a3
Where a1,a2,a3 are random generated numbers and x,y are parameters.
But I cant work with it, I want to find f(0,0) where [0,0] is [x,y] and [a1,a2,a3] were set before,but my code doesnt work. And then I want to convert this function to tensorflow tensor.Here is my code, string with "##" dont work.
import tensorflow as tf
from random import random, seed
import numpy as np
def mypolyval(x, min_point, min_value):
res = min_value
for i in range(len(min_point)):
res += (x[i] - min_point[i]) ** 2
return res
class FunGen:
def __init__(self, dim, n):
self.dim = dim
self.n = n
self.functions = []
self.x = []
def c2(self):
seed(10)
for _ in range(self.n):
min_point = [random() for _ in range(self.dim)]
min_value = random()
f = np.vectorize(mypolyval, excluded=['x'])
##print(f(x=np.array([0, 0]), min_point=min_point, min_value=min_value))
self.functions.append((f, min_point, min_value))
return self.functions
functions = FunGen(2, 1).c2()
for i in functions:
print(type(i[0]))
f=i[0]
## print(f(x=[0, 0], min_value=i[1], min_point=i[2]))
##a=tf.convert_to_tensor(f,dtype=np.float32)