|
|
@ -393,7 +393,31 @@ public class PrismUtils |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Format a large integer, represented by a double, as a string. |
|
|
|
|
|
|
|
|
* Normalise the given entries in the vector in-place such that that they sum to 1, |
|
|
|
|
|
* I.e., for all indizes of entries, set<br> |
|
|
|
|
|
* {@code vector[s] = vector[s] / sum}, where<br> |
|
|
|
|
|
* {@code sum = sum_{s in entries} (vector[s])<br> |
|
|
|
|
|
* If {@code sum = 0.0}, all entries are set to {@code NaN}. |
|
|
|
|
|
* @param vector the vector |
|
|
|
|
|
* @param entries Iterable over the entries (must not contain duplicates) |
|
|
|
|
|
* @return the altered vector |
|
|
|
|
|
*/ |
|
|
|
|
|
public static double[] normalise(double[] vector, IterableInt entries) |
|
|
|
|
|
{ |
|
|
|
|
|
double sum = 0.0; |
|
|
|
|
|
for (PrimitiveIterator.OfInt iter = entries.iterator(); iter.hasNext();) { |
|
|
|
|
|
int state = iter.nextInt(); |
|
|
|
|
|
sum += vector[state]; |
|
|
|
|
|
} |
|
|
|
|
|
for (PrimitiveIterator.OfInt iter = entries.iterator(); iter.hasNext();) { |
|
|
|
|
|
int state = iter.nextInt(); |
|
|
|
|
|
vector[state] /= sum; |
|
|
|
|
|
} |
|
|
|
|
|
return vector; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Format a large integer, represented by a double, as a string. Un |
|
|
*/ |
|
|
*/ |
|
|
public static String bigIntToString(double d) |
|
|
public static String bigIntToString(double d) |
|
|
{ |
|
|
{ |
|
|
|