User guides

List of some usefull tutorials on how to use the diffirent features of FenicsATL

FenGrapher Linear regression

This is an example on how to use linear regression and check box filtering with FenGraphs.FenBokehGrapher.

We first generate random data for illustration :

            X = np.linspace(0, 2000, 2000)
            Y = np.linspace(0, 2000, 2000)

            mu = 0  # mean
            sigma = 50  # standard deviation
            noise_X = np.random.normal(mu, sigma, len(X))
            noise_Y = np.random.normal(mu, sigma, len(Y))

            X_with_noise = X + noise_X #Our noisy X array 
            Y_with_noise = Y + noise_Y #Our noisy Y array


            #Labelization of the points and color coding them
            labelsDogs = ['dogs' for ii in range(0,500)] ; ColorsDogs = [0 for ii in range(0,500)] 
            labelsCats = ['cats' for ii in range(500,1000)] ; ColorsCats = [1 for ii in range(500,1000)]
            labelsBirds = ['birds' for ii in range(1000,1500)] ; ColorsBirds = [2 for ii in range(1000,1500)] 
            labelsHumans = ['humans' for ii in range(1500,2000)] ; ColorsHumans = [3 for ii in range(1500,2000)]

            #Giving series name to the arrays for tooltips
            Labels = labelsDogs + labelsCats + labelsBirds + labelsHumans ; Colors = ColorsDogs + ColorsCats + ColorsBirds + ColorsHumans
            Labels = pd.Series(Labels,name='Labels') ; Colors = pd.Series(Colors,name='Colors')

We this we define Plot our FenGrapher object with our generated data, and using custom tooltips we show the @label as Kind.

            Plot = FATL.FenBokehGrapher(X_with_noise,Y_with_noise,Labels,labels=Labels,colors=Colors,tooltips=[("Kind","@labels")])

Now we can plot the object using histogram plottype with a combo filter (Slider + Checkboxes).

            Plot.plotter(plotType='histogram',filters=[('Combo'),],title='Linear regression Example and checkbox',linear_fit = True)

FENICS t-SNE plotting

Using FenGraphs.FenBokehGrapher and FenGraphs.FenBokehTSNE we can plot and interact with different FENICS boards.

Initialisation of the FenGraphs.FenBokehTSNE :

    tsne_bokeh = FATL.FenBokehTSNE(Slow_filtred,normalize=False,perplexity=30,n_iter=1000,learning_rate=2000)

Save output path

    OutputPath = main_dir+'fen1_output/t-sne/slow/HTML/'

Declaration of a custom filter, combo filter with a slider + checkboxes

    custom_filter = [('Combo',dict(labels_filter=FEN1_ids,
                                    radio_categories=[dict(name = 'FEN1 LTT',indexes=FEN1_ids),
                                    dict(name = 'FEN1 FAILED',indexes=FENICS_fail),]))]

Declaration of a custom tooltip :

    tooltips=[("card","FENICS0@version @labels"),("burnTime","@burnTime"),
                                        ("StatusFast","@StatusFast"),("StatusSlow","@StatusSlow")]

Declaration of a new FenBokehGrapher object with FenGraphs.FenBokehTSNE object attributes tsne_bokeh.tsne_x,tsne_bokeh.tsne_y and a custom tooltips:

    FenGraph = FATL.FenBokehGrapher(tsne_bokeh.tsne_x,tsne_bokeh.tsne_y,FENICS.Board.version,
                                FENICS.Board.burnTime,FENICS.Board.StatusFast,FENICS.Board.StatusSlow,
                                colors=FENICS.Board.burnTime ,labels=FENICS.Board.id,tooltips=tooltips)

Plotting FenGraph object using FenGraphs.FenBokehTSNE.plotter()

    FenGraph.plotter(plotType='histogram',filters=custom_filter,
        title=f't-SNE : FENICS01 SLOW; normed {tsne_bokeh.normed}; t-SNE params : perplexity={tsne_param.perplexity},n_iter={tsne_param.n_iter},learning_rate={tsne_param.learning_rate}')

   

Saving FenGraph object to HTML with FenGraphs.FenBokehTSNE.save_as_html()

    FenGraph.save_as_html(path=OutputPath,filename=f'FEN1_SLOW_t-SNE_perplexity_{tsne_param.perplexity}_wburn_normed_{tsne_bokeh.normed}.html')

FenGrapher custom filters

In this section we will see custom filters and tool tips. We are using a Height, Weight dataset from UCL, and loading it in Python, we convert heights and weights to SI, and we calculate and labelize the dataset using topsante IMC categories.

    # Load the CSV dataset into a DataFrame
    df = pd.read_csv('../data/HeightWeight.csv',index_col=0)

    # Convert height from inches to centimeters, weight from pounds to kilograms
    df['Height'] = df['Height'] * 2.54 ; df['Weight'] = df['Weight'] * 0.453592

    #IMC calculation
    df['IMC'] = df['Weight']/(df['Height'] / 100) ** 2

    # TOP Santé categories
    categories = [df['IMC'] < 18.5,
                (df['IMC'] >= 18.5) & (df['IMC'] < 25),
                (df['IMC'] >= 25) & (df['IMC'] < 30),
                (df['IMC'] >= 30) & (df['IMC'] < 35),
                (df['IMC'] >= 35) & (df['IMC'] < 40),
                df['IMC'] >= 40]

    labels = ['Insuffisance pondérale (maigreur)',
            'Corpulence normale',
            'Surpoids',
            'Obésité modérée',
            'Obésité sévère',
            'Obésité morbide ou massive']

    # Dataset labelization
    df['LabelsText'] = np.select(categories, labels)

    df['LabelsID'],_ = pd.factorize(df['LabelsText'])

Here we want to see and filter people by height and their IMC category, we can define these custom tooltip (for curson scatter point informations) and custom radio boxes to select each IMC category.

Tool tips declaration wr want to see the heights, the weights, the IMC and it's category:

    Custom_tooltips=[("Height","@Height cm"),("Weight","@Weight Kg"),("IMC","@IMC"),("Catégorie","@LabelsText")]

Same features as the custom Tool tips where FenGrapher will extract the informations

    args = [df.Height,df.Weight,df.IMC,df.LabelsText]

Custom combo filter (Slider + RadioBoxes), and the different IMC categories wanted, on change la valeur par default du Slider avec step=0.5 et le titre avec title:

    Custom_filter = [('Combo',dict(step=2,title='height cm',radio_categories=[dict(name = 'IMC : maigreur',indexes=[0]),
                                             dict(name = 'IMC : normale',indexes=[1]),
                                             dict(name='IMC : Surpoids',indexes=[2])
                                             ]))]

Using FenGraphs.FenBokehTSNE and some random parameters we try to see if we are able to separate the different categories :

    Plot = FATL.FenBokehGrapher(TSNE.tsne_x,TSNE.tsne_y,*args,labels=df.LabelsID,colors=df.Height,tooltips=Custom_tooltips)

We plot using plotter and in plottype='scatter' :

    Plot.plotter(plotType='scatter',filters=Custom_filter,title='Lienar regression Example and checkbox')