MEMENTO 메멘토 패턴

  • 객체 내부의 상태를 잡아내며, 저장 , 복구 시킨다.

#include <iostream>
using namespace std; #include <list> class Memento{ public: Memento(int _state) : state(_state) {} int getState() const { return state; } private: int state; }; class Originator{ public: void setState(int _state){ state = _state; cout<< "setState : " << state << endl; } void setMemento(Memento* _memento){ if(_memento){ state = _memento->getState(); delete _memento; cout << "setMemento : " << state << endl; } } Memento* createMemento(){ cout << "createMemento : " << state << endl; return new Memento(state); } private: int state; }; class Caretaker{ public: void pushMememto(Memento* _memento) { mlist.push_back(_memento); } Memento* popMemento() { Memento* _memento = mlist.back(); mlist.pop_back(); return _memento; } private: list<Memento*> mlist; }; int main(){ Caretaker caretaker; Originator *originator = new Originator(); originator->setState(1); caretaker.pushMememto(originator->createMemento()); originator->setState(3); caretaker.pushMememto(originator->createMemento()); originator->setState(5); caretaker.pushMememto(originator->createMemento()); originator->setMemento(caretaker.popMemento()); originator->setMemento(caretaker.popMemento()); originator->setMemento(caretaker.popMemento()); }



COMMAND 명령 패턴

  • 요청을 객체 형태로 캡슐화 시킨다.
  • 콜백을 객체지향으로 표현한 것.

#include <iostream> using namespace std; class Receiver{ public: void action() { cout << "Receiver" << endl; } }; class Command{ public: virtual void execute() = 0; }; class ConcreteCommnad : public Command{ public: void setReceiver(Receiver* r) { _receiver = r; } void execute() { _receiver->action(); } private: Receiver* _receiver; }; class Invoker{ public: void SetCommand(Command* c) { _command = c; } void Execute() { _command->execute(); } private: Command* _command; }; int main(){ Invoker invoker; Receiver receiver; ConcreteCommnad concretecommand; concretecommand.setReceiver(&receiver); invoker.SetCommand(&concretecommand); invoker.Execute(); return 0; }

// Command 클래스를 template 시켜 Invoke를 사용하지 않음. class Receiver{ public: virtual void action() = 0; }; class ConcreteClass1 : public Receiver{ public: void action() { cout << "ABCDE" << endl; } }; class ConcreteClass2 : public Receiver{ public: void action() { cout << "12345" << endl; } }; template<typename T> class Command{ public: Command(T* r) : _receiver(r) {} ~Command() { if(_receiver) delete _receiver; } void excute() { _receiver->action(); } private: T* _receiver; }; int main(){ Command<ConcreteClass1> command1(new ConcreteClass1()); Command<ConcreteClass2> command2(new ConcreteClass2()); command1.excute(); command2.excute(); return 0; }


Confusion matrix

  • 알고리즘 성능 평가에 사용.

 

Predicted

Positive  

 Negative

Actual 

 Positive

TP 

FN 

 Negative

FP 

TN 

  • TP : True로 예측하고 실제 값도 True
  • TN : False로 예측하고 실제 값도 False
  • FP : True로 예측하고 실제는 False
  • FN : False로 예측하고 실제는 True


Accuarcy

  • 전체 중 맞게 맞게 예측한 비율


Precision

  • Positive에 속하는 것들 중 실제 Positvie 인것.



Recall (sensitivty)

  • 실제로 Positive인 것들 중 Positive로 예측한 비율


Specificity

  • Negative에 속하는 것들 중 실제 Negative 인것.



F1 Measure

  • 위의 Precision과 Recall을 이용.


RMSE(Root Mean Square Error) 평균 제곱근 오차

  • 회귀 문제의 성능 지표.
  • 오차가 커질수록 RMSE 값은 커지며, 예측에 얼마나 많은 오류가 있다.
  • X = 데이터, m = 샘플 수, h = 예측 함수(hypothesis)


MAE(Mean Absolute Error) 평균 절대 오차
  • 이상치로 보이는 구역이 많을 경우 사용 하는 지표.





*RMSE, MAE 모두 예측값과 타깃값 사이의 거리를 재는 방법.

  • Euclidian norm(L2 norm), Manhattan norm 등을 사용.


지도학습(Supervised learning)

data x , label y

  • k-Neareast Neighbors
  • Linear Regression
  • Support Vector Machines
  • Decision Tree
  • Random Forests
  • Neural Networks
  • Classification, Object Detection, Segmentation, Captioning(DL)

비지도학습(UnSupervised learning)

- only data x

  • Clustering (K-Means, Hierachical Cluster Analysis, Expectation Maximization)
  • dimensionality reduction(Principal Component Analysis, kernel PCA, LLE, t-SNE)
  • Associaiton rule Learning(Apriori, Eclat)
  • Feature Learning, Density estimation, Generative Model(DL)


+ Recent posts