954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

to convert python+numpy prog to java

i am trying to implement a fitness function for GA. i got a code written in python. i don't have any idea about python. can someone help me to convert it into java the code is here
# there are many ways to do an eigenvalue decomp, this is just one way
>>> import numpy as NP
>>> import numpy.linalg as LA

>>> # calculate covariance matrix of the data set (leaving out response variable column)
>>> C = NP.corrcoef(d3, rowvar=0)
>>> C.shape
     (4, 4)
>>> C
     array([[ 1.  , -0.11,  0.87,  0.82],
            [-0.11,  1.  , -0.42, -0.36],
            [ 0.87, -0.42,  1.  ,  0.96],
            [ 0.82, -0.36,  0.96,  1.  ]])

>>> # now calculate eigenvalues & eivenvectors of the covariance matrix:
>>> eva, evc = LA.eig(C)
>>> # now just get value proprtions of each eigenvalue:
>>> # first, sort the eigenvalues, highest to lowest:
>>> eva1 = NP.sort(eva)[::-1]
>>> # get value proportion of each eigenvalue:
>>> eva2 = NP.cumsum(eva1/NP.sum(eva1))   # "cumsum" is just cumulative sum
>>> title1 = "ev value proportion"
>>> print( "{0}".format("-"*len(title1)) )
-------------------
>>> for row in q :
        print("{0:1d} {1:3f} {2:3f}".format(int(row[0]), row[1], row[2]))

   ev value  proportion    
   1   2.91   0.727
   2   0.92   0.953
   3   0.14   0.995
   4   0.02   1.000
darsha
Newbie Poster
1 post since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

sure, but
a) do you mean tell you in java terms what each part means, or create java that mimics the functionality of the above code? (I'll do either)
b) wtf is numpy? I am not cursing cuz im mad, its for effect.. :D

FALL3N
Junior Poster in Training
84 posts since May 2010
Reputation Points: 10
Solved Threads: 2
 

or ignore my help, that's cool too...

FALL3N
Junior Poster in Training
84 posts since May 2010
Reputation Points: 10
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: