tipos basicos
Publicado por kaleb (20 intervenciones) el 06/08/2007 17:35:51
Hola Tengo el siguiente codigo, en el que necesito trabajar con flotantes y con enteros. Pero me da una excepcion por problemas con los tipos. Os pongo el codigo por si podeis ayudarme :
static float log_bin(float num, int base)
{
double n1, b1;
n1=Math.log((double)num);
b1=Math.log(base);
return (float)(n1/b1);
}
static float Calc_Entropy(ArrayList ac){
ArrayList p = new ArrayList<Float>(ac.size());
float p_aux;
int aux;
for(int i=0; i<ac.size(); i++)
p.add(0.0);
for(int j=0; j<ac.size(); j++) {
aux=((Integer)ac.get(j)).intValue();
p_aux=((Float)p.get(aux)).floatValue(); /EN ESTA LINEA DA PROBLEMAS
p.add(aux, p_aux+1);
}
int n =p.size();
float H_x=0, pi;
for(int i = 0; i<n; i++){
pi = ((Float)p.get(i)).floatValue();
H_x = H_x + pi* log_bin(pi,i);
}
return -H_x;
}
public static void main(String args[])
{
......
float hy;
hy=Calc_Entropy(ac1); //ac1 es un ArrayList inicializado con 0 y 1 tipo entero) En esta linea da problemas
System.out.println(hy);
}
static float log_bin(float num, int base)
{
double n1, b1;
n1=Math.log((double)num);
b1=Math.log(base);
return (float)(n1/b1);
}
static float Calc_Entropy(ArrayList ac){
ArrayList p = new ArrayList<Float>(ac.size());
float p_aux;
int aux;
for(int i=0; i<ac.size(); i++)
p.add(0.0);
for(int j=0; j<ac.size(); j++) {
aux=((Integer)ac.get(j)).intValue();
p_aux=((Float)p.get(aux)).floatValue(); /EN ESTA LINEA DA PROBLEMAS
p.add(aux, p_aux+1);
}
int n =p.size();
float H_x=0, pi;
for(int i = 0; i<n; i++){
pi = ((Float)p.get(i)).floatValue();
H_x = H_x + pi* log_bin(pi,i);
}
return -H_x;
}
public static void main(String args[])
{
......
float hy;
hy=Calc_Entropy(ac1); //ac1 es un ArrayList inicializado con 0 y 1 tipo entero) En esta linea da problemas
System.out.println(hy);
}
Valora esta pregunta


0