<commit_before>#! /usr/bin/env python3

from sklearn.preprocessing import scale
from sklearn.model_selection import cross_val_score, cross_val_predict, cross_validate, learning_curve, validation_curve

import pandas as pd
import numpy as np
import sys

njobs = -1

algs = {'knn' : 'kNN', 'dtree' : 'DTree', 'svm' : 'SVM'}

def splitXY(dfXY):
    """
    Takes a dataframe with all X (features) and Y (labels) information and 
    produces five different pandas datatypes: a dataframe with nuclide info 
    only + a series for each label column.

    Parameters
    ----------
    dfXY : dataframe with nuclide concentraations and 4 labels: reactor type, 
           cooling time, enrichment, and burnup

    Returns
    -------
    dfX : dataframe with only nuclide concentrations for each instance
    rY : dataframe with reactor type for each instance
    cY : dataframe with cooling time for each instance
    eY : dataframe with fuel enrichment for each instance
    bY : dataframe with fuel burnup for each instance
    oY : dataframe with ORIGEN reactor name for each instance

    """

    lbls = ['ReactorType', 'CoolingTime', 'Enrichment', 'Burnup', 'OrigenReactor']
    nonlbls = ['AvgPowerDensity', 'ModDensity', 'UiWeight']
    dfX = dfXY.drop(lbls, axis=1)
    for nonlbl in nonlbls+['total']:
        if nonlbl in dfX.columns: 
            dfX.drop(nonlbl, axis=1, inplace=True)
    r_dfY = dfXY.loc[:, lbls[0]]
    c_dfY = dfXY.loc[:, lbls[1]]
    e_dfY = dfXY.loc[:, lbls[2]]
    b_dfY = dfXY.loc[:, lbls[3]]
    #o_dfY = dfXY.loc[:, lbls[4]]
    return dfX, r_dfY, c_dfY, e_dfY, b_dfY

def get_hyperparam(param, train_name):
    """
    
    
    """
    nuc15_hp = {'reactor' :    {'k' : 1, 'depth' : 20, 'feats' : 10, 'g' : 0.50, 'c' : 75000},
                'burnup' :     {'k' : 3, 'depth' : 20, 'feats' : 10, 'g' : 0.50, 'c' : 75000},
                'cooling' :    {'k' : 3, 'depth' : 20, 'feats' : 15, 'g' : 0.10, 'c' : 75000},
                'enrichment' : {'k' : 3, 'depth' : 20, 'feats' : 15, 'g' : 0.10, 'c' : 75000},
                }
    nuc29_hp = {'reactor' :    {'k' : 1, 'depth' : 50, 'feats' : 10, 'g' : 0.10, 'c' : 12500},
                'burnup' :     {'k' : 3, 'depth' : 50, 'feats' : 10, 'g' : 0.50, 'c' : 12500},
                'cooling' :    {'k' : 3, 'depth' : 50, 'feats' : 29, 'g' : 0.01, 'c' : 40000},
                'enrichment' : {'k' : 3, 'depth' : 50, 'feats' : 29, 'g' : 0.00005, 'c' : 40000},
                }
    
    if '15' in train_name:
        hp = nuc15_hp
    else:
        hp = nuc29_hp

    k = hp[param]['k']
    depth = hp[param]['depth']
    feats = hp[param]['feats']
    g = hp[param]['g']
    c = hp[param]['c']

    return k, depth, feats, g, c

def convert_g_to_mgUi(X):
    """
    Converts nuclides from ORIGEN simulations measured in grams to 
    concentrations measured in mg / gUi

    Parameters<commit_msg>updates based on hyperparam optimization<commit_after>#! /usr/bin/env python3

from sklearn.preprocessing import scale
from sklearn.model_selection import cross_val_score, cross_val_predict, cross_validate, learning_curve, validation_curve

import pandas as pd
import numpy as np
import sys

njobs = -1

algs = {'knn' : 'kNN', 'dtree' : 'DTree', 'svm' : 'SVM'}

def splitXY(dfXY):
    """
    Takes a dataframe with all X (features) and Y (labels) information and 
    produces five different pandas datatypes: a dataframe with nuclide info 
    only + a series for each label column.

    Parameters
    ----------
    dfXY : dataframe with nuclide concentraations and 4 labels: reactor type, 
           cooling time, enrichment, and burnup

    Returns
    -------
    dfX : dataframe with only nuclide concentrations for each instance
    rY : dataframe with reactor type for each instance
    cY : dataframe with cooling time for each instance
    eY : dataframe with fuel enrichment for each instance
    bY : dataframe with fuel burnup for each instance
    oY : dataframe with ORIGEN reactor name for each instance

    """

    lbls = ['ReactorType', 'CoolingTime', 'Enrichment', 'Burnup', 'OrigenReactor']
    nonlbls = ['AvgPowerDensity', 'ModDensity', 'UiWeight']
    dfX = dfXY.drop(lbls, axis=1)
    for nonlbl in nonlbls+['total']:
        if nonlbl in dfX.columns: 
            dfX.drop(nonlbl, axis=1, inplace=True)
    r_dfY = dfXY.loc[:, lbls[0]]
    c_dfY = dfXY.loc[:, lbls[1]]
    e_dfY = dfXY.loc[:, lbls[2]]
    b_dfY = dfXY.loc[:, lbls[3]]
    #o_dfY = dfXY.loc[:, lbls[4]]
    return dfX, r_dfY, c_dfY, e_dfY, b_dfY

def get_hyperparam(param, train_name):
    """
    
    
    """
    nuc15_hp = {'reactor' :    {'k' : 1, 'depth' : 33, 'feats' : 9, 'g' : 0.07, 'c' : 285000},
                'burnup' :     {'k' : 7, 'depth' : 64, 'feats' : 14, 'g' : 0.50, 'c' : 100000},
                'cooling' :    {'k' : 2, 'depth' : 61, 'feats' : 15, 'g' : 0.10, 'c' : 100000},
                'enrichment' : {'k' : 4, 'depth' : 36, 'feats' : 5, 'g' : 0.10, 'c' : 100000},
                }
    nuc29_hp = {'reactor' :    {'k' : 1, 'depth' : 30, 'feats' : 17, 'g' : 0.07, 'c' : 23000},
                'burnup' :     {'k' : 7, 'depth' : 73, 'feats' : 27, 'g' : 0.50, 'c' : 40000},
                'cooling' :    {'k' : 4, 'depth' : 58, 'feats' : 28, 'g' : 0.01, 'c' : 40000},
                'enrichment' : {'k' : 4, 'depth' : 51, 'feats' : 27, 'g' : 0.00005, 'c' : 40000},
                }
    
    if '15' in train_name:
        hp = nuc15_hp
    else:
        hp = nuc29_hp

    k = hp[param]['k']
    depth = hp[param]['depth']
    feats = hp[param]['feats']
    g = hp[param]['g']
    c = hp[param]['c']

    return k, depth, feats, g, c

def convert_g_to_mgUi(X):
    """
    Converts nuclides from ORIGEN simulations measured in grams to 
    concentrations measured in mg / gUi

    Parameters
{'fraction_non_alphanumeric': 0.15493200206576002, 'fraction_numerical': 0.04406954725426063, 'mean_word_length': 2.46039309112567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '601664', 'n_tokens_mistral': 2403, 'n_tokens_neox': 2159, 'n_words': 627}