public static void Decode_ThreeStrings()
 {
     var input = new string[] { "a", "b","c" };
     var coder = new NetworkOutputCoder(input);
     var decoded = coder.Decode(new double[] { 0,1,0 });
     Assert.True(decoded == "b");
 }
 public static void Encode_ThreeString()
 {
     var input = new string[] {"a", "b", "c"};
     var coder = new NetworkOutputCoder(input);
     var endcoded = coder.Encode("b");
     Assert.True(endcoded.SequenceEqual(new double[]{0,1,0}));
 }
 public static void Decode_OneString()
 {
     var input = new string[] { "a" };
     var coder = new NetworkOutputCoder(input);
     var decoded = coder.Decode(new double[] {1});
     Assert.True(decoded=="a");
 }
 public static WrappedKohonenNetwork Get(IEnumerable<TeachingSet> teachingSets)
 {
     var inputsCount = teachingSets.First().Inputs.First().Length;
     var coder = new NetworkOutputCoder(teachingSets);
     var network = KohonenNetworkFactory.Get(inputsCount , coder.CodingTableCount);
     return new WrappedKohonenNetwork(network, coder);
 }
 private static void Teach(string teachingSamplesFolder, string fileToSaveNetwork, string fileToSaveCoder = null, double teachingSpeed = 0.5)
 {
     var teachingSets = (new FolderTeachingSetsLoader()).Load(teachingSamplesFolder);
     var coder = new NetworkOutputCoder(teachingSets);
     var samples = TeachingSamplesFactory.GetSamples(teachingSets, coder);
     var network = KohonenNetworkFactory.Get(samples.First().Input.Length, coder.CodingTableCount);
     var teacher = new KohonenNetworkTeacher(samples, teachingSpeed);
     teacher.Teach(network);
     (new KohonenNetworkSaver()).Save(fileToSaveNetwork, network);
     if (fileToSaveCoder != null)
     {
         (new NetworkOutputCoderSaver()).Save(fileToSaveCoder, coder);
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args">
        /// 1: path to folder with teaching samples files
        /// 2: teaching speed 
        /// 3: path to file to save network
        /// </param>
        static void Main(string[] args)
        {
            try
            {
                var teachingSets = (new FolderTeachingSetsLoader()).Load(args[0]);
                var coder = new NetworkOutputCoder(teachingSets);
                var samples = TeachingSamplesFactory.GetSamples(teachingSets, coder);
                //TODO: var network = KohonenNetworkFactory.Get(coder.EncodedArrayLength, coder.CodingTableCount);
                var teachingSpeed = double.Parse(args[1]);
                var teacher = new KohonenNetworkTeacher(samples, teachingSpeed);
                //teacher.Teach(network);
                //(new KohonenNetworkSaver()).Save(args[2],network);

            }
            catch (Exception e)
            {
                Console.WriteLine("Exceptiond occured: \n"+ e.Message +"\n");
            }
        }
 public static KohonenNetworkTeacher Get(IEnumerable<TeachingSet> set, NetworkOutputCoder coder, double teachingSpeed)
 {
     return new KohonenNetworkTeacher(TeachingSamplesFactory.GetSamples(set,coder), teachingSpeed);
 }
 public static void EmptyInput()
 {
     var input = new string[] {};
     var coder = new NetworkOutputCoder(input);
 }
 public static IEnumerable<TeachingSample> GetSamples(IEnumerable<TeachingSet> set,
     NetworkOutputCoder coder)
 {
     return set.SelectMany(x => x.Inputs.Select(y => new TeachingSample(y, coder.Encode(x.Output)))).Mix();
 }