- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在努力弄清楚如何在参数优化方法上设置界限(最小/最大)。 Twiddle是优化算法:https://www.youtube.com/watch?v=2uQ2BSzDvXs .我怎样才能确保 p(参数)保持在某个域内?下面是我在 Python 中的 Twiddle 实现:
def twiddle(objFunction, args, init=0.5, tolerance=0.00001, domain=(0,float("inf"))):
"""Optimize a single parameter given an objective function.
This is a local hill-climbing algorithm. Here is a simple description of it:
https://www.youtube.com/watch?v=2uQ2BSzDvXs
@param args (tuple) Arguments necessary for the objective function.
@param tolerance (float) Number used to determine when optimization has
converged to a sufficiently good score.
@param objFunction(function)Objective Function used to quantify how good a
particular parameter choice is.
@param init (float) Initial value of the parameter.
@param domain (tuple) Domain of parameter values, as (min, max).
@return (dict) Contains:
"parameter" (float) Threshold that returns the largest score from the
Objective function.
"score" (float) The score from the objective function given the
threshold.
"""
pastCalls = {}
x = init
delta = 0.1
bestScore = objFunction(x, args)
pastCalls[x] = bestScore
while delta > tolerance: #and x >= domain[0]+tolerance and x <= domain[1]-tolerance:
x += delta
if x not in pastCalls:
score = objFunction(x, args)
pastCalls[x] = score
score = pastCalls[x]
if score > bestScore:
bestScore = score
delta *= 2
else:
x -= 2*delta
if x not in pastCalls:
score = objFunction(x, args)
pastCalls[x] = score
score = pastCalls[x]
if score > bestScore:
bestScore = score
delta *= 2
else:
x += delta
delta *= 0.5
print "Parameter:", x
print "Best score:", bestScore
print "delta:", delta
print
return {"parameter": x,
"score": bestScore}
例如我想将正弦函数作为 objFunction
运行,但域设置为 [0, 2*pi]。
最佳答案
明白了!与@AlexMartelli 的评论类似,该算法需要防止每次递增/递减 x 时越界。为了保持爬山算法的核心功能,步长 delta
必须调整为当前位置与外边界之间距离的一半。这样,算法仍然倾向于向边界方向移动,如果最大值在边界处,则可以到达那里,并且可以在必要时从边界移回。代码如下:
def twiddle(objFunction, args, init=0.5, tolerance=0.00001, domain=(float("-inf"), float("inf"))):
"""Optimize a single parameter given an objective function.
This is a local hill-climbing algorithm. Here is a simple description of it:
https://www.youtube.com/watch?v=2uQ2BSzDvXs
@param args (tuple) Arguments necessary for the objective function.
@param tolerance (float) Number used to determine when optimization has
converged to a sufficiently good score.
@param objFunction(function)Objective Function used to quantify how good a
particular parameter choice is.
@param init (float) Initial value of the parameter.
@param domain (tuple) Domain of parameter values, as (min, max).
@return (dict) Contains:
"parameter" (float) Threshold that returns the largest score from the
Objective function.
"score" (float) The score from the objective function given the
threshold.
"""
pastCalls = {}
x = init
delta = 0.1
bestScore = objFunction(x, args)
pastCalls[x] = bestScore
while delta > tolerance:
# Keep x within bounds
if x+delta > domain[1]:
delta = abs(domain[1] - x) / 2
x += delta
if x not in pastCalls:
score = objFunction(x, args)
pastCalls[x] = score
score = pastCalls[x]
if score > bestScore:
bestScore = score
delta *= 2
else:
# Keep x within bounds
if x-delta < domain[0]:
delta = abs(domain[0] - x) / 2
x -= 2*delta
if x not in pastCalls:
score = objFunction(x, args)
pastCalls[x] = score
score = pastCalls[x]
if score > bestScore:
bestScore = score
delta *= 2
else:
x += delta
delta *= 0.5
print "Parameter:", x
print "Best score:", bestScore
print "Step size:", delta
print
return {"parameter": x,
"score": bestScore}
关于python - twiddle 优化器的域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27593423/
这是我的本地域名 http://10.10.1.101/uxsurvey/profile/dashboard 在 Controller 中,我为用户列表设置了一个操作 redirect(control
要处理 Canonical URL,最佳做法是执行 301 重定向还是更好地为 www 和非 www 域使用相同的 IP 地址? 例如: 想要的规范 URL/域是 http://example.com
1 内网基础 内网/局域网(Local Area Network,LAN),是指在某一区域内有多台计算机互联而成的计算机组,组网范围通常在数千米以内。在局域网中,可以实现文件管理、应用软件共享、打印机
1 内网基础 内网/局域网(Local Area Network,LAN),是指在某一区域内有多台计算机互联而成的计算机组,组网范围通常在数千米以内。在局域网中,可以实现文件管理、应用软件共享、打印机
我想创建一个 weblogic 集群,其中有两个托管服务器,每个服务器在物理上独立的远程计算机上运行 根据weblogic文档 All Managed Servers in a cluster mus
我正在运行 grails 3.1.4,但在创建允许我将多个域对象绑定(bind)到其他几个域对象的模式时遇到了问题。作为我正在尝试做的一个例子: 我有三个类(class)。书籍、作者和阅读列表。 作者
我试图使用@count函数来根据它获取数据,但是在没有崩溃报告的情况下它以某种方式崩溃了。 这是代码 class PSMedia: Object { @objc dynamic var id
有谁知道是否有办法只输入字母字符而不输入数字?我想过这样的事情 CREATE DOMAIN countryDomain AS VARCHAR(100) CHECK( VALUE ??? );
我的代码: const checkoutUrl = 'https://example.com/checkout/*' window.onload = startup() function st
一些不是我编写的应用程序,也不是用 PHP 编写的,它为域 www.example.com 创建了一个 cookie。 我正在尝试替换该 cookie。所以在 PHP 中我做到了: setcookie
什么是 oauth 域?是否有任何免费的 oauth 服务?我可以将它用于 StackApps registration 吗? ?我在谷歌上搜索了很多,但找不到答案。 最佳答案 这是redirect_
自从 In October 2009, the Internet Corporation for Assigned Names and Numbers (ICANN) approved the cre
我使用 apache 作为我的应用程序 Web 服务器的代理,并希望即时更改与 sessionid cookie 关联的域名。 该cookie有一个与之关联的.company.com域,我想使用apa
我只想托管一个子域到cloudflare。我不想将主域名的域名服务器更改为他们的域名服务器。真的有可能吗? 最佳答案 是的,这是可能的,但是需要通过CloudFlare合作伙伴进行设置,或者您需要采用
When using socket in the UNIX domain, it is advisable to use path name for the directory directory m
想象两个共享一个域类的 Grails 应用程序。也许是 Book 域类。 一个应用程序被标识为数据的所有者,一个应用程序必须访问域数据。类似于亚马逊和亚马逊网络服务。 我想拥有的应用程序将使用普通的域
我有一个包含字段“URL”的表单。第一部分需要用户在文本框中填写。第二部分是预定义的,显示在文本框的右侧。 例如,用户在文本框中输入“test”。第二部分预定义为“.example.com”。因此,总
如果我要关闭并取消分配 azure 中的域 Controller ,从而生成新的 vm Generationid,我需要采取哪些步骤来恢复它? 最佳答案 what steps do I need to
我想尝试使用 Azure 作为托管提供商(我有一个域)。我读过那篇文章https://learn.microsoft.com/en-us/azure/app-service-web/web-sites
所以.... 我想知道是否有人可以在这方面协助我? 基本上,我已经创建了一个自托管的Docker容器,用作构建代理(Azure DevOps) 现在,我已经开始测试代理,并且由于我们的放置文件夹位于W
我是一名优秀的程序员,十分优秀!