mousestyles.visualization package

Submodules

mousestyles.visualization.distribution_plot module

mousestyles.visualization.distribution_plot.plot_exponential(estimation)[source]

Return the histogram of all estimators of exponential to check the distribution.

Parameters:estimation (dataframe) – dataframe of strain, mouse, day and the estimator
Returns:plot – The histogram of all estimators of exponential.
Return type:histogram
mousestyles.visualization.distribution_plot.plot_fitted(strain, mouse, day, hist=True, density=False)[source]

Return the plot of one single mouse day -fitted power law -fitted exponential -histogram of distance -kernel density curve

Parameters:
  • strain (int) – the strain number of the mouse
  • mouse (int) – the mouse number in its strain
  • day (int) – the day number
  • hist (boolean) – Plot histogram if True
  • density (boolean) – plot density if True
Returns:

plot

Return type:

1 histogram (blue) + 2 fitted curve + 1 density (cyan)

mousestyles.visualization.distribution_plot.plot_powerlaw(estimation)[source]

Return the histogram of all estimators of power law to check the distribution.

Parameters:estimation (dataframe) – dataframe of strain, mouse, day and the estimator
Returns:plot – The histogram of all estimators of power law
Return type:histogram
mousestyles.visualization.distribution_plot.plot_relative_dist(strain, mouse, day)[source]

Return the relative distribution of distance of a single mouse day The relative distribution of a comparison distribution with density g vs a reference distribution with density f is g(F^(-1)(x))/f(F^(-1)(x)) It’s a prob distribution on [0, 1].

Parameters:
  • strain (int) – the strain number of the mouse
  • mouse (int) – the mouse number in its strain
  • day (int) – the day number
Returns:

  • pdf_rel_power (numpy.ndarray) – the relative distribution, referencing the best fit powerlaw distribution, at grid points np.arange(0, 1.0, 0.02)
  • pdf_rel_exp (numpy.ndarray) – the relative distribution, referencing the best fit exponential distribution, at grid points np.arange(0, 1.0, 0.02)

mousestyles.visualization.dynamics module

mousestyles.visualization.dynamics.plot_dynamics(df, strain_num, interval_length_initial=array([ 600, 1200, 1800, 2400, 3000, 3600, 4200, 4800, 5400, 6000, 6600, 7200]), plot_time_range=array([36000, 36001, 36002, 36003, 36004, 36005, 36006, 36007, 36008, 36009, 36010, 36011, 36012, 36013, 36014, 36015, 36016, 36017, 36018, 36019, 36020, 36021, 36022, 36023, 36024, 36025, 36026, 36027, 36028, 36029, 36030, 36031, 36032, 36033, 36034, 36035, 36036, 36037, 36038, 36039, 36040, 36041, 36042, 36043, 36044, 36045, 36046, 36047, 36048, 36049, 36050, 36051, 36052, 36053, 36054, 36055, 36056, 36057, 36058, 36059, 36060, 36061, 36062, 36063, 36064, 36065, 36066, 36067, 36068, 36069, 36070, 36071, 36072, 36073, 36074, 36075, 36076, 36077, 36078, 36079, 36080, 36081, 36082, 36083, 36084, 36085, 36086, 36087, 36088, 36089, 36090, 36091, 36092, 36093, 36094, 36095, 36096, 36097, 36098, 36099]))[source]

returns a plot that can help understand the behavior dynamics that are obtained from the best simulation. The data used as input is the pandas DataFrame generated by function create_time_matrix. The output is a plot that summarizes the dynamics of a fake mouse of the given strain_num. The strain_num could be chosen. Of note is that 0 represents IS, 1 represents eating, 2 represents drinking, 3 represents others activity in AS. In the plot, blue represents IS, bright green represents eating, yellow represents drinking, and red represents other activities in AS.

Parameters:
  • df (Pandas.DataFrame) – a huge data frame containing info on strain, mouse no., mouse day, and different states at chosen time points.
  • starin_num (int) – an integer specifying the desired mouse strain. strain_num is 0, 1, or 2.
  • interval_length_initial (numpy.ndarray) – a numpy.ndarray specifying the range of time interval that it optimizes on.
  • plot_time_range (numpy.ndarray) – a numpy.ndarray specifying the range of time range of the plot.
Returns:

