-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
54 lines (49 loc) · 2.1 KB
/
Program.cs
File metadata and controls
54 lines (49 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using symbolicregression1.Models;
namespace SymbolicRegression1
{
class Program
{
static void Main(string[] args)
{
//Set up initial Data Points
List<Tuple<float,float>> Data = new List<Tuple<float, float>>();
Data.Add(new Tuple<float,float>(0,0.375f));
Data.Add(new Tuple<float,float>(1,1.123f));
Data.Add(new Tuple<float,float>(2,0.5f));
Data.Add(new Tuple<float,float>(3,-0.359f));
Data.Add(new Tuple<float,float>(4,0.165f));
Data.Add(new Tuple<float,float>(5,1.078f));
Data.Add(new Tuple<float,float>(6,0.684f));
Data.Add(new Tuple<float,float>(7,-0.285f));
string Command = Console.ReadLine();
if (Command == "run")
{
double OptimalFitness = 0;
Chromosome BestParent = new Chromosome();
BestParent.GenerateParent(6);
Console.WriteLine(BestParent.Display());
for (int i = 0; i < 10000000; i++)
{
Chromosome child = BestParent.Clone();
child.Mutate();
if (child.GetFitness(Data) > BestParent.GetFitness(Data))
{
Console.WriteLine("Child Fitness: " + child.GetFitness(Data) + " Parent Fitness " + BestParent.GetFitness(Data));
BestParent = child.Clone();
Console.WriteLine(BestParent.Display() + " Fitness: " + BestParent.GetFitness(Data));
if (OptimalFitness == BestParent.GetFitness(Data))
break;
}
}
}
}
//Examine:
//(sin(x*1.5)+0.5)*0.75
//Vs:
//(0+x+sin((x * 1.55200069563091))-x+0.99404109967595+sin((x * 1.44250526998309)))*0.385520038374476
//Vs:
//(0+x-x+0.0324822794797282+sin((x * 1.49997493228874))+0.467162608386559)*0.75008695141882
}
}