public NodeFactory(NodeFuncGenerator funcGenerator, IDictionary <NodeType, double> probabilityMap)
        {
            if (probabilityMap.Count == 0)
            {
                throw new ArgumentException();
            }

            foreach (var item in probabilityMap)
            {
                if (item.Value < 0)
                {
                    throw new ArgumentException();
                }
            }

            funcGenerator_ = funcGenerator;

            typeDistributionMap_ = new Dictionary <NodeType, double>();
            double sum = 0.0d;

            for (int i = 0; i < probabilityMap.Count; i++)
            {
                sum += probabilityMap.ElementAt(i).Value;
                typeDistributionMap_.Add(probabilityMap.ElementAt(i).Key, sum);
            }
            typeDistributionMapMax_ = sum;
        }
Example #2
0
        public TeacherTester()
        {
            Logger.Log(this, "App start");

            NodeFuncGenerator             funcGenerator      = new NodeFuncGenerator();
            Dictionary <NodeType, double> nodeProbabilityMap = new Dictionary <NodeType, double>()
            {
                { NodeType.add, 1.0d },
                { NodeType.compare, 1.0d },
                { NodeType.copy, 0.0d },
                { NodeType.inverse, 1.0d },
                { NodeType.log, 1.0d },
                { NodeType.multiply, 1.0d },
                { NodeType.reverse, 1.0d }
            };
            NodeFactory      nodeFactory     = new NodeFactory(funcGenerator, nodeProbabilityMap);
            List <DataPoint> dataPoints      = GenerateSinWaveDataPoints(100, 0.19d);
            Network          network         = new Network(nodeFactory, dataPoints, 1000);
            double           addRemoveChance = 0.5;
            PatchFactory     patchFactory    = new PatchFactory(network, nodeFactory, addRemoveChance);
            NetworkTeacher   networkTeacher  = new NetworkTeacher(network, patchFactory);

            Logger.Log(this, String.Format("initial error: {0}", network.CalculateTrainingSqrError()));
            networkTeacher.Teach(
                teachingTime: TimeSpan.FromSeconds(10000000.0d),
                wantedNoOfNodes: 300,
                changesPerPatch: 8,
                patchesPerTeachingSerie: 1
                );
            Logger.Log(this, String.Format("error after learning: {0}", network.CalculateTrainingSqrError()));

            Logger.Log(this, "App finish");
            Console.ReadKey();
        }
        public TeacherTester()
        {
            Logger.Log(this, "App start");

            NodeFuncGenerator funcGenerator = new NodeFuncGenerator();
            Dictionary<NodeType, double> nodeProbabilityMap = new Dictionary<NodeType, double>()
            {
                {NodeType.add, 1.0d},
                {NodeType.compare, 1.0d},
                {NodeType.copy, 0.0d},
                {NodeType.inverse, 1.0d},
                {NodeType.log, 1.0d},
                {NodeType.multiply, 1.0d},
                {NodeType.reverse, 1.0d}
            };
            NodeFactory nodeFactory = new NodeFactory(funcGenerator, nodeProbabilityMap);
            List<DataPoint> dataPoints = GenerateSinWaveDataPoints(100, 0.19d);
            Network network = new Network(nodeFactory, dataPoints, 1000);
            double addRemoveChance = 0.5;
            PatchFactory patchFactory = new PatchFactory(network, nodeFactory, addRemoveChance);
            NetworkTeacher networkTeacher = new NetworkTeacher(network, patchFactory);

            Logger.Log(this, String.Format("initial error: {0}", network.CalculateTrainingSqrError()));
            networkTeacher.Teach(
                teachingTime: TimeSpan.FromSeconds(10000000.0d),
                wantedNoOfNodes: 300,
                changesPerPatch: 8,
                patchesPerTeachingSerie: 1
            );
            Logger.Log(this, String.Format("error after learning: {0}", network.CalculateTrainingSqrError()));

            Logger.Log(this, "App finish");
            Console.ReadKey();
        }
Example #4
0
 public void Transform(NodeType nodeType)
 {
     nodeType_ = nodeType;
     ParentsNo = 2;
     if (nodeType == TrendPredictorLib.NodeType.copy) //IMPORTANT: TODO: This is heavy hack - inputs was not working - fix it by changing this property someway for inputs
     {
         ParentsNo = 1;
     }
     calculateFoo_ = NodeFuncGenerator.GenerateFunc(nodeType);
 }
 public void SetUp()
 {
     NodeFuncGenerator nodeFuncGenerator = new NodeFuncGenerator();
     NodeFactory nodeFactory = new NodeFactory(
         nodeFuncGenerator,
         new Dictionary<NodeType, double>() { { NodeType.add, 1.0d } });
     network = new Network(
         nodeFactory: nodeFactory,
         trainingData: new List<DataPoint>()
         {
             new DataPoint(new List<double>(){2.0d, 2.0d, 2.0d}, 5.0d) //IMPORTANT: TODO: was modified from "new DataPoint(new List<double>(){2.0d, 2.0d}, 5.0d)" - now test can work incorrectly
         },
         maxHierarchy: 1000
     );
     patchFactory = new PatchFactory(network, nodeFactory, 1.0d);
     networkTeacher = new NetworkTeacher(network, patchFactory);
 }
        public NodeFactory(NodeFuncGenerator funcGenerator, IDictionary<NodeType, double> probabilityMap)
        {
            if (probabilityMap.Count == 0)
                throw new ArgumentException();

            foreach (var item in probabilityMap)
            {
                if (item.Value < 0)
                    throw new ArgumentException();
            }

            funcGenerator_ = funcGenerator;

            typeDistributionMap_ = new Dictionary<NodeType, double>();
            double sum = 0.0d;
            for (int i = 0; i < probabilityMap.Count; i++)
            {
                sum += probabilityMap.ElementAt(i).Value;
                typeDistributionMap_.Add(probabilityMap.ElementAt(i).Key, sum);
            }
            typeDistributionMapMax_ = sum;
        }
        public void SinWaveTrainingTest()
        {
            NodeFuncGenerator funcGenerator = new NodeFuncGenerator();
            Dictionary<NodeType, double> nodeProbabilityMap = new Dictionary<NodeType,double>()
            {
                {NodeType.add, 1.0d},
                {NodeType.compare, 1.0d},
                {NodeType.copy, 0.0d},
                {NodeType.inverse, 1.0d},
                {NodeType.log, 1.0d},
                {NodeType.multiply, 1.0d},
                {NodeType.reverse, 1.0d}
            };
            NodeFactory nodeFactory = new NodeFactory(funcGenerator, nodeProbabilityMap);
            List<DataPoint> dataPoints = GenerateSinWaveDataPoints(100, 0.35d);
            Network network = new Network(nodeFactory, dataPoints, 1000);
            double addRemoveChance = 0.5;
            PatchFactory patchFactory = new PatchFactory(network, nodeFactory, addRemoveChance);
            NetworkTeacher networkTeacher = new NetworkTeacher(network, patchFactory);

            networkTeacher.Teach(TimeSpan.FromSeconds(0.1d), 2000, 3, 30);
        }