在 DNN 训练和输入的偏导数结束时返回逆 Hessian 矩阵

2023-12-13

使用 Keras 和 Tensorflow 作为后端,我构建了一个 DNN,它以恒星光谱作为输入(7213 个数据点)并输出三个恒星参数(温度、重力和金属丰度)。该网络在我的测试集上训练良好并预测良好,但为了使结果在科学上有用,我需要能够估计我的错误。这样做的第一步是获得逆 Hessian 矩阵,这似乎仅使用 Keras 是不可能的。因此,我尝试使用 scipy 创建一个解决方法,使用 scipy.optimize.minimize 和 BFGS、L-BFGS-B 或 Netwon-CG 作为方法。其中任何一个都将返回逆 Hessian 矩阵。

这个想法是使用 Adam 优化器训练模型 100 个周期(或直到模型收敛),然后运行一次 BFGS 迭代或函数(或其他函数之一)以返回模型的 Hessian 矩阵。

这是我的代码:

from scipy.optimize import minimize

import numpy as np

from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.optimizers import Adam


# Define vars
activation = 'relu'
init = 'he_normal'
beta_1 = 0.9
beta_2 = 0.999
epsilon = 1e-08

input_shape = (None,n)
n_hidden = [2048,1024,512,256,128,32]
output_dim = 3

epochs = 100
lr = 0.0008
batch_size = 64
decay = 0.00

# Design DNN Layers

model = Sequential([

    Dense(n_hidden[0], batch_input_shape=input_shape, init=init, activation=activation),

    Dense(n_hidden[1], init=init, activation=activation), 

    Dense(n_hidden[2], init=init, activation=activation),

    Dense(n_hidden[3], init=init, activation=activation),

    Dense(n_hidden[4], init=init, activation=activation),

    Dense(n_hidden[5], init=init, activation=activation),

    Dense(output_dim, init=init, activation='linear'),
])


# Optimization function
optimizer = Adam(lr=lr, beta_1=beta_1, beta_2=beta_2, epsilon=epsilon, decay=decay)


# Compile and train network
model.compile(optimizer=optimizer, loss='mean_squared_error')

#train_X.shape = (50000,7213)
#train_Y.shape = (50000,3)
#cv_X.shape = (10000,7213)
#cv_Y.shape = (10000,3)

history = model.fit(train_X, train_Y, validation_data=(cv_X, cv_Y),
             nb_epoch=epochs, batch_size=batch_size, verbose=2)


weights = []
for layer in model.layers:
    weights.append(layer.get_weights())

def loss(W):
    weightsList = W
    weightsList = np.array(W)
    new_weights = []
    for i, layer in enumerate((weightsList)):
        new_weights.append(np.array(weightsList[i]))
    model.set_weights(np.array(new_weights))
    preds = model.predict(train_X)
    mse = np.sum(np.square(np.subtract(preds,train_Y)))/len(train_X[:,0])
    print(mse)
    return mse


x0=weights    
res = minimize(loss, x0, args=(), method = 'BFGS', options={'maxiter':1,'eps':1e-6,'disp':True})
#res = minimize(loss, x0, method='L-BFGS-B', options={'disp': True, 'maxls': 1, 'gtol': 1e-05, 'eps': 1e-08, 'maxiter': 1, 'ftol': 0.5, 'maxcor': 1, 'maxfun': 1})
#res = minimize(loss, x0, args=(), method='Newton-CG', jac=None, hess=None, hessp=None, tol=None, callback=None, options={'disp': False, 'xtol': 1e-05, 'eps': 1.4901161193847656e-08, 'return_all': False, 'maxiter': 1})
inv_hess = res['hess_inv']

1)该模型训练得非常好,但是当尝试使用之前训练的权重运行 scipy 最小化器进行单次迭代时,我遇到了问题。

尝试 method=BFGS 时的输出:

