Skip to content

Instantly share code, notes, and snippets.

View Benzidrine's full-sized avatar

Taran Benzidrine

View GitHub Profile
@Benzidrine
Benzidrine / detect_NaNs.py
Created March 16, 2022 03:43
detect_NaNs
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
@Benzidrine
Benzidrine / fill_nans_create_columns.py
Created March 16, 2022 03:38
fill_nans_create_columns
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
@Benzidrine
Benzidrine / break_up_by_string.py
Created March 16, 2022 03:36
break_up_by_string
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
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))
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));
public class ComputationManager
{
public ComputationManager() {}
public static double Compute(List<Gene> Genes, double x)
{
double y = 0;
foreach(Gene g in Genes)
{
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:
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;
}
public void Mutate()
{
Random rnd = new Random();
int Index = rnd.Next(0,genes.Count);
genes[Index] = GenerateGene();
}
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());