This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def detect_NaNs(df_temp : pd.DataFrame, name = '', silent : bool = False, plot : bool = True): | |
""" | |
Detect NaNs in a provided dataframe and return the columns that NaNs were detected in | |
Parameters | |
---------- | |
df_temp : pd.DataFrame | |
Dataframe to detect NaN values in | |
name : str | |
Name of the dataframe which helps give a more descriptive read out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fill_nans_create_columns(df_temp : pd.DataFrame, columns : typing.List, value : float = 0): | |
""" | |
Fill NaN of provided columns and create columns to signify they weren't there. | |
Parameters | |
---------- | |
df_temp : pd.DataFrame | |
Dataframe to modify | |
columns : typing.List | |
Columns of the provided dataframe to modify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def break_up_by_string(df_temp : pd.DataFrame, splitting_string : str): | |
""" | |
Break up columns by string to create new columns from each split. | |
Parameters | |
---------- | |
df_temp : pd.DataFrame | |
Dataframe to start splitting up object columns | |
splitting_string : str | |
String to split up columns by |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ComputationManager | |
{ | |
public ComputationManager() {} | |
public static double Compute(List<Gene> Genes, double x) | |
{ | |
double y = 0; | |
foreach(Gene g in Genes) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string Display () | |
{ | |
string Result = ""; | |
//Prefix allows for brackets which correct the order of operations for the statement | |
string Prefix = ""; | |
foreach (Gene g in genes) | |
{ | |
switch(g.Operation) | |
{ | |
case Geneset.Add: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public double GetFitness(List<Tuple<Single,Single>> LineValues) | |
{ | |
double Fitness = 0; | |
foreach (var item in LineValues) | |
{ | |
Fitness -= Math.Abs((item.Item2 - ComputationManager.Compute(genes,item.Item1))); | |
} | |
return Fitness; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Mutate() | |
{ | |
Random rnd = new Random(); | |
int Index = rnd.Next(0,genes.Count); | |
genes[Index] = GenerateGene(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Chromosome | |
{ | |
List<Gene> genes {get; set;} | |
//Generates a random parent of set length | |
public void GenerateParent(int Length) | |
{ | |
genes = new List<Gene>(); | |
for(int i = 0; i < Length; i++) | |
{ | |
genes.Add(GenerateGene()); |
NewerOlder