Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The problem of zero score is fixed. #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import torch
from typing import Tuple

import numpy as np
Expand Down Expand Up @@ -119,9 +120,13 @@ def _fit_initial_velocity_and_acceleration_profile(

A_T, R_T = np.transpose(A, (0, 2, 1)), np.transpose(R, (0, 2, 1))

# Convert A and R to PyTorch tensors
A_tensor = torch.tensor(batch_matmul(A_T, A), dtype=torch.float32)
R_tensor = torch.tensor(batch_matmul(R_T, R), dtype=torch.float32)

# Compute regularized least squares solution.
intermediate_solution = batch_matmul(
np.linalg.pinv(batch_matmul(A_T, A) + jerk_penalty * batch_matmul(R_T, R)), A_T
torch.linalg.inv(A_tensor + jerk_penalty * R_tensor), A_T
)
x = np.einsum("bij, bj -> bi", intermediate_solution, y)

Expand Down Expand Up @@ -174,9 +179,14 @@ def _fit_initial_curvature_and_curvature_rate_profile(
Q[0, 0] = initial_curvature_penalty

# Compute regularized least squares solution.
A_T = A.transpose(0, 2, 1)
A_T = A.transpose(0, 2, 1) # 确保 A_T 在这里定义

# Convert A and Q to PyTorch tensors
A_tensor = torch.tensor(batch_matmul(A_T, A), dtype=torch.float32)
Q_tensor = torch.tensor(Q, dtype=torch.float32) # Convert Q to tensor

intermediate = batch_matmul(np.linalg.pinv(batch_matmul(A_T, A) + Q), A_T)
# Compute regularized least squares solution.
intermediate = batch_matmul(torch.linalg.inv(A_tensor + Q_tensor), A_T) # Use Q_tensor
x = np.einsum("bij,bj->bi", intermediate, y)

# Extract profile from solution.
Expand Down