background preloader

Coding

Facebook Twitter

Optimize.minimize — SciPy v0.14.0 Reference Guide. Minimization of scalar function of one or more variables. See also minimize_scalar Interface to minimization algorithms for scalar univariate functions show_options Additional options accepted by the solvers Notes This section describes the available solvers that can be selected by the ‘method’ parameter. Unconstrained minimization Method Nelder-Mead uses the Simplex algorithm [R101], [R102].

Method Powell is a modification of Powell’s method [R103], [R104] which is a conjugate direction method. Method CG uses a nonlinear conjugate gradient algorithm by Polak and Ribiere, a variant of the Fletcher-Reeves method described in [R105] pp. 120-122. Method BFGS uses the quasi-Newton method of Broyden, Fletcher, Goldfarb, and Shanno (BFGS) [R105] pp. 136. Method Newton-CG uses a Newton-CG algorithm [R105] pp. 168 (also known as the truncated Newton method). Method Anneal uses simulated annealing, which is a probabilistic metaheuristic algorithm for global optimization. Constrained minimization. Optimization and root finding (scipy.optimize) — SciPy v0.14.0 Reference Guide. Data fitting using fmin. We have seen already how to find the minimum of a function using fmin, in this example we will see how use it to fit a set of data with a curve minimizing an error function: from pylab import *from numpy import *from numpy.random import normal from scipy.optimize import fmin # parametric function, x is the independent variable# and c are the parameters.# it's a polynomial of degree 2 fp = lambda c, x: c[0]+c[1]*x+c[2]*x*x real_p = rand(3) # error function to minimize e = lambda p, x, y: (abs((fp(p,x)-y))).sum() # generating data with noise n = 30 x = linspace(0,1,n) y = fp(real_p,x) + normal(0,0.05,n) # fitting the data with fmin p0 = rand(3) # initial parameter value p = fmin(e, p0, args=(x,y)) print 'estimater parameters: ', p print 'real parameters: ', real_p xx = linspace(0,1,n*3) plot(x,y,'bo', xx,fp(real_p,xx),'g', xx, fp(p,xx),'r') show() The parameters will be printed also: Optimization terminated successfully.

Python - Scipy minimize fmin - problems with syntax. 2.7. Mathematical optimization: finding minima of functions — Scipy lecture notes. Mathematical optimization deals with the problem of finding numerically minimums (or maximums or zeros) of a function. In this context, the function is called cost function, or objective function, or energy. Here, we are interested in using scipy.optimize for black-box optimization: we do not rely on the mathematical expression of the function that we are optimizing. Note that this expression can often be used for more efficient, non black-box, optimization. Prerequisites Numpy, ScipyIPythonmatplotlib References Mathematical optimization is very ... mathematical. Convex Optimization by Boyd and Vandenberghe (pdf available free online).Numerical Optimization, by Nocedal and Wright. 2.7.1. Not all optimization problems are equal.

Dimensionality of the problem The scale of an optimization problem is pretty much set by the dimensionality of the problem, i.e. the number of scalar variables on which the search is performed. 2.7.1.1. Optimizing convex functions is easy. Note 2.7.1.3. Noisy gradients. Monte Carlo Simulation Basics. [ Preface ] [ Sales Forecast Example ] A Monte Carlo method is a technique that involves using random numbers and probability to solve problems. The term Monte Carlo Method was coined by S. Ulam and Nicholas Metropolis in reference to games of chance, a popular attraction in Monte Carlo, Monaco (Hoffman, 1998; Metropolis and Ulam, 1949). Computer simulation has to do with using computer models to imitate real life or make predictions. When you create a model with a spreadsheet like Excel, you have a certain number of input parameters and a few equations that use those inputs to give you a set of outputs (or response variables).

This type of model is usually deterministic, meaning that you get the same results no matter how many times you re-calculate. [ Example 1: A Deterministic Model for Compound Interest ] Figure 1: A parametric deterministic model maps a set of input variables to a set of output variables. In Example 2, we used simple uniform random numbers as the inputs to the model. Making a Simple Interactive Map Prototype with D3…For Total Beginners Who are Totally Impatient | suffen.us.

The goal of this piece will be to get you up and running with a simple interactive map accessible by web browser. Rather than make sure you know everything ranging from computing basics to fundamentals of programming to web development to geospatial graphics to data visualization, we’re going to get to a prototype as quickly as possible. For those who are daunted by the former, the latter approach can produce tangible results which are good for morale, and many people learn better this way. We’ll be using D3.js, a javascript library (or collection of tools that can be called upon within a script) that helps map information from input files and join that information to Scalable Vector Graphics (SVG) objects. Your web browser can draw these with the proper instructions by default, but D3 provides the tools to bind data to them. I want to make a distinction among the kinds of instructional articles for this kind of material, and where this one fits in. What you will need The data to use.

Dr. Bunsen / Bootstrap in Picture. Introduction I was waiting in line at my local bank recently and spotted an urn filled with coins on a table in the corner of the lobby. When I got to the head of the line, I inquired about it and the clerk told me the urn was part of a contest among some of the bank employees. The objective of the contest was to guess the average mint year among all the coins in the urn without going over the true average.

