ArangoDB3.9.0-alpha.하나 넣었어요.

39985 단어 arangodbtech

ArangoDB3.9알파1 출시


설치(Docker Desktop)


Dockerfile
FROM arangodb/arangodb-preview:3.9.0-alpha.1
docker-compose.yml
version: '3'

services:
  hello-arangodb:
    build: .
    ports:
      - '8529:8529'
    environment:
      ARANGO_ROOT_PASSWORD: "rootアカウントのパスワード指定"
      ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY: "2G"
#      ARANGO_ROOT_PASSWORD_FILE: 
#      ARANGO_NO_AUTH: 0
#      ARANGO_RANDOM_ROOT_PASSWORD: 0
    volumes:
      - ./arangodb3:/var/lib/arangodb3
      - ./arangodb3-apps:/var/lib/arangodb3-apps

되다


3.9야!
3.9

수정점


https://www.arangodb.com/docs/3.9/release-notes-new-features39.html#prune-variable

Decay Functions


DECAY_EXP()
DECAY_LINEAR()
DECAY_GAUSS()
예를 봐도 뭘 하는지 전혀 모르기 때문에 가장 쉬운 DECAYLINAR을 조사했습니다.
arangodb-3.9.0-alpha.1\arangod\Aql\Functions.cpp

DECAY_LINEAR


AqlValue Functions::DecayLinear(arangodb::aql::ExpressionContext* expressionContext,
                                AstNode const& node,
                                VPackFunctionParameters const& parameters) {

  auto linearDecayFactory = [](const double origin,
                               const double scale,
                               const double offset,
                               const double decay) {
    const double s = scale / (1.0 - decay);
    return [=](double arg) {
      double max = std::max(0.0, std::fabs(arg - origin) - offset);
      double val = std::max((s - max) / s, 0.0);
      return val;
    };
  };

  return decayFuncImpl(expressionContext, node, parameters, linearDecayFactory);
}
DECAY_LINEAR(5, 0, 10, 0, 0.2) // 0.6origin0scale10offset0decay0.2λ 함수arg5const double s = scale / (1.0 - decay);s12.5double max = std::max(0.0, std::fabs(arg - origin) - offset);max5double val = std::max((s - max) / s, 0.0);val0.6...어디에 써야 할지 모르겠지만 어디에 쓸 수 있겠지...

DECAY_EXP


AqlValue Functions::DecayExp(arangodb::aql::ExpressionContext* expressionContext,
                             AstNode const& node,
                             VPackFunctionParameters const& parameters) {

  auto expDecayFactory = [](const double origin,
                            const double scale,
                            const double offset,
                            const double decay) {
    const double lambda = std::log(decay) / scale;
    return [=](double arg) {
      double numerator = lambda * std::max(0.0, std::abs(arg - origin) - offset);
      double val = std::exp(numerator);
      return val;
    };
  };

  return decayFuncImpl(expressionContext, node, parameters, expDecayFactory);
}
자연 대수로 감쇠 계산을 하자..

DECAY_GAUSS


AqlValue Functions::DecayGauss(arangodb::aql::ExpressionContext* expressionContext,
                               AstNode const& node,
                               VPackFunctionParameters const& parameters) {

  auto gaussDecayFactory = [](const double origin,
                              const double scale,
                              const double offset,
                              const double decay) {
    const double sigmaSqr = - (scale * scale) / (2 * std::log(decay));
    return [=](double arg) {
      double max = std::max(0.0, std::fabs(arg - origin) - offset);
      double numerator = max * max;
      double val = std::exp(- numerator / (2 * sigmaSqr));
      return val;
    };
  };

  return decayFuncImpl(expressionContext, node, parameters, gaussDecayFactory);
}
고스 함수를 이용한 감쇠 계산이죠...

Vector Functions


COSINE_SIMILARITY()
L1_DISTANCE()
L2_DISTANCE()
난 자꾸 알겠어.

COSINE_SIMILARITY

