Home
News
Feed
search engine
by
freefind
advanced
IntermediateEntropyAnalyzer
2015-01-13
azim58 - IntermediateEntropyAnalyzer import java.util.*; import java.math.*; /* * see * http://www.azim58.wikispaces.net/Maximum%2C+Minimum%2C+and+Intermediate +Entropy * for an explanation of this class */ public class IntermediateEntropyAnalyzer { private UsefulTools useful_tools = new UsefulTools(); private ArrayList array_all_partitions = new ArrayList(); private ArrayList array_number_of_bins_with_unique_number_of_elements = new ArrayList(); private ArrayList array_entropy = new ArrayList(); private int number_of_elements = 0; /** * @param args */ public static void main(String[] args) { TODO Auto-generated method stub IntermediateEntropyAnalyzer iea = new IntermediateEntropyAnalyzer(100); } IntermediateEntropyAnalyzer(int number_of_elements) { System.out.println(useful_tools.getTime()); this.number_of_elements = number_of_elements; String output = "Partition;Number of Bins with Unique Number of Elements;Entropy"+"\n"; Partition partition = new Partition(); partition.partition(number_of_elements); String all_partitions = partition.getPartition(); String a_all_partitions[] = all_partitions.split("\n"); ArrayList array_all_partitions = new ArrayList(); for(int i=0; i<a_all_partitions.length; i++) { array_all_partitions.add(a_all_partitions[i].toString().substring(1)); } now we have all possible partitions of this number into an array now let's go through each partition and find the number of bins with unique element each has as well as the entropy value for each partition for(int partition_count = 0; partition_count<array_all_partitions.size(); partition_count++) { ArrayList current_partition = new ArrayList(); ArrayList current_partition_without_repeats = new ArrayList(); String s_current_partition = array_all_partitions.get(partition_count).toString(); current_partition = useful_tools.stringWithCommasToArrayList(s_current_partition); double number_of_bins_with_unique_number_of_elements =determineNumberOfBinsWithUniqueNumberOfElements(current_partition); double entropy = determineEntropy(current_partition); array_number_of_bins_with_unique_number_of_elements.add(number_of_bins_with _unique_number_of_elements); array_entropy.add(entropy); output+=current_partition+";"+number_of_bins_with_unique_number_of_elements +";"+entropy+"\n"; } useful_tools.createTextFile("C:\\Users\\Owner\\Desktop\\temp", "intermediate_entropy_for_number_" + number_of_elements + ".txt", output); System.out.println(useful_tools.getTime()); } public double determineNumberOfBinsWithUniqueNumberOfElements(ArrayList list) { list = useful_tools.removeDuplicates(list); return list.size(); } 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; } }
azim58wiki: