我一直在 C++ 和 numpy 中发现关于函数处理复杂无限数log的行为的奇怪行为。log具体来说,log(inf + inf * 1j)等于(inf + 0.785398j)我期望的值(inf + nan * 1j)。
当取复数的对数时,实部是输入的绝对值的对数,虚部是输入的相位。返回 0.785398 作为 的虚部log(inf + inf * 1j)意味着它假设inf实部和虚部中的 s 具有相同的长度。这个假设似乎与其他计算不一致,例如 ,inf - inf == nan它inf / inf == nan假设 2 infs 不一定具有相同的值。
为什么假设log(inf + inf * 1j)不同?
重现 C++ 代码:
#include <complex>
#include <limits>
#include <iostream>
int main() {
double inf = std::numeric_limits<double>::infinity();
std::complex<double> …Run Code Online (Sandbox Code Playgroud) 我是机器学习和张量流的初学者.在尝试张量流的第一步中,我尝试了一个简单的多元线性回归.然而,似乎该模型陷入了局部最低限度.这是我的代码.
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=1)
return tf.Variable(initial)
# dataset
xx = np.random.randint(0,1000,[1000,3])/1000.
yy = xx[:,0] * 2 + xx[:,1] * 1.4 + xx[:,2] * 3
# model
x = tf.placeholder(tf.float32, shape=[None, 3])
y_ = tf.placeholder(tf.float32, shape=[None])
W1 = weight_variable([3, 1])
y = tf.matmul(x, W1)
# training and cost function
cost_function = tf.reduce_mean(tf.square(y - y_))
train_function = tf.train.AdamOptimizer(1e-2).minimize(cost_function)
# create a session
sess = tf.Session()
# train …Run Code Online (Sandbox Code Playgroud)