NeuroLive.NET :: Towards self-reorganizing machine intelligence

13Jan/111

MySQL command via shell script (using variables in SQL)

Running mysql commands on the shell is pretty simple. However, things can get tricky if you need to enclose variables within those aprostophes in your script. Spend some time trying to figure this out.

The short sample code below shows how it can be done. Note the cats on "`echo $1`". Hope this helps you as well.

1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
 
mysql_user="root"
mysql_pass="root"
 
do_mysql() {
mysql -u $mysql_user -p$mysql_pass -e "`echo $1`"
}
 
dbname="neurodb"
do_mysql "drop database $dbname; \g"
Print This Post
10Nov/102

Getting bitmap from a view (visible, invisible, onCreate)

There are a couple of ways to obtain a bitmap image from a visible view object. However, its a bit more tricky to obtain the bitmap from invisible (or hidden) views.

1. Obtaining bitmaps from visible views

The first approach would be to use the drawing cache of the view class (recommended). Note that while v.getDrawingCache() would provide the actual bitmap representation, it is necessary to create an immutable clone of this referenced object. Otherwise, the bitmap would be lost when the cache is cleared.

1
2
3
4
5
6
7
8
9
private Bitmap getScreenViewBitmap(View v) {
    v.setDrawingCacheEnabled(true);        
    v.buildDrawingCache(true);
 
    // creates immutable clone 
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
 
    v.setDrawingCacheEnabled(false); // clear drawing cache
}

The second approach would be to expose the createSnapshot() method available in the view class itself. Doing so would change the android api and require some framework changes. Here, the @hide comment would be useful to avoid updates to the api-methods in the actual build itself.

1
2
3
4
5
6
7
8
9
View.class {
/** 
 * expose the api and hide it from the build
 * {@hide}
 */
public Bitmap createSnapshot(int backgroundColor, boolean skipChildren) {
    return createSnapshot(Bitmap.Config.RGB_565, backgroundColor, skipChildren);
}
}

However, these methods normally would not work for invisible or hidden views. The bitmaps would be 0kb or null.

2. Bitmaps from invisible (hidden) view / or within Activity.onCreate()

How do you get a view that is invisible? The problem lies with the fact that the width and height properties of hidden views = 0. You need to utilize a measurement feature of the view.

1
2
3
4
5
6
7
8
9
10
11
12
13
private Bitmap getScreenViewBitmap(View v) {
    v.setDrawingCacheEnabled(true);
 
    // this is the important code :)  
    // Without it the view will have a dimension of 0,0 and the bitmap will be null          
    v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); 
 
    v.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false); // clear drawing cache
}

Alternatively, if you are only trying to get a snapshot of the screen, it would be easy to use the getDisplay().width() and height() as proxies for the actual size of the view .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/.. somewhere ../ 
mWidth = getWindowManager().getDefaultDisplay().getWidth();
mHeight = getWindowManager().getDefaultDisplay().getHeight();
 
private Bitmap getScreenViewBitmap(View v) {
    v.setDrawingCacheEnabled(true);
 
    // this is the important line :)  
    // Without it the view will have a dimension of 0,0 and the bitmap will be null          
    v.layout(0, 0, mWidth, mHeight); 
 
    v.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false); // clear drawing cache
}
Print This Post
10Jul/090

Machine intelligence is real intelligence

AI or artificial human intelligence (AHI) is was originally conceived to develop methods to help machines exhibit human-like thinking processes. However, we have far from achieved this objective.

Instead a discipline of real machine intelligence (RMI) matured from these researches. Why deal with something that is artificial when machines have some form of real smarts to make some form of decisions, bounded by the policies set by humans. They can intelligently do things, like agents, robots, based on heuristic or statistically determined decisions boundaries. Machines are also capable of deciphering deep patterns that are difficult for humans to visualize.

The worst thing is to let the machine act smart, especially in the field of UI (user-interactive) environments. Let humans decide how they want to communicate with other humans. Outsource the menial tasks to the machine.

Bottomline machine intelligence is real; artificial intelligence is by far still artificial.

Now machine intelligence has two parts. The hardware side studies the interaction with the environment, and low level intelligence is used to manage the sensitivity of environmental signals. The software side does the high level intelligent thinking, which is then (in my view) computational intelligence.

Coming back to AHI, to do it, you need to at least provide emotional states to the machines. The machine needs to feel happy, sad etc, to evaluate its decisions and utility functions. Human intelligent behaviour is founded not only on rational thinking, but also on irrational considerations. That said, machine intelligence forms the analytical part of human intelligence, and a machine with only RMI in this sense falls short of being called an artificial human.

Also on the linguistic traits of the human. These are only small parts.

Anyway, this only means that the AHI should be a parameterless model. RMI cannot be parameter free. Afterall it doesnt decide the objective functions, because it does not do the risk-taking.

The objective function is determined by the risk-taker, or in this case, the human. And machine intelligence is only very well a decision-support tool.

Print This Post