/// <summary> /// Divide the example set into a number of smaller example sets, with /// the sizes given in an array of values. /// </summary> /// <param name="sizes">The sizes to divide the result sets</param> /// <returns>A shuffled subsets of the original example set</returns> public ExampleSet[] DivideRandom(int[] sizes) { CheckSizeLimits(sizes); ExampleSet[] result = new ExampleSet[sizes.Length]; ArrayList indexes = new ArrayList(); Random r = new Random(); for (int i = 0; i < Count; i++) { indexes.Add(i); } for (int sizeIdx = 0; sizeIdx < sizes.Length; sizeIdx++) { ExampleSet xset = new ExampleSet(); for (int i = 0; i < sizes[sizeIdx]; i++) { int randIdx = (int)indexes[r.Next(indexes.Count)]; Example ex = (Example)examples[randIdx]; indexes.Remove(randIdx); xset.AddExample(ex); } result[sizeIdx] = xset; } return(result); }
/// <summary> /// Evaluates the network, returning the evaluation of the error. /// </summary> /// <param name="examples">The examples to evaluate</param> /// <param name="network">The network to evalute</param> /// <returns>An error report for the valuation.</returns> public Dictionary <String, double> Evaluate(Network network, ExampleSet examples) { ZeroErrors(); for (int i = 0; i < examples.Count; i++) { Example example = examples[i]; Dictionary <String, double> results = network.Process(example.Inputs); CalculateErrors(example.Expected, results); } return(errorValues); }
/// <summary> /// Divide an example set linearly (by simply iterating), with the given number of elements. /// The total number of elements for each returned sub-example must be less than or /// equal to the number of elements in the original example set. /// </summary> /// <param name="sizes">The sizes of the sub-sets</param> /// <returns>A group of example subsets</returns> public ExampleSet[] DivideLinear(int[] sizes) { CheckSizeLimits(sizes); ExampleSet[] result = new ExampleSet[sizes.Length]; int startAt = 0; for (int sizeIdx = 0; sizeIdx < sizes.Length; sizeIdx++) { ExampleSet xset = new ExampleSet(); for (int i = 0; i < sizes[sizeIdx]; i++) { xset.AddExample((Example)(examples[i + startAt])); } startAt += sizes[sizeIdx]; result[sizeIdx] = xset; } return(result); }
/// <summary> /// Constructs and example set from data read in as key, value pairs. takes an /// array of input keys and ouptut keys to divide the raw data into a set of /// inputs and expected values. /// </summary> /// <param name="data">A list of name value pairs of raw data</param> /// <param name="inputs">A list of names of input values</param> /// <param name="outputs">A list of names of output values</param> /// <returns>A constructed example set</returns> public static ExampleSet MakeExamples(List <Dictionary <String, double> > data, List <String> inputs, List <String> outputs) { ExampleSet result = new ExampleSet(); foreach (Dictionary <String, double> datum in data) { Example ex = new Example(); foreach (String name in inputs) { ex.Inputs[name] = datum[name]; } foreach (String name in outputs) { ex.Expected[name] = datum[name]; } result.AddExample(ex); } return(result); }
/// <summary> /// Evaluates the network, returning the evaluation of the error. /// </summary> /// <param name="examples">The examples to evaluate</param> /// <param name="network">The network to evalute</param> /// <returns>An error report for the valuation.</returns> public Dictionary<String, double> Evaluate(Network network, ExampleSet examples) { ZeroErrors(); for(int i = 0; i < examples.Count; i++) { Example example = examples[i]; Dictionary<String, double> results = network.Process(example.Inputs); CalculateErrors(example.Expected, results); } return errorValues; }
/// <summary> /// Divide an example set linearly (by simply iterating), with the given number of elements. /// The total number of elements for each returned sub-example must be less than or /// equal to the number of elements in the original example set. /// </summary> /// <param name="sizes">The sizes of the sub-sets</param> /// <returns>A group of example subsets</returns> public ExampleSet[] DivideLinear(int[] sizes) { CheckSizeLimits(sizes); ExampleSet[] result = new ExampleSet[sizes.Length]; int startAt = 0; for(int sizeIdx = 0; sizeIdx < sizes.Length; sizeIdx++) { ExampleSet xset = new ExampleSet(); for(int i = 0; i < sizes[sizeIdx]; i++) { xset.AddExample((Example)(examples[i + startAt])); } startAt += sizes[sizeIdx]; result[sizeIdx] = xset; } return result; }
/// <summary> /// Divide the example set into a number of smaller example sets, with /// the sizes given in an array of values. /// </summary> /// <param name="sizes">The sizes to divide the result sets</param> /// <returns>A shuffled subsets of the original example set</returns> public ExampleSet[] DivideRandom(int[] sizes) { CheckSizeLimits(sizes); ExampleSet[] result = new ExampleSet[sizes.Length]; ArrayList indexes = new ArrayList(); Random r = new Random(); for(int i = 0; i < Count; i++) { indexes.Add(i); } for(int sizeIdx = 0; sizeIdx < sizes.Length; sizeIdx++) { ExampleSet xset = new ExampleSet(); for(int i = 0; i < sizes[sizeIdx]; i++) { int randIdx = (int)indexes[r.Next(indexes.Count)]; Example ex = (Example)examples[randIdx]; indexes.Remove(randIdx); xset.AddExample(ex); } result[sizeIdx] = xset; } return result; }
/// <summary> /// Constructs and example set from data read in as key, value pairs. takes an /// array of input keys and ouptut keys to divide the raw data into a set of /// inputs and expected values. /// </summary> /// <param name="data">A list of name value pairs of raw data</param> /// <param name="inputs">A list of names of input values</param> /// <param name="outputs">A list of names of output values</param> /// <returns>A constructed example set</returns> public static ExampleSet MakeExamples(List<Dictionary<String, double> > data, List<String> inputs, List<String> outputs) { ExampleSet result = new ExampleSet(); foreach(Dictionary<String, double> datum in data) { Example ex = new Example(); foreach(String name in inputs) { ex.Inputs[name] = datum[name]; } foreach(String name in outputs) { ex.Expected[name] = datum[name]; } result.AddExample(ex); } return result; }