niedziela, 12 stycznia 2014

Inertial behaviour estimation system

This is something I was working on lately. The guy on the movie  is wearing a arduino-powered accelometer readers (elbows, legs and torso) that collects data at 100Hz each. Machine learning approach was used to tag each frame using training data and only torso sensor. Method is very simple but it will be boosted in future.


środa, 5 września 2012

Rough Set approch for document retrieval (part 1)


Setting up an search engine it's an extremely easy task. I've seen a lot's of production level implementation built on top of Lucene or Solr with very little effort. But when  time passes and application is getting bigger and bigger search result is starting to be little bit messy. And then people came up with a lot's of ideas how to work your search result out. One of home-made most common (and very simple) solution I've seen so far is to gather keywords from search result and put them back along with original query to search engine. Actually is not that bad idea, one can find a lots of stuff around the subject in literature under the term: [query expansion].

I'm working recently in a group where [Rough Sets] theory is very popular. So let's try to put our simple idea for QE in this formalism. With every term from dataset there is a set of terms that collocate with it. Upper approximation of this set consists of terms that have first-order [collocation] higher than certain threshold. This approach is well described in [paper]. Authors derive Extended Weighting Scheme from standard TF-IDF weighting making use of this higher-order collocation feature, (U_R(d_i) is sum of sets of upper approx for all t in document d_i):


Method was orginally developed for document clustering but the weighting schemata obviously follows our simple intuition for QE and moves it to indexing time.  I've implemented this formula in python using sparse matrices. Implementation is time/space efficient but not incremental (which means you need to "see" all the documents at indexing time)


import numpy as np
from math import log 
from scipy import sparse 
import timeit

def sparse_trsm(A, fi = 10):   
    A = sparse.csc_matrix(A, dtype=float)
    E, M = [], float(A.shape[0])
    Acoo = A.tocoo(copy = False)
    A.data = np.ones(len(A.data))
    C = A.transpose().dot(A) # 0.6s, lot's of allocation
    A = A.tocsr()
    np.putmask(C.data, C.data < fi, 0)
    C.eliminate_zeros()     

    for i in xrange(A.shape[0]):
        words = A.indices[A.indptr[i]: A.indptr[i + 1]]
        if len(words) > 0:
            #you can fix C[words,:] slicing here 
            U = np.setdiff1d( C[words,:].indices, words) #1.19s
        else : 
            U = []
        E.append(U)
    # 0.00802702903748s  2.67190599442s
    f_D = A.sum(axis = 0).tolist()[0] 
    idf = [log(M / ti) for ti in f_D ]
    idfs2 = np.vectorize(lambda i: log(M/i) / (1+log(M/i))) ( f_D )
    data = tuple( (1 + log(v)) * idf[t]  for (t, v) in zip(Acoo.col, Acoo.data))
    A = sparse.coo_matrix((data, (Acoo.row, Acoo.col))).tocsr() 
    A = A.tocsr(copy = False)
    cols = [i for s in E for i in s]
    rows = [j for s in  [[i] * l for (i, l) in enumerate(map(len, E))] for j in s]
    data = []
    append = data.append

    mintfidf = [min( A.data[ A.indptr[i] : A.indptr[i + 1] ])  
                   if A.indptr[i] != A.indptr[i + 1] else 0. for i in xrange(int(M))]
    for i,j in zip(rows, cols):
        wij = mintfidf[i] * idfs2[j]
        append(wij)        
    W = sparse.coo_matrix((data,(rows,cols)), shape = (A.shape) )
    return A + W, W 

Well it seems that  python isn't that slow - indexing of 10 000 of documents from routers data set took 160sec.
But here comes bummer: number of changes depends on the size of document collection:
For first 1000 docs number of nonzero elements in output doc-term matrix if 140 times larger. It's just that: thresholding of such feature as first-order collocation is too simple. Need to came up with something else. I'm thinking about something like a "second-order TF-IDF" for ngrams will be nice over here.

Art & Science Festiwal

Recently I had the opportunity to co-ordinate an event in our dept. This was a part of [art&science festival] on our university. With bunch of students we put together some exhibitions loosely connected with human-computer-interaction. It was lot of fun! We used all of those things... you know: kinnect, wii, cameras, infrared leds, augumented reality, arduino etc. (see selected videos below). It isn't much but we were able to mount all this in just one week starting almost from scratch. 



 



During the event I met some older guy (engineer I suppose) who was amazed how fast we arranged so many stuff. Well... Today we just have better tools. Open-Source and Open-hardware just kicks ass - It's a industrial revolution. Just watch this  TED to learn more.


niedziela, 26 lutego 2012

Interactive Table

