- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将推车和杆模拟与 python 3.7 和 Julia 1.2 进行比较。在 python 中,模拟被编写为如下所示的类对象,而在 Julia 中只是一个函数。使用 Julia 解决问题的时间是一致的 0.2 秒,这比 python 慢得多。我不太了解 Julia ,无法理解为什么。我的猜测是它与编译或循环的设置方式有关。
import math
import random
from collections import namedtuple
RAD_PER_DEG = 0.0174533
DEG_PER_RAD = 57.2958
State = namedtuple('State', 'x x_dot theta theta_dot')
class CartPole:
""" Model for the dynamics of an inverted pendulum
"""
def __init__(self):
self.gravity = 9.8
self.masscart = 1.0
self.masspole = 0.1
self.length = 0.5 # actually half the pole's length
self.force_mag = 10.0
self.tau = 0.02 # seconds between state updates
self.x = 0
self.x_dot = 0
self.theta = 0
self.theta_dot = 0
@property
def state(self):
return State(self.x, self.x_dot, self.theta, self.theta_dot)
def reset(self, x=0, x_dot=0, theta=0, theta_dot=0):
""" Reset the model of a cartpole system to it's initial conditions
" theta is in radians
"""
self.x = x
self.x_dot = x_dot
self.theta = theta
self.theta_dot = theta_dot
def step(self, action):
""" Move the state of the cartpole simulation forward one time unit
"""
total_mass = self.masspole + self.masscart
pole_masslength = self.masspole * self.length
force = self.force_mag if action else -self.force_mag
costheta = math.cos(self.theta)
sintheta = math.sin(self.theta)
temp = (force + pole_masslength * self.theta_dot ** 2 * sintheta) / total_mass
# theta acceleration
theta_dotdot = (
(self.gravity * sintheta - costheta * temp)
/ (self.length *
(4.0/3.0 - self.masspole * costheta * costheta /
total_mass)))
# x acceleration
x_dotdot = temp - pole_masslength * theta_dotdot * costheta / total_mass
self.x += self.tau * self.x_dot
self.x_dot += self.tau * x_dotdot
self.theta += self.tau * self.theta_dot
self.theta_dot += self.tau * theta_dotdot
return self.state
from cartpole import CartPole
import time
cp = CartPole()
start = time.time()
for i in range(100000):
cp.step(True)
end = time.time()
print(end-start)
function cartpole(state, action)
"""Cart and Pole simulation in discrete time
Inputs: cartpole( state, action )
state: 1X4 array [cart_position, cart_velocity, pole_angle, pole_velocity]
action: Boolean True or False where true is a positive force and False is a negative force
"""
gravity = 9.8
masscart = 1.0
masspole = 0.1
l = 0.5 # actually half the pole's length
force_mag = 10.0
tau = 0.02 # seconds between state updates
# x = 0
# x_dot = 0
# theta = 0
# theta_dot = 0
x = state[1]
x_dot = state[2]
theta = state[3]
theta_dot = state[4]
total_mass = masspole + masscart
pole_massl = masspole * l
if action == 0
force = force_mag
else
force = -force_mag
end
costheta = cos(theta)
sintheta = sin(theta)
temp = (force + pole_massl * theta_dot^2 * sintheta) / total_mass
# theta acceleration
theta_dotdot = (gravity * sintheta - costheta * temp)/ (l *(4.0/3.0 - masspole * costheta * costheta / total_mass))
# x acceleration
x_dotdot = temp - pole_massl * theta_dotdot * costheta / total_mass
x += tau * x_dot
x_dot += tau * x_dotdot
theta += tau * theta_dot
theta_dot += tau * theta_dotdot
new_state = [x x_dot theta theta_dot]
return new_state
end
@time include("cartpole.jl")
function run_sim()
"""Runs the cartpole simulation
No inputs or ouputs
Use with @time run_sim() for timing puposes.
"""
state = [0 0 0 0]
for i = 1:100000
state = cartpole( state, 0)
#print(state)
#print("\n")
end
end
@time run_sim()
最佳答案
你的 Python 版本在我的笔记本电脑上需要 0.21 秒。以下是同一系统上原始 Julia 版本的计时结果:
julia> @time run_sim()
0.222335 seconds (654.98 k allocations: 38.342 MiB)
julia> @time run_sim()
0.019425 seconds (100.00 k allocations: 10.681 MiB, 37.52% gc time)
julia> @time run_sim()
0.010103 seconds (100.00 k allocations: 10.681 MiB)
julia> @time run_sim()
0.012553 seconds (100.00 k allocations: 10.681 MiB)
julia> @time run_sim()
0.011470 seconds (100.00 k allocations: 10.681 MiB)
julia> @time run_sim()
0.025003 seconds (100.00 k allocations: 10.681 MiB, 52.82% gc time)
state = (0, 0, 0, 0)
然后类似地更新状态:
new_state = (x, x_dot, theta, theta_dot)
julia> @time run_sim()
0.132459 seconds (479.53 k allocations: 24.020 MiB)
julia> @time run_sim()
0.008218 seconds (4 allocations: 160 bytes)
julia> @time run_sim()
0.007230 seconds (4 allocations: 160 bytes)
julia> @time run_sim()
0.005379 seconds (4 allocations: 160 bytes)
julia> @time run_sim()
0.008773 seconds (4 allocations: 160 bytes)
关于python-3.x - Cart-Pole Python 性能比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57979983/
到目前为止,基本上我的脚本将值发送到网关,然后被重定向到 CS 购物车。在该页面中,我获取返回的值并对其进行操作。 我使用 fn finish 和 fn 更改订单状态来完成订单,但无论我做什么,我都会
到目前为止,基本上我的脚本将值发送到网关,然后被重定向到 CS 购物车。在该页面中,我获取返回的值并对其进行操作。 我使用 fn finish 和 fn 更改订单状态来完成订单,但无论我做什么,我都会
我创建了一个上下文处理器,通过在购物车应用程序目录中创建一个新文件并将其命名为 context_processors.py,将当前购物车设置为模板的请求上下文: from .cart import C
我网页顶部的购物车 block 和每个产品中的“添加到购物车”按钮都消失了。这种情况发生在我网站的每个页面上,而且是突然发生的(请原谅,如果我能记忆起/缩小我所做的更改是导致这种情况的原因,那么我就不
我正在尝试在 Shopify 中制作一个 ajaxed 购物车。我已使产品页面将商品添加到购物车,而无需刷新或转到购物车页面。要查看购物车,您可以单击输入或带有 .cart-show 的链接,因此我将
我试图弄清楚如何将 css 类添加到 SimpleCartJS 的购物车表中生成。 (我使用的购物车布局是这样的: http://bootsnipp.com/snippets/featured/sho
我有一个函数add_to_cart想要反向重定向到由single_product函数呈现的产品详细信息页面,该函数具有产品id的slug,无法找到解决它的方法。正在获取这个错误 Reverse for
有人知道购物车(或类似商品)的Unicode字符吗?我找到了比萨饼(U + 1F355),热线电话(U + 2706)以及这是什么(U + 26A7),但没有该死的购物车! 最佳答案 到目前为止,没有
此代码段为我提供了以下错误消息: def cartItems(cart): items=[] for item in cart: items.append(Produc
我想在 prestashop os-commerce 上获取购物车内容。怎么做到的? 最佳答案 您应该看一下位于 classes/Cart.php 中的 Cart 类。有一个名为 getProduct
我正在使用 Magento 购物者主题 (http://shopper.queldorei.com/)。 当我将产品添加到我的购物车时,它会添加多个元素 Cart 我发现是 jQuery 在这里犯
CS-Cart ajax 工作正常,我也收到响应,但如何在我的 View (checkout.tpl)文件上使用 html/js 响应。 Controller (前端):send_sms.php us
我只在 Magento 上工作了几天,但它已经很令人困惑了。我开始思考这个问题,但目前有一个问题是我的思考。 我的客户想要顶部链接旁边的购物篮功能,而不是顶部链接中的“我的购物车”。简单地说,我想做的
在作业中,我们被要求对 CART 模型执行交叉验证。我试过使用 cvFit函数来自 cvTools但收到一条奇怪的错误消息。这是一个最小的例子: library(rpart) library(cvTo
在主产品信息页面中,它显示了完整的产品描述,我试图放入超长的 HTML 代码来进行打包交易。在编写了大约 1200 行 html 后,我遇到了困难。 我可以做一些改变来扩大产品描述的最大字符长度吗?
我想在 shopify 的 cart.liquid 页面上添加结帐进度条。当用户点击产品上的添加到购物车时,我想显示一个进度条。任何帮助将不胜感激。 最佳答案 只要您的客户离开购物车页面去结账,新的
我在代码中存储多个 ID 时遇到问题。我需要将 id 保存在单个变量(数组)中,因为我将在 cart.php 中调用它来显示添加到购物车的元素。这是我的代码。 Marketech | Bu
我今天工作的服务器的主机在安装 x-cart 后关闭了该站点,因为在服务器上发出了以下命令,他们认为这是一个安全漏洞: ls -la 2>&1 id 2>&1;whoami 2>&1; id 2>&1
您好,我正在尝试创建一个在线电子商务商店,尽管有 paypal 购物车上传功能,但我一切正常,我一直在关注来自 developphp.com 的一系列视频这是我的文件 cart.php 中的代码 a
我有一个 cs-cart 项目,它以我不希望的方式显示页面标题(嗯,以客户不喜欢的方式)。 我希望它显示:在主页上:公司名称在其他页面上:公司名称 |页面标题(即公司名称|关于我们)等 我有以下脚本:
我是一名优秀的程序员,十分优秀!