OrganizedDistributionGenerator

2015-01-13

azim58 - OrganizedDistributionGenerator


import java.util.*;

public class OrganizedDistribution



private int number_of_elements = 0;
private ArrayList pool_of_ones = new ArrayList();
private ArrayList other_numbers = new ArrayList();
private ArrayList completeDistribution = new ArrayList();
private boolean assembled = false;
private double entropy;
/**

* @param args
*/
public static void main(String[] args) {
TODO Auto-generated method stub



public void initialize(int number_of_elements)

assembled = false;
this.number_of_elements = number_of_elements;
for(int i=0; i<number_of_elements; i++)
{
pool_of_ones.add(1);

}
public void addOtherNumber(int number)

assembled = false;
other_numbers.add(number);

public void subtract_from_pool_of_one()

assembled = false;
pool_of_ones.remove(pool_of_ones.size()-1);

public int getPoolOfOnesSize()



return pool_of_ones.size();

public ArrayList getCompleteDistribtion()

if(assembled==false)
{
assembleCompleteDistribution();

return completeDistribution;
}
public void assembleCompleteDistribution()

assembled = true;
completeDistribution.clear();
for(int i= 0; i<other_numbers.size(); i++)
{
completeDistribution.add(other_numbers.get(i).toString());

for(int i=0; i<pool_of_ones.size(); i++)

completeDistribution.add(pool_of_ones.get(i).toString());

}


public int getMaxOtherNumber()

return
Integer.valueOf(other_numbers.get(other_numbers.size()-1).toString());

public int getSize()

return other_numbers.size()+pool_of_ones.size();

public void removeOtherNumber()

assembled = false;
other_numbers.remove(other_numbers.size()-1);



public double determineEntropyOfThisDistribution()

if(assembled==false)
{
assembleCompleteDistribution();

ArrayList list = completeDistribution;
double sum = 0;
double total_number_of_elements=0;
for(int i=0; i<list.size(); i++)

total_number_of_elements+=Double.valueOf(list.get(i).toString());

for(int i=0; i<list.size(); i++)

double current_frequency = 0;
current_frequency = Double.valueOf(list.get(i).toString());
if(current_frequency!=0)
{
double ratio = current_frequency/total_number_of_elements;
double ratio_and_log =ratio*Math.log(ratio);
sum+=ratio_and_log;

}
sum = 0-sum;
double entropy_of_distribution = sum;
this.entropy = entropy_of_distribution;
return entropy_of_distribution;
}


public double determineEntropy(ArrayList list)

double sum = 0;
double total_number_of_elements=0;
for(int i=0; i<list.size(); i++)
{
total_number_of_elements+=Double.valueOf(list.get(i).toString());

//-Sum (from i=0 to n) p(Xi)*log(Xi)
for(int i=0; i<list.size(); i++)

double current_frequency = 0;
current_frequency = Double.valueOf(list.get(i).toString());
if(current_frequency!=0)
{
double ratio = current_frequency/total_number_of_elements;
double ratio_and_log =ratio*Math.log(ratio);
sum+=ratio_and_log;

}
sum = 0-sum;
double entropy_of_distribution = sum;


return entropy_of_distribution;
}


}