Images, snippets, snapshots, math

View Gabriele Lami's profile on LinkedIn

domenica 19 luglio 2009

Mandelbrot in Rebol

mandelbrot in rebol
And this is my interpretation of Mandelbrot fractal using Rebol:

This language allow to write a gui using few rows of code.
There is still a problem with zoom functionality ( I hope to fix it soon ).

You can see also my ruby mandelbrot .

domenica 12 luglio 2009

Latent Semantic Indexing ( LSI )

LSI is a simple but powerful indexing and retrieval method that is able to identify patterns in the relationships between the terms and concepts contained in a text corpus.
The mathematics of LSI easy to understand cause is based entirely on vector and matrix algebra.
I'll post soon some code ( if someone needs code, my mail is always open ).
A good link to start your journey is: lsi.research.telcordia.com/lsi/LSIpapers.html .

sabato 11 luglio 2009

Peano in Js

peano javascript


You Can find Here 'peano', my interpretation of Peano Curve in jQuery ( javascript ) using canvas ( if you insist to use iexplorer you must download also exCanvas.pack.js to see something ).
To see this image you need only the last jQuery js library and a browser...
Ah, you also need to rename the file with 'HTML' as extension.

Metamorphosis ( Music animation )

Follow this link...

http://vimeo.com/1747316?pg=embed&sec=1747316

lunedì 6 luglio 2009

context-free art

A little piece of context-free art:

circles.cfdg
context-free artstartshape trails
background {b -1}
rule trail {
trail{
sat 0.001
a -0.001
r 0.4
y 0.5
s 0.999y 0.5
}
SQUARE{s 1}
}
rule trail 0.001 {
trail{flip 90} ring{x 5}
}
rule trails {
140*{r 120}trail{b 1 sat 0 h 100}
}
rule ring {
120*{r 5}SQUARE{s 4 0.5 y 6 h 100}
}

Rebol Search File

Another little Rebol program:

rebTest.r

REBOL [Title: "Ricerca"]
mainWin: layout [
banner green "Ricerca Parola" box brick 580x2
text "Parola da cercare"
infi1: field infi2: field ""
text "nome file"
selFile: text-list data read %. [
infi2/data: value
infi2/text: value
show infi2
]

button "Ricerca" [
fil1: to-file infi2/data
text: read fil1
outOne: copy ""
while [ text: find text infi1/data ] [
formattedStuff: reduce [ " ( " index? text " ) " copy/part text 10 ]
append outOne "^/ ( indice ) riga: "
append outOne form formattedStuff
text: next text
]
tuno/text: form outOne show tuno
]
at 260x70
tuno: area 340x300 across
text "Risultato"
]
windowHelp: layout [
backcolor linen
h2 "Help Window"
text 300 { Inserisci la parola da ricercare e il nome del file...
}
button "Chiudimi" [ unview/only windowHelp ]
]

windowHelp/offset: mainWin/offset + (mainWin/size * 1x0) + 10x0
view/new mainWin
view/new windowHelp
do-events

'Text Categorization with SVM

A really nice pdf about 'Text Categorization with Support Vector Machines' ( from University of Dortmund ) :

http://www.cs.cornell.edu/People/tj/publications/joachims_97b.pdf

I'll try to post soon some code in Python about this problem...

My first time in Rebol and numbers


Rebol is a fantastic language!
You can try this code in the Rebol/view Console:
numbers.r


REBOL [Title: "Numbers Test"]
ena: 121
positions: []
dimPal: 3

