Я использую модель SupervisedDBNregression () и хочу найти оптимальные входные значения для этой модели, которые сводят к минимуму среднеквадратичное отклонение.Я применяю алгоритм Particle Swarm Optimization (PSO), но мой код выдает ошибку типа параметра.Какой параметр мне нужно изменить с float32 на int23 / int64?Заранее спасибо!
Я безуспешно пытался изменить переменные конструкции на целые.
from pyswarm import pso
from dbn.tensorflow import SupervisedDBNRegression
# Objective function to be minimized
def mse(z):
a, b, c, d, e, f , g = z
predictedY = DBN(z).fit(trainX,trainY)
return mean_squared_error(testY,predictedY)
# Constraint function
def DBN(z):
a, b, c, d, e, f , g = z
return SupervisedDBNRegression(hidden_layers_structure=[a,b],
learning_rate_rbm=c,
learning_rate=d,
n_epochs_rbm=e,
n_iter_backprop=f,
batch_size=g,
activation_function='relu')
constraints = [DBN]
#Define the lower and upper bounds for z
lb = [1,1,0.0000005,0.0000005, 1, 100,1]
ub = [20,20,0.1,0.1,10,5000,200]
xopt, fopt = pso(mse, lb, ub, ieqcons=constraints)
------------------ ОШИБКА --------------------
TypeError Traceback (most recent call last)
<ipython-input-13-19b53f82d36c> in <module>()
24 ub = [20,20,0.1,0.1,10,5000,200]
25
---> 26 xopt, fopt = pso(mse, lb, ub, ieqcons=constraints)
______________________________ x кадров __________________________________
/usr/local/lib/python3.6/dist-packages/dbn/tensorflow/models.py in weight_variable(func, shape, stddev, dtype)
22
23 def weight_variable(func, shape, stddev, dtype=tf.float32):
---> 24 initial = func(shape, stddev=stddev, dtype=dtype)
25 return tf.Variable(initial)
26
/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/random_ops.py in truncated_normal(shape, mean, stddev, dtype, seed, name)
176 seed1, seed2 = random_seed.get_seed(seed)
177 rnd = gen_random_ops.truncated_normal(
--> 178 shape_tensor, dtype, seed=seed1, seed2=seed2)
179 mul = rnd * stddev_tensor
180 value = math_ops.add(mul, mean_tensor, name=name)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_random_ops.py in truncated_normal(shape, dtype, seed, seed2, name)
958 _, _, _op = _op_def_lib._apply_op_helper(
959 "TruncatedNormal", shape=shape, dtype=dtype, seed=seed, seed2=seed2,
--> 960 name=name)
961 _result = _op.outputs[:]
962 _inputs_flat = _op.inputs
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords)
608 _SatisfiesTypeConstraint(base_type,
609 _Attr(op_def, input_arg.type_attr),
--> 610 param_name=input_name)
611 attrs[input_arg.type_attr] = attr_value
612 inferred_from[input_arg.type_attr] = input_name
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py in _SatisfiesTypeConstraint(dtype, attr_def, param_name)
58 "allowed values: %s" %
59 (param_name, dtypes.as_dtype(dtype).name,
---> 60 ", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
61
62
TypeError: Value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64
Я ожидаю, что PSO даст значения для гиперпараметра z где-то между нижней границей (lb) и верхней границей (ub).