0.458706819754
0.457811632697
0.458706716791
...
0.350124572422
0.350186770445
0.350125320636

ValueErrorTraceback (most recent call last)
---> 19 res = minimize(loss, x0, args=(), method = 'BFGS', tol=1, options={'maxiter':1,'eps':1e-6,'disp':True})#,'gtol':0.1}, tol=5)

/opt/anaconda3/lib/python2.7/site-packages/scipy/optimize/_minimize.pyc in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
    442         return _minimize_cg(fun, x0, args, jac, callback, **options)
    443     elif meth == 'bfgs':
--> 444         return _minimize_bfgs(fun, x0, args, jac, callback, **options)

/opt/anaconda3/lib/python2.7/site-packages/scipy/optimize/optimize.pyc in _minimize_bfgs(fun, x0, args, jac, callback, gtol, norm, eps, maxiter, disp, return_all, **unknown_options)
    963         try:  # this was handled in numeric, let it remaines for more safety
--> 964             rhok = 1.0 / (numpy.dot(yk, sk))
    965         except ZeroDivisionError:
    966             rhok = 1000.0

ValueError: operands could not be broadcast together with shapes (7213,2048) (2048,1024) 

尝试 method=L-BFGS-B 时的输出:

ValueErrorTraceback (most recent call last)

---> 20 res = minimize(loss, x0, method='L-BFGS-B', options={'disp': True, 'maxls': 1, 'gtol': 1e-05, 'eps': 1e-08, 'maxiter': 1, 'ftol': 0.5, 'maxcor': 1, 'maxfun': 1})


/opt/anaconda3/lib/python2.7/site-packages/scipy/optimize/_minimize.pyc in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
    448     elif meth == 'l-bfgs-b':
    449         return _minimize_lbfgsb(fun, x0, args, jac, bounds,
--> 450                                 callback=callback, **options)


/opt/anaconda3/lib/python2.7/site-packages/scipy/optimize/lbfgsb.pyc in _minimize_lbfgsb(fun, x0, args, jac, bounds, disp, maxcor, ftol, gtol, eps, maxfun, maxiter, iprint, callback, maxls, **unknown_options)
    300         raise ValueError('maxls must be positive.')
    301 
--> 302     x = array(x0, float64)
    303     f = array(0.0, float64)
    304     g = zeros((n,), float64)

ValueError: setting an array element with a sequence.

尝试方法时的输出=Newton-CG

ValueErrorTraceback (most recent call last)

---> 21 res = minimize(loss, x0, args=(), method='Newton-CG', jac=None, hess=None, hessp=None, tol=None, callback=None, options={'disp': False, 'xtol': 1e-05, 'eps': 1.4901161193847656e-08, 'return_all': False, 'maxiter': 1})


/opt/anaconda3/lib/python2.7/site-packages/scipy/optimize/_minimize.pyc in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
    445     elif meth == 'newton-cg':
    446         return _minimize_newtoncg(fun, x0, args, jac, hess, hessp, callback,
--> 447                                   **options)
    448     elif meth == 'l-bfgs-b':
    449         return _minimize_lbfgsb(fun, x0, args, jac, bounds,

/opt/anaconda3/lib/python2.7/site-packages/scipy/optimize/optimize.pyc in _minimize_newtoncg(fun, x0, args, jac, hess, hessp, callback, xtol, eps, maxiter, disp, return_all, **unknown_options)
   1438     _check_unknown_options(unknown_options)
   1439     if jac is None:
-> 1440         raise ValueError('Jacobian is required for Newton-CG method')

ValueError: Jacobian is required for Newton-CG method

2)下一个任务是获得模型输出相对于模型输入的导数。例如,对于一个恒星参数(输出之一),例如温度,我需要找到关于每个 7213 输入的偏导数。然后对 3 个输出中的每一个执行相同的操作。

所以基本上,我的第一个任务(1)是找到一种方法来返回模型的逆 Hessian 矩阵,接下来(2)我需要找到一种方法来返回输出相对于输入的一阶偏导数。

