Medial Code Documentation
|
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 |
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);
.
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..
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..
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 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.
outPath | The output file (recomanded html) |
vec3d | the 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 |
seriesNames | same 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 |
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.
outPath | the location to save the html file (recommend ending file ext with .html) |
data | is 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 |
title | graph title |
xName | x Axis name |
yName | y Axis name |
seriesNames | same size vector to data with coresponding labels to each data |
refreshTime | Time in milliseconds for the file to be refreshed by the browser (default 0, taken as do not refresh) |
chart | type Can be: "scatter", "bar", "pie" |
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.
outPath | the location to save the html file (recommend ending file ext with .html) |
data | is 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 |
title | graph title |
xName | x Axis name |
yName | y Axis name |
seriesNames | same size vector to data with coresponding labels to each data |
refreshTime | Time in milliseconds for the file to be refreshed by the browser (default 0, taken as do not refresh) |
chart | type Can be: "scatter", "bar", "pie" |
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.
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