unitar: func [ ele enne ][ either (( (ele // enne) == 1 ) or (( ele // enne) == (enne - 1)))[ 1 ] ["-"] ]

evaluateUni: func [ en ] [
for j 1 en 1[ st: copy ""
for i 1 en 1[
append st unitar i * j en
sr: square-root en
if ( unitar i * j en ) == 1 [ append positions ( as-pair i j ) * 350 / en + 23x23 ]
]
]
positions
]
evaluateUni ena

refre: does[
positions: copy []
evaluateUni ena
pis: copy []
posi: copy positions
foreach p posi[ insert tail pis reduce[ 'fill-pen 160.209.215.100 'circle p dimPal ] ]
out: form ( length? positions ) / 2 == ( ena - 1 )
insert tail pis reduce [ 'text 230x5 join "numero primo: " out ]
scrn/effect/draw: copy []
append scrn/effect/draw pis
show scrn
]

refreNoEval: does[
pis: copy []
posi: copy positions
foreach p posi[ insert tail pis reduce[ 'fill-pen 160.209.215.100 'circle p dimPal ] ]
out: form ( length? positions ) / 2 == ( ena - 1 )
insert tail pis reduce [ 'text 230x5 join "numero primo: " out ]
scrn/effect/draw: copy []
append scrn/effect/draw pis
show scrn
]
lay: layout [

scrn: box 400x400 black effect [
draw [ text "unit" ]
rotate 50
gradmul 180.180.210 180.60.255
]
slider 200x16 ena / 300 [
ena: to-integer value * 300
inpNum/data: form ena
inpNum/text: form ena
show inpNum
refre
]
inpNum: field form ena [
print to-integer inpNum/text
ena: to-integer inpNum/text
]
at 330x460
btn "Change" [
refre
]
slider 100x15 dimPal / 10 [
dimPal: to-integer value * 10
refreNoEval
]
]

view lay

lunedì 3 novembre 2008

My second site!!!

And this is my second site created with appengine: http://javarubyscala.appspot.com/view/StartPage

mercoledì 22 ottobre 2008

My first Google App Engine test !!!

This is the link http://0052631578947368421.appspot.com !!! a wiki-like site ( learned in a codelab of GooogleDeveloperDay ) with login!!!
Info about appengine are here:http://code.google.com/appengine/ .
Basically you can create ( in Python ) and deploy a webapp .
More info soon... 

martedì 14 ottobre 2008

Mandelbrot in Scala

I'm also working on a more complex mandelbrot set program in Scala.
Soon i'll post the source code.
This is the output:

Esoteric ruby Mandelbrot

Inspired from this article i've decided to
play with code in order to create my version of Madelbrot set program in ruby.
This is the code:

( not true, the code is here because the blogger editor didn't work fine when a code contain <

or > )


The code is intentionally obscure.

Is possible to decide: position, zoom factor, number of iterations, and number of lines.
The output should be like this:







domenica 5 ottobre 2008

Vedic Math first lesson

the Sutra says: "By one more than the previous one".
With this sutra you can calculate mentally this fraction:





easy, isn't it?
In the next few days i'll give the explanation of this method.

sabato 4 ottobre 2008

Code reduction ( obfuscation in ruby code )

This ruby code is equivalent to the code in previous post


N = 13; k = N-1; r = (1..k).to_a ; e = [r.first, r.last];
r.each{a print(r.map{b e.include?(b*a%N)?"1 ":" "},"\n")}

venerdì 3 ottobre 2008

My first Ruby program!

This is my first Ruby program!

N = 13
def un( el, en )
[1, en-1].include?(el%en)?re=1:re=" "; return re
end

(N-1).times do a
(1...N-1).to_a.each{b print un((b+1)*(a+1),N), " "}
print "\n"
end
A little obscure, isn't it?
The output is ( as desired ):

1                     1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

The same program in Scala can be written in this way:
object something {
val un = ( el:Double, en:Double ) =>
if( Array(1,en-1).contains( el%en) ) "1 " else " "

def main(args : Array[String]) : Unit = {
val N = 23
for(i <- 1 to N-1){ new Array(N-1)

.indices.foreach(el => print( un((el+1)*(i),N) ))
println()
}
}
}
and the output with N=23 is:
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

giovedì 2 ottobre 2008

"Eyes follow mouse" in js

here is my interpretation of "eyes follow mouse" in javascript.
Nothing special but works fine.

an important function in this js is this one:

function objMove( obj, xPos, yPos ){
obj.style.left = xPos + "px";
obj.style.top = yPos + "px";
}



is a function that move an object of the page.
the important thing is that works with ie, opera and firefox
an example of this eyes follow mouse at work.

Missing number





the result has 8 digits and the missing number is ... 8
soon i'll post some of Vedic maths

lunedì 29 settembre 2008

xml viewer in Scala

This is a snapshot of a program thought to show an xml
graphically




The xml source for this tree is here
The idea is to create a graphical editor for xml and processDefiniton
of Jbpm.
Soon I'll post some code ...

venerdì 26 settembre 2008

Haar wavelet transform in Scala

This is my first try to write a wavelet(ondine in Italian) transform in Scala.
Naturally i've choose Haar wavelet transform, the simplest!
This is the core of the transformation:



def waveletCalc( values: List[Double] ):List[List[Double]]=
haarCalc( values , List( ) ).reverse

def haarCalc( vals: List[Double], cc: List[List[Double]] )
:List[List[Double]] =
vals.length / 2 match {
case 1 => cc ::: List( List((vals(0) - vals(1) ) / 2 ) ,
List(( vals(0) + vals(1) ) / 2 ))
case _ => haarCalc( vals.indices.dropRight(vals.length/2)
.map(_*2).map(el=>(vals(el) + vals(el+1))/2),
cc ::: List( vals.indices.dropRight(
vals.length/2).map(2*_).map(el=>
(vals (el) - vals(el + 1))/2)))
}


The algorithm is recursive and returns as a result a list of lists.
This arrangement is the most convenient since a base of wavelets has two indexes.
Soon i'll try to post the complete class with the inverse transform and a brief
description on this particular wavelets transform.
I strongly recommend to copy and paste the code in an editor to read it better...
you can find a more complete code here

mercoledì 24 settembre 2008

Algebraic group


Today I started to write a class in Scala to represent a group (in the mathematical sense).
To test closure, i.e.:







the code I wrote is:

def closure( ): Boolean =
elements.forall(
el => elements.forall(
el2 => elements.exists(
el2.*(el, this).name == _.name ) ) )





'elements' is the list of all group elements and and each element has a different 'name'.
The following piece of code is the product of two elements.

  el2.*(el, this)

the * operator is defined as follows:

def *( b : groupElement ,group: genericGroup ) : groupElement

the code is not optimized, but it is amazing how, in this language,
we can write a test like this in a way so simple!
this is only a snippet of the entire code...
I hope to post the complete code soon