Converting java code into processing
in
Programming Questions
•
7 months ago
Hi, is it possible to use functions made in java in processing?
or should i convert my java into processing first?
I been trying to use this implementation of shannon entropy in processing:
but i get errors, any idea how to make it work? here is the code:
- public static Double calculateShannonEntropy(List<String> values) {
- Map<String, Integer> map = new HashMap<String, Integer>();
- // count the occurrences of each value
- for (String sequence : values) {
- if (!map.containsKey(sequence)) {
- map.put(sequence, 0);
- }
- map.put(sequence, map.get(sequence) + 1);
- }
- // calculate the entropy
- Double result = 0.0;
- for (String sequence : map.keySet()) {
- Double frequency = (double) map.get(sequence) / values.size();
- result -= frequency * (Math.log(frequency) / Math.log(2));
- }
- return result;
- }
- void setup() {
- calculateShannonEntropy("asd das ds sfffs");
- }
1