design a regress function whose coeficients satisfy certain conditions
1166 단어 conditionsKKT
Given n points (x_1, x_2, ...x_n) as independent variables, where x_i can be a value or a vector, and the dependent variables (y_1, y_2, ... y_i), design a regression that satifies:
1. f(x) = t(w) * x (assume the the attribute of x corresponding w_0 is 1)
2. sigma(w) = 1
3. w_i >= 0
3. minimize sigma(y - f(x))^2
Solution:
The solution is based on KKT condition which is a generized from langrange muptiply method.
KKT conditions of this question:
1. delta(siagma(y - f(x))^2 + a * delta(w) + sigma(b_i * delta(w_i)) = 0
2. sigma(w) = 1
solve about equotions, we get:
b_i = 0
rbind(
cbind(2 * t(X) *X, c(1, ....),
c(w, 1)
) * c(w, a) = 2 * t(X) * Y
R code: ( assume x is a vector, whose first element is 1 correponding w_0)
regress <- function(x, y) {
A <- 2 * t(x) %*% x
B <- rep(1, nrow(A))
C <- 2 * t(x) %*% y
D <- c(rep(1, nrow(A)), 0)
left <- rbind(cbind(A, B), D)
coef <- solve(left, c(C, 1))
coef[1:length(coef) - 1]
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Perl에서 Yoda 조건을 피해야 합니다.내 Perl에서 소위 을 주장했던 2000년대 중반의 짧은 시간을 기억합니다. 의 왼쪽에 상수를 배치합니다. 실수로 = 대신 단일 == 을 입력한 경우 컴파일러는 변수를 대신 catch합니다. 예: 그리고 이기 때문...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.