在这个代码的基础上改一下W的形状:def objective_function(x): weights = x[:11] T = x[11] composite_index = pearson_fusion(data

动态 未结 0 137
小小草
小小草 LV1 2023年9月23日 23:40 发表
在这个代码中,`W`的形状是由随机游走过程生成的,因此不能直接改变它的形状。如果要进行矩阵乘法,需要将另一个矩阵的形状与`W`相兼才行。 可以尝试将`weights`的形状转换为`(11, N+1)`,然后再进行矩阵乘法。具体代码如下: ```python def objective_function(x): weights = x[:11] T = x[11] composite_index = pearson_fusion(data, weights) N = len(composite_index) dt = T/N t = np.linspace(0, T, N+1) dW = np.sqrt(dt)*np.random.randn(N) W = np.cumsum(dW) W = np.insert(W, 0, 0) weights = np.repeat(weights, N+1).reshape((11, N+1)) Z = np.dot(weights, W) print(weights.shape,Z.shape) return -(Z[np.argmax(Z > 0.9*np.max(Z))] - actual_failure_time) ``` 这里使用了`np.repeat()`函数将`weights`重复`N+1`次,并且使用`reshape()`函数将其形状转换为`(11, N+1)`。然后再执行矩阵乘法`np.dot(weights, W)`。这样就可以避免形状不兼容的错误。
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复