Recently, together with [andrut] we made a interactive table. The table was used for closing exhibition of an culture-educational project [dzwiękospacery].



It was made with [Processing] and a little bit of OpenCV

środa, 14 grudnia 2011

Turn off kde screen dimming

Even if you mess around with power manager policies, kde will turn off the screen if mouse was'nt moved nor key wasn't pressed. Apparently this little script prevents kde from turning screen off.



#!/bin/bash

for (( ; ; ))
do
dbus-send --print-reply --type=method_call --dest=org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SimulateUserActivity
sleep 60
done

niedziela, 20 listopada 2011

Arduino Sonar Grid

Because of the small project that I did recently I had to build sonar grid on Arduino. The circuit was gathering data from five ultrasonic sensors LV MaxSonar EZ0 and was sending readings to computer via Firmata. I turns out that each sonar will interfere with every other so the signal you will get can be very noisy (depending it on sonar mutual locations and room layout). Something you can do (with this particular sonar) is to turn-off all others sonar in the time of reading data. So if you read data for sonar connected to pin 0 others should not send the ultrasonic wave.

Here goes modified minimal Firmata implementation to achieve this.


#include <Firmata.h>

int analogPin = 0; // counter for reading analog pins
int digitalPin = 0; //conuter for turning on/off digital pins (RX for sensors)
unsigned long currentMillis; // store the current value from millis()
unsigned long previousMillis; // for comparison with currentMillis

void setup()
{
Firmata.setFirmwareVersion(0, 2);

for (digitalPin=2;digitalPin<=7;digitalPin++){
pinMode(digitalPin, OUTPUT);
}
Firmata.begin(57600);
}

void loop()
{
while(Firmata.available())
Firmata.processInput();

currentMillis = millis();
if(currentMillis - previousMillis > 20) {
previousMillis += 20; // run this every 20ms

for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) {
for (digitalPin=2;digitalPin<=7;digitalPin++){
if (digitalPin - 2 == analogPin) {
digitalWrite(digitalPin, HIGH);
}
else {
digitalWrite(digitalPin, LOW);
}
}
delay(40); //wait wait man!
Firmata.sendAnalog(analogPin, analogRead(analogPin));
}
}
}


Analog output (AN pin) from all sonar are connected to A0-A5 pins on Arduino (since we are reading from analog). RX pin (which controls measuring state of sonar) are connected to digital pins 2-5. As you probably see this will get way much lower signal resolution that we can get from one sonar. MaxSonar works in 49ms cycles and sends 42Hz waves at the begining of each cyle only if RX pin is HIGH or unconnected. After changing digital pins state you need to wait a while to seetle state on it and also you need to wait for the sonar to its cycle begining (40ms delay gives very smooth signal).

Of course this is easiest possible solution. Depeding on your need you can read from sonars in pairs on weave reading with differents operations.

wtorek, 17 maja 2011

VLC + p2p real time audio/video streaming

Recently I was coordinating this art event. My responsibility was to setup real-time a/v streams in five cities. Every city was streaming a/v from hd camera and also realy big projector was showing streams from other cities. We decided to go for p2p architecture and use some additional player which can randomly switch streams.

We decided to use VLC ...and first bummer: Vlc dosen't support grabbing video from firewire (or I wasn't able to find this option in UI). We are sure we don't want to put ieee 1394 as v4l device, because only way to do that is by vloopback - and this module... well it isn't quite stable.

This line was used to setup stream with transcoding it by h264.

dvgrab - -noavc -nostop | cvlc - -vvv --no-sub-autodetect-file :demux=rawdv
--sout'#transcode{vcodec=h264,vb=600,acodec=mp3,ab=56,scale=0,width=720,height=576,channels=2}:
duplicate{dst=std{access=http,mux=ts,dst=0.0.0.0:8085}}'

also stream tittle is a neat feature:

#transcode{vcodec=h264,vb=1500,scale=1,width=1024,height=576,
sfilter='marq{marquee=Toruń %Y/%m/%d%H:%M%S,position=10,size=14}',
acodec=mp3,ab=196,channels=2,samplerate=44100}:http{mux=ts,dst=:8081/}

stream merging was achieved by

cvlc url1:port url2:port ... --sout="#gather:http{mux=ts,dst=localhost:8079/}" --sout-keep


this will loopback merged stream to localhost on 8079, just open it in any player and switch streams by vlc ui. Depending on option http-cache (buffer size) switching will be little bit delayed (but this is what we wanted to achieve here). Also notice that --sout-keep will only work if stream config is identicall, so you have two option: transocde it on the client or make same setup on server.

Look also here: auto-reconnect, and someone advised me to take a look on twisted-based streaming software