for Robot Artificial Inteligence

PID Check 그리고 Kill(command & c++)

|

COMMAND

ps aux | grep {process id}
kill - {pid id}

https://askubuntu.com/questions/180336/how-to-find-the-process-id-pid-of-a-running-terminal-program

https://askubuntu.com/questions/797957/how-to-kill-a-daemon-process-in-linux

https://stackoverflow.com/questions/46479196/best-practice-pid-file-for-unix-daemon

C++

#include <istream>
#include <sys/types.h>
#include <signal.h>

int main()
{
    pid_t pid=0;
    std::ifstream ifs("/var/run/httpd.pid", ios::in);

    ifs >> pid;
    if(pid)
        kill(pid, SIGTERM);

    return 0;
}

SKILL PID IN C++

Comment  Read more

Max Mixture와 Switchable constraints

|

SLAM에서 최적화를 할때 Log LikelyHood를 통한 error Function(Object Function)을 만들고 미지수에 대해 최적화를 하여 값을 구한다.

각 노드간에 연결되어 있는 constraints에 대하여 Gaussian Distribution으로 나타내게 되면 unimodel형식이며

이에 대한 각 노드간에 연결되어 있는 constraints값을 통해 error function을 정의하여서 Gaussian Newton이나 LM 방법을 사용을 하여서 Non Linear System에 대한 Optimization을 한다.

허나, GPS의 튀는 값으로 잘못된 edge가 연결이 되거나 Descriptor Matching을 통해 잘못 loop closure가 일어날 경우, 맵이 쉽게 일그러진다.

즉, node간에 잘못된 constraints가 생기게 된다면, 위와 같이 multi model gaussian distributions 형상이 나오는데, 이에 대한 Object Function에 대해 Optimization를 하게 된다면, Error가 점점 커지기 때문이다.

이에 생겨난게 Max Mixture 이다.

Max Mixture

Max Mixture는 이 두 multi model을 가지고 있는 Object function중에 Maximum LikelyHood를 가지고 있는 Constraints과 edge만 가지고 Least Square, Optimization을 하겠다라는 의미이다.

Multi Model를 구하고 Object Function을 만드는 방법은 다음과 같다.

먼저 Multi model을 구하는 것은 아래와 같다.

Multi Model을 만들고 error function을 만들어 Optimization을 해야하기에 log likleyhood를 사용하지만, Sum은 Log LikelyHood에 들어갈 수없는데, 그 이유는 값이 Negative(-) 값이 나오기 때문이다.

이에 Sum of Gaussian Distribution이 아닌, Maximum of Gaussian을 하여서 Multi Model을 만든다.

Max Mixture Robust Pose Graph

이렇게 multi model을 구할 수 있지만, Max Mixture Robust Pose Graph에서는 전체 노드와 constraints중 Maximum LikelyHood를 가지고 있는 노드와 constraints을 가지고 object function을 써서 Optimization을 하는 것이다. Iteration을 할때 Maximum LikelyHood를 가지는 node들과 constraints의 object function으로 최적화를 한다.

코드는 아래와 같다.

void EdgeSE2Mixture::UpdateBelief(int i)
{
  //required for multimodal max-mixtures, for inlier/outliers the vertices would not change
  this->setVertex(0,allEdges[i]->vertex(0));
  this->setVertex(1,allEdges[i]->vertex(1));           

  double p[3];
  allEdges[i]->getMeasurementData(p);
  this->setMeasurement(g2o::SE2(p[0],p[1],p[2]));
  this->setInformation(allEdges[i]->information());  
}

//get the edge with max probability
void EdgeSE2Mixture::computeError()
{
  int best = -1;
  double minError = numeric_limits<double>::max();
  for(unsigned int i=0;i<numberComponents;i++){    
    double thisNegLogProb = getNegLogProb(i);
    if(minError>thisNegLogProb){
      best = i;
      minError = thisNegLogProb;
    }
  }

  bestComponent = best;
  UpdateBelief(bestComponent);
  //cerr << "\nBest component is "<<bestComponent<<"\n";

  //this will be used by the optimizer
  g2o::EdgeSE2::computeError();
}

double EdgeSE2Mixture::getNegLogProb(unsigned int c)
{  
  allEdges[c]->computeError();
  //cerr << "\nchi2 for " <<c<<" "<< allEdges[c]->chi2();
  return -log(weights[c]) +
	  0.5*log(determinants[c]) +
	  0.5*allEdges[c]->chi2();
}

pick one well made unimodel Gaussian model, with that use it as object function(cost function) to do optimization iteratively.(Iteratively pick best uni-model Gaussian model)

Switchable constraints

