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``````

Answered by FALL3N 0 in a post from

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

## All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.