问题标签 [casadi]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
matlab - 如何离散非线性系统
我如何离散以下非线性系统。我使用 Matlab 和 Casadi 进行模型预测控制。常数 C 介于 0 和 1 之间。
感谢您的时间和帮助。
python - 如何将 Pytorch 模型转换为 CasADi 函数?
考虑到船舶的速度和运行条件,我有一个程序试图将船舶的阻力降至最低。我想将程序转换为使用 CasADi 进行更快的优化。在优化循环中,程序使用 PyTorch 神经网络来预测力。如何将 PyTorch 模型转换为与 CasADi 兼容的模型?
python - 覆盖零数组时出错“无法将输入数组从形状 (8,1) 广播到形状 (8,)”
我想覆盖零数组列,但它给出了一个错误:
无法将输入数组从形状 (8,1) 广播到形状 (8,)
python - casadi中样条的导数
我正在使用 python 库 doMPC 开发 MPC,我必须使用 casadi 符号框架来表达我的所有目标函数和约束。
我需要使用插值三次样条并使用它的导数。但是,我在文档中找不到合适的方法。我非常感谢您的帮助。作为参考,我使用了以下interpolant
功能:
python - 如何在 Tensorflow 2.x 中获得符号梯度
我想转换https://web.casadi.org/blog/tensorflow/,它是使用 Tensorflow 2 用 casadi 在 Tensorflow 1 中编写的。我已经更改了代码,但tf.disable_v2_behavior()
必须完成它才能使其工作。
现在我想纯粹使用 Tensorflow 2.x 来编写这个。默认情况下启用急切执行,我想用它@tf.function
来计算梯度,
这是目前更新的代码,
问题:
在该get_reverse
方法中,在计算梯度时,即 grad = tf.gradients(self.t_out, self.t_in,grad_ys=adj_seed)
,我得到符号形式,即 [<tf.Tensor 'gradients/Sin_grad/mul:0' shape=(2, 2) dtype=float32>, <tf.Tensor 'gradients/MatMul_grad/MatMul_1:0' shape=(2, 1) dtype=float32>]
在 Tensorflow 1 中。
然而,在 Tensorflow 2 中,我总是得到数值结果。我可以访问图表,但这些图表不可调用。self.t_out[0].get_concrete_function(self.t_in).graph
类似于这里
在 Tensorflow 1 中获得符号梯度的更好方法是什么?
预期行为:
grad
应该返回梯度的符号形式而不是数值评估
python - How to improve the execution time of gradient estimation using tf.GradientTape in tensorflow 2.x
The objective is to implement https://web.casadi.org/blog/tensorflow/, which was written using Tensorflow 1.x and gpflow 1.x, using Tensorflow 2.x and gpflow 2.x .
I have implemented it in Tensorflow 2.x (I attached them at the end of the question). However, still, I could not get as faster as the initial implementation, i.e., using Tensorflow 1.x and gpflow 1.x.
Here are execution time
Using Tensorflow 1.x and gpflow 1.x.
Using Tensorflow 2.x and gpflow 2.x.
According to these execution times, it mainly depends on the gradient estimation nlp_grad_f. Tensorflow 1.x uses graph-based gradient estimation which seems to be rather faster than Tensorflow 2.x tf.GradientTape
My question as follows: What's the proper way to implement the gradient estimation in Tensorflow 2.x or how to improve this code further? I've checked https://www.tensorflow.org/api_docs/python/tf/function and what I could to make it faster. I want it to reduce as faster as I get in Tensorflow 1.x.
For reference, I include all the codebase, in case someone wants to execute and see it.
ocp.py
tensorflow_casadi_mod_ocp.py
python - do_mpc:如何使用时变参数
这是一个基本问题,但很难从文档和示例中收集它的工作方式。我想为电池控制器创建一个简单的 MPC - 给定已知负载 ( P_load
)、已知太阳能发电 ( P_solar
) 和已知能源成本 (energy_charge
和demand_charge
),如何正确设置tvp_fun()
以使用这些值数组?
以下是我设置 TVP 的方法template_model.py
:
以下是我如何定义它们template_mpc.py
:
在template_simulator.py
我只是执行以下操作:
但是,我在运行时收到此错误消息python main.py
: