Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
edited
Given that the words "uncertain" and "uncertainty" are fairly ubiquitous, it's hard to Google "uncertainty arithmetic" and get anything immediately helpful. Thus, can anyone suggest a good library of routines, in almost any programming/scripting language, that implements handling of uncertain values, as per this description:
Use uncertainty arithmetic to record values that are approximations, for which there is a measured tolerance. This is when we are unsure about a value, but know the upper and lower bounds it can have, expressed as a ±value.
I believe "Interval Arithmetic" is the more common name for what you're looking for.
boost::interval would be my first choice for a supporting library.
If you are looking for an error propagation module (this is different from interval arithmetic, but error propagation is what is commonly used by scientists), I would suggest that you have a look at my uncertainties Python module. It handles error/uncertainty propagation in a transparent way, and, contrary to many implementations, properly handles correlations between variables.
Have a look at Thomas Flanagan's Error Propagation Java class. The approach it uses is most excellent for handling uncertainty without excess trouble.
for reference, as it's probably way too late for you, I'd suggest BIAS/Profil: http://www.ti3.tuhh.de/keil/profil/index_e.html
It's not a library, but your question reminded me of an example in "Expert F#" that describes probabilistic workflows:
instead of writing expressions to compute, say, integers, we instead write expressions that compute distributions of integers. This case study is based on a paper by Ramsey and Pfeffer from 2002.
You can read the excerpt on google books.
I'd probably go about this by declaring a class called UncertainValue, with methods and properties such as (psuedocode):
class UncertainValue
{
private double upperbound;
private double lowerbound;
private double nominalvalue;
private double certainty;
...
UncertainValue add(UncertainValue value);
UncertainValue multiply(UncertainValue factor);
}
I realise this doesn't answer your question in terms of finding a pre-made library, sorry.
INTLAB (INTerval LABoratory) is a well-known library for interval arithmetic and verified numerical linear algebra. It is based on MATLAB/Octave. You can download this library from here:
http://www.ti3.tu-harburg.de/rump/intlab/
kv library is an interval arithmetic library made by C++ and Boost C++ libraries. Multiple precision interval arithmetic is available. It also has a verified ODE solver.
http://verifiedby.me/kv/index-e.html
For other interval arithmetic libraries/software, check the following website:
http://www.cs.utep.edu/interval-comp/intsoft.html
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
My larger goal is implementing analytic derivatives for a generic structural eigenvalue problem. Inside my model I develop the mass and stiffness matrices, and am using scipy.linalg.eig to solve for all eigenvalues/vectors. Currently, there are about 100 degrees of freedom in the finite element model (Euler beam elements), but only the first (smallest eigenvalues) three to five eigenvalue/vector pairs are of interest. Eventually I would like to solve the problem using a reduced basis, but that isn't the current goal.
I am attempting to implement a modal method reverse algorithmic differentiation formula described in a recent paper by He, Jonsson, and Martins (https://doi.org/10.2514/1.J060726). This formulation expresses the mass and stiffness matrix reverse seeds in terms of the eigenvalues, eigenvectors and the reverse seeds of both. My understanding is that OpenMDAO and the MAUD architecture develops these seeds when total derivatives are computed.
Is this something that compute_jacvec_product and the Matrix-Free API would allow me to implement? If so, do d_inputs[] and d_outputs[] correspond to the seed values? Or is an algorithmic differentiation like this even possible to implement at the component-level in OpenMDAO?
I am also familiar with TACS and Mphys for structural problems, and am exploring if it might make more sense to incorporate those into my model rather than a from-scratch FE model...
EDIT:
I've implemented a quick explicit component for the eigenvalue problem, linked here
You have the right idea. I can't be a lot more specific without some example code, but the d_inputs and d_outputs do in fact carry the seeds in forward and reverse modes for explicit components.
For Implicit components the reverse seed is carried in the d_residuals vector and the fwd seeds are carried in both the d_inputs and d_outputs vectors.
If you are trying to use AD, you might find the functional API helpful. It's new, and was specifically designed to help make AD more usable. Its not strictly required. You could obviously just write functions yourself, and then put a thing component wrapper layer around them. But the functional API is meant to let you avoid the wrapper boiler plate code.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
In quite a few of my more recent programs, I've been using basic calculus to replace if statements such as in a for loop I've used:
pos = cbltSz*(x-1) to get the position of a small cube relative to a large one rather than saying something like if(x == 0){pos = -cbltSz}. This is more or less to neaten up the code a little bit. But it got me thinking. To what extent would using maths out-perform pre-defined statements/ functions? and how much would it vary from language to language? This is assuming that my maths used is preferable to the alternative in a way other than aesthetic.
Modern CPUs have deep pipelines, so that a branch misprediction may come at a considerable performance impact. On the other hand, they tend to have considerable floating-point computation power, often being able to perform multiple floating-point operations in parallel on different ALUs. So there might be a performance benefit to this approach. But it all depends. If the application is already doing a lot of number crunching, the ALUs might be saturated. If the branch predictor does a good job, branch mispredictions may be rare in many applications.
So I'd go with the usual rules for optimizations: don't try to hand-optimize everything. Don't optimize at the cost of readability and maintainability. If you have a performance bottleneck, identify the hot portions of your codebase and consider alternatives for those. Try out alternatives in benchmarks, because theoretic considerations only get you so far.
Note that your statements pos = cbltSz*(x-1) and if(x == 0){pos = -cbltSz} are not equivalent if x is non-zero: the first sets pos to some definite value while the second leaves it to its previous value. The significance of this difference depends on the rest of your program. The two statements also differ in clarity--the second expresses your purpose better and the first does not "neaten up the code a little bit". In most programs, improved clarity is more important than a slight increase in speed.
So the answer to your question depends on too many factors to get a full answer here.
What most early programming language designers didn't understand, and many still don't understand, is that mathematical functions are a bit different from user-defined functions. If we've done any trig at all, we all know what sin(PI/8) is going to mean,and we're happy embedding the class in expressions like
rx = cos(theta) * x - sin(theta) * y;
But functions you write yourself are only seldom like basic mathematical functions. They take several parameters, they return several parameters, it's not usually quite clear what they do. The last thing you want is to embed them in complicated expressions.
Secondly, maths has its own system of notation for a reason. The cut down, ascii-only system of a programming language breaks down as soon as expressions go above a certain low complexity. (I use the rule of three, three levels of nested parentheses are all your user can take in). And, without special programming support, programming functions cannot escape their domain.
pow(sqrt(-1), sqrt(-1));
won't do what you want unless you have a complex math library installed.
As for performance, some Fortran and C compilers optimise mathematical routines very aggressively, with constant propagation and the like. Others won''t. It just depends.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I am looking for a recommendation (or comparison) of solvers for second order cone programming with regard to evaluation speed. The solver must be free for non-profit use or open source.
I am fairly open regarding the environment: stand-alone solutions, libraries, Matlab, Python, R, etc. are all acceptable.
My problem has significant sparsity in the constraints which I believe can be exploited by good solvers to speed up the calculation.
As you probably know, cvxpy uses either cvxopt
or ecos as solver.
I've used ecos only a tiny bit, for LP not cones (3x faster then cvxopt on one testcase).
It's ~ 5k lines c + python wrapper, does everything! in scipy.sparse.csc format; might be worth a look.
you might want to take a look to the benchmark maintained at
http://plato.la.asu.edu/bench.html
there you can find both SOCP and QP tests of various size. Most of the solvers would provide you with several interfaces, no issues on that. For a list of solvers look here
http://en.wikipedia.org/wiki/Second-order_cone_programming
I am not sure it is complete but you can start from here.
In my experience, for large size problems commercial solvers, as MOSEK and CPLEX, will give much better performances and stability, well of course I am biased as you might imagine given my username.
Remember that most of the commercial vendors nowadays can provide you either an academic or a trial license. This can be handy to tests and comparisons.
In my opinion, you may consider leaving to the user the choice on which solver to use. It is a little bit more work to do, but it gives much more flexibility to you and to the user. You can draw some inspiration here
Ipopt - COIN-OR Project:
Cbc :
I suggest you to use a commercial solver to come up with a good formulation that such a solver can solve as fast as you want. This is then the ground to compare with others. If you have some nice large scale problems you need help with, you can contact us at mosek.com.
cbc: https://projects.coin-or.org/Cbc
ipopt: https://projects.coin-or.org/Ipopt
In addition to CVXPY (http://www.cvxpy.org/), you might also consider QCML (https://github.com/cvxgrp/qcml), which generates C code specific to your problem.
CVXPY has been improving very rapidly. The issues in Check constraints are ok in cvxpy with actual values are from a totally obsolete version. Assuming your problem isn't too large (less than a million variables), CVXPY will probably meet your needs. Even with large problems you can use the SCS solver in CVXPY to find a fast (though somewhat less accurate) solution.
There exist also SCS (splitting conic solver) under the MIT licence, it is written in C and it has multiple ports (Python, R ..).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
Do you know a good and especially easy guide to code one's own Computational Fluid Dynamics solver, for the 2D Euler equations?
I just would like to understand what commercial software like Fluent is doing. And when it's easy enough I would like to show some friends how to do and code that.
Unfortunately I couldn't find how to translate this http://en.wikipedia.org/wiki/Euler_equations_%28fluid_dynamics%29 into a numeric application.
Has anyone done this before? Any help is appreciated,
Andreas
Yes, lots of people have done it before.
The trick is to write conservation laws for mass, momentum, and energy as integral equations and turn them into matrix equations so you can solve them numerically. The transformation process usually involves discretizing a control volume using simple shapes like triangles and quadrilaterals for 2D and tetrahedra and bricks for 3D and assuming distributions of pertinent variables within the shape.
You'll need to know a fair amount about linear algebra, and numerical integration if the problem is transient.
There are several techniques for doing it: finite differences, finite elements, and boundary elements (if a suitable Green's function exists).
It's not trivial. You'll want to read something like this:
http://www.amazon.com/Numerical-Transfer-Hemisphere-Computational-Mechanics/dp/0891165223
This book:
http://www.amazon.com/Computational-Fluid-Dynamics-John-Anderson/dp/0070016852
is a pretty straightforward, simple description of what it takes to write a CFD code. It's suitable for an undergraduate level intro with more practical examples than theory.
Your 6 year old question is still fairly common among all Computational Fluid Dynamics (CFD) newbies ("How hard can this be?"). However, one must at this stage be careful to not trivialize the math behind solving a given system of equations.
To those new to (or interested) in CFD -
Before you start thinking about coding, it is important to understand the nature of the equations you are trying to solve. An elliptic problem (like a Poisson solver for potential flow) is very different from a hyperbolic system (like the Euler equations) in which information "propagates" through the numerical domain in the form of different wave modes. Which is my first point,
1. Know the properties of the system and study the equations - For this step, you will need to go through math textbooks on partial differential equations, and know how to classify different equations. (See Partial Differential Equations for Scientists and Engineers by Farlow, or revisit your undergraduate math courses.)
2. Study linear algebra - The best CFD experts I know, have strong fundamentals in linear algebra.
Moving to a specific case for hyperbolic problems, e.g. the Euler equations
3. Read on spatial and temporal discretization - This is the point that is less well understood by people new to CFD. Since information propagates in a definite direction and speed in hyperbolic problems, you cannot discretize your equations arbitrarily. For this, you need to understand the concept of Riemann problems, i.e. given a discontinuous interface between two states at a given time, how does the system evolve? Modern finite-volume methods, use spatial discretizations that replicate how information is propagated through your simulation in space and time. This is called upwinding. Read Toro's book on Riemann solvers for a good introduction to upwinding.
4. Understand the concept of stability - Not all discretizations and time-integration methods will lead to a stable solution. Understand the concept of a limiting time-step (CFL-condition). If you don't follow the laws of upwinding, it will be difficult to get a stable solution.
At this point of time, you will have a clearer idea of what goes into a CFD code and you can start worrying about which language to use to code. Most widely used CFD codes are written in C or Fortran for computational speed and parallelization. However, if you intend to code only to learn, you can use Matlab or Python, which will be less frustrating to work with. I should also mention that coding a 2D Euler solver is a typical homework problem for new graduate students in Aerospace engineering, so try and be humble and open to learning if you succeed.
For anyone who is looking into CFD, know that it is a challenging and amazing field, with many advancements. If you wish to succeed, read up on papers (especially the fundamentals) and don't give up if you can't understand a topic. Keep working hard, and you will find yourself pushing the boundaries of what CFD can do.
The answer to your question depends on the approach you want to use to solve the 2D Euler equation . Personally , I recommend the finite Volume approach and to understand it, I think you should take a look on this book:
Computational Fluid Dynamics: Principles and Applications by Jiri Blazek.
It's a good book that takes from the beginning to stand the finite volume method to writing your own code and it also comes with a companion code to guide along the way . It's very good book, it did me wonders when I was writing my Master's thesis.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I would like to compile a list of tips and tricks on mathematical programming optimization, often I read in the forums things like:
Compare distance using the distance square value because square root
calculation is more expensive
(variable * 0.5) is faster than (variable / 2.0)
For me being an programming enthusiast I would like to do my best in wath optimization is concern, Any contribution would be much appreciated
Two key points.
MEASURE - dont assume you know what is slow and/or why. Measure it in real production code. Then only worry about the bit that is chewing up most of your time.
Optimise your algorithm not your code. Look for somethig that you're doing that is o(N^2) instead of o(N) or is o(N) instead of o(ln(N)) and switch to an algorithm with better asymptotic behaviour.
I would say, the first thing to pin down before thinking of optimisation is the scope and intended purpose of your library. For example, is this library 2D or 3D does it includes geometrical algorithms, like convex hull?
Like most people developing such library you will run into a few unavoidable issues. Things like precisions errors can definitely drive you mad at times. Beware of degenerated triangles as well.
Consider algorithms that include an epsilon or tolerance carefully. This is a neat feature to have, but it will make your algorithms more complex.
If you venture in the world of 3D, treat point and vector differently (this is one of the most common issue in 3D math). Consider meta programming for template multiplications (this one will get flamed I feel it) as it can considerably speed up rendering.
In general, try to avoid virtual calls for anything but substantial algorithms, small classes like vectors or points should not be inherited (another flaming opportunity).
I would say, start by sticking to good development practice, read Efficient C++ and More Efficient C++ by Scott Meyers and If you take short cuts like comparing the squared value to avoid a square root calculation, comment your code so future developer can understand the maths.
Finally, do not try to over optimize up front, use a profiler for this. Personally I often start by coding the most elegant solution (should I say what I consider the most elegant solution) and then optimize, you will be surprised at how good a job the C++ optimizer often do.
Hope this helps
Martin