I explained to the teller that I had an unhealthy interest in these sorts of contests and then asked for one additional clarification about the rules: could the contestants pick up a few of the coins to inspect them before submitting a guess? The clerk shrugged and said she didn’t see any problem with that. The contest piqued my interests because it was somewhat unusual. Most guessing contests involve estimating the number of jellybeans in a jar or the number of snakes on a plane. Overview Experiment The bias of the original estimator is \widehat{\theta} - \theta. Confidence Estimation #! How to use Javascript. Create a Game Character with HTML5 and JavaScript - Part 1 { William Malone } By William Malone In Part 1 of this series we will design a game character from scratch.

We will start with a drawing on paper and with the help of JavaScript we will create a breathing, blinking character on HTML5 canvas. Hopefully by the end of Part 1 you will have the tools and inspiration to create a character of your own. Idea to Pixels First we start with an idea. The next step is to get our idea to pixels. Next we color in the outlines. We are creating a dynamic character so we create our character in distinct parts. Head Hair Torso Legs Left Arm Right Arm Each part is saved as a seperate png image. Draw on HTML5 Canvas With the design of our character complete and in the form of six images, we start the process putting our character on canvas. First we create a new object to hold our image references called images.

We want to know when all of the images are loaded so we can begin drawing. During the redraw process the canvas will be cleared and all parts will be redrawn. Eyes Shadow. 10 cool HTML5 games and how to create your own. Thanks to Apple dropping support for Flash on iOS, HTML5 has gained a lot of traction and is getting very popular. For games, HTML5 (understand canvas and a lot of javascript) is slowly replacing Flash on online gaming websites and mobile games.

I have done in this post a selection of cool and popular HTML5 games, maybe it will give you some motivation to create your own. 10 cool HTML games A list of pretty cool games, make sure to check out the source to understand how they work. 1. Control two characters at the same time and try to let them meet. 2. Defend your planet against incoming meteorites. 3. Addicting simple game where you race with a stick figure in levels designed by other users. 4. Your hero has fallen into a sinkhole and has a broken arm. 5. Not exactly a game, but a game emulator that gives you access to old games that you’ve probably missed. 6. A shoot-em-up with cool isometric 3D graphics. 7. A game created by Kevin Roast. 8. 9. A pretty entertaining tower defence game. Permalinks for Google Drive Images. While Google Drive lets you upload any file, the support for files that can't be edited using Google Docs/Sheets/Slides is limited. For example, you can embed PDF files and videos, but Google doesn't offer permalinks for images.

So you've uploaded a photo to Google Drive and the only options are to download the file and link to the image page. But what if you want to embed that image in a web page or simply post a direct link to the image? You may think that right-clicking the image lets you copy the image URL, but that's not true. Even if you check the source code of a page or use features like Firefox's "view page info", you'll get a link that doesn't work. Fortunately, there's an easy solution - replace this URL from the address bar: with: (where FILEID is a long sequence of digits and letters). This only works if you've changed the visibility options to "public on the Web" or "anyone with the link" in the Share dialog.

How to create a spoiler or show-hide effect. Here is a very simple show/hide effect code for you to copy and use. This effect is also known as a spoiler or a peek-a-boo. It uses a small inline Javascript. You can use this code anywhere, be it in the sidebar or in your blog post, as long as you can add the spoiler code to it. [Update Mar 2013] See our new and improved content spoiler. This code will add a button, clicking it will expand the content, showing the hidden part.

See it in action, click the button now, Here is the hidden content. Simply put the content you want hidden inside the division tags, replacing the phrase HIDDEN CONTENT HERE. Customization You can replace “Show/hide” text with your own, in line 5. Enjoy! How To Show Or Hide Blogger Post Or Widget Content. There are times when we want to collapse our Blogger post or widget content initially and expand it manually to view the content or perhaps the other way round.

Thanks to Random Snippets , we can now do something like this: Show text To learn how to do this, continue reading. In this post, I'm going to show you how to do it step by step based on the instructions available on the site. To Hide Your Text or HTML Codes Initially 1. <script language="javascript"> function toggle() { var ele = document.getElementById("toggleText"); var text = document.getElementById("displayText"); if(ele.style.display == "block") { ele.style.display = "none"; text.innerHTML = "Show text"; } else { ele.style.display = "block"; text.innerHTML = "Hide text"; } } </script> <a href="javascript:toggle();" id="displayText">Show text</a><br /> <div id="toggleText" style="display: none;"> Your text/HTML code here </div> 2. 3. 5. 6. 7.

To Change The 'Show text' and 'Hide text' Text 1. Hide text 1. 1. 3. Note: 1.

R

Mathematica. Linux for Beginners. Gillespie Algorithm. Python Quick Hacks and Codes. Tutorial - Table of contents. Floats, figures and captions - Getting to grips with LaTeX. By Andrew Roberts In the previous tutorial, the importing of graphics was introduced. However, just having a picture stuck in-between paragraphs does not look professional. For starters, we want a way of adding captions, and to be able to cross-reference. What we need is a way of defining figures. It would also be good if LaTeX could apply similar principles to when it arranges text to look its best, to arranging pictures too.

This is where floats come into play. Floats Floating elements refer to anything within a document that cannot be broken over a page. The most common problem is that there is not enough space on the remainder of a given page to fit the specified figure. Figures To create a figure, you must use the figure environment (tricky, eh?!). \begin{figure}[placement specifier] ... figure contents ... In the previous section, I was saying how floats are used to allow LaTeX to handle figures, whilst maintaining the best possible presentation. Tables Captions Wrapping figures Summary.