Switchable constraints로 마찬가지다, node간에 잘못된 constraints을 무시를하여서 Optimization을 하는데 목적이다.

Reference

Least Square Deep Explain

Robust Pose Graph

MAX-MIXTURE CODE

Switchable Constraint CODE

OPENSLAM CODE

Comment  Read more

Gaussian Distribution에서 Maximum LikelyHood(Log LikelyHood)를 구하고, 그의 용도

|

Maximum LikelyHood는 Modeling이나 classificiation, 최적의 Model을 선택하는데 많이 사용이 되고, 또한 Least Square를 통해(Gaussian Distribution에 Means값이 최대 likelihood가 되도록 계속적으로 최적화, “홀쭉해 지게 하기”) 미지수에 대한 최적의 해를 구하는데도 사용하게 되는데, 최적화 문제를 푸는데 있어서 Maximum LikelyHood보다 log-likleyhood를 사용하여서 더 쉽게 풀 수 있다.

likleyhood의 크기가 커지면 커질수록 optimization 프로세스에 불리하다, 그러므로 log를 이용하여서 수를 줄이고 이를 통해 optimization을 한다.

The log-likelihood is usually easier to optimize than the likelihood function.

Log likelihood is used in statistics and machine learning because of calculus. It’s easier to take the derivative of a log of a product than it is of the product itself. The likelihood is a big product, often of exponential functions, such as this one when you’re working with normal distributions.

즉, likelihood를 통해서 최적화를 통해 미지수를 구할 수 있을 뿐만 아니라, 주어진 데이터와 Gaussian Modeling된 Model에 대해 classificiation을 할 수 있다.

Super Well Maximum LikelyHood Explain

Comment  Read more

Deep Understanding of Reference LRValue and Pointer Relationship

|

  1. Concepts of left and right values
  • The left value is a value that can be assigned on the left side of the assignment number; the left value must have an entity in memory;

  • Right values are assigned to other variables on the right side of the assignment number; right values can be in memory or in CPU registers.

  • When an object is used as a right value, its content (value) is used, and when it is used as a left value, its address is used.

  1. citation

Reference is optimized by C++ grammar, and the essence of reference is realized by pointer. Reference to an alias equivalent to a variable.

References can change the pointer’s direction and the value pointed to by the pointer. The basic rules cited are:

When declaring a reference, it must be initialized, and once bound, it cannot be bound to other objects; that is, the reference must be initialized, and the reference cannot be redefined;

All operations on references are equivalent to operations on the original object.

  1. Explain it with Example.

(1) case L Value는 R Value값을 읽는다. Reference L Value는 R Value의 Address를 읽는다.

(2) case L Value는 R Value값을 읽는다. Reference R Value일 경우, L Value는 순수하게 Address를 읽는다.

(3) case

Pointer = 메모리공간의 일련번호(address) 그렇기 때문에 Pointer는 Address를 가르켜야 한다.

NOTE : 예제 3번에 마지막 cout에 b앞에 “*“를 넣어줘야 한다.

포인터는 어드레스를 읽지만, 표현할때(RValue로 사용할 때에는)에는 어드레이스에 있는 밸류를 표현하기 때문이다.

만약 RVALUE로 사용할때 앞에 “*” 붙여주지 않는다면, pointer의 address로 표현이 될것이다.

또한 만약 Pointer가 Initialize가 되었다면(Pointing some address)면

int i = 5;
int* p = &i;
*p = 2;

// 이런식으로 표혀할 수도 있고,
int*p = nullptr; //initialize 하여서
int i = 5;
*p = i; // 이런식으로 바로 사용할 수 있다.

// 이미 이니셜라이즈가 되었는데 address를 새로 주려고 한다면 error 가 생긴다

int i = 5;
int* p = nullptr;
*p = &i; // 컴파일 에러! 에러! 에러! 에러! 이미 이니셜라이즈 했는데 address를 받는 것이므로 

아래식으로 compile에러 없이 pointer에 밸류를 바꿀 수 있다. 이는 i의 값도 바뀌게 된다. 이는 포인터가 initialize가 되었을때에 value값을 바꾸는 방법이다.

void text(int& j)
{
  cout << j << endl;
}

void text(int* j)
{
  cout << *j << endl;
}

// those are samething
int i = 5;
test(i)


int i = 5;
test(&i)

REFERENCE

google

difference between pointer and reference

example of pointer reference

Comment  Read more

Ceres Easy Installation

|

Ceres는 Non Linear Least Square를 푸는 문제에 사용됨으로, Object Function을 Customize를 할 수 있다는 것이 장점이다.

Easy Installation Click this

Comment  Read more