॥ स्वक्ष ॥ - Tag - Algorithms॥ स्वक्ष ॥ SVAKSHA, Free/Libre Open Source Software (FOSS), Linux, Ubuntu, Debian, Bioinformatics, Julia, Python, Pandas, Numpy, Scipy, Women, India and much more...2016-05-29T09:43:53+02:00SVAKSHAurn:md5:16313DotclearProgramming with Juliaurn:md5:824ec2573e073b517a6b354446028b7f2012-03-11T09:46:00+05:30SVAKSHAJuliaAlgorithms <p>Using (or talking) about R makes me want to rant sometimes and if you've
ever written a line of Fortran code, you would have certainly wanted to
experiment with a new language stack for scientific programming. Yup, I am
aware of scipy, numpy, sympy, sage, et al.. and despite their existence, when I
came across this <a href="http://mailman.linuxchix.org/pipermail/indichix/2012-January/001774.html">language
for scientific programming in January this year</a>, sheer curiosity** made me
give it a spin.</p>
Starting the year with a scientific language that has clean syntax and some
nicer documentation made me feel warm and fuzzy, until, it refused to build due
to a BLAS dependency. That problem didnt last for long though, as I was able to
pull a fresh commit which had fixed this issue. Its nice to see an active team
having interesting (read, sane) development discussions. A Matlab coder has
opined <a href="http://2pif.info/op/julia.html">thus about Julia</a> while an R
programmer has done a comparison between <a href="http://vincebuffalo.org/2012/03/07/thoughts-on-julia.html">Julia and R</a>.
<p>After some trial-and-error, I managed to grok its syntax, enough to rewrite
an old fortran code in JuliaLang [Julia is still pre-release and I ran Version
0.0.0+1331430882.r69af from Commit 69afb7032d (2012-03-11 07:39:42)]:</p>
<blockquote>
<p>#!/usr/bin/env julia<br />
# -*- coding: utf-8 -*-<br />
#*****************************************************************************<br />
# COPYRIGHT (C) 2012 VidAyer <svaksha@gmail.com><br />
# LICENSE: GNU AGPLv3, http://www.gnu.org/licenses/agpl-3.0.html<br />
#*****************************************************************************<br />
#
http://en.wikipedia.org/wiki/Pearson_correlation#Geometric_interpretation<br />
# Example, suppose 5 countries have gross national products<br />
# of 1, 2, 3, 5, and 8 billion dollars, resp. Suppose these 5 countries<br />
# (in the same order) are found to have 11%, 12%, 13%, 15%, and<br />
# 18% poverty. Then let x and y be ordered 5-element vectors containing<br />
# the above data: x = (1, 2, 3, 5, 8) and y = (0.11, 0.12, 0.13, 0.15,
0.18).<br />
#*****************************************************************************<br />
<br />
gnp = [1, 2, 3, 5, 8]<br />
poverty = [0.11, 0.12, 0.13, 0.15, 0.18]<br />
vectorgnpgnp = 0.0<br />
vectorpovertypoverty = 0.0<br />
vectorgnppoverty = 0.0<br />
costheta = 0.0<br />
n = 1.0<br />
<br />
vectorgnpgnp = vectorgnpgnp + gnp[n]*gnp[n]<br />
vectorpovertypoverty = vectorpovertypoverty + poverty[n]*poverty[n]<br />
vectorgnppoverty = vectorgnppoverty + gnp[n]*poverty[n]<br />
costheta = vectorgnppoverty /
(sqrt(vectorgnpgnp)*sqrt(vectorpovertypoverty))<br />
<br />
# Terminal Out<br />
println("The Vector product value of Cos Theta is: ",costheta) #
correct value should be 0.9208 <br />
println("The Vector product of GNP and Poverty coordinates:
",vectorgnppoverty) # correct value should be 2.930 <br />
println("The Vector product of GNP is: ",vectorgnpgnp) # correct value
should be 103.0 <br />
println("The Vector product of Poverty coordinates is:
",vectorpovertypoverty) # correct value should be 0.9830E-01</p>
</blockquote>
<br />
I was avoiding blogging this code snippet here - code belongs in a DVCS, not in
a blog. But I've intentionally not uploaded this program to github because its
not fully functional yet -- see my comments within the code. When I cross-check
the results from the <a href="https://github.com/svaksha/algorithms-fortran95/blob/master/pearsonCorrelationAlGeo.f95">
fortran code</a> (or as mentioned in the <a href="http://en.wikipedia.org/wiki/Pearson_correlation#Geometric_interpretation">WP
page --Geometric_interpretation</a>.) I find "sqrt" isnt working as it should
-- I need to figure out the syntax a wee bit more, so I'll push this when it
works perfectly.<br />
<br />
<br />
** PS: That it was named after a woman (or atleast I like to think so) isnt
what prompted my interest! No kidding!GraphTheoryurn:md5:0f0a4f97a0c57c6a2f349c97eff0b80e2008-01-10T17:42:00+05:30SVAKSHASTEMAlgorithms <p>Being ill and drowsy with medication, this week I stuck to surfing, and saw
this <a href="http://www.qdh.org.uk/wordpress/?p=198">math problem</a>, to be
precise its graph theory <img src="/themes/default/smilies/smile.png" alt=":)" class="smiley" /> Among the various ideas, i suggested Warshall's
algorithm for shortest path. If its planer there is Kuratowski's theorem. Which
will work better now?</p>