COSINE_SIMILARITY([0,1], [1,0]) // 0라고 쓰여 있는데... 모르겠다.. 왠지 알 수 있는 게 뭔지 모르겠다..
조사 후, 여현의 유사도를 요구하는 것을 알게 되었다.
\vec{a}\cdot\vec{b} = |\vec{a}||\vec{b}|cos\theta \\
cos\theta =\dfrac{\vec{a}\cdot\vec{b}}{|\vec{a}||\vec{b}|}
구cos\theta
AqlValue Functions::CosineSimilarity(
    arangodb::aql::ExpressionContext* expressionContext,
    AstNode const& node,
    VPackFunctionParameters const& parameters) {

  auto cosineSimilarityFunc = [expressionContext, &node]
        (const VPackSlice lhs, const VPackSlice rhs, const VPackValueLength& length) {

    double numerator{};
    double lhsSum{};
    double rhsSum{};

    for (VPackValueLength i = 0; i < length; ++i) {
      auto lhsSlice = lhs.at(i);
      auto rhsSlice = rhs.at(i);
      if (!lhsSlice.isNumber() || !rhsSlice.isNumber()) {
        registerWarning(expressionContext,
                        getFunctionName(node).c_str(),
                        TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH);
        return AqlValue(AqlValueHintNull());
      }

      double lhsVal = lhsSlice.getNumber<double>();
      double rhsVal = rhsSlice.getNumber<double>();

      numerator += lhsVal * rhsVal;
      lhsSum += lhsVal * lhsVal;
      rhsSum += rhsVal * rhsVal;
    }

    double denominator = std::sqrt(lhsSum) * std::sqrt(rhsSum);
    if (denominator == 0.0) {
      registerWarning(expressionContext,
                      getFunctionName(node).c_str(),
                      TRI_ERROR_QUERY_INVALID_ARITHMETIC_VALUE);
      return AqlValue(AqlValueHintNull());
    }

    return ::numberValue(numerator / denominator, true);
  };

  return DistanceImpl(expressionContext, node, parameters, cosineSimilarityFunc);
}
numerator로 내적을 계산하고, lhsSumrhsSum로 크기(곱하기)를 계산하면 대체로 틀림없다

L1_DISTANCE

L1_DISTANCE([-1,-1], [2,2]) // 6 그래프에서 X 또는 Y 방향만 이동할 수 있음(기울기 불가)
AqlValue Functions::L1Distance(
    arangodb::aql::ExpressionContext* expressionContext,
    AstNode const& node,
    VPackFunctionParameters const& parameters) {

  auto L1DistFunc = [expressionContext, &node]
        (const VPackSlice lhs, const VPackSlice rhs, const VPackValueLength& length) {

    double dist{};

    for (VPackValueLength i = 0; i < length; ++i) {
      auto lhsSlice = lhs.at(i);
      auto rhsSlice = rhs.at(i);
      if (!lhsSlice.isNumber() || !rhsSlice.isNumber()) {
        registerWarning(expressionContext,
                        getFunctionName(node).c_str(),
                        TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH);
        return AqlValue(AqlValueHintNull());
      }

      dist += std::abs(lhsSlice.getNumber<double>() -
                       rhsSlice.getNumber<double>());
    }

    return ::numberValue(dist, true);
  };

  return DistanceImpl(expressionContext, node, parameters, L1DistFunc);
}
dist += std::abs(lhsSlice.getNumber<double>() - rhsSlice.getNumber<double>());니까 아마 맞을 거예요.

L2_DISTANCE

L2_DISTANCE([1,1], [5,2]) // 4.1231056256176606이므로 두 점 사이의 거리를 계산합니다.
AqlValue Functions::L2Distance(
    arangodb::aql::ExpressionContext* expressionContext,
    AstNode const& node,
    VPackFunctionParameters const& parameters) {

  auto L2DistFunc = [expressionContext, &node]
        (const VPackSlice lhs, const VPackSlice rhs, const VPackValueLength& length) {

    double dist{};

    for (VPackValueLength i = 0; i < length; ++i) {
      auto lhsSlice = lhs.at(i);
      auto rhsSlice = rhs.at(i);
      if (!lhsSlice.isNumber() || !rhsSlice.isNumber()) {
        registerWarning(expressionContext,
                        getFunctionName(node).c_str(),
                        TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH);
        return AqlValue(AqlValueHintNull());
      }

      double diff = lhsSlice.getNumber<double>() - rhsSlice.getNumber<double>();

      dist += std::pow(diff, 2);
    }

    return ::numberValue(std::sqrt(dist), true);
  };

  return DistanceImpl(expressionContext, node, parameters, L2DistFunc);
}
dist += std::pow(diff, 2);제곱근return ::numberValue(std::sqrt(dist), true);제곱근을 구하면 틀림없다

좋은 웹페이지 즐겨찾기