我正在尝试使用遗传算法构建一个4 x 4数独求解器.我有一些问题,价值收敛到局部最小值.我正在使用排名方法并删除最后两个排名答案的可能性,并用两个排名最高的答案可能性之间的交叉替换它们.为了避免局部mininma的其他帮助,我也使用变异.如果在特定的生成量内未确定答案,则我的人口中充满了全新的随机状态值.但是,我的算法似乎陷入局部最小值.作为健身功能,我正在使用:
(开放平方的总金额*7(每个方格可能违反;行,列和方框)) - 违规总数
population是整数数组的ArrayList,其中每个数组都是基于输入的sudoku可能的结束状态.确定人群中每个阵列的适应度.
有人能够帮助我确定为什么我的算法会收敛于局部最小值,或者可能会建议使用一种技术来避免局部最小值.任何帮助是极大的赞赏.
健身功能:
public int[] fitnessFunction(ArrayList<int[]> population)
{
int emptySpaces = this.blankData.size();
int maxError = emptySpaces*7;
int[] fitness = new int[populationSize];
for(int i=0; i<population.size();i++)
{
int[] temp = population.get(i);
int value = evaluationFunc(temp);
fitness[i] = maxError - value;
System.out.println("Fitness(i)" + fitness[i]);
}
return fitness;
}
Run Code Online (Sandbox Code Playgroud)
交叉功能:
public void crossover(ArrayList<int[]> population, int indexWeakest, int indexStrong, int indexSecStrong, int indexSecWeak)
{
int[] tempWeak = new int[16];
int[] tempStrong = new int[16];
int[] tempSecStrong = new …Run Code Online (Sandbox Code Playgroud) 我有很多点导致 getOrthodromicDistance 方法在 geotools lib 中失败并出现异常,而这些点是有效的经纬度点:
\n\n抛出异常的点(纬度,经度):
\n\nval p1= (5.318765,-75.786109)\nval p2= (-6.32907,106.09254)\nRun Code Online (Sandbox Code Playgroud)\n\n例如例外:\n 点 75\xc2\xb047,2'W 06\xc2\xb019,7'S 和 106\xc2\xb005,6'E 05\xc2\xb019,1'N 没有收敛。\njava.lang。 ArithmeticException: org.geotools.referencing 上的点 75\xc2\xb047,2'W 06\xc2\xb019,7'S 和 106\xc2\xb005,6'E 05\xc2\xb019,1'N.\n 没有收敛.GeodeticCalculator.computeDirection(GeodeticCalculator.java:1073)
\n\nScala 中使用的代码:
\n\n def latlonDistance(p1:(Double,Double), p2:(Double,Double)):Double={\n val world= new GeodeticCalculator()\n world.setStartingGeographicPoint(p1._2, p2._1)\n world.setDestinationGeographicPoint(p2._2, p1._1)\n world.getOrthodromicDistance\n }\nRun Code Online (Sandbox Code Playgroud)\n\n注意:我在 latlonDistance 中传递的点格式是 (lat,lon) 如上所述,而 setStartingGeographicPoint、setDestinationGeographicPoint 需要 (lon,lat) \norder。
\n\n使用的版本:
\n\n <dependency>\n <groupId>org.geotools</groupId>\n <artifactId>gt-referencing</artifactId>\n <version>13.2</version>\n </dependency>\nRun Code Online (Sandbox Code Playgroud)\n\n在 python 中按预期工作:
\n\n>>> from geopy.distance import vincenty\n>>> pt1= [5.318765,-75.786109]\n>>> pt2= …Run Code Online (Sandbox Code Playgroud) 我用lme4运行一个简单的GLMM ...
model1 <- glmer.nb(S ~ Days*Grazing*Biome + (Days|Site), data=mydata, verbose=T, control=ctrl)
Run Code Online (Sandbox Code Playgroud)
...并从bobyqa遇到收敛代码1:“ bobyqa-超出了最大功能评估数”。所以我查找了stackoverflow,发现了这个有趣的线程。
我检修了如下所示的控制对象:
ctrl = glmerControl(optimizer = "bobyqa",
#restart_edge=T,
boundary.tol = 1e-5,
calc.derivs=TRUE,
use.last.params=FALSE,
sparseX = FALSE,
tolPwrss=1e-7,
compDev=TRUE,
nAGQ0initStep=TRUE,
## optimizer args
optCtrl = list(maxfun = 1e5))
Run Code Online (Sandbox Code Playgroud)
但是我仍然遇到同样的错误。然后我跟着另一个链接说,
所以我做了model1 @ optinfo $ feval并说... 172
我必须承认我在期待别的东西,所以我尝试了从1e3到1e8的所有操作,但是我仍然陷于困境。
我的lme4版本是1.1-10;我正在使用Win10 64位R3.1.3(也许应该升级我的R?)
任何(!)帮助或评论都非常感谢!干杯
我想使用优秀的rugarch包在两个不同的时间序列上估计 EGARCH 模型,但求解器无法收敛。我不想使用“混合”求解器选项,因为这会在循环通过“gosolnp”求解器时引入随机性。我的两个问题是:(1)我的数据是否有一些奇怪的东西导致收敛失败,(2)如果没有,有没有办法修改ugarchfit()函数,以便它“更努力地”找到解决方案?以下是我正在使用的数据和代码。
library("rugarch")
ABC <- c(-0.003311,-0.009967,-0.010067,-0.023729,0.006944,-0.010345,0.02439,-0.006803,-0.017123,-0.003484,0.017483,0.054983,0.032573,-0.018927,-0.006817,-0.019608,-0.003333,0.006689,0.006645,-0.009901,0,0.01,0.006601,0,0.009836,0.022727,-0.003175,-0.009554,0.022508,-0.003145,0.006309,-0.021944,0.012821,-0.015823,-0.028939,-0.009934,0.020067,0.045902,-0.012539,-0.003175,0.003185,0.012698,-0.003135,0.009434,-0.003115,-0.00625,0.003145,0.003135,-0.025,0.00641,0.012739,-0.003145,0.009464,-0.009375,0.009464,0,-0.0125,0,0.003165,-0.009464,0.006369,-0.028481,0.035831,-0.003145,0.009464,-0.00625,0.003145,-0.00627,-0.009464,-0.012739,0,-0.006452,0.016234,-0.003195,0.012821,0,0.003544,-0.003185,-0.00639,-0.022508,0.009868,0.006515,-0.003236,0,-0.012987,0.013158,-0.003247,-0.013029,0.0033,0,-0.016447,-0.006689,-0.003367,0.003378,0.013468,0.063123,0.0125,0.006173,-0.006135,-0.033951,-0.003195,-0.003205,0.022508,0.025157,0,-0.006135,-0.009259,-0.018692,0.009524,0.006289,-0.003125,0.015674,0.003086,0.003077,-0.009202,0,0.003096,-0.006173,-0.006211,0,-0.009375,-0.006309,-0.006349,0.00639,-0.003175,0,0.003185,-0.009524,0.009615,-0.003175,-0.009554,0.003215,-0.003205,0,0,0.003215,-0.009615,0.006472,-0.003215,0.000387,0.003257,-0.003247,0.006515,-0.003236,0.012987,0.022436,-0.003135,-0.006289,-0.003165,0.009524,0.044025,0.006024,0.005988,-0.005952,0,-0.017964,-0.003049,0,-0.006116,-0.009231,-0.018634,0.009494,-0.00627,-0.003155,0.009494,0.015674,0.021605,0,0.003021,-0.003012,0,-0.003021,-0.006061,-0.003049,-0.006116,-0.003077,0.003086,-0.006154,0.009288,-0.003067,-0.006154,0,0,-0.01548,0.012579,0.009317,-0.003077,-0.003086,0.006192,-0.006154,0,-0.012384,-0.00627,-0.006309,0.003175,-0.018987,0.016129,-0.009524,0.009615,0.003175,0.018987,-0.006211,0.025,-0.005732,-0.009288,0.00625,-0.006211,-0.009375,0.012618,-0.012461,0.009464,-0.00625,0.003145,-0.003135,0,0.003145,-0.003135,0,-0.006289,0.009494,-0.003135,0.009434,-0.006231,-0.015674,-0.009554,-0.025723,0.0033,-0.003289,-0.006601,0.006645,-0.013201,-0.006689,0.013468,-0.003322,-0.003333,0.006689,0.013289,-0.019672,0.006689,-0.006645,-0.003344,0.006711,0.036667,0.006431,0,-0.00639,0.009646,0.015924,0.003135,0.03125,0.012121,-0.005988,0.021084)
DEF <- c(0.004876,0.029923,-0.072242,-0.015235,-0.011603,0.015652,-0.021832,-0.015755,-0.008448,-0.038565,0.035914,-0.052679,0.005703,0.02741,-0.028059,0.004733,-0.00895,-0.035646,0.176934,-0.023869,-0.039468,-0.016079,0.00227,-0.015851,-0.02439,-0.021226,0.001928,-0.025493,0.027641,0.036023,0.02828,0.001803,-0.011251,0.015476,-0.035858,-0.003719,-0.0042,0.009372,-0.019499,0.023201,0.018047,0.005,0.037087,0.012647,-0.03273,0.036509,0.016323,0.040152,-0.001219,-0.002441,0.039967,0.023137,0.006899,0.007613,-0.007933,-0.026276,-0.003911,0.006677,0.023875,-0.014144,-0.002714,-0.031104,0.027689,0.003124,0.005839,-0.020898,0.030435,0.034906,0.036694,0.004648,-0.017438,-0.034408,-0.006752,0.010196,0.043738,-0.053725,0.008327,-0.035285,0.002724,-0.006209,-0.052714,-0.006595,0.025726,-0.024272,-0.011194,0.005451,-0.004587,0.002514,0.035102,-0.008478,0.052117,0.010836,0.009188,-0.016692,0.033179,-0.025766,0.013415,-0.00643,0.059764,0.002155,0.005376,-0.001069,-0.00571,0,0.005025,-0.001786,0.030411,0.003125,0.010038,-0.014051,-0.025721,-0.018195,0.005451,0.011926,-0.005714,0.002874,0.022206,0.018921,-0.016162,0.013632,-0.048276,-0.018841,0.038405,0.043385,0.000341,0.001363,-0.006805,0.030832,-0.000332,0.016955,0.019941,-0.019551,-0.033998,0.016582,0,0.008655,-0.00099,0.008259,-0.017038,0.007,-0.011917,0.01206,0.005958,0.009543,0.088983,-0.027237,0,-0.004615,0.007728,0.003681,-0.012836,0.017028,0,0.005784,-0.006659,-0.001828,0.000611,-0.012508,0.022552,-0.01148,0.008863,0.003332,0.003925,0.005714,-0.007775,-0.009946,-0.007915,-0.013194,-0.000622,0.015557,0.026961,-0.002387,-0.009569,-0.020229,0.00678,-0.015611,0.001866,0.007759,-0.020942,0.003146,0.017874,0.029883,0.014358,-0.009142,-0.004167,0.002926,0.003287,-0.010125,-0.000903,-0.003312,-0.010876,0.006109,-0.006679,-0.005807,0.006148,0.001528,-0.00244,0.017431,-0.011422,-0.00304,0.021653,-0.017612,-0.005773,-0.018643,0.000934,-0.009023,-0.000314,-0.009736,-0.001269,-0.005081,-0.019151,0.020827,0.000956,-0.018153,-0.013947,0.008224,-0.014356,-0.012248,0.009048,-0.003985,-0.012671,-0.008105,0.011236,-0.017508,0.019877,0.014113,-0.003976,-0.018629,0.002373,-0.002705,-0.014242,-0.02924,-0.00567,0.002851,0.000711,0.01598,0.019224,0.00823,-0.009524,0.015797,-0.025693,0.001388,-0.014553,0.014065,-0.003467,-0.008699,-0.004914,0.00388,-0.002811,-0.003524,-0.004597,-0.004263)
ugarchfit(spec = ugarchspec(mean.model = list(armaOrder = c(0, 0), include.mean = TRUE), variance.model = list(model = "eGARCH", garchOrder = c(1, 1))), data = ABC)
ugarchfit(spec = ugarchspec(mean.model = list(armaOrder = c(0, 0), include.mean = TRUE), variance.model = list(model = "eGARCH", garchOrder = c(1, 1))), data = DEF)
Run Code Online (Sandbox Code Playgroud) 我有一个用于回归预测的神经网络,这意味着输出是 0 到 1 范围内的实数值。
我对所有层都使用了 drop out,错误突然增加并且从未收敛。
drop out 可用于回归任务吗?因为如果我们忽略一些节点,那么最后一层的节点就会减少,预测值肯定会与实际值有很大差异。所以反向传播的误差会很大,模型会被破坏。那么为什么我们要在神经网络中使用 dropout 来执行回归任务呢?
Python和熊猫新手在这里.我正在尝试使用statsmodels来拟合逻辑回归来计算选民投票的概率.我在区域工作; 所以有时函数不会收敛,我得到以下错误:警告:已超过最大迭代次数.
我已经将最大迭代次数增加到1000.然后我尝试将"警告"变成异常.我已导入警告并包含warnings.simplefilter('error',Warning)以尝试捕获它,但它似乎不是真正的Python警告.相反,它是statsmodels在达到最大迭代次数时打印出来的东西.
所以现在我想知道是否有办法说:
if sm.Logit(y, covs).fit(maxiter=1000) doesn't converge:
do something else
Run Code Online (Sandbox Code Playgroud) 我目前正在研究 10 年内六个法国海湾的贝类毒性。我创建了一个代表这一年出现的毒素数量的代理。现在我想通过各种参数来解释这种毒性。目前,我专注于研究微藻大量繁殖对毒性的影响。为了做到这一点,我描述了每年一次的盛开:一年中观察到的最大细胞数、盛开的持续时间、开始的一周等......
因为我的毒性数据很少,所以我想让事情变得非常简单,所以我在这些绽放参数中的 1、2 或 3 个参数上测试 glms,并且我允许交互。
该代码适用于对数正态族,但我想与伽马分布甚至准伽马进行比较(均值方差在 var=2*mean² 的图形上运行良好)。
当我从 gamma 开始时,我收到以下消息:
Error: no valid set of coefficients has been found: please supply starting values
In addition: Warning message:
In log(ifelse(y == 0, 1, y/mu)) : NaNs produced
Run Code Online (Sandbox Code Playgroud)
它出现在第七个模型中:一个只有一个参数的模型:Proxy~DuréeB!
我读到我需要找到带start=参数的coef ,但我有 15 000 个模型要检查,包含 1、2或3 个参数。所以这里是我的问题:
这是我的代码和数据:
output<-sapply(models, function (x) { # x<-models[7]
glm.01<-glm(as.formula(x), family=Gamma, data=TestGLM)
Aic<-AIC(glm.01) #+2*sum(log(TestGLM$Proxy))# correction for log normal AIC
Dev<-(glm.01$null.deviance-glm.01$deviance)/(glm.01$null.deviance)
c(Aic, Dev) …Run Code Online (Sandbox Code Playgroud) 我正在用 glmer 函数进行模拟。对于每次模拟,我将估计值提取到数据库中,但我也希望有一个变量来指示模拟数据是否正确收敛。(我收到警告,例如奇异收敛,错误收敛,...但无论如何都会给出估计值)。
我试试
assign("last.warning", NULL, envir = baseenv()) # clear the previous warning
mod1=glmer(y~x+(1+x|study), family="binomial", data=test1)
warningss1=ifelse(length(warnings())>0, "yes", "no"); warningss1
Run Code Online (Sandbox Code Playgroud)
它永远不会回报我,即使它不同`
请考虑我的食谱末尾的这段代码deploy_to_tomcat:
unless Chef::Config[:solo]
chat_message "Deployed #{artifact_name} `#{Time.new.strftime("%Y-%m-%d %H:%M")}`"
end
Run Code Online (Sandbox Code Playgroud)
它发布一条消息进行聊天:部署了 my-web-app 2016-11-03 12:31
但是,我注意到时间戳有点Time.new过时 - 它似乎是编译配方时的时间戳,而不是几分钟后资源覆盖并运行时的时间戳。
所以我尝试了这个,但它不起作用(timeNow 仍然是undefined发布消息聊天时的时间)
timeNow = "undefined"
ruby_block "set-time-now" do
block do
timeNow = Time.new.strftime("%Y-%m-%d %H:%M:%S")
end
end
unless Chef::Config[:solo]
chat_message "Deployed #{artifact_name} `#{timeNow}`"
end
Run Code Online (Sandbox Code Playgroud)
有没有更简单的方法让我的时间戳反映实际时间(而不是食谱开始时)?
我想在带有噪声的时间序列数据中找到达到某个值的时刻。如果数据中没有峰值,我可以在 MATLAB 中执行以下操作。
代码从这里
% create example data
d=1:100;
t=d/100;
ts = timeseries(d,t);
% define threshold
thr = 55;
data = ts.data(:);
time = ts.time(:);
ind = find(data>thr,1,'first');
time(ind) %time where data>threshold
Run Code Online (Sandbox Code Playgroud)
但是当有噪音时,我不确定必须做什么。
In the time-series data plotted in the above image I want to find the time instant at which the y-axis value 5 is reached. The data actually stabilizes to 5 at t>=100 s. But due to the presence of noise in the data, we see a …
algorithm signal-processing time-series data-analysis convergence
convergence ×10
r ×4
algorithm ×2
glm ×2
chatops ×1
chef-infra ×1
date ×1
dropout ×1
exception ×1
gamma ×1
geotools ×1
java ×1
lme4 ×1
mixed-models ×1
python ×1
ruby ×1
statsmodels ×1
sudoku ×1
time-series ×1
volatility ×1
warnings ×1