I've got a an audio processing app that takes an input audio file, processes it, and spits out a modified output audio file. This audio processing app has 10-15 parameters that affect how it processes the audio, and thus affects the content of the output audio file (it might have, say, a different frequency response, be louder, quieter, etc.). All these parameters have constrained ranges (x0 must be < 1 and > -1 for example).
The output audio file is evaluated by a tool that gives it a score. This tool knows what the "ideal" output should sound like, and scores the output file accordingly. A score of 1.0 means the output is ideal, i.e. the input file was processed with the best possible parameter set. A score of 0 means the output is completely wrong.
So with 10-15 parameters with their valid ranges, the combinations are endless! I'd be sitting here manually tweaking these parameters forever until I got the best solution. I've checked out some LP/MIP solvers (CBC, MS Solver Foundation, GKLP) but these use a mathematical equation as an objective function... you don't "plug in" an external evaluation function as far as I can see.
Is a LP/MIP solver the right tool to aid in the parameter tuning? Any ideas?
Thanks,
akevan
You could use a general heuristic like simulated annealing or genetic algorihms. Your evaluation process would be the fitness/objective function.
You could use the SPOT packet (R programming language). It allows you to find (near-)optimal parameter settings using significantly less runs than brute force. You can use any programming language for your fitness function code, SPOT has an adapter for that, and offers an automatic mode with default setup (You don't have to worry about the design types and prediction models). It has a steep learning curve, but once you understood the basics, it is a powerful tool. Here is a quick guide; chapter 2.6 offers a concrete example. The SPOT package comes with several examples.
If you had the objective function, then yes LP would be the ideal approach (and would give the ideal answer); the solution would be purely analytic. But in the absence of the function it seems you've correctly understood the problem becomes an integer programming problem. I have less knowledge of integer programming, but I believe that too assumes an objective function to solve. Even with the function, integer programs are NP-hard.
So it seems you would need to use brute force to detect a local maxima, and then tune it. I realize that is exactly what you didn't want to do, but that is what comes to mind.
Related
I'm creating a small application that requires a live feed of phonemes to be output as the user speaks into their microphone. In my case, the speed of the recognition output is the number 1 priority, even over accuracy. Using C# is the preference, but if a better speed can be accomplished using a different language and/or library (Like CMUSphinx), I would switch.
Using System.Speech.Recognition, along with DictationGrammar("grammar:dictation#pronunciation"), I've been able to create a simple and effective phoneme recognizer that does output phonemes as you speak into the mic, with generally impressive accuracy (subscribing to the SpeechRecognitionEngine.SpeechHypothesized event allows me to see live output). The problem is, it has a minimum delay of around .5s between the user speaking and the output which is too much to work well with the project. I know that in general this is a fairly high speed, especially considering the good accuracy, but I really need something faster, even if the accuracy takes a big hit. Is there any way to configure a SpeechRecognitionEngine to throw accuracy out the window in order to spew out hypothesis faster? I found some exposed settings using SpeechRecognitionEngine.UpdateRecognizerSetting, but they seem to have little effect on the output for phoneme recognition.
I've also looked into CMUSphinx, a free speech recognition project that looked promising. Sphinx4 was easy to compile and set up a test is Java, but I couldn't figure out how to configure it to live output phonemes, and it's word recognition was relatively slow. Here, I found some notes about phoneme recognition using their other project, pocketsphinx. I was able to also download and compile it, but unable to run any tests successfully. Has anyone use CMUSphinx or Pocketsphinx with phonemes? Is it capable of high, live output speeds? Or perhaps there is even more alternatives? I really am looking for something extremely basic, but fast.
Edit: Was able to get pocketsphinx recognizing phonemes, but it was too slow to use in the project
I am using simulated annealing to solve a cryptanalysis problem and I've hit a brick wall. I cannot for the life of me get my probability function to operate correctly, it either takes a worse solution too often (so I bounce around a score of 0.03 and 0.2) or it doesn't take it often enough (so I get stuck at 0.35). I've looked around the internet but I only come across examples where the problems involve finding the MINIMUM value....my problem needs to find the MAXIMUM value, worst score is 0, best is 1.
I need advice on Temperature and what probability function I should use.
The Simulated Annealing article on Wikipedia provides some general guidance on how SA temperatures should be initialized and decreased. Efficient selection of these parameters is normally very problem specific and may need to be identified through tedious trial-and-error.
Normally, optimization algorithms search for the minimum of the objective function. If you want to use such an algorithm as-is on your maximization problem, ask the optimizer to minimize the negation of your objective function. For example, let's say that the objective function for which you want to find the maximum is f(x)=score. You should then request the optimizer to minimize -f(x), i.e. -score (or, as you indicate in the comment above, 1-score).
There are lots of simulated annealing and other global optimization algorithms available online, see for example this list on the Decision Tree for Optimization Software. Unfortunately these codes are normally not written in C#, but if the codes are written in Fortran or C it is normally fairly easy to interface with these codes via P/Invoke.
If you do not require that the optimizer necessarily find the global optimum, there are also some derivative-free optimizers listed here. At least one of these codes is available in a C# version, namely BOBYQA (in fact, this algorithm has been adapted to C# by me :-).
First - This is not meant to be a 'which is better, ignorant nonionic war thread'... But rather, I generally need help in making an architecture decision / argument to put forward to my boss.
Skipping the details - I simply just would love to know and find the results of anyone who has done some performance comparisons of Shell vs [Insert General Purpose Programming Language (interpreted) here), such as C# or Java...
Surprisingly, I have spent some time on Google on searching here to not find any of this data. Has anyone ever done these comparisons, in different use-cases; hitting a database like in a XYX # of loops doing different types of SQL (Oracle pref, but MSSQL would do) queries such as any of the CRUD ops - and also not hitting database and just regular 50k loop type comparison doing different types of calculations, and things of that nature?
In particular - for right now, I need to a comparison of hitting an Oracle DB from a shell script vs, lets say C# (again, any GPPL thats interpreted would be fine, even the higher level ones like Python). But I also need to know about standard programming calculations / instructions/etc...
Before you ask 'why not just write a quick test yourself? The answer is: I've been a Windows developer my whole life/career and have very limited knowledge of Shell scripting - not to mention *nix as a whole.... So asking the question on here from the more experienced guys would be grealty beneficial, not to mention time saving as we are in near perputual deadline crunch as it is ;).
Once upon a time, ye olde The Great Computer Language Shootout did include some shell scripts.
So, courtesy of the Internet Archive, from 2004 -
Note the shell scripts didn't have programs for many of the tests.
Score Missing-Tests
Java 20 1
Perl 16 0
Python 16 0
gawk 12 6
mawk 10 6
bash 7 12
Note shell scripts can sometimes be small and fast :-)
"Reverse a file"
CPU (sec) Mem (KB) Lines Code
bash 0.0670 1464 1
C gcc 0.0810 4064 59
Python 0.3869 13160 6
It is highly dependent on what the script is doing. I've seen poorly written shell scripts sped up by one, two even three orders of magnitude by making simple changes.
Typically, a shell script is simply some glue logic that runs utilities that are usually compiled C or C++. If that's the case, there may not be much that can be done to speed things up. If the grunt work is being done by a poorly written utility that's compiled, it's just doing a lot of wasted effort really fast.
That said, Python or Perl are going to be much faster than a shell script, but a VM or native code will be faster yet.
Since you can't tell us any details, we can't really provide specific help.
If you want to see a simple demonstration for comparison, try my pure-Bash implementation of hexdump and compare it to the real thing:
$ time ./bash-hexdump /bin/bash > /dev/null
real 7m17.577s
user 7m2.570s
sys 0m14.745s
$ time hexdump -C /bin/bash > /dev/null
real 0m2.459s
user 0m2.260s
sys 0m0.176s
One of the main reasons the Bash version is slow is that it reads the file character by character which is necessary to handle null bytes (shells aren't very good at handling binary data), but the primary reason is the speed of execution. Here is an example of a Python script I found:
$ time ./hexdump.py /bin/bash > /dev/null
real 0m11.694s
user 0m11.605s
sys 0m0.040s
I simply just would love to know and
find the results of anyone who has
done some performance comparisons
of...
The abiding lesson of such comparisons is that the particular details matter - a lot.
Not only the particular details of the task, but (shouldn't we know this as programmers) the particular details of how the shell script is written.
So can you find someone who understands that shell language and can check that shell script was written in an efficient way? (Wouldn't it be nice if changing a couple of lines took it from 40 minutes to 5 minutes.)
Just did this very simple benchmark on my system, and the results are as expected.
Add up all integers between 1 and 50,000 and output answer at each step
Bash: 3 seconds
C: 0.5 seconds
If you are writing code and you have concerns about the speed of processing, you should be writing code that is either compiled directly to assembly or compiled for a modern VM.
But... with Moore's Law kicking up processing power every 18 months, I wonder: are the performance requirements really necessary? Even interpreted code runs incredibly fast on most modern systems, and it's only going to get better with time. Do you really need the kind of speed improvements that compiled code would give you?
If the answer is no, then write in whatever makes you happy.
While this doesn't include "Shell" (aka sh/bash/ksh/powerscript) languages, it is a relatively large list of "language [implementation] performance" -- packed full with generalities and caveats. In any case, someone may enjoy it.
http://benchmarksgame.alioth.debian.org/
As mentioned above, you won't be able to do SQL queries from shell. Languages which runs on a VM will take a little time upfront because of the VM factor but otherwise the difference should be negligible.
If the question really is to decrease it from 40 to 5 minutes that I will try to find out which piece is taking the majority of the time. If the query is running for the longest time then switching language won't help you much.
Again (without much detail in the question) I would start with looking into different components of the system to see which one is the bottleneck.
I have written an application in C# that generates all the words that can be existed in the combination of alphabets, numbers and few special characters.
The problem is that it isn't memory efficient as it is adapting Recursion and also some collection like List.
Is there any way I can make it to run in limited memory environment?
Umair
Convert it to an iterative function.
Unfortunately C# compiler does not perform tail call optimization, which is something that you want to happen in this case. CLR supports it, kinda, but you shouldn't rely on it.
Perhaps left of field, but maybe you can write the recursive part of your program in F#? This way you can leverage guaranteed tail call optimization and reuse bits of your C# code. Whilst a steep learning curve, F# is a more suitable language for these combinatorial tasks.
Well...I am not sure whom with I go amongst you but I got the solution. I am using more than one process one that is interacting with user and other for finding the words combination. The other process finds 5000 words, save them and quit. Communication is being achieved through WCF. This looks pretty fine as when process quits = frees memory.
Well, you obviously cannot store the intermediate results in memory (unless you've got some sort of absurd computer at your disposal); you will have to write the results to disk.
The recursion depth isn't a result of the number of considered characters - its determined by what the maximum string length you're willing to consider.
For instance, my install of python 2.6.2 has it's default recursion limit set to 1000. Arguable, I should be able to generate all possible 1-1000 length strings given a character set within this limitation (now, I think the recursion limit applies to total stack depth, so the actual limit may be less than 1000).
Edit (added python sample):
The following python snippet will produce what you're asking for (limiting itself to the given runtime stack limits):
from string import ascii_lowercase
def generate(base="", charset=ascii_lowercase):
for c in charset:
next = base + c
yield next
try:
for s in generate(next, charset):
yield s
except:
continue
for s in generate():
print s
One could produce essentially the same in C# by try/catching on StackOverflowException. As I'm typing this update, the script is running, chewing up one of my cores. However, memory usage is constant at less than 7MB. Now, I'm only print to stdout since I'm not interested in capturing the result, but I think it proves the point above. ;)
Addendum to the example:
Interesting note: Looking closer at running processes, python is actually I/O bound with the above example. It's only using 7% of my CPU, while the rest of the core is bound rending the results in my command window. Minimizing the window allows python to climb to 40% of total CPU usage, this is on a 2 core machine.
One more consideration: When you concatenate or use some other method to generate a string in C#, it occupies its own memory and may stick around for a while. If you are generating millions of strings, you are likely to notice some performance drag.
If you don't need to keep your many strings around, I would see if there's away to avoid generating the strings. For example, maybe you have a character array that you keep updating as you move through the character combinations, and if you're outputting them to a file, you would output them one character at a time so you don't have to build the string.
I would like to create a simulation of a factory floor, and I am looking for ideas on how to do this. My thoughts so far are:
• A factory is a made up of a bunch of processes, some of these processes are in series and some are in parallel. Each process would communicate with it's upstream and downstream and parallel neighbors to let them know of it’s through put
• Each process would it's own basic attributes like maximum throughput, cost of maintenance as a result of through put
Obviously I have not fully thought this out, but I was hoping somebody might be able to give me a few ideas or perhaps a link to an on line resource
update:
This project is only for my own entertainment, and perhaps learn a little bit alnong the way. I am not employed as a programmer, programming is just a hobby for me. I have decided to write it in C#.
Simulating an entire factory accurately is a big job.
Firstly you need to figure out: why are you making the simulation? Who is it for? What value will it give them? What parts of the simulation are interesting? How accurate does it need to be? What parts of the process don't need to be simulated accurately?
To figure out the answers to these questions, you will need to talk to whoever it is that wants the simulation written.
Once you have figured out what to simulate, then you need to figure out how to simulate it. You need some models and some parameters for those models. You can maybe get some actual figures from real production and try to derive models from the figures. The models could be a simple linear relationship between an input and an output, a more complex relationship, and perhaps even a stochastic (random) effect. If you don't have access to real data, then you'll have to make guesses in your model, but this will never be as good so try to get real data wherever possible.
You might also want to consider to probabilities of components breaking down, and what affect that might have. What about the workers going on strike? Unavailability of raw materials? Wear and tear on the machinery causing progressively lower output over time? Again you might not want to consider these details, it depends on what the customer wants.
If your simulation involves random events, you might want to run it many times and get an average outcome, for example using a Monte Carlo simulation.
To give a better answer, we need to know more about what you need to simulate and what you want to achieve.
Since your customer is yourself, you'll need to decide the answer to all of the questions that Mark Byers asked. However, I'll give you some suggestions and hopefully they'll give you a start.
Let's assume your factory takes a few different parts and assembles them into just one finished product. A flowchart of the assembly process might look like this:
Factory Flowchart http://img62.imageshack.us/img62/863/factoryflowchart.jpg
For the first diamond, where widgets A and B are assembled, assume it takes on average 30 seconds to complete this step. We'll assume the actual time it takes the two widgets to be assembled is distributed normally, with mean 30 s and variance 5 s. For the second diamond, assume it also takes on average 30 seconds, but most of the time it doesn't take nearly that long, and other times it takes a lot longer. This is well approximated by an exponential distribution, with 30 s as the rate parameter, often represented in equations by a lambda.
For the first process, compute the time to assemble widgets A and B as:
timeA = randn(mean, sqrt(variance)); // Assuming C# has a function for a normally
// distributed random number with mean and
// sigma as inputs
For the second process, compute the time to add widget C to the assembly as:
timeB = rand()/lambda; // Assuming C# has a function for a uniformly distributed
// random number
Now your total assembly time for each iGadget will be timeA + timeB + waitingTime. At each assembly point, store a queue of widgets waiting to be assembled. If the second assembly point is a bottleneck, it's queue will fill up. You can enforce a maximum size for its queue, and hold things further up stream when that max size is reached. If an item is in a queue, it's assembly time is increased by all of the iGadgets ahead of it in the assembly line. I'll leave it up to you to figure out how to code that up, and you can run lots of trials to see what the total assembly time will be, on average. What does the resultant distribution look like?
Ways to "spice this up":
Require 3 B widgets for every A widget. Play around with inventory. Replenish inventory at random intervals.
Add a quality assurance check (exponential distribution is good to use here), and reject some of the finished iGadgets. I suggest using a low rejection rate.
Try using different probability distributions than those I've suggested. See how they affect your simulation. Always try to figure out how the input parameters to the probability distributions would map into real world values.
You can do a lot with this simple simulation. The next step would be to generalize your code so that you can have an arbitrary number of widgets and assembly steps. This is not quite so easy. There is an entire field of applied math called operations research that is dedicated to this type of simulation and analysis.
What you're describing is a classical problem addressed by discrete event simulation. A variety of both general purpose and special purpose simulation languages have been developed to model these kinds of problems. While I wouldn't recommend programming anything from scratch for a "real" problem, it may be a good exercise to write your own code for a small queueing problem so you can understand event scheduling, random number generation, keeping track of calendars, etc. Once you've done that, a general purpose simulation language will do all that stuff for you so you can concentrate on the big picture.
A good reference is Law & Kelton. ARENA is a standard package. It is widely used and, IMHO, is very comprehensive for these kind of simulations. The ARENA book is also a decent book on simulation and it comes with the software that can be applied to small problems. To model bigger problems, you'll need to get a license. You should be able to download a trial version of ARENA here.
It maybe more then what you are looking for but visual components is a good industrial simulation tool.
To be clear I do not work for them nor does the company I work for currently use them, but we have looked at them.
Automod is the way to go.
http://www.appliedmaterials.com/products/automod_2.html
There is a lot to learn, and it won't be cheap.
ASI's Automod has been in the factory simulation business for about 30 years. It is now owned by Applied Materials. The big players who work with material handling in a warehouse use Automod because it is the proven leader.