public RandomVariable toRandomVariable() {
List<String> states = new List<String>();
Dictionary<String, int> stateCount = new Dictionary<String, int>();
foreach (Particle p in particles) {
String state = p.getState();
if (!(states.Contains(state))) {
states.Add(state);
stateCount.Add(state, 0);
}
stateCount[state]++;
}
RandomVariable result = new RandomVariable(states);
foreach (String state in stateCount.Keys) {
result.setProbabilityOf(state,
((double) stateCount[state] / particles.Count));
}
return result;
}