optimization

Optimise a function with two parameters and constraints in R using solnp function?

混江龙づ霸主 提交于 2020-01-05 05:31:29
问题 I have the following function and would like to optimise parameters x and y in order to maximise the output. I am trying to do that using optimise . EDIT Thanks to the comments here I am able to optimise using Rsolnp::solnp . But now I get error when I add upper and lower bounds. See example below Ojective function: my_fn <- function(x) { z <- ifelse(x[1] < 1000000, 0, ifelse(x[1] < 19500000, x[1] * 0.0175, ifelse(x[1] < 20500000, x[1] * 0.0190, ifelse(x[1] < 21500000, x[1] * 0.0220, ifelse(x

Can gcc make my code parallel?

你。 提交于 2020-01-05 05:18:09
问题 I was wondering if there is an optimization in gcc that can make some single-threaded code like the example below execute in parallel. If no, why? If yes, what kind of optimizations are possible? #include <iostream> int main(int argc, char *argv[]) { int array[10]; for(int i = 0; i < 10; ++ i){ array[i] = 0; } for(int i = 0; i < 10; ++ i){ array[i] += 2; } return 0; } Added: Thanks for OpenMP links, and as much as I think it's useful, my question is related to compiling same code without the

Performance benefits for “SVG Tiny 1.2” in today’s mobile & desktop browsers?

大城市里の小女人 提交于 2020-01-05 04:28:10
问题 I am trying to find the best way to export a complex vector graphic (i.e., an architectural plan, weighing in at several megabytes uncompressed) for optimal display on the web – and I wonder, if the generally recommended SVG 1.1 option in Illustrator is the best choice. From what I've learned so far, Scalable Vector Graphics Tiny 1.2 specification ... used to have limited viewer support , but not anymore. has no effect on file size; best way to reduce it is by shaving off unnecessary decimals

What are some possible optimizations for NSDateFormatter's stringFromDate?

回眸只為那壹抹淺笑 提交于 2020-01-05 04:14:20
问题 I am currently profiling my iPhone application start-up in an attempt to get it to start as quickly as possible. In the first 19 seconds of my application being started I call NSDateFormatter's stringFromDate method 6 times with the following format string: @"h:mm a zzz" The NSDateFormatter instance itself is shared by all calls and I only set the date format once, but those 6 calls to stringFromDate amount to 17.3% of my start-up CPU time. Note: The dates are dynamic so I can't just save the

Resolving how to give an attribute in a class in Python

自闭症网瘾萝莉.ら 提交于 2020-01-04 15:54:08
问题 I have the following class: class Point(object): __slots__= ("x","y","z","data","classification") def __init__(self,x,y,z,n=None): self.x = float(x) self.y = float(y) self.z = float(z) self.data = [self.x,self.y,self.z] def set_classification(self,n): self.classification = n p = Point(10,20,30) p.data [10.0, 20.0, 30.0] p.set_classification(0) p.data [10.0, 20.0, 30.0] I have the following questions: First, the parameters to create the Point object are x,y , and z . Classification is an

In which direction are CSS selectors validated?

荒凉一梦 提交于 2020-01-04 14:40:31
问题 I remember watching a video a while back online that was a talk given by an engineer at Yahoo and in it he mentioned that CSS selectors are read, by the browser, right to left and not left to right. Meaning #body .header .links a would actually pull out all anchors on the page filtering those with a parent of class links that had a parent of class header that had a parent with id body . I can't find the video and was wondering if anyone has any references to reinforce this or is it not

How to get the optimized choice from arrays

。_饼干妹妹 提交于 2020-01-04 14:14:50
问题 I have several arrays of hashes (let's say I have three) as follows: a = [{ cost: 10, value: 20}, { cost: 9, value: 20}, { cost: 10, value: 22}, { cost: 2, value: 10} ] b = [{ cost: 4, value: 20}, { cost: 9, value: 20}, { cost: 15, value: 22}, { cost: 12, value: 10} ] c = [{ cost: 10, value: 21}, { cost: 9, value: 20}, { cost: 10, value: 22}, { cost: 3, value: 10} ] I need to find out which choice of hashes, one from each array, gives me the maximum sum of :value keeping the sum of :cost

Optimal HashSet Initialization (Scala | Java)

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 14:06:42
问题 I'm writing an A.I. to solve a "Maze of Life" puzzle. Attempting to store states to a HashSet slows everything down. It's faster to run it without a set of explored states. I'm fairly confident my node (state storage) implements equals and hashCode well as tests show a HashSet doesn't add duplicate states. I may need to rework the hashCode function, but I believe what's slowing it down is the HashSet rehashing and resizing. I've tried setting the initial capacity to a very large number, but

Realtime Updates in AngularJS

拈花ヽ惹草 提交于 2020-01-04 09:53:05
问题 In an attempt to learn Angular & Codeigniter I have expanded the initial new tutorial (from CI). In it's current stage, it automatically displays new posts & removes deleted posts from the page & of course updates model/DB. -- I assume I'm not doing this the most effective way for AngularJS though. Feedback on my code would be helpful for that. -- However, my main concern is how to do differential updates in Angular? When I accomplished this via jQuery, I simply appended a timestamp to my

Scipy minimize: How to pass args to both the objective and the constraint

只谈情不闲聊 提交于 2020-01-04 09:22:18
问题 My MWE is as follows def obj(e, p): S = f(e) + g(p) return S I would like to minimize this function over only e and pass p as an argument to the function. However, I also would like a constraint that depends on p and e that is of the form p + e < 1 I tried cons = {'type': 'ineq', 'fun': lambda e, p: -e -p + 1, 'args': (p)} And then, I try to minimize this for the case of p = 0.5 minimize(obj, initial_guess, method = 'SLSQP', args = 0.5, constraints = cons) but this doesn't work. I get the