optimization

Between of two strings

和自甴很熟 提交于 2019-12-24 22:16:24
问题 I have simple method in C# : public static string BetweenOf(string ActualStr, string StrFirst, string StrLast) { return ActualStr.Substring(ActualStr.IndexOf(StrFirst) + StrFirst.Length, (ActualStr.Substring(ActualStr.IndexOf(StrFirst))).IndexOf(StrLast) + StrLast.Length); } How can i optimise this ? 回答1: Here's how the code from @Chris here stacks up against a regular expression test: void Main() { string input = "abcdefghijklmnopq"; string first = "de"; string last = "op"; Regex re1 = new

CHAID error using caret in R: model fit failed for Resample01: alpha2=0.05, alpha3=-1, alpha4=0.05 Error : is.factor(x) is not TRUE

≯℡__Kan透↙ 提交于 2019-12-24 21:44:14
问题 CHAID error using caret in R: model fit failed for Resample01: alpha2=0.05, alpha3=-1, alpha4=0.05 Error : is.factor(x) is not TRUE I'm getting the error above when trying to run a CHAID model in caret. The model runs fine with this data just by using the CHAID function. Any suggestions? Code below: model_weights <- ifelse(as.character(train_data$outcome) == "Sucess", 5.4,1) model_tree_caret_cost = caret::train(outcome ~ ., data = train_data, method = "chaid", #tuneGrid = tunegrid, #costs =

Speeding up a function

五迷三道 提交于 2019-12-24 21:25:35
问题 I want to calculate the first differences for a large panel data set. At the moment this however takes more than an hour. I am really curious to know if there are still any options left to speed up the process. As an example database: set.seed(1) DF <- data.table(panelID = sample(50,50), # Creates a panel ID Country = c(rep("A",30),rep("B",50), rep("C",20)), Group = c(rep(1,20),rep(2,20),rep(3,20),rep(4,20),rep(5,20)), Time = rep(seq(as.Date("2010-01-03"), length=20, by="1 month") - 1,5),

Does the .NET JIT optimize nested try/catch statements?

依然范特西╮ 提交于 2019-12-24 21:24:56
问题 I've been thinking about nested try/catch statements and started to think about under which conditions, if any, the JIT can perform an optimization or simplification of the compiled IL. To illustrate, consider the following functionally-equivalent representations of an exception handler. // Nested try/catch try { try { try { foo(); } catch(ExceptionTypeA) { } } catch(ExceptionTypeB) { } } catch(ExceptionTypeC) { } // Linear try/catch try { foo(); } catch(ExceptionTypeA) { } catch

Does having several indices all starting with the same columns negatively affect Sybase optimizer speed or accuracy?

故事扮演 提交于 2019-12-24 19:54:24
问题 We have a table with, say, 5 indices (one clustered). Question: will it somehow negatively affect optimizer performance - either speed or accuracy of index picks - if all 5 indices start with the same exact field? (all other things being equal). It was suggested by someone at the company that it may have detrimental effect on performance, and thus one of the indices needs to have the first two fields switched. I would prefer to avoid change if it is not necessary, since they didn't back up

optim function with infinite value

这一生的挚爱 提交于 2019-12-24 19:24:31
问题 To minimize a function with respect to 3 parameters, I use the optim function and "L-BFGS-B" method. Here is the error message : Error in optim(c(3, 0.01, 0.75), fn = f, lower = c(0.6, 0.0001, 0.1), : L-BFGS-B needs finite values of 'fn' I already checked the values of the function when at least one of the three parameters reaches the "border" (ie the lower or the upper values) but it never gives an infinite value. How to know which values gave an infinite value in the optim function? 回答1: A

Short (ASCII, 7-bit per character) string storage and comparison optimization in C++

主宰稳场 提交于 2019-12-24 19:24:29
问题 In my project I'm using huge set of short strings in ASCII 7-bit and have to process (store, compare, search etc) these strings with maximum performance. Basically, I build some Index array of uint64_t type and each element stores 9 characters of a word and use that index as Numeric element for any string comparison operation. Current implementation works fast, but may be it's possible to improve it a bit if you will.. This function converts up to 9 initial characters to uint64_t value - any

Limiting Cypher queries

本秂侑毒 提交于 2019-12-24 19:11:57
问题 I am currently using a neo4j database with 50000 nodes and 2 million relationships to perform cypher MATCH queries, like the one below: start startnode = node(42660), endnode = node(30561) match startnode-[r*1..3]->endnode return r; This query by itself provides 443 rows, but I only want Cypher to find 5 matches and return those only. Allow me to clarify: I do not just want Cypher to return only 5 results, I also want cypher to STOP querying once it finds 5 results. I DO NOT want Cypher to

How to get “first-order optimality” with python script

社会主义新天地 提交于 2019-12-24 18:56:36
问题 I curious about how to get "first-order optimality" value using python script. For optimatization python has many module like scipy.optimize and openopt. But I confused how to use that module to get first-order optimality This is sample matlab script to get first-order optimality [x,resnorm,residual,exitflag,output,lambda]= lsqcurvefit(func,x0,xdata,tdata); foo = output.firstorderopt %get first-order optimality value this is some of foo reference from mathworks here Thanks for your attention,

How can I improve this function under CUDA?

只谈情不闲聊 提交于 2019-12-24 18:53:22
问题 Can I improve the following function under CUDA ? What the function does is, Given a min and max , ELM1 and ELM , check if any three numbers of array ans[6] are found in any row, from min to max , in array D1 , D2 , D3 , D4 , D5 , D6 , if found return 1. I tried using loops , OR -ing, AND -ing, replacing goto with flag etc. etc. But this seems to be the fastest way. __device__ bool THREEA(unsigned int n0, unsigned int n,unsigned int* ST1,unsigned int* D1, unsigned int* D2,unsigned int* D3