Can I implement algorithmic differentiation in OpenMDAO using matrix seeds? [closed] - openmdao

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.

Related

Machine Learning Suggestions [closed]

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 5 years ago.
Improve this question
I have data of a lot of students who got selected by some colleges based on their marks. Iam new to machine Learning. Can I have some suggestions how can I add Azure Machine Learning for predicting the colleges that they can get based on their marks
Try a multi-class logistic regression - also look at this https://gallery.cortanaanalytics.com/Experiment/da44bcd5dc2d4e059ebbaf94527d3d5b?fromlegacydomain=1
Apart from logistic regression, as #neerajkh suggested, I would try as well
One vs All classifiers. This method use to work very well in multiclass problems (I assume you have many inputs, which are the marks of the students) and many outputs (the different colleges).
To implement one vs all algorithm I would use Support Vector Machines (SVM). It is one of the most powerful algorithms (until deep learning came into the scene, but you don't need deep learning here)
If you could consider changing framework, I would suggest to use python libraries. In python it is very straightforward to compute very very fast the problem you are facing.
use randomforesttrees and feed this ML algorithm to OneVsRestClassifer which is a multi class classifier
Keeping in line with other posters' suggestions of using multi-class classification, you could use artificial neural networks (ANNs)/multilayer perceptron to do this. Each output node could be a college and, because you would be using a sigmoid transfer function (logistic) the output for each of the nodes could be directly viewed as the probability of that college accepting a particular student (when trying to make predictions).
Why don't you try softmax regression?
In extremely simple terms, Softmax takes an input and produces the probability distribution of the input belonging to each one of your classes. So in other words based on some input (grade in this case), your model can output the probability distribution that represents the "chance" a given sudent has to be accepted to each college.
I know this is an old thread but I will go ahead and add my 2 cents too.
I would recommend adding multi-class, multi-label classifier. This allows you to find more than one college for a student. Of course this is much easier to do with an ANN but is much harder to configure (say with the configuration of the network; number of nodes/hidden nodes or even the activation function for that matter).
The easiest method to do this as #Hoap Humanoid suggests is to use a Support Vector Classifier.
To do any of these method its a given that you have to havea well diverse data set. I cant say the number of data points you need that you have to experiment with but the accuracy of the model is dependent on number of data points and its diversity.
This is very subjective. Just applying any algorithm that classifies into categories won't be a good idea. Without performing Exploratory Data Analysis and checking following things you can't be sure of a doing predictive analytics, apart from missing values:
Quantitative and Qualitative variable.
Univariate, Bivariate and multivariate distribution.
Variable relationship to your response(college) variable.
Looking for outliers(multivariate and univariate).
Required variable transformation.
Can be the Y variable broken down into chunks for example location, for example whether a candidate can be a part of Colleges in California or New York. If there is a higher chance of California, then what college. In this way you could capture Linear + non-linear relationships.
For base learners you can fit Softmax regression model or 1 vs all Logistic regression which does not really matters a lot and CART for non-linear relationship. I would also do K-nn and K-means to check for different groups within data and decide on predictive learners.
I hope this makes sense!
The Least-square support vector machine (LSSVM) is a powerful algorithm for this application. Visit http://www.esat.kuleuven.be/sista/lssvmlab/ for more information.

Unsupervised Learning in R? Classify Matrices - what is the right package? [closed]

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 7 years ago.
Improve this question
Recently I watched a lot of Stanford's hilarious Open Classroom's video lectures. Particularly the part about unsupervised Machine Learning got my attention. Unfortunately it stops were it might get even more interesting.
Basically I am looking to classify discrete matrices by an unsupervised algorithm. Those matrices just contain discrete values of the same range. Let's say I have 1000s of 20x15 matrices that with values ranging from 1-3. I just started to read through the literature and I feel that image classification is way more complex (color histograms) and that my case is rather a simplification of what is done there.
I also looked at the Machine Learning and Cluster Cran Task Views but do not know where to start with a practical example.
So my question is: which package / algorithm would be a good pick to start playing around and working on the problem in R?
EDIT:
I realized that I might have been to imprecise: My matrix contains discrete choice data – so mean clustering might(!) not be the right idea. I do understand with what you said about vectors and observation but I am hoping for some function that accepts matrices or data.frames, because I have several observations over time.
EDIT2:
I realize that a package / function, introduction that focuses on unsupervised classification of categorical data is what would help me the most right now.
... classify discrete matrices by an unsupervised algorithm
You must mean cluster them. Classification is commonly done by supervised algorithms.
I feel that image classification is way more complex (color histograms) and that my case is rather a simplification of what is done there
Without knowing what your matrices represent, it's hard to tell what kind of algorithm you need. But a starting point might be to flatten your 20*15 matrices to produce length-300 vectors; each element of such a vector would then be a feature (or variable) to base a clustering on. This is the way must ML packages, including the Cluster package you link to, work: "In case of a matrix or data frame, each row corresponds to an observation, and
each column corresponds to a variable."
So far I found daisy from the cluster package respectively the argument "gower" which refers to Gower's similarity coefficient to handle multiple modes of data. Gower seems to be a fairly only distance metric, still it's what I found for use with categorical data.
You might want to start from here : http://cran.r-project.org/web/views/MachineLearning.html

Beginners guide to own CFD code? 2D Euler Equation [closed]

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.

Math programming optimization [closed]

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

Explain the proof by Vinay Deolalikar that P != NP [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
Recently there has been a paper floating around by Vinay Deolalikar at HP Labs which claims to have proved that P != NP.
Could someone explain how this proof works for us less mathematically inclined people?
I've only scanned through the paper, but here's a rough summary of how it all hangs together.
From page 86 of the paper.
... polynomial time
algorithms succeed by successively
“breaking up” the problem into
smaller subproblems that are joined to
each other through conditional
independence. Consequently, polynomial
time algorithms cannot solve
problems in regimes where blocks whose
order is the same as the underlying
problem instance require simultaneous
resolution.
Other parts of the paper show that certain NP problems can not be broken up in this manner. Thus NP/= P
Much of the paper is spent defining conditional independence and proving these two points.
Dick Lipton has a nice blog entry about the paper and his first impressions of it. Unfortunately, it also is technical. From what I can understand, Deolalikar's main innovation seems to be to use some concepts from statistical physics and finite model theory and tie them to the problem.
I'm with Rex M with this one, some results, mostly mathematical ones cannot be expressed to people who lack the technical mastery.
I liked this ( http://www.newscientist.com/article/dn19287-p--np-its-bad-news-for-the-power-of-computing.html ):
His argument revolves around a particular task, the Boolean satisfiability problem, which asks whether a collection of logical statements can all be simultaneously true or whether they contradict each other. This is known to be an NP problem.
Deolalikar claims to have shown that
there is no program which can complete
it quickly from scratch, and that it
is therefore not a P problem. His
argument involves the ingenious use of
statistical physics, as he uses a
mathematical structure that follows
many of the same rules as a random
physical system.
The effects of the above can be quite significant:
If the result stands, it would prove
that the two classes P and NP are not
identical, and impose severe limits on
what computers can accomplish –
implying that many tasks may be
fundamentally, irreducibly complex.
For some problems – including
factorisation – the result does not
clearly say whether they can be solved
quickly. But a huge sub-class of
problems called "NP-complete" would be
doomed. A famous example is the
travelling salesman problem – finding
the shortest route between a set of
cities. Such problems can be checked
quickly, but if P ≠ NP then there is
no computer program that can complete
them quickly from scratch.
This is my understanding of the proof technique: he uses first order logic to characterize all polynomial time algorithms, and then shows that for large SAT problems with certain properties that no polynomial time algorithm can determine their satisfiability.
One other way of thinking about it, which may be entirely wrong, but is my first impression as I'm reading it on the first pass, is that we think of assigning/clearing terms in circuit satisfaction as forming and breaking clusters of 'ordered structure', and that he's then using statistical physics to show that there isn't enough speed in the polynomial operations to perform those operations in a particular "phase space" of operations, because these "clusters" end up being too far apart.
Such proof would have to cover all classes of algorithms, like continuous global optimization.
For example, in the 3-SAT problem we have to evaluate variables to fulfill all alternatives of triples of these variables or their negations. Look that x OR y can be changed into optimizing
((x-1)^2+y^2)((x-1)^2+(y-1)^2)(x^2+(y-1)^2)
and analogously seven terms for alternative of three variables.
Finding the global minimum of a sum of such polynomials for all terms would solve our problem. (source)
It's going out of standard combinatorial techniques to the continuous world using_gradient methods, local minims removing methods, evolutionary algorithms. It's completely different kingdom - numerical analysis - I don't believe such proof could really cover (?)
It's worth noting that with proofs, "the devil is in the detail". The high level overview is obviously something like:
Some some sort of relationship
between items, show that this
relationship implies X and that
implies Y and thus my argument is
shown.
I mean, it may be via Induction or any other form of proving things, but what I'm saying is the high level overview is useless. There is no point explaining it. Although the question itself relates to computer science, it is best left to mathematicians (thought it is certainly incredibly interesting).

Resources