有人对这两项任务有一定的了解吗? 谢谢。

EDIT

我正在尝试使用 theano.gradient.jacobian() 返回输出的雅可比矩阵。我的输入。我已将模型转换为模型权重的函数,并将该函数用作 theano.gradient.jacobian() 中的第一个参数。当我尝试使用多维数组运行梯度时,我的问题出现了,我的模型权重和输入数据的形式是多维数组。

import theano.tensor as T

weights_in_model = T.dvector('model_weights')
x = T.dvector('x')

def pred(x,weights_in_model):
    weights = T.stack((weights_in_model[0],weights_in_model[1]), axis=0)
    x = T.shape_padright(x, n_ones=1)

    prediction=T.dot(x, weights)
    prediction = T.clip(prediction, 0, 9999.)

    weights = T.stack((weights_in_model[2],weights_in_model[3]), axis=0)
    prediction = T.shape_padright(prediction, n_ones=1)
    prediction = T.dot(prediction, weights)
    prediction = T.clip(prediction, 0, 9999.)

    weights = T.stack((weights_in_model[4],weights_in_model[5]), axis=0)
    prediction = T.shape_padright(prediction, n_ones=1)
    prediction = T.dot(prediction, weights)
    prediction = T.clip(prediction, 0, 9999.)

    weights = T.stack((weights_in_model[6],weights_in_model[7]), axis=0)
    prediction = T.shape_padright(prediction, n_ones=1)
    prediction = T.dot(prediction, weights)
    prediction = T.clip(prediction, 0, 9999.)

    weights = T.stack((weights_in_model[8],weights_in_model[9]), axis=0)
    prediction = T.shape_padright(prediction, n_ones=1)
    prediction = T.dot(prediction, weights)
    prediction = T.clip(prediction, 0, 9999.)

    weights = T.stack((weights_in_model[10],weights_in_model[11]), axis=0)
    prediction = T.shape_padright(prediction, n_ones=1)
    prediction = T.dot(prediction, weights)
    prediction = T.clip(prediction, 0, 9999.)


    weights = T.stack((weights_in_model[12],weights_in_model[13]), axis=0)
    prediction = T.shape_padright(prediction, n_ones=1)
    prediction = T.dot(prediction, weights)
    T.flatten(prediction)

    return prediction


f=theano.gradient.jacobian(pred(x,weights_in_model),wrt=x)
h=theano.function([x,weights_in_model],f,allow_input_downcast=True)


x = train_X
weights_in_model = model.get_weights()
h(x,weights_in_model)

最后一行给出了错误:

TypeError: ('Bad input argument to theano function with name "<ipython-input-365-a1ab256aa220>:1"  at index 0(0-based)', 'Wrong number of dimensions: expected 1, got 2 with shape (2000, 7213).')

但是当我将输入更改为:

weights_in_model = T.matrix('model_weights')
x = T.matrix('x')

我从该行收到错误:

f=theano.gradient.jacobian(pred(x,weights_in_model),wrt=x)

reading:

AssertionError: tensor.jacobian expects a 1 dimensional variable as `expression`. If not use flatten to make it a vector

关于如何解决这个问题有什么想法吗?


找到答案!: 此代码用于预测模型的一个输出值。目前我正在修改它来计算 3 个雅可比矩阵;每个输出一个。

import theano
import theano.tensor as T
import theano.typed_list
theano.config.optimizer='fast_compile'
theano.config.exception_verbosity='high'

# Declare function input placeholders
weights_in_model = theano.typed_list.TypedListType(theano.tensor.dmatrix)()
x = T.matrix('x')

