Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120152590
DataLayer.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jul 2, 07:45
Size
4 KB
Mime Type
text/x-c
Expires
Fri, Jul 4, 07:45 (2 d)
Engine
blob
Format
Raw Data
Handle
27148277
Attached To
R8820 scATAC-seq
DataLayer.cpp
View Options
#include <DataLayer.hpp>
#include <stdexcept> // std::invalid_argument
#include <cmath> // log()
#include <matrices.hpp>
DataLayer::DataLayer()
{}
DataLayer::DataLayer(const matrix2d_i& data,
size_t n_class,
size_t n_shift,
bool flip)
:data(data),
flip(flip),
n_row(data.size()),
n_col(data[0].size()),
n_class(n_class),
l_model(n_col - n_shift + 1),
n_shift(n_shift),
n_flip(flip + 1)
{ // models cannot be initialise here
// as the number of categories depend
// on the exact class
}
DataLayer::DataLayer(const matrix2d_i& data,
const matrix3d_d& model,
bool flip)
: data(data),
model(model),
flip(flip),
n_row(data.size()),
n_col(data[0].size()),
n_class(model.size()),
l_model(model[0].size()),
n_category(model[0][0].size()),
n_shift(n_col - l_model + 1),
n_flip(flip + 1)
{ // check if model is not too long
if(this->n_col < this->l_model)
{ char msg[4096] ;
sprintf(msg,
"Error! model is longer than data : %zu / %zu",
this->l_model, this->n_col) ;
throw std::invalid_argument(msg) ;
}
this->n_shift = this->n_col - this->l_model + 1 ;
}
DataLayer::~DataLayer()
{}
matrix3d_d DataLayer::get_model() const
{ return this->model ; }
void DataLayer::check_loglikelihood_dim(const matrix4d_d& loglikelihood) const
{ if(loglikelihood.size() != this->n_row)
{ char msg[4096] ;
sprintf(msg,
"Error! loglikelihood matrix 1st dimension is not "
"equal to data row number : %zu / %zu",
loglikelihood.size(), this->n_row) ;
throw std::invalid_argument(msg) ;
}
else if(loglikelihood[0].size() != this->n_class)
{ char msg[4096] ;
sprintf(msg,
"Error! loglikelihood matrix 2nd dimension is not "
"equal to model class number : %zu / %zu",
loglikelihood[0].size(), this->n_class) ;
throw std::invalid_argument(msg) ;
}
else if(loglikelihood[0][0].size() != this->n_shift)
{ char msg[4096] ;
sprintf(msg,
"Error! loglikelihood matrix 3rd dimension is not "
"equal to model shift state number : %zu / %zu",
loglikelihood[0][0].size(), this->n_shift) ;
throw std::invalid_argument(msg) ;
}
else if(loglikelihood[0][0][0].size() != this->n_flip)
{ char msg[4096] ;
sprintf(msg,
"Error! loglikelihood matrix 4th dimension is not "
"equal to model flip state number : %zu / %zu",
loglikelihood[0][0][0].size(), this->n_flip) ;
throw std::invalid_argument(msg) ;
}
}
void DataLayer::check_loglikelihood_max_dim(const vector_d& loglikelihood_max) const
{ if(loglikelihood_max.size() != this->n_row)
{ char msg[4096] ;
sprintf(msg,
"Error! loglikelihood_max length is not "
"equal to data row number : %zu / %zu",
loglikelihood_max.size(), this->n_flip) ;
throw std::invalid_argument(msg) ;
}
}
void DataLayer::check_posterior_prob_dim(const matrix4d_d& posterior_prob) const
{ if(posterior_prob.size() != this->n_row)
{ char msg[4096] ;
sprintf(msg,
"Error! posterior_prob matrix 1st dimension is not "
"equal to data row number : %zu / %zu",
posterior_prob.size(), this->n_row) ;
throw std::invalid_argument(msg) ;
}
else if(posterior_prob[0].size() != this->n_class)
{ char msg[4096] ;
sprintf(msg,
"Error! posterior_prob matrix 2nd dimension is not "
"equal to model class number : %zu / %zu",
posterior_prob[0].size(), this->n_class) ;
throw std::invalid_argument(msg) ;
}
else if(posterior_prob[0][0].size() != this->n_shift)
{ char msg[4096] ;
sprintf(msg,
"Error! posterior_prob matrix 3rd dimension is not "
"equal to model shift state number : %zu / %zu",
posterior_prob[0][0].size(), this->n_shift) ;
throw std::invalid_argument(msg) ;
}
else if(posterior_prob[0][0][0].size() != this->n_flip)
{ char msg[4096] ;
sprintf(msg,
"Error! posterior_prob matrix 4th dimension is not "
"equal to model flip state number : %zu / %zu",
posterior_prob[0][0][0].size(), this->n_flip) ;
throw std::invalid_argument(msg) ;
}
}
const double DataLayer::p_min = 1e-100 ;
const double DataLayer::p_min_log = log(DataLayer::p_min) ;
Event Timeline
Log In to Comment