Skip to content


How to name interfaces in Java (and to some degree other languages)

I’ve always wondered (and debated) about how to name interfaces and abstract classes, and this discussion here is pretty insightful: http://stackoverflow.com/questions/541912/interface-naming-in-java

Since the Plone days, I’m used to interfaces that starts with an I, but the discussion highlights some very good points against this:

  • Interfaces define functionality in the form of a contract, their names should not reflect their type (interface), but rather should focus on the functions they enforce
  • Interface names should be short, easy to read, and as basic to its function as possible. On this note, it should also be as generic as possible, (i.e. the name should stay away from words that hints at possible implementation details)
  • There are times when Interfaces gets changed into Abstract classes, and the I prefix is annoying to deal with

Thoughts?

Posted in Java. Tagged with , , .

Setting up an Android development platform

Came across something I wrote a while ago on how to setup an Android development platform with Eclipse. Thought I’d archive it on here.

Posted in Android. Tagged with , , , .

find and remove all .svn directories (linux)

Note for self:

  1. cd into the directory
  2. find . -iname .svn -exec rm -rf {} \;

Posted in Linux. Tagged with , , .

Android manipulating the UI from a thread

There are times when we need to run things through another thread, and have the returns (call backs etc) displayed on the UI. The UI thread cannot be manipulated from another thread, so the Android API has provided a number of ways to do this:

Activity.runOnUiThread: http://developer.android.com/reference/android/app/Activity.html#runOnUiThread(java.lang.Runnable)

Example (in a call back function):

                final MainAct hl = this;
		hl.runOnUiThread(new Runnable() {
			public void run() {
				hl.lblActivity.setText(hyp);
				hl.btnStartActivity.setEnabled(true);
				hl.btnSpeak.setEnabled(true);
			}
		});

View.post: http://developer.android.com/reference/android/view/View.html#post(java.lang.Runnable)

 

Posted in Android, Java. Tagged with , , , , .

Archos A32 tablet adb connection on Linux (OpenSuSE 11.3)

Spent the better half of an hour trying to connect this little bugger.. Their website http://www.archos.com/support/support_tech/updates_adb.html?country=us&lang=en provided some instructions, but guess what…  it doesnt work (outdated and missing steps).

Note this guide is for the Archos A32 device, which ahs Vendor ID 0x0e79. If you have another device, find the ID by doing lsusb in the console, note the line with your device, in the example below the id you need is in bold:

Bus 002 Device 017: ID 0e79:1411 Archos, Inc.

Working steps below:

  1. su
  2. cd /etc/udev/rules.d
  3. Look for a empty slot around the 50s (as in there isnt a file already there starting with 5x, x being the number you want. I used 53).
  4. vi 5x-android.rules
  5. SUBSYSTEM==”usb”,ATTRS{idVendor}=”e79″,MODE=”0666″ (Some people will use SYSFS instead of ATTRS, however note that SYSFS will be gone in a future version of udev)
  6. Make sure the phone is plugged in, in debug mode
  7. [Optional] To check if the rule is working, do udevadm test /[PATH TO USB DEVICE] (the path is found by using lsusb -t, noting down the bus number and locating it in /sys/bus/usb/, you can cat the idVendor to confirm it is the correct USB)
  8. udevadm control –reload-rules
  9. exit out of root (otherwise you create the file in next step under root, and will have to run adb through root later)
  10. create a ~/.android/adb_usb.ini file with 0x0e79 as the first line
  11. Replug device
  12. adb kill-server
  13. adb start-sever
  14. adb devices
  15. ???
  16. profit

Hope this helps

Posted in Technology. Tagged with , , , , .

Blogging directions – Academic

So other than the various hacks and code pieces and guides on compiling packages and random rants/links, I will now start adding posts on Bayesian Networks.

Posted in Bayesian Networks.

Bayesian Networks in LA Times

