Пользовательская функция активации в керасе с использованием мощности с десятичной точкойPython

Программы на Python
Ответить Пред. темаСлед. тема
Гость
 Пользовательская функция активации в керасе с использованием мощности с десятичной точкой

Сообщение Гость »


I am working on a personal project in Keras, although I am a novice at it, where I need to create a custom activation function that allows raising a sigmoid function to a decimal power. I have run several tests, and when I use decimal points, the prediction results indicate NaN, but if I use integer values in the power, the model works. I have been pondering this issue for a while and would greatly appreciate your support. Thanks:

import numpy as np import pandas as pd import keras from keras.models import Sequential from keras.layers import Dense from keras.layers import Activation import matplotlib.pyplot as plt from scikeras.wrappers import KerasRegressor from sklearn.model_selection import KFold from sklearn.model_selection import cross_val_score from sklearn.preprocessing import MinMaxScaler from keras import backend as K def custom_activation(x): #return (K.sigmoid((x**0.9))) return (1 / (1 + K.exp((0.9/0.9)*(K.pow(-x,K.constant(1)))))) dataframe = pd.read_csv("housing.csv", delim_whitespace=True, header=None) dataset = dataframe.values X = dataset[:, :13] Y = dataset[:, 13] scaler = MinMaxScaler() X_normalized = scaler.fit_transform(X) y_normalized = scaler.fit_transform(Y.reshape(-1, 1)) model = Sequential() model.add(Dense(100, activation=custom_activation)) model.add(Dense(1, activation='linear')) model.compile(loss='mean_squared_error', optimizer='adam') a = model.fit(X_normalized, y_normalized,epochs=100, batch_size=32, verbose=1) y_hat = model.predict(X_normalized) In the code, when the values of the exponents are decimals, the results give NaN. I have replicated the costum equation with this example, and it shows that the function does work, but when implementing it in the ANN, it fails.
tensor = K.constant(X_normalized) result_tensor = 1 / (1 + K.exp((0.9/0.5)*(-tensor**0.5))) [0.5 0.68215114 0.61508656 ... 0.724061 0.8581489 0.6315888 ] [0.50691146 0.5 0.7080713 ... 0.7922898 0.8581489 0.6929465 ] [0.5069081 0.5 0.7080713 ... 0.7922898 0.85701793 0.61146235] ... [0.51112956 0.5 0.7626321 ... 0.8457388 0.8581489 0.6436505 ] [0.5153265 0.5 0.7626321 ... 0.8457388 0.8571911 0.6573859 ] [0.50966954 0.5 0.7626321 ... 0.8457388 0.8581489 0.67732555]], shape=(506, 13), dtype=float32)

Источник: https://stackoverflow.com/questions/780 ... imal-point
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»