59 int id = rhs[0].toInt();
60 string method(rhs[1].toString());
63 if (method ==
"new") {
75 if (method ==
"delete") {
80 else if (method ==
"clear") {
84 else if (method ==
"load") {
85 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
87 bool loadFromString =
false;
88 for (
int i=3; i<nrhs; i+=2) {
89 string key(rhs[i].toString());
91 objname = rhs[i+1].toString();
92 else if (key ==
"FromString")
93 loadFromString = rhs[i+1].toBool();
96 "Unrecognized option %s", key.
c_str());
99 obj_[id] = (loadFromString ?
100 Algorithm::loadFromString<LogisticRegression>(rhs[2].toString(), objname) :
101 Algorithm::load<LogisticRegression>(rhs[2].toString(), objname));
103 else if (method ==
"save") {
105 string fname(rhs[2].toString());
108 FileStorage fs(fname, FileStorage::WRITE + FileStorage::MEMORY);
120 else if (method ==
"empty") {
124 else if (method ==
"getDefaultName") {
128 else if (method ==
"getVarCount") {
132 else if (method ==
"isClassifier") {
136 else if (method ==
"isTrained") {
140 else if (method ==
"train") {
141 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=1);
144 for (
int i=4; i<nrhs; i+=2) {
145 string key(rhs[i].toString());
147 dataOptions = rhs[i+1].toVector<
MxArray>();
148 else if (key ==
"Flags")
149 flags = rhs[i+1].toInt();
152 "Unrecognized option %s", key.
c_str());
157 dataOptions.
begin(), dataOptions.
end());
162 dataOptions.
begin(), dataOptions.
end());
163 bool b = obj->
train(data, flags);
166 else if (method ==
"calcError") {
167 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=2);
170 for (
int i=4; i<nrhs; i+=2) {
171 string key(rhs[i].toString());
173 dataOptions = rhs[i+1].toVector<
MxArray>();
174 else if (key ==
"TestError")
175 test = rhs[i+1].toBool();
178 "Unrecognized option %s", key.
c_str());
183 dataOptions.
begin(), dataOptions.
end());
188 dataOptions.
begin(), dataOptions.
end());
195 else if (method ==
"predict") {
196 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=2);
198 for (
int i=3; i<nrhs; i+=2) {
199 string key(rhs[i].toString());
201 flags = rhs[i+1].toInt();
202 else if (key ==
"RawOutput")
203 UPDATE_FLAG(flags, rhs[i+1].toBool(), StatModel::RAW_OUTPUT);
206 "Unrecognized option %s", key.
c_str());
210 float f = obj->
predict(samples, results, flags);
215 else if (method ==
"get_learnt_thetas") {
219 else if (method ==
"get") {
221 string prop(rhs[2].toString());
222 if (prop ==
"Iterations")
224 else if (prop ==
"LearningRate")
226 else if (prop ==
"MiniBatchSize")
228 else if (prop ==
"Regularization")
230 else if (prop ==
"TermCriteria")
232 else if (prop ==
"TrainMethod")
236 "Unrecognized property %s", prop.
c_str());
238 else if (method ==
"set") {
240 string prop(rhs[2].toString());
241 if (prop ==
"Iterations")
243 else if (prop ==
"LearningRate")
245 else if (prop ==
"MiniBatchSize")
247 else if (prop ==
"Regularization")
249 else if (prop ==
"TermCriteria")
251 else if (prop ==
"TrainMethod")
255 "Unrecognized property %s", prop.
c_str());
259 "Unrecognized operation %s", method.
c_str());
const ConstMap< int, string > InvTrainingMethodType
Option values for Inverse Training methods.
virtual bool isTrained() const=0
virtual float predict(InputArray samples, OutputArray results=noArray(), int flags=0) const=0
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
virtual int getIterations() const=0
virtual void setMiniBatchSize(int val)=0
virtual void setTrainMethod(int val)=0
virtual void setLearningRate(double val)=0
virtual bool isOpened() const
virtual double getLearningRate() const=0
struct mxArray_tag mxArray
Forward declaration for mxArray.
virtual int getRegularization() const=0
const ConstMap< string, int > RegularizationType
Option values for Regularization kinds.
virtual void setTermCriteria(TermCriteria val)=0
virtual bool train(const Ptr< TrainData > &trainData, int flags=0)
cv::Ptr< cv::ml::TrainData > loadTrainData(const std::string &filename, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Read a dataset from a CSV file.
virtual String releaseAndGetString()
virtual int getTrainMethod() const=0
const ConstMap< string, int > TrainingMethodType
Option values for Training methods.
virtual void setRegularization(int val)=0
map< int, Ptr< LogisticRegression > > obj_
Object container.
int last_id
Last object id to allocate.
virtual void write(FileStorage &fs) const
InputOutputArray noArray()
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
virtual void setIterations(int val)=0
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
virtual String getDefaultName() const
virtual Mat get_learnt_thetas() const=0
Global constant definitions.
virtual bool empty() const
virtual bool isClassifier() const=0
virtual float calcError(const Ptr< TrainData > &data, bool test, OutputArray resp) const
virtual void save(const String &filename) const
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
cv::Ptr< cv::ml::TrainData > createTrainData(const cv::Mat &samples, const cv::Mat &responses, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of TrainData using options in arguments.
virtual TermCriteria getTermCriteria() const=0
std::map wrapper with one-line initialization and lookup method.
void create(int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)
Common definitions for the ml module.
virtual int getVarCount() const=0
virtual int getMiniBatchSize() const=0
const ConstMap< int, string > InvRegularizationType
Option values for Inverse Regularization kinds.