[Archived from http://www.cs.ubc.ca/~murphyk/Bayes/la.times.html]

I have highlighted some interesting parts (imho).. This article is surprisingly technical for something from the LA Times heh

Improbable Inspiration

The future of software may lie in the obscure theories of an 18th century cleric named Thomas Bayes.

By LESLIE HELM, Times Staff Writer

 


When Microsoft Senior Vice President Steve Ballmer first heard his company was planning to make a huge investment in an Internet service offering movie reviews and local entertainment information in major cities across the nation, he went to Chairman Bill Gates with his concerns.

After all, Ballmer has billions of dollars of his own money in Microsoft stock, and entertainment isn’t exactly the company’s strong point.

But Gates dismissed such reservations. Microsoft’s competitive advantage, he responded, was its expertise in “Bayesian networks.”

Asked recently when computers would finally begin to understand human speech, Gates began discussing the critical role of “Bayesian” systems.

Ask any other software executive about anything “Bayesian” and you’re liable to get a blank stare.

Is Gates onto something? Is this alien-sounding technology Microsoft’s new secret weapon?

Quite possibly.

Bayesian networks are complex diagrams that organize the body of knowledge in any given area by mapping out cause-and-effect relationships among key variables and encoding them with numbers that represent the extent to which one variable is likely to affect another.

Programmed into computers, these systems can automatically generate optimal predictions or decisions even when key pieces of information are missing.

When Microsoft in 1993 hired Eric Horvitz, David Heckerman and Jack Breese, pioneers in the development of Bayesian systems, colleagues in the field were surprised. The field was still an obscure, largely academic enterprise.

Today the field is still obscure. But scratch the surface of a range of new Microsoft products and you’re likely to find Bayesian networks embedded in the software. And Bayesian nets are being built into models that are used to predict oil and stock prices, control the space shuttle and diagnose disease.

Artificial intelligence (AI) experts, who saw their field discredited in the early 1980s after promising a wave of “thinking” computers that they ultimately couldn’t produce, believe widening acceptance of the Bayesian approach could herald a renaissance in the field.

Bayesian networks provide “an overarching graphical framework” that brings together diverse elements of AI and increases the range of its likely application to the real world, says Michael Jordon, professor of brain and cognitive science at the Massachusetts Institute of Technology.

Microsoft is unquestionably the most aggressive in exploiting the new approach. The company offers a free Web service that helps customers diagnose printing problems with their computers and recommends the quickest way to resolve them. Another Web service helps parents diagnose their children’s health problems.

The latest version of Microsoft Office software uses the technology to offer a user help based on past experience, how the mouse is being moved and what task is being done.

“If his actions show he is distracted, he is likely to need help,” Horvitz says. “If he’s been working on a chart, chances are he needs help formatting the chart.”

“Gates likes to talk about how computers are now deaf, dumb, blind and clueless. The Bayesian stuff helps deal with the clueless part,” says Daniel T. Ling, director of Microsoft’s research division and a former IBM scientist.

Bayesian networks get their name from the Rev. Thomas Bayes, who wrote an essay, posthumously published in 1763, that offered a mathematical formula for calculating probabilities among several variables that are causally related but for which–unlike calculating the probability of a coin landing on heads or tails–the relationships can’t easily be derived by experimentation.

Early students of probability applied the ideas to discussions about the existence of God or efforts to improve their odds in gambling. Much later, social scientists used it to help clarify the key factors influencing a particular event.

But it was the rapid progress in computer power and the development of key mathematical equations that made it possible for the first time, in the late 1980s, to compute Bayesian networks with enough variables that they were useful in practical applications.

The Bayesian approach filled a void in the decades-long effort to add intelligence to computers.

In the late 1970s and ’80s, reacting to the “brute force” approach to problem solving by early users of computers, proponents of the emerging field of artificial intelligence began developing software programs using rule-based, if-then propositions. But the systems took time to put together and didn’t work well if, as was frequently the case, you couldn’t answer all the computer’s questions clearly.

Later companies began using a technique called “neural nets” in which a computer would be presented with huge amounts of data on a particular problem and programmed to pull out patterns. A computer fed with a big stack of X-rays and told whether or not cancer was present in each case would pick out patterns that would then be used to interpret X-rays.

But the neural nets won’t help predict the unforeseen. You can’t train a neural net to identify an incoming missile or plane because you could never get sufficient data to train the system.

In part because of these limitations, a slew of companies that popped up in the early 1980s to sell artificial intelligence systems virtually all went bankrupt.

Many AI techniques continued to be used. Credit card companies, for example, began routinely using neural networks to pick out transactions that don’t look right based on a consumer’s past behavior. But increasingly, AI was regarded as a tool with limited use.

Then, in the late 1980s–spurred by the early work of Judea Pearl, a professor of computer science at UCLA, and breakthrough mathematical equations by Danish researchers (Hugin.. wow..) — AI researchers discovered that Bayesian networks offered an efficient way to deal with the lack or ambiguity of information that has hampered previous systems.

Horvitz and his two Microsoft colleagues, who were then classmates at Stanford University, began building Bayesian networks to help diagnose the condition of patients without turning to surgery.

The approach was efficient, says Horvitz, because you could combine historical data, which had been meticulously gathered, with the less precise but more intuitive knowledge of experts on how things work to get the optimal answer given the information available at a given time.

Horvitz, who with two colleagues founded Knowledge Industries to develop tools for developing Bayesian networks, says he and the others left the company to join Microsoft in part because they wanted to see their theoretical work more broadly applied.

Although the company did important work for the National Aeronautics and Space Administration and on medical diagnostics, Horvitz says, “It’s not like your grandmother will use it.”

Microsoft’s activities in the field are now helping to build a groundswell of support for Bayesian ideas.

“People look up to Microsoft,” says Pearl, who wrote one of the key early texts on Bayesian networks in 1988 and has become an unofficial spokesman for the field. “They’ve given a boost to the whole area.”

A researcher at German conglomerate Siemens says Microsoft’s work has drawn the attention of his superiors, who are now looking seriously at applying Bayesian concepts to a range of industrial applications.

Scott Musman, a computer consultant in Arlington, Va., recently designed a Bayesian network for the Navy that can identify enemy missiles, aircraft or vessels and recommend which weapons could be used most advantageously against incoming targets.

Musman says previous attempts using traditional mathematical approaches on state-of-the-art computers would get the right answer but would take two to three minutes.

“But you only have 30 seconds before the missile has hit you,” says Musman.

General Electric is using Bayesian techniques to develop a system that will take information from sensors attached to an engine and, based on expert opinion built into the system as well as vast amounts of data on past engine performance, pinpoint emerging problems.

Microsoft is working on techniques that will enable the Bayesian networks to “learn” or update themselves automatically based on new knowledge, a task that is currently cumbersome.

The company is also working on using Bayesian techniques to improve upon popular AI approaches such as “data mining” and “collaborative filtering” that help draw out relevant pieces of information from massive databases. The latter will be used by Microsoft in its new online entertainment service to help people identify the kind of restaurants or entertainment they are most likely to enjoy.

Still, as effective as they are proving to be in early use, Bayesian networks face an uphill battle in gaining broad acceptance.

“An effective solution came just as the bloom had come off the AI rose,” says Peter Hart, head of Ricoh’s California Research Center at Menlo Park, a pioneer of AI.

And skeptics insist any computer reasoning system will always fall short of people’s expectations because of the computer’s tendency to miss what is often obvious to the human expert.

Still, Hart believes the technology will catch on because it is cost-effective. Hart developed a Bayesian-based system that enabled Ricoh’s copier help desk to answer twice the number of customer questions in almost half the time.

Hart says Ricoh is now looking at embedding the networks in products so customers can see for themselves what the likely problems are. He believes auto makers will soon build Bayesian nets into cars that predict when various components of a car need to be repaired or replaced.

 

Posted in Bayesian Networks. Tagged with , .

Samsung Galaxy S (SGH-T959) development USB driver

Couldnt find the USB driver from the official website, so I’m archiving them here:

http://ucla.jamesyxu.com/custom_uploads/samsung_android/

Both 32bits and 64bits are here. The phone tested carries model number SGH-T959

For linux, the default driver that came with the SDK will work. However, some systems (like mine) will show:

?????? No Permission

If this happens:

  • lsusb
  • Take note of the matching string for the phone (Bus 001 Device 039: ID 04e8:681d Samsung Electronics Co., Ltd)
  • The bold parts above are VendorID:ProductID
  • edit /etc/udev/rules.d (for details look at http://ucla.jamesyxu.com/?p=126)

Posted in Technology. Tagged with , , , .

Android PocketSphinx, custom dictionaries

This post also requires Linux, and that you have followed steps here: http://ucla.jamesyxu.com/?p=118

  1. Create a text file, with one phrase per line
  2. Build a dict using http://www.speech.cs.cmu.edu/tools/lmtool-new.html
  3. Download the dict and lm file.
  4. Covert the lm file into a dmp by using the console command (you need to have compiled the tools first) sphinx_lm_convert -i file.lm -o file.dmp (where file is the file you downloaded)
  5. Upload these onto the android emulator/device, and update the code accordingly to load the correct files

If sphinx_lm_convert complains about library not found etc, use ldd and strace to track down which library. The sphinx libraries gets installed to /user/local/lib so you may need to export LD_LIBRARY_PATH=/usr/local/lib

If you need to create a more complex model, refer to http://cmusphinx.sourceforge.net/wiki/tutoriallm

Posted in Technology. Tagged with .

Building PocketSphinxAndroidDemo (from CMUSphinx project)

This is done with CMUSphinx 0.7 (so sphinxbase 0.7 and pocketsphinx 0.7). The files are archived at the end of the article. The process also require access to a linux machine and the Eclipse IDE.

  1. Download Sphinx base and pocket sphinx (http://cmusphinx.sourceforge.net/wiki/download/)
  2. Create a directory somewhere, untar both to ./sphinxbase and ./pocketsphinx (lose the -0.x version suffix)
  3. For each of the two, do the usual ./autogen.sh ./configure, make, make install (make install require root)
  4. Check ./pocketsphinx/swig has libpocketsphinx_jni.so in it. If not, do a make in that directory
  5. Download the PocketSpinxAndroiDemo
  6. untar it to the same directory created in 2
  7. cp -r ./pocketsphinx/swig/edu ./PocketSphinxAndroidDemo/jni/
  8. cd ./PocketSphinxAndroidDemo/jni/
  9. Update SPHINX_PATH to the directory created in 2
  10. Open Android.mk, edit LOCAL_STATIC_LIBRARIES from whatever it was before to “pocketsphinx sphinxlm sphinxfeat sphinxfe sphinxutil” (without qoutes)
  11. Install Android NDK (http://developer.android.com/sdk/ndk/index.html)
  12. stay in the jni directory, do a ndk-build (see the ndk link about for instructions on building if it is not clear)

Now we are ready to open this in Eclipse

  1. Open eclipse and import the project, ignore any build warnings/errors
  2. Untick Project -> Build Automatically (This is personal choice, since the JNI build process is heavy I dont like it building all the time)
  3. Project -> Properties -> Builders
  4. Select SWIG -> Edit -> for Working Directory, select Browse Workspace and pick the jni directory, In the Refresh tab, select The folder containing the selected resource, in Build Options, untick Specify working set of relevant resources (This option may be hidden in the dialog, if you dont see it, maximize the Configuration window).
  5. Select NDK build -> Edit -> Set the correct location for ndk-build, select the correct Working directory (Browse workspace and then select the jni directory). In the Refresh tab, select The project containing the selected resource, in Build Options, untick Specify working set of relevant resources (This option may be hidden in the dialog, if you dont see it, maximize the Configuration window).
  6. Project -> Build Project. If you see any errors, check that step 4 and 5 are carried out correctly. The project should build without error. A console may appear with red texts, just confirm that they are warning messages from building the c code and you should be ok

We should now have a built Android application ready for testing

  1. In the emulator (or phone), create under primary storage (whatever is returned by the getExternalStorageDirectory). For example if you have a sdcard this would be /mnt/sdcard
  2. If using the emulator, call adb shell from a console window, and use mkdir command for the step below (to create directories on the emulator)
  3. Create directory structure: Android/edu.cmu.pocketsphinx/hmm/en_US/hub4wsj_sc_8k, Android/edu/edu.cmu.pocketsphinx/lm/en_US/
  4. Copy pocketsphinx/model/hmm/en_US/hub4wsj_sc_8k/* into the emulator/phone
  5. Copy pocketsphinx/model/lm/en_US/* into emulator/phone
  6. In eclipse, open the RecognizerTask.java file, look for c.setString(“-lm”
  7. Make sure the files loaded in the code around step 6 exists (especially the .dict file may have a different name)
  8. Now we can run the application!

If the app crashes for any reason, go to sdcard/Android/edu.cmu.pocketsphinx and there should be a log file (pocketsphinx.log) from the native library.

Misc thought

  • On my machine (OpenSuSE 11.3) the swig directory was empty after make. Go into swig directory and call make, the errors will be displayed (for me it was because I didn’t have swig installed)
  • By default make install installs to /usr/local/lib which can cause problems on some systems. If you get errors with any of the sphinx stuff saying some library is not found, use the ldd and strace commands to see where they are looking for the libs, and symlink them. Alternatively supply another install location to make install
  • While working in eclipse, if you see any errors along the lines of “Refresh scope invalid”, check step 4 and 5 are carried out from the Eclipse section above.

Files required **Before downloading these archives, try using the latest build from the official website first**:

Posted in Java. Tagged with , , , .