dynamics_plot – a plot of behavior dynamics of a fake mouse of the given strain_num. The x-axis is the time stamps that start from 0. For strain_num = 0, the x-aixs is from 0 to 92,400. For stain_num = 1, the x-axis is from 0 90,000. For strain_num = 2, the x-axis is from 0 to 88,800. We assign different colors for different states. In the plot, blue represents IS, bright green represents eating, yellow represents drinking, and red represents other activities in AS.

Return type:

plot

Examples

>>> row_i = np.hstack((np.zeros(40)))
>>> time_df_eg = np.vstack((row_i, row_i, row_i))
>>> time_df_eg = pd.DataFrame(time_df_eg)
>>> time_df_eg.rename(columns={0:'strain'}, inplace=True)
>>> plot_dynamics_plot(time_df_eg, 0,
              np.arange(10, 40, 10), np.arange(0, 40, 1))

mousestyles.visualization.path_diversity_plotting module

mousestyles.visualization.path_diversity_plotting.plot_box(list_of_arrays, title=u'Box Plot of Distribution', width=4, height=4)[source]

Make a box plot of the desired metric (path length, speed, angle, etc) per mouse, day or strain.

Parameters:
  • list_of_arrays (list) – each element of the list is a numpy array containing data on the metric to be plotted per mouse, day, or strain.Data is typically generated from another function in the package.
  • title (str) – desired title of the plot
  • width (int) – first argument in figure size specifying width of plot
  • height (int) – second argument in figure size specifying height of plot
Returns:

box plot

Return type:

box plot of the desired metric combinations

mousestyles.visualization.path_diversity_plotting.plot_hist(list_of_arrays, title=u'Histogram of Distribution', xlab=u'X Values', ylab=u'Y Values', leg=True)[source]

Make a histogram of the desired metric (path length, speed, angle, etc) per mouse, day, or strain.

Parameters:
  • list_of_arrays (list) – each element of the list is a numpy array containing data on the metric to be plotted per mouse, day, or strain.Data typically generated from another function in the package.
  • title (str) – desired title of the plot
  • xlab (str) – desired x axis label of the plot
  • ylab (str) – desired y axis label of the plot
  • leg (bool) – indicates whether a legend for the plot is desired
Returns:

hist plot

Return type:

histogram of the desired metric combinations

mousestyles.visualization.plot_classification module

mousestyles.visualization.plot_classification.plot_comparison(comparison)[source]

Plots the F1 Measure of different classification models. It is a side-by-side barplot. For each strain, it plots the F-1 measure of RandomForest, GradientBoosting, SVM. :param comparison: :type comparison: dataframe, columns of F-1 measures of 3 :param methods:

Returns:
Return type:None
mousestyles.visualization.plot_classification.plot_performance(result)[source]

Plots the performance of classification model.It is a side-by-side barplot. For each strain, it plots the precision, recall and F-1 measure. :param result: F-1 measure. :type result: dataframe, columns of precision, recall and

Returns:
Return type:None

mousestyles.visualization.plot_clustering module

mousestyles.visualization.plot_clustering.plot_dendrogram(mouse_day, method, dist)[source]

Returns a linkage matrix and plot the dendrogram

Parameters:
  • mouse_day (a 170 * M numpy array,) – column 0 : strain, column 1: mouse, other columns corresponding to feature avg/std of a mouse over 16 days
  • method (string,) – method of calculating distance between clusters
  • dist (string,) – distance metric
Returns:

Z – The hierarchical clustering encoded as a linkage matrix.

Return type:

ndarray

mousestyles.visualization.plot_clustering.plot_lastp_dist(Z, method, dist, p=10)[source]

Plot the distances between clusters of last p merges in hierarchical clustering

Parameters:
  • Z (ndarray) – The hierarchical clustering encoded as a linkage matrix
  • p (int, optional) – number of merges to plot
mousestyles.visualization.plot_clustering.plot_strain_cluster(count_data, groupby_cluster=True)[source]

Plot the side by side bar chart showing the strain distribution of mice in different clusters or the cluster distribution in different strains

Parameters:
  • count_data (Dictionary) – A dictionary object with the keys are the cluster numbers and the values are lists containing strain counts
  • groupbu_cluster (Boolean) – If True, then the barchart is group by cluster otherwise by strain

mousestyles.visualization.plot_lomb_scargle module

mousestyles.visualization.plot_lomb_scargle.lombscargle_visualize(periods, power, sig, N, cycle, cycle_power, cycle_pvalue)[source]

Use Lomb-Scargel method on different strain and mouse’s data to find the best possible periods with highest p-values, and plot the Lomb Scargle power versus periods plot. use the periods as time sequence to predict the corresponding LS power, draw the plot.

There will also be stars and horizontal lines indicating the p-value of significance. Three stars will be p-value in [0,0.001], two stars will be p-value in [0.001,0.01], one star will be p-value in [0.01,0.05]. The horizontal line is the LS power that has p-value of 0.05.

Parameters:
  • periods (numpy array of the same length with 'power') – use as time sequence in LS model to make predictions
  • power (numpy array of the same length with 'periods') – the corresponding predicted power of periods
  • sig (list, tuple or numpy array, default is [0.05].) – significance level to be used for plot horizontal line.
  • N (int) – the length of time sequence in the fit model
  • cycle (numpy array) – periods
  • cycle_power (numpy array) – LS power corrsponding to the periods in ‘cycle’
  • cycle_pvalue (numpy array) – p-values corresponding to the periods in ‘cycle’
Returns:

Return type:

Lomb Scargle Power versus Periods (hours) plot with significant levels.

Examples

mousestyles.visualization.plot_path module

mousestyles.visualization.plot_path.plot_path(movement, paths, title=u'example plot of path', alpha=0.1, linewidth=1.0, xlim=[-16.24, 3.76], ylim=[0.9, 43.5])[source]

Plot the lines along paths.

Parameters:
  • movement (pandas.DataFrame) – CX, CY coordinates. Must have length greater than 1.
  • paths (list) – a list containing the indices for all paths.
  • title (str) – the title of the plot. Default is ‘example plot of path’
  • alpha (numeric) – graphical parameter which determines strongness of each line. Default is .1.
  • linewidth (numeric) – graphical parameter which determines the width of each line. Default is 1.
  • ylim (xlim,) – list of length 2 indicating the end points of the plot.
Returns:

Return type:

Drawing the plot of the path.

Examples

>>> movement = data.load_movement(1,2,1)
>>> sep = path_index(movement, 1, 1)
>>> plot_path(movement, sep)

mousestyles.visualization.plot_ultradian module

mousestyles.visualization.plot_ultradian.compare_strain(feature, n_strain=3, bin_width=15, disturb_t=False)[source]

Use the data from function find_cycle and plotting method from function lombscargle_visualize to compare the Lomb-Scargle plots between different strains.

Parameters:
  • feature (string in {"AS", "F", "M_AS", "M_IS", "W", "Distance"}) – “AS”: Active state probalibity “F”: Food consumed (g) “M_AS”: Movement outside homebase “M_IS”: Movement inside homebase “W”: Water consumed (g) “Distance”: Distance traveled
  • n_strain (int, defalt is 3) – nonnegative integer indicating total number of strains to be compared
  • bin_width (int, minute unit, default is 15 minutes) – number of minutes, the time interval for data aggregation
  • disturb_t (boolean, default is False) – If True, add uniformly distributed noise to the time sequence which are used to fit the Lomb Scargle model. This is to avoid the singular matrix error that could happen sometimes.
Returns:

Return type:

Lomb Scargle Power versus Periods (hours) plot with significant levels.

Examples

mousestyles.visualization.plot_ultradian.plot_strain_seasonal(strains, mouse, feature, bin_width, period_length)[source]

Use seansonal decomposition model on the time series of specified strain, mouse, feature and bin_width. return the seasonal term and the plot of seasonal term by mouse of a set of mouses in a strain

Parameters:
  • strain (list, set or tuple) – nonnegative integer indicating the strain number
  • mouse (list, set or tuple) – nonnegative integer indicating the mouse number
  • feature ({"AS", "F", "M_AS", "M_IS", "W", "Distance"}) – “AS”: Active state probalibity “F”: Food consumed (g) “M_AS”: Movement outside homebase “M_IS”: Movement inside homebase “W”: Water consumed (g) “Distance”: Distance traveled
  • bin_width (int) – number of minutes, the time interval for data aggregation
  • period_length (float or int) – number of hours, usually the significant period length indicated by Lomb-scargle model
Returns:

seasonal_plot

Return type:

plot of seasonal term by mouse

Examples

>>> res = plot_strain_seasonal(strains={0, 1, 2,}, mouse={0, 1, 2, 3},
                               feature="W",
                               bin_width=30, period_length = 24)

Module contents