Exemple #1
0
        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);
        }
Exemple #2
0
        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;
	}
 public void testSettingValuesOnInvalidStateThrowsException()
 {
     aDistribution.setProbabilityOf("invalid", 0.5);
 }