optimization

Maximize nonlinear regression function in R

与世无争的帅哥 提交于 2020-02-29 00:12:29
问题 Given a linear model obtained from the function call reg = lm(...) , how can you find the coefficients that maximize the obtained regression function? I'm aware of the function optim(...) , but it requires a function as an input. I haven't figured out how to extract this from the regression model. It should be noted that I'm using non-linear terms in my regression analysis (squared variables, to be precise). In other words, by regression function looks like y_hat = kx_11*x_1+kx_12*x_1^2 + kx

Maximize nonlinear regression function in R

一世执手 提交于 2020-02-29 00:09:24
问题 Given a linear model obtained from the function call reg = lm(...) , how can you find the coefficients that maximize the obtained regression function? I'm aware of the function optim(...) , but it requires a function as an input. I haven't figured out how to extract this from the regression model. It should be noted that I'm using non-linear terms in my regression analysis (squared variables, to be precise). In other words, by regression function looks like y_hat = kx_11*x_1+kx_12*x_1^2 + kx

Is this method faster than Math.random()?

半城伤御伤魂 提交于 2020-02-26 21:37:28
问题 I am a beginner and have currently started working on a game for Android which uses a particle swarm optimization algorithm. I am now trying to optimize my code a little and i have quite a lot of Math.random() in for-loops which is running almost all the time. So i was thinking of a way to get around and skip all the Math.random() calls. By using a method like this: float random[] = new float[100]; static int randomIndex=0; private float myRandom(){ if(randomIndex >= 99) randomIndex = 0; else

Trying to optimize and understand runtime on a recursive function that prints divisors of a number

那年仲夏 提交于 2020-02-25 08:32:06
问题 The following is a recursive function that prints the divisors of a number (it has to be recursive). Without the commented out part, the program's worst case scenario are primes, the while loop will have to run all the way up to n, so the runtime would be: O(n). With the commented part, primes now run on O(sqrt(n)) but it becomes slower on numbers that aren't primes, but that for loop should make counting up to a divisor faster in any case. Can anyone explain why the runtime is slower? I've

Efficiently check an FP bit-pattern for being a whole integer. Faster to branch once on a combination of conditions?

吃可爱长大的小学妹 提交于 2020-02-24 09:05:06
问题 I have the next ASM code: mov r10 , 9007199254740990 ; mask mov r8 , rax shr r8 , 53 sub r8 , 1023 cmp r8 , 52 ; r8 - 52 < 0 setnb ch shrx r11 , r10 , r8 and r11 , rax setne cl ; r11 == 0 test rcx , rcx jz @C_2 ret @C_2: ; integer ret Well, here we have only one branch instruction. And we can rewrite this code by replacing SETcc instructionos on corresponding Jump instructions, and thus we'll get two branch instructions in the code above. My question is, which code will run faster in common

Find minimum distance between points of two lists in Python

怎甘沉沦 提交于 2020-02-23 09:40:47
问题 I have two lists of coordinates: s1 = [(0,0), (0,1), (1,0), (1,1)] s2 = [(3,2), (1,9)] I want to calculate the minimum distance of each point in s1 to any point in s2. e.g. the results should be as follows. result = [3.60, 3.16, 2.82, 2.23] Question: What is the most optimized way in terms of execution time, to achieve this result? So far I've tried this but the execution time is not promising: import math def nearestDistance(boundary, p): minDistList = map(lambda b: (b[0] - p[0])**2 + (b[1]

Convolutional Neural Network (CNN) with max-pooling

房东的猫 提交于 2020-02-21 10:44:10
问题 I've implemented a simple CNN program with Python that can machine learn on the MNIST data set. I've implemented 3 layers: ConvPoolLayer, which convolves and then does mean pooling FullyConnectedLayer, which is a fully connected hidden layer SoftmaxLayer, which basically gives the softmax output of the network It's in the ConvPoolLayer that I've implemented mean pooling. Here's the line of code that does mean pooling during forward propagation: # 'activation' is a numpy array of 3D

Android M startActivity battery optimization

纵然是瞬间 提交于 2020-02-20 01:37:36
问题 I'm developing an app that should alert an user if is near a place. and of course have to do that also if the phone is in idle. With DOZE now I understood that I have to whitelist my app, and to do that I saw that I can start an intent with the action request thanks to Buddy's answer in this post Intent intent = new Intent(); String packageName = context.getPackageName(); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm.isIgnoringBatteryOptimizations

Android M startActivity battery optimization

╄→尐↘猪︶ㄣ 提交于 2020-02-20 01:33:08
问题 I'm developing an app that should alert an user if is near a place. and of course have to do that also if the phone is in idle. With DOZE now I understood that I have to whitelist my app, and to do that I saw that I can start an intent with the action request thanks to Buddy's answer in this post Intent intent = new Intent(); String packageName = context.getPackageName(); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm.isIgnoringBatteryOptimizations

Android M startActivity battery optimization

自古美人都是妖i 提交于 2020-02-20 01:32:10
问题 I'm developing an app that should alert an user if is near a place. and of course have to do that also if the phone is in idle. With DOZE now I understood that I have to whitelist my app, and to do that I saw that I can start an intent with the action request thanks to Buddy's answer in this post Intent intent = new Intent(); String packageName = context.getPackageName(); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm.isIgnoringBatteryOptimizations