# Define model function
def pred(x,weights_in_model): 
    weights = T.concatenate((weights_in_model[0],weights_in_model[1]), axis=0)
    x = T.concatenate((x, T.ones((T.shape(x)[0], 1))), axis=1)

    prediction = T.dot(x, weights)
    prediction = T.clip(prediction, 0, 9999.)

    weights = T.concatenate((weights_in_model[2],weights_in_model[3]), axis=0)
    prediction = T.concatenate((prediction, T.ones((T.shape(prediction)[0], 1))), axis=1)
    prediction = T.dot(prediction, weights)
    prediction = T.clip(prediction, 0, 9999.)

    weights = T.concatenate((weights_in_model[4],weights_in_model[5]), axis=0)
    prediction = T.concatenate((prediction, T.ones((T.shape(prediction)[0], 1))), axis=1)
    prediction = T.dot(prediction, weights)
    prediction = T.clip(prediction, 0, 9999.)

    weights = T.concatenate((weights_in_model[6],weights_in_model[7]), axis=0)
    prediction = T.concatenate((prediction, T.ones((T.shape(prediction)[0], 1))), axis=1)
    prediction = T.dot(prediction, weights)
    prediction = T.clip(prediction, 0, 9999.)

    weights = T.concatenate((weights_in_model[8],weights_in_model[9]), axis=0)
    prediction = T.concatenate((prediction, T.ones((T.shape(prediction)[0], 1))), axis=1)
    prediction = T.dot(prediction, weights)
    prediction = T.clip(prediction, 0, 9999.)

    weights = T.concatenate((weights_in_model[10],weights_in_model[11]), axis=0)
    prediction = T.concatenate((prediction, T.ones((T.shape(prediction)[0], 1))), axis=1)
    prediction = T.dot(prediction, weights)
    prediction = T.clip(prediction, 0, 9999.)


    weights = T.concatenate((weights_in_model[12],weights_in_model[13]), axis=0)
    prediction = T.concatenate((prediction, T.ones((T.shape(prediction)[0], 1))), axis=1)
    prediction = T.dot(prediction, weights)
    prediction = T.flatten(prediction)
    return prediction

# Create gradient function
f=theano.gradient.jacobian(pred(x,weights_in_model),wrt=x)

# Compile function
h=theano.function([x,weights_in_model],f,allow_input_downcast=True)


# Get function inputs
weights_in_model_ = model.get_weights()
x_=train_data

# Reshape bias layers
weights_in_model_[1] = np.reshape(weights_in_model_[1], (1, 2048))
weights_in_model_[3] = np.reshape(weights_in_model_[3], (1, 1024))
weights_in_model_[5] = np.reshape(weights_in_model_[5], (1, 512))
weights_in_model_[7] = np.reshape(weights_in_model_[7], (1, 256))
weights_in_model_[9] = np.reshape(weights_in_model_[9], (1, 128))
weights_in_model_[11] = np.reshape(weights_in_model_[11], (1, 32))
weights_in_model_[13] = np.reshape(weights_in_model_[13], (1, 1))

# Compute Jacobian (returns format with a bunch of zero rows)
jacs = h(x_, weights_in_model_)

# Put Jacobian matrix in proper format (ie. shape = (number_of_input_examples, number_of_input_features)

jacobian_matrix = np.zeros((jacs.shape[0],jacs.shape[2]))
for i, jac in enumerate(jacs): 
    jacobian_matrix[i] = jac[i]

