optimization

Does effective Cython cProfiling imply writing many sub functions?

与世无争的帅哥 提交于 2019-12-31 06:01:39
问题 I am trying to optimize some code with Cython, but cProfile is not providing enough information. To do a good job at profiling, should I create many sub-routines func2, func3,... , func40 ? Note below that i have a function func1 in mycython.pyx , but it has many for loops and internal manipulations. But cProfile does not tell me stats for those loops . 2009 function calls in 81.254 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000

R: Question about Optimizing - Invalid Function Value in Optimize

只谈情不闲聊 提交于 2019-12-31 05:47:07
问题 R Programming Question - Hello, we are two summer research students participating in a research program. After trial and error, we have not been able to pinpoint what is causing the error of "Invalid Function Value in Optimize" in our Optimizing code. If you could offer any insight, it would be appreciated. H_fun <- function(c) { val = -current_c_weight*c - X_counts%*%log( exp(rep(c,length(current_Theta))*current_Theta) - current_elongation_rates ) print('#########iteration display###########

R customized constraints optim function

99封情书 提交于 2019-12-31 05:43:08
问题 Goal: Estimate sigma1 and sigma2 with the "optim" function, while sigma2 must be greater than sigma1 Simulate data (y) I have the following kind of data y: N<-50 delta<-matrix(rep(0, N*N), nrow=N, ncol=N) for(i in 1:(N )){ for (j in 1:N) if (i == j+1 | i == j-1){ delta[i,j] <- 1; } } sigma1<-5 sigma2<-10 diagonal=2*sigma1^2+sigma2^2 nondiag<--sigma1^2*delta Lambda_i<-(diag(diagonal,N)+-nondiag)/diagonal sig<-as.matrix(diagonal*Lambda_i) sig mu<-rep(0, N) y<-as.vector(mvnfast::rmvn(1,mu, sig))

Optimize matching elements from two large data sets using Levenshtein distance (comparing each element to each other element)

被刻印的时光 ゝ 提交于 2019-12-31 04:33:06
问题 I am currently working on a problem to find the best matches of data in a List namely "ListA" from another List called "ListB". Whenever I find a match of an element for "ListA" with any element in "ListB" which has a confidence and accuracy with 70% or greater I add the matched string from List B and the string in List A to a tuple which i further save in a database. Levenshtien algorithm gives me a number which I compare with my threshold of 70 and if the values returned is equal or greater

Optimizing assembly generated by Microsoft Visual Studio Compiler

断了今生、忘了曾经 提交于 2019-12-31 04:30:51
问题 I'm working on a project with matrix multiplication. I have been able to write the C code and I was able to generate the assembly code for it using the Microsoft visual studio 2012 compiler. The compiler generated code is shown below. The compiler used the SSE registers, which is exactly what I wanted, but it is not the best code. I wanted to optimize this code and write it inline with the C code but I don't understand the assembly code. Basically the assembly code is good for only one

Regression with equality and inequality constrained coefficients in R

人走茶凉 提交于 2019-12-31 04:28:07
问题 I am trying to obtain estimated constrained coefficients using RSS. The beta coefficients are constrained between [0,1] and sum to 1. Additionally, my third parameter is constrained between (-1,1). Utilizing the below I can obtain a nice solution using simulated variables but when implementing the methodology on my real data set I keep arriving at a non-unique solution. In turn, I'm wondering if there is a more numerically stable way to obtain my estimated parameters. set.seed(234) k = 2 a =

all combinations of k numbers between 0 and n whose sum equals n, speed optimization

微笑、不失礼 提交于 2019-12-31 04:25:09
问题 I have this R function to generate a matrix of all combinations of k numbers between 0 and n whose sum equals n. This is one of the bottlenecks of my program as it becomes extremely slow even with small numbers (because it is computing the power set) Here is the code sum.comb <- function(n,k) { ls1 <- list() # generate empty list for(i in 1:k) { # how could this be done with apply? ls1[[i]] <- 0:n # fill with 0:n } allc <- as.matrix(expand.grid(ls1)) # generate all combinations, already using

Should FirebaseDatabase.getInstance() be used sparingly?

浪子不回头ぞ 提交于 2019-12-31 04:05:23
问题 For example when I use a SQLiteDatabase in android, it is generally not a good idea to open/close lots of SQLiteDatabase helpers. Instead it is better to create a sort of singleton which makes sure you only have 1 database open. Say I have a class with static methods doing lots of Firebase operations which require a DatabaseReference. example: static void checkIfUserIsMatched(...) static void notifyUser(...) static void modifyUser(...) Is it OK to call FirebaseDatabase.getInstance() inside

Pushing arrays based on each row inputs dynamically

爷,独闯天下 提交于 2019-12-31 03:48:04
问题 Based on my code I want to push each row's inputs to each array. If it is row1, it should push all the input values of row 1 to array a1 . The second row's inputs should be pushed to array a2 and so on. This is mainly for performance optimization of my code since the rows of my real code are 20+ and I am trying to do it like below but without success. I want to be able to know each row's data (for validation purpose) $('#check').click(function(event){ event.preventdefault; var a1=[];var a2=[]

Where is the flaw in my algorithm for consolidating gold mines?

随声附和 提交于 2019-12-31 03:47:14
问题 The setup is that, given a list of N objects like class Mine { public int Distance { get; set; } // from river public int Gold { get; set; } // in tons } where the cost of moving the gold from one mine to the other is // helper function for cost of a move Func<Tuple<Mine,Mine>, int> MoveCost = (tuple) => Math.Abs(tuple.Item1.Distance - tuple.Item2.Distance) * tuple.Item1.Gold; I want to consolidate the gold into K mines. I've written an algorithm, thought it over many times, and don't