How can one manage thousands of IF…THEN…ELSE rules?
programmers.stackexchange.com
programmers.stackexchange.com
Unfortunately, once your dimensions get large it becomes difficult for humans to visualize the optimizations, which is where Espresso[2][3] comes in handy.
[1] http://en.wikipedia.org/wiki/Karnaugh_map
[2] http://embedded.eecs.berkeley.edu/pubs/downloads/espresso/in...
[3] ftp://ftp.cs.man.ac.uk/pub/amulet/balsa/other-software/espresso-ab-1.0.tar.gz
http://code.google.com/p/eqntott/
I haven't touched this code since 2008, so beware of grues, but I remember it being a really slick system for minimizing boolean logic when you combine eqntott with espresso. Just the thing for an electrical engineering student who's sick of doing K-maps, which described me nicely at the time.
This phrase gives me the same feeling I'd get from finding an old Thomas Bangalter track or something.
Expert systems were particularly big in AI in the '80s, and considerably less hot now, but still widely used in industry. There are a lot of issues that come up, most of which aren't really purely technical, such as: 1) how you extract knowledge from people who might know it; and 2) how you validate that the knowledge you've extracted is actually what they know, for example by validating that it produces the same decisions that they would make; and 3) how you allow updates/revisions to the knowledge base over time. Once you have the rules and some reason to believe that they're any good, actually managing and applying them can be done through one of several rule engines, such as Drools or Jess.
The keyword "knowledge engineering" may also turn up relevant info.
For example a video game consists of millions of possibilities/results in movement based on environment - it's not approached as a collection of thousands of if/then/else statements.
In fact the movement of cows seems very much like video game coding, it needs a "cow engine".
Imagine being given a problem such as "add any two given integers but do not use math operators".
A person without anything but if/then/else knowledge would proceed to try to write
if (a==1 && b==2) c==3
and repeat it for every variation until they gave up.Someone with more core experience and coding instinct would immediately recognize there must be away to set patterns for 0-9 and then analyze each decimal place, apply a matrix, or a number of other approaches.
I write AI perception systems for "realtime simulations", and you are exactly correct.
while on the surface it may seem like "if/else" will give you the solution you need, the sheer number of permutations will make it infeasable.
That said, there are "known solutions" and some novel solutions to this problem too. Perhaps if/else is really what this person needs, but there are other potentially better solutions documented.
Do you have any material one can read to learn more about this?
Custom (non-physics) solutions involve declarative sets of constraints being solved by some sort of engine; such solutions often start to resemble physics engines even if the physical rules even if the constraints are not exactly physical.
Learning how to use a physics engine, first, then how those physics engines work, is a good start to understanding these kinds of problems.
Edit: I'm really surprised the stackexchange answers don't mention this.
There are C#, Flash, Java versions if you aren't into C++. Lots of documentation on the web, but the getting started guide is good enough.
AI is often cast as constraint solving, and a physics engine is basically a constraint solver. Of course, for real the AI engine runs next to the physics engine. Ah! I should have mentioned Rodney Brooks' work:
http://en.wikipedia.org/wiki/Subsumption_architecture
where you model intelligence as a bunch of simple prioritized reflex-like behaviors. Now, on each step, you have each "entity" execute their reflexes according to the current environment, where some reflexes act to disable others. The reflexes are incredibly simple, you probably couldn't even express A* path finding, but you could have the act as ants following a diffusely scented trail. Also see his paper "Elephant's Don't Play Chess."
It may not necessarily be realistic but then most players won't be familiar with cow movements.
Genetic Programming
ADTree
Random Forest
Decision Tree
Most of the work would be in figuring out the best way to gather all the data.
*opinion.
ADTrees, Random Forests, and Decision trees are all classifiers, so they serve this guy's needs. Genetic Programming is not a machine learning technique: it is an optimization method for a very specific task and is quite unsuited for his purposes.
For example, understanding the spectral theorem makes SVD (hence PCA) and the DFT class of algorithms much clearer. Understand the notion of Lp-Norms, convexity, adjoints, loss functions and regularization and a whole bunch of seemingly different algorithms collapse into facets of the same thing. Hook it up to automatic differentiation then some optimization algorithms and you can write anything from Neural networks, SVMs, regularized logistic regression to Non negative tensor factorization in a few lines. You stop making arbitrary divisions between classification or optimization. Much the same kind of collapse can be done for the dual [2] notion of probabilistic algorithms by thinking in terms of graphs, simplices, parametrizations, families and conjugacy.
The best thing from all this is you stop thinking of which algorithm should I use and start thinking of what do I want to do? What is the best mathematical model for this? What would really be great would be a machine learning language. Where one could work with things akin to folds and maps on various structures and manifolds and disappear the incidental complexity. Stuff like [3] is really encouraging for that direction.
[1] The problem of learning a distribution usually is called unsupervised learning, but in this case, supervised learning formally is a special case of unsupervised learning; if we admit that all the functional relations or associations that we are trying to learn have any element of noise or stochasticity, then this connection between supervised and unsupervised problems is quite general.
http://www.princeton.edu/~wbialek/our_papers/bnt_01a.pdf
[2] http://golem.ph.utexas.edu/category/2007/01/duality_between_...
[3] http://www.ipam.ucla.edu/publications/gss2012/gss2012_10605....
In this case, Genetic Programming uses trees as its representation, and so it could be used as a tree-based classifier, but the OP has already indicated that he expects enormous numbers of rules, necessitating huge trees. For Genetic Programming, this translates into a gigantic search space.
As it was my thesis work, I'm always ready to promote Genetic Programming where appropriate. This is not the place. There are better tools for this task.
But that aside I believe that such a search space could be handled by GP. That very problem is what I've been tackling for sometime now. Its position on my list reflects that particular bias. But there are techniques. I use EDA's like MOSES and was heavily inspired by http://www-ia.hiof.no/~rolando/ but have my own original contributions. The method is also interactive for tough problems, these really help in reducing the search space. Although I have not succeeded in a use yet, I have been thinking hard about how category theory could be used to constrain space or perform particular automatic transofrmations (https://www.cs.ox.ac.uk/jeremy.gibbons/publications/origami...., https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/a...).
Wikipedia says Genetic Programming is a specialization of genetic algorithms where the objects are programs. I think this is the only thing I have ever seen where the specialization turns out to be more general than the parent.
I'd also like to point out that I although all ML learns models, all those I gave can learn stuff as what amounts to a bunch of IF-THEN statements. Well GP need not be so limited. And Random Forests lose the trees in the forest (harder to interpret) but yeah, that's why I formed that particular list.
Trust me. I am not.
[1] http://en.wikipedia.org/wiki/Eurisko
As an aside, My definition of Machine learning is more inclusive than yours. I mean if you are going to separate out optimization then I guess you don't count stochastic gradient descent or Matrix factorization as part of machine learning? Machine learning is basically the combination of statistics and optimization where you can work with a lot of data and the output of your computation is more important than the model.
I think GP is "not only" for evolving assembly programs -- http://www.genetic-programming.org/combined.html
A Prolog program is essentially a list of rules that are written as an implication. Something like:
moves_to(Cow, Location) :-
hungry(Cow),
current_location(Cow, OldLoc),
food_in(OldLoc, OldFood), food_in(Location, Food),
Food > OldFood.
In human language: a cow moves to a location if it's hungry and there's more food in that location than in current location.I should probably write a proper answer.
edit: Added a proper answer to the stackoverflow with an almost complete introductory Prolog example. It's waiting for your upvotes :)
You start by writing a logic flowchart that you understand, then you reduce the logic flowchart to code, usually automatically. This is how a logic flowchart looks:
http://en.wikipedia.org/wiki/File:LampFlowchart.svg
Here is the article it appears in:
http://en.wikipedia.org/wiki/Flowchart
The single most important parts of this process are:
1. That you understand the logic diagram and see that it meets the program's requirements.
2. That there is a way to turn the logic flowchart into code, ideally without human intervention.
3. That the rebuild time be short between adding a new logical step and testing the resulting program.
Basically, many of the solutions proposed are more or less specialized state machines (decision trees, markov chains, rete algorithm).
I'm a big fan of state machines, but systems like this are often multitasking and (for all practical purposes) stateless. OTOH it might be more accurate to say their state is formally unpredictable.
A system like the one being described would be more like a multi-threaded critical-path flowchart, where multiple processes are active at a given time. And at any time a high-level linear programming result might mandate a change of strategy based on available resources, even though individual processes continued to follow the tactical flowchart.
So even though a state machine approach looks attractive (as it always does), it's a matter of deciding how many states and how many levels. Because of the nature of the original problem and the number of connections with everyday reality, the fact that it was a state machine might escape the attention of even a careful observer.
What do the states of the cows and the landscape look like? What is changed by the if-then-else results. Does he already have his rules? Is this for a biology project or a video game, etc.
You could use a finite automaton system, an array of cow-states, a cow DSL or something else depending on the answers to these and other questions.
[insert joke about "till the cows come home"]
"How can one manage thousands of IF…THEN…ELSE rules? By developing a drinking problem"
http://en.wikipedia.org/wiki/Decision_tree
It's basically thousands of if-this-then-that statements, but dressed up into something you can reason about and most importantly train and build automagically.
I'd consider taking a look at recurrent neural networks if you're looking at your data as a time series or if its more of a static problem that doesn't take into account the last N things that came before, you might consider tree based methods or even DBNs if you can get a lot of data together (say 50000-100000 samples)
Potential pitfall: if you're using a NN based approach, you will judge results based on test performance, but you won't get as much insight into the "rules" your network has learned.
I have modeled a logistics lookup system (assign "best" courier for an ecommerce setup) using a search solution. The rules were modeled as documents in a search index and looked up using weights. Fundamentally, what I did was flatten an if-then-else hierarchy and assign weights based on (roughly) level of nesting.
The con of this model is obvious - it is at best a heuristic. However, with clever overrides built in (as a separate search index?), you can get pretty close to the ideal solution.
The pro of this model is scalability - when your rules are in millions, this system scales beautifully.
Never mind the fact that you can throw in black swan type of events into the mix or just unknown unknowns you could never think of (maybe a cow has a frog phobia and panics when it sees the frog and starts a stampede or whatever it is that cattle do).
Philip Ball's (former editor of Nature) book Critical Mass[2] is an excellent read about the interesting effects that happen when you look at large number of complex interacting actors. He discusses the effects in traffic, pedestrian models, finance, plant growth etc. I highly recommend it.
[1]http://www.youtube.com/watch?v=8SmRBTJ-jeU This is just a video I picked out quickly, there are much better resources, I just can't find them on my phone.
[2]http://www.amazon.co.uk/Critical-Mass-Thing-Leads-Another/dp...
The more modern Rete based software projects are probably also easy to work with.
Considering the question-asker has a specific problem to solve, I would even hazard they probably aren't a programmer by trade.
When did HN become so touchy-freely? It's important that people start learning somewhere. If you show any interest in programming, I highly recommend learning more. However, there comes a time when you must have a certain amount of experience. This is a profession where important things are made. Even people who should know better end up building systems that leak our sensitive personal information, or let others impersonate us.
I didn't say that such a person shouldn't be hired, but I certainly implied that the original question is a better indicator of their capability than the always positive keyword soup and "years experience" that many people slather on their résumé.
If "avoiding IF-THEN spaghetti" is all you require from contributors, fine. Let's not pretend that this is better than an early high school effort.
So why would someone hire them to be a programmer? And yet, unlike other skilled professions, rank amateurs often present themselves as competent programmers. It would be valuable to include evidence to the contrary with résumés.
you've never been a complete novice programmer before?
I certainly wasn't hired when I was. What kind of ridiculous statement is this?
The poster is asking the wrong question. They are asking about how to manage incidental complexity, when they should be asking how to avoid inherent complexity. Incidentally complex code is the worst possible code to maintain, and you'll thank yourself for not letting contributors commit it.
I've littered the net with my share of dumb questions, and I have no regrets.
Even something as simple as a Decision Tree might be enough?