下一个任务是找到输出的 Hessian 矩阵。模型权重!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 DNN 训练和输入的偏导数结束时返回逆 Hessian 矩阵 的相关文章

  • 下载 PyQt6 的 Qt Designer 并使用 pyuic6 将 .ui 文件转换为 .py 文件

    如何下载 PyQt6 的 QtDesigner 如果没有适用于 PyQt6 的 QtDesigner 我也可以使用 PyQt5 的 QtDesigner 但是如何将此 ui 文件转换为使用 PyQt6 库而不是 PyQt5 的 py 文件
  • Python PAM 模块的安全问题?

    我有兴趣编写一个 PAM 模块 该模块将利用流行的 Unix 登录身份验证机制 我过去的大部分编程经验都是使用 Python 进行的 并且我正在交互的系统已经有一个 Python API 我用谷歌搜索发现pam python http pa
  • 使用 openCV 对图像中的子图像进行通用检测

    免责声明 我是计算机视觉菜鸟 我看过很多关于如何在较大图像中查找特定子图像的堆栈溢出帖子 我的用例有点不同 因为我不希望它是具体的 而且我不确定如何做到这一点 如果可能的话 但我感觉应该如此 我有大量图像数据集 有时 其中一些图像是数据集的
  • 如何使用固定的 pandas 数据框进行动态 matplotlib 绘图?

    我有一个名为的数据框benchmark returns and strategy returns 两者具有相同的时间跨度 我想找到一种方法以漂亮的动画风格绘制数据点 以便它显示逐渐加载的所有点 我知道有一个matplotlib animat
  • pandas 替换多个值

    以下是示例数据框 gt gt gt df pd DataFrame a 1 1 1 2 2 b 11 22 33 44 55 gt gt gt df a b 0 1 11 1 1 22 2 1 33 3 2 44 4 3 55 现在我想根据
  • SQL Alchemy 中的 NULL 安全不等式比较?

    目前 我知道如何表达 NULL 安全的唯一方法 SQL Alchemy 中的比较 其中与 NULL 条目的比较计算结果为 True 而不是 NULL 是 or field None field value 有没有办法在 SQL Alchem
  • Python tcl 未正确安装

    我刚刚为 python 安装了graphics py 但是当我尝试运行以下代码时 from graphics import def main win GraphWin My Circle 100 100 c Circle Point 50
  • 从列表中的数据框列中搜索部分字符串匹配 - Pandas - Python

    我有一个清单 things A1 B2 C3 我有一个 pandas 数据框 其中有一列包含用分号分隔的值 某些行将包含与上面列表中的一项的匹配 它不会是完美的匹配 因为它在其中包含字符串的其他部分 该列 例如 该列中的一行可能有 哇 这里
  • feedparser 在脚本运行期间失败,但无法在交互式 python 控制台中重现

    当我运行 eclipse 或在 iPython 中运行脚本时 它失败了 ascii codec can t decode byte 0xe2 in position 32 ordinal not in range 128 我不知道为什么 但
  • 在pyyaml中表示具有相同基类的不同类的实例

    我有一些单元测试集 希望将每个测试运行的结果存储为 YAML 文件以供进一步分析 YAML 格式的转储数据在几个方面满足我的需求 但测试属于不同的套装 结果有不同的父类 这是我所拥有的示例 gt gt gt rz shorthand for
  • 当玩家触摸屏幕一侧时,如何让 pygame 发出警告?

    我使用 pygame 创建了一个游戏 当玩家触摸屏幕一侧时 我想让 pygame 给出类似 你不能触摸屏幕两侧 的错误 我尝试在互联网上搜索 但没有找到任何好的结果 我想过在屏幕外添加一个方块 当玩家触摸该方块时 它会发出警告 但这花了很长
  • 如何将 numpy.matrix 提高到非整数幂?

    The 运算符为numpy matrix不支持非整数幂 gt gt gt m matrix 1 0 0 5 0 5 gt gt gt m 2 5 TypeError exponent must be an integer 我想要的是 oct
  • 从 pygame 获取 numpy 数组

    我想通过 python 访问我的网络摄像头 不幸的是 由于网络摄像头的原因 openCV 无法工作 Pygame camera 使用以下代码就像魅力一样 from pygame import camera display camera in
  • 如何将 PIL 图像转换为 NumPy 数组?

    如何转换 PILImage来回转换为 NumPy 数组 这样我就可以比 PIL 进行更快的像素级转换PixelAccess允许 我可以通过以下方式将其转换为 NumPy 数组 pic Image open foo jpg pix numpy
  • Python:计算字典的重复值

    我有一本字典如下 dictA unit1 test1 alpha unit1 test2 beta unit2 test1 alpha unit2 test2 gamma unit3 test1 delta unit3 test2 gamm
  • VSCode:调试配置中的 Python 路径无效

    对 Python 和 VSCode 以及 stackoverflow 非常陌生 直到最近 我已经使用了大约 3 个月 一切都很好 当尝试在调试器中运行任何基本的 Python 程序时 弹出窗口The Python path in your
  • 在 Pandas DataFrame Python 中添加新列[重复]

    这个问题在这里已经有答案了 例如 我在 Pandas 中有数据框 Col1 Col2 A 1 B 2 C 3 现在 如果我想再添加一个名为 Col3 的列 并且该值基于 Col2 式中 如果Col2 gt 1 则Col3为0 否则为1 所以
  • 对输入求 Keras 模型的导数返回全零

    所以我有一个 Keras 模型 我想将模型的梯度应用于其输入 这就是我所做的 import tensorflow as tf from keras models import Sequential from keras layers imp
  • 如何使用google colab在jupyter笔记本中显示GIF?

    我正在使用 google colab 想嵌入一个 gif 有谁知道如何做到这一点 我正在使用下面的代码 它并没有在笔记本中为 gif 制作动画 我希望笔记本是交互式的 这样人们就可以看到代码的动画效果 而无需运行它 我发现很多方法在 Goo
  • 循环标记时出现“ValueError:无法识别的标记样式 -d”

    我正在尝试编码pyplot允许不同标记样式的绘图 这些图是循环生成的 标记是从列表中选取的 为了演示目的 我还提供了一个颜色列表 版本是Python 2 7 9 IPython 3 0 0 matplotlib 1 4 3 这是一个简单的代

随机推荐

  • 获取连接到 C# .NET WebAPI 应用程序的客户端的 IP 地址

    我试过 private const string HttpContext MS HttpContext private const string RemoteEndpointMessage System ServiceModel Chann
  • zend 与 select 的关系

    我是 zend 的新手 我被要求重新开发一个曾经用纯 PHP 编写的网站并将其放入 zend 框架中 我在数据库关系方面遇到很多麻烦 我似乎无法专心定义和查询关系 我想找一个类别 从该类别中 我希望能够找到与其关联的所有类别信息 并能够查询
  • 是否可以使用Python的requests库设置代理链?

    标准情况如下 公司的安全策略要求所有员工使用公司的代理服务器 需要授权 来获取任何 https 资源 为了通过 Python 解释器成功使用任何互联网连接 我必须手动 set HTTP PROXY http
  • 价格 woocommerce 中的小数分隔符

    Hi everyone I have this configuration in my woocommerce And in my product I have this 但当我显示价格时 它返回 4 95 而不是 4 95 我用这个来获取
  • 在 Hibernate 中混合 HQL 和 Criteria API

    是否可以混合使用 HQL 和 Criteria API 我有一个String包含 HQL 中的 where 条件和Criteria它已经建成并从其他地方获得 我想知道是否可以添加where条件String to Criteria add w
  • 使用 Spring CloudVault 时应用程序初始化时出现禁止错误

    使用 Spring Cloud HOXTON SR6 和 Spring boot 2 3 2 启动服务时 尝试访问 secret application 和 secret application profile 时出现 403 错误 这些路
  • 按自定义顺序对字符串数组进行排序

    我想按照我提到的顺序对字符串数组中的一组固定字符串进行排序 例如 文本文件 图像文件 音频文件 视频文件 应用程序文件 其他文件 示例1 如果我的字符串数组输入是这样的 inputval 0 Other files inputval 1 I
  • 用于获取 JavaFX WebView 控制台事件的公共 API 是什么?

    我想记录 WebView 控制台事件 他们有时会发现所使用的底层浏览器中的怪癖 并可以帮助排除故障 可以使用 Sun 实现类与 WebView 控制台交互 import WebConsoleListener setDefaultListen
  • 将方法指针从 C# 传递到 Delphi DLL

    我在将字符串作为 PChar 传递到 Delphi 构建的 DLL 时遇到了一些问题 感谢 Jens M hlenhoff 解决了它 现在我有另一个问题 如果 Delphi 声明是常规类型过程 则在传递给 DLL 时我已成功回调 c 方法
  • 将 razor 视图渲染为字符串而不修改 html

    我之前找到过有关如何将 MVC 4 视图渲染为字符串的答案 但是 我开始使用视觉工作室2013而现在的结果并不如预期 见下文 lt A gt lt B gt lt C gt class panel lt D gt gt lt E gt cl
  • MongoDB 和类验证器唯一验证 - NESTJS

    TL DR 我正在尝试在我的验证器中运行猫鼬查询 您好 我正在尝试制作一个自定义装饰器 如果该字段的值已存在 它会抛出错误 我正在尝试在验证路线的类中使用猫鼬模型 与解析器 控制器不同 InjectModel 不适用于验证器类 我的验证器是
  • 使用 jquery ui 模式对话框提交表单

    提交表单时 我在使用 JQuery UI 模态对话框时遇到困难 目的是您点击提交按钮 模式弹出窗口 根据您在模式中的选择 表单要么提交 要么不提交 相反 模式会弹出并自动提交 前端 div title Basic dialog p Plea
  • 如何将 JavaScript 对象编码为 JSON?

    有没有一种将 JavaScript 对象编码为 JSON 的好方法 我有一个键值对列表 其中名称来自复选框 并且值根据该框是否被选中而为 true 或 false var values checks checkbox each functi
  • 在颜色空间中的scale_fill/color中粘贴名称不能循环工作

    使用时缩放填充连续发散 from colorspace里面一个for loop or function不粘贴name图例标题并通过错误 如下例所示 library ggplot2 library colorspace set seed 10
  • 尝试用 JPanel 画线

    我正在尝试使用画线JPanel我已经碰壁了 我可以将两侧朝下 但是一旦涉及到从 x 线中减去 一切都会出错 package GUIstuff import java awt Graphics import javax swing JPane
  • 为什么无符号n位整数的最大值是2ⁿ-1而不是2ⁿ?

    The maximum value of an n bit integer is 2n 1 Why do we have the minus 1 Why isn t the maximum just 2n The 1因为整数是从0开始的 但
  • 如何在 C++ 端获取 QQuickItem 的有效实例

    好吧 我进行了很多搜索 但还没有找到好的解决方案 我是新来的Qt 我有一堂课是QQuickItem像这样 class MyQuickItemClass public QQuickItem Q OBJECT SetInfo SomeCppCl
  • 如何使用 SQL 查找缺失的数据行?

    我的问题 我有一个MySQL数据库 它按时间顺序存储大量气象数据 每10分钟插入一次新数据 不幸的是 已经发生了几次停电 因此某些行丢失了 我最近设法从气象站获取了某些备份文件 现在我想用它们来填充丢失的数据 DB 的结构如下 示例 dat
  • 使用 string.Replace 来匹配整个单词

    我正在使用 NET 2 0 和 WinForms 目前 我需要一段代码来将给定文本中的一个字符串替换为另一个字符串 但在文本中它应该只查找整个单词 我的意思是 string name COUNTER 40 CLOCK COUNTER 60
  • 在 DNN 训练和输入的偏导数结束时返回逆 Hessian 矩阵

    使用 Keras 和 Tensorflow 作为后端 我构建了一个 DNN 它以恒星光谱作为输入 7213 个数据点 并输出三个恒星参数 温度 重力和金属丰度 该网络在我的测试集上训练良好并预测良好 但为了使结果在科学上有用 我需要能够估计