Medial Code Documentation
Loading...
Searching...
No Matches
Functions | Variables
MedPlot.h File Reference

A Library to plot graphs in HTML using plotly.js
Example Code:
vector<map<float, float>> data(2); //plot 2 series of two lines

//create data for lines:
int numPnt = 1000;
float m1 = 2;
float n1 = 3;
float m2 = -4;
float n2 = 9;
for (int i = 0; i < numPnt; ++i)
{
float x = (i - numPnt / 2) / float(100.0);
float y = m1 * (i - numPnt / 2) / 100 + n1;
data[0][x] = y;

y = m2 * (i - numPnt / 2) / 100 + n2;
data[1][x] = y;
}
//end creation of data, now plot:

vector<string> seriesNames = {"line_1", "line_2"};
createHtmlGraph("test.html", data, "Graph Title", "x", "y", seriesNames);
. More...

#include <map>
#include <vector>
#include <string>

Go to the source code of this file.

Functions

string float2Str (float num)
 prety print float number
 
map< float, float > BuildHist (vector< float > featNums)
 makes histogram for vector of numbers and stores it in map object
 
map< float, float > BuildAggeration (const vector< vector< float > > &vec_x, const vector< float > &y, float(*aggFunction)(const vector< float > &), float(*combineFeat)(const vector< float > &)=NULL)
 proccess data to plot x,y.
 
void Build3Data (const vector< float > &x1, const vector< float > &x2, const vector< float > &y, float(*aggFunction)(const vector< float > &), vector< vector< float > > &data, int min_filter_cnt=10)
 proccess data to plot x,y,z.
 
void createHtmlGraph (const string &outPath, const vector< map< float, float > > &data, const string &title="", const string &xName="", const string &yName="", const vector< string > &seriesNames=vector< string >(), int refreshTime=0, const string &chart_type="scatter", const string &mode="lines", const string &template_str="")
 Will create Html Graph string - you will decide where to save it to disk.
 
void createScatterHtmlGraph (const string &outPath, const vector< vector< pair< float, float > > > &data, const string &title="", const string &xName="", const string &yName="", const vector< string > &seriesNames=vector< string >(), int refreshTime=0, const string &chart_type="scatter", const string &mode="markers", const string &template_str="")
 Will create Html Graph string - you will decide where to save it to disk.
 
void createHtml3D (const string &outPath, const vector< vector< vector< float > > > &vec3d, const vector< string > &seriesNames, bool heatmap=true, const string &title="", const string &xName="x", const string &yName="y", const string &zName="z")
 Plot of 3D graph data.
 
string createCsvFile (const map< float, float > &data)
 returns a csv string content of all features with header name for each feature to save in csv format
 
string createCsvFile (const vector< vector< float > > &data, const vector< string > &headers)
 returns a csv string content of all features with header name for each feature to save in csv format
 
void down_sample_graph (map< float, float > &points, int points_count=10000)
 Down sampling the number of points in the graph to points_count if has more points in the data.
 
void get_ROC_working_points (const vector< float > &preds, const vector< float > &y, const vector< float > &weights, vector< float > &pred_threshold, vector< float > &true_rate, vector< float > &false_rate, vector< float > &ppv, vector< float > &pr, const vector< bool > &indexes=empty_bool_arr)
 calculates true_rate, false_rate, ppv based on labels(y) and predictions scores(preds) indexes is used for filtering samples
 
void plotAUC (const vector< vector< float > > &all_preds, const vector< vector< float > > &y, const vector< vector< float > > &weights, const vector< string > &modelNames, string baseOut, bool print_y=true)
 plot AUC Graph for all scores and each score has diffrent label size
 
void plotAUC (const vector< vector< float > > &all_preds, const vector< float > &y, const vector< string > &modelNames, string baseOut, const vector< bool > &indexes=empty_bool_arr, const vector< float > *weights=NULL)
 Plot AUC Graph for all scores for same labels.
 

Variables

string BaseResourcePath
 
vector< bool > empty_bool_arr
 

Detailed Description

A Library to plot graphs in HTML using plotly.js
Example Code:
vector<map<float, float>> data(2); //plot 2 series of two lines

//create data for lines:
int numPnt = 1000;
float m1 = 2;
float n1 = 3;
float m2 = -4;
float n2 = 9;
for (int i = 0; i < numPnt; ++i)
{
float x = (i - numPnt / 2) / float(100.0);
float y = m1 * (i - numPnt / 2) / 100 + n1;
data[0][x] = y;

y = m2 * (i - numPnt / 2) / 100 + n2;
data[1][x] = y;
}
//end creation of data, now plot:

vector<string> seriesNames = {"line_1", "line_2"};
createHtmlGraph("test.html", data, "Graph Title", "x", "y", seriesNames);
.

Function Documentation

◆ Build3Data()

void Build3Data ( const vector< float > &  x1,
const vector< float > &  x2,
const vector< float > &  y,
float(*)(const vector< float > &)  aggFunction,
vector< vector< float > > &  data,
int  min_filter_cnt = 10 
)

proccess data to plot x,y,z.

x is vector of signals and combineFeat will be used if this vector size > 1 to transform each row of signals into single number that will be considred as X. aggFunction will be used to select which value of Y to return for each transformed X value - it could by mean, median, max, min, prctile..

◆ BuildAggeration()

map< float, float > BuildAggeration ( const vector< vector< float > > &  vec_x,
const vector< float > &  y,
float(*)(const vector< float > &)  aggFunction,
float(*)(const vector< float > &)  combineFeat = NULL 
)

proccess data to plot x,y.

x is vector of signals and combineFeat will be used if this vector size > 1 to transform each row of signals into single number that will be considred as X. aggFunction will be used to select which value of Y to return for each transformed X value - it could by mean, median, max, min, prctile..

◆ createCsvFile() [1/2]

string createCsvFile ( const map< float, float > &  data)

returns a csv string content of all features with header name for each feature to save in csv format

Returns
returns the csv string content of all features with header name

◆ createCsvFile() [2/2]

string createCsvFile ( const vector< vector< float > > &  data,
const vector< string > &  headers 
)

returns a csv string content of all features with header name for each feature to save in csv format

Returns
returns the csv string content of all features with header name

◆ createHtml3D()

void createHtml3D ( const string &  outPath,
const vector< vector< vector< float > > > &  vec3d,
const vector< string > &  seriesNames,
bool  heatmap = true,
const string &  title = "",
const string &  xName = "x",
const string &  yName = "y",
const string &  zName = "z" 
)

Plot of 3D graph data.

Parameters
outPathThe output file (recomanded html)
vec3dthe 3d vector, first dim is vector of all series each sereis in diffrent color. second dim is of size 3 for x,y,z axis data and thirds dim is the data in each axis
seriesNamessame size vector to data with coresponding labels to each data
heatmap- if true will print heatmap, else 3d graph
title- graph title
xName- the x axis name
yName- the y axis name
zName- the z axis name

◆ createHtmlGraph()

void createHtmlGraph ( const string &  outPath,
const vector< map< float, float > > &  data,
const string &  title = "",
const string &  xName = "",
const string &  yName = "",
const vector< string > &  seriesNames = vector< string >(),
int  refreshTime = 0,
const string &  chart_type = "scatter",
const string &  mode = "lines",
const string &  template_str = "" 
)

Will create Html Graph string - you will decide where to save it to disk.

Parameters
outPaththe location to save the html file (recommend ending file ext with .html)
datais vector of series to plot with coresponding names in vector seriesNames. each element in the vector is series to plot represented by map<float, float> object the plot will print the iteration on the keys with their corresponding values. the map object is used to store vector of tuples (x,y) to plot in each series
titlegraph title
xNamex Axis name
yNamey Axis name
seriesNamessame size vector to data with coresponding labels to each data
refreshTimeTime in milliseconds for the file to be refreshed by the browser (default 0, taken as do not refresh)
charttype Can be: "scatter", "bar", "pie"

◆ createScatterHtmlGraph()

void createScatterHtmlGraph ( const string &  outPath,
const vector< vector< pair< float, float > > > &  data,
const string &  title = "",
const string &  xName = "",
const string &  yName = "",
const vector< string > &  seriesNames = vector< string >(),
int  refreshTime = 0,
const string &  chart_type = "scatter",
const string &  mode = "markers",
const string &  template_str = "" 
)

Will create Html Graph string - you will decide where to save it to disk.

Parameters
outPaththe location to save the html file (recommend ending file ext with .html)
datais vector of series to plot with coresponding names in vector seriesNames. each element in the vector is series to plot represented by map<float, float> object the plot will print the iteration on the keys with their corresponding values. the map object is used to store vector of tuples (x,y) to plot in each series
titlegraph title
xNamex Axis name
yNamey Axis name
seriesNamessame size vector to data with coresponding labels to each data
refreshTimeTime in milliseconds for the file to be refreshed by the browser (default 0, taken as do not refresh)
charttype Can be: "scatter", "bar", "pie"

◆ down_sample_graph()

void down_sample_graph ( map< float, float > &  points,
int  points_count = 10000 
)

Down sampling the number of points in the graph to points_count if has more points in the data.

the interpulation is linear.

◆ get_ROC_working_points()

void get_ROC_working_points ( const vector< float > &  preds,
const vector< float > &  y,
const vector< float > &  weights,
vector< float > &  pred_threshold,
vector< float > &  true_rate,
vector< float > &  false_rate,
vector< float > &  ppv,
vector< float > &  pr,
const vector< bool > &  indexes = empty_bool_arr 
)

calculates true_rate, false_rate, ppv based on labels(y) and predictions scores(preds) indexes is used for filtering samples

Returns
updates true_rate, false_rate, ppv