Трапециевидная интеграция с использованием нейронной сети - PullRequest
0 голосов
/ 03 апреля 2020

Я пытаюсь применить правило трапеции к дробной производной, используя нейронную сеть. Все хорошо, кроме (t-1)**(m1-alpha-1)*(1+t**2*u) этой строки. Если я удаляю -1 из (t-1), сеть работает иначе, она выдает следующую ошибку: TypeError: Ожидается float32, вместо этого получено (-0.8910065241883681-0.45399049973954625j) типа 'complex'.

import math
%tensorflow_version 1.x
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
N = 200
a = 0
b = 2.0
x = np.arange(a, b, (b-a)/N).reshape((N,1))
# Boundary conditions
A = 0.0
B = -1.0

# Define the number of neurons in each layer
n_nodes_hl1 = 10
n_nodes_hl2 = 10

# Define the number of outputs and the learning rate
n_classes = 1
learn_rate = 0.01

# Define input / output placeholders
x_ph = tf.placeholder('float', [None, 1],name='input')

# Define standard deviation for the weights and biases
hl_sigma = 0.02

def neural_network_model(data):
    hidden_1_layer = {'weights': tf.Variable(tf.random_normal([1, n_nodes_hl1], stddev=hl_sigma)),
                      'biases': tf.Variable(tf.random_normal([n_nodes_hl1], stddev=hl_sigma))}

    hidden_2_layer = {'weights': tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2], 
                     stddev=hl_sigma)),
                      'biases': tf.Variable(tf.random_normal([n_nodes_hl2], stddev=hl_sigma))}

   output_layer = {'weights': tf.Variable(tf.random_normal([n_nodes_hl2, n_classes], 
                    stddev=hl_sigma)),
                   'biases': tf.Variable(tf.random_normal([n_classes], stddev=hl_sigma))}
l1 = tf.add(tf.matmul(data, hidden_1_layer['weights']), hidden_1_layer['biases'])

l1 = tf.nn.relu(l1)   

l2 = tf.add(tf.matmul(l1, hidden_2_layer['weights']), hidden_2_layer['biases'])
l2 = tf.nn.relu(l2)

output = tf.add(tf.matmul(l2, output_layer['weights']), output_layer['biases'], name='output')

return output
pred = neural_network_model(x_ph)
u = A  + B*x_ph+  (x_ph)*pred
def f(t):
    return (t-1)**(m1-alpha-1)*(1+t**2*u)
N1 = 5
alpha = 0.85
T1 = 1.0
a1 = 0.0 
b1 = 2.0 
h1 = (b1-a1)/N1
m1 = math.ceil(T1/h1)
s1 = 0.5*f(a1) + 0.5*f(b1) 
for k1 in range(1,N1):
   s1 += f(a1+k1*h1)
print(h1*s1/(2*math.gamma